OpenVPN 3 Core Library
Loading...
Searching...
No Matches
data_epoch.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12
13#ifndef CRYPTO_DATA_EPOCH_H
14#define CRYPTO_DATA_EPOCH_H
15
16#include <cstdint>
17#include <cstdio>
18#include <array>
19
25
26
27namespace openvpn {
41void ovpn_hkdf_expand(const uint8_t *secret,
42 const uint8_t *info,
43 int info_len,
44 uint8_t *out,
45 int out_len);
46
66void ovpn_expand_label(const uint8_t *secret,
67 size_t secret_len,
68 const uint8_t *label,
69 size_t label_len,
70 const uint8_t *context,
71 size_t context_len,
72 uint8_t *out,
73 size_t out_len);
74
75OPENVPN_EXCEPTION(epoch_key_exception);
76
78{
80 constexpr static int IV_SIZE = 12;
81
82 std::uint16_t epoch = 0;
83 openvpn::SSLLib::CryptoAPI::CipherContextAEAD cipher;
84 std::array<uint8_t, IV_SIZE> implicit_iv{};
85
86 /* will calculate the ID from the packet id and the implicit IV and store the result in
87 * the iv_dest parameter */
88 void calculate_iv(uint8_t *packet_id, std::array<uint8_t, IV_SIZE> &iv_dest);
89};
90
91
96
101
103{
104 public:
105 /* SHA256 digest size */
106 constexpr static int SECRET_SIZE = 32;
107
108 std::array<uint8_t, SECRET_SIZE> keydata{};
109 std::uint16_t epoch = 0;
110
111
112 /* Constructs a default epoch that is not initialised. Epoch 0 doubles as
113 * marker of an uninitialised key */
114 EpochKey() = default;
115
117 EpochKey(decltype(keydata) keydata, uint16_t epoch)
119 {
120 }
121
124 EpochKey(StaticKey key);
125
130 void iterate();
131
135 std::pair<StaticKey, StaticKey> data_key(openvpn::CryptoAlgs::Type cipher);
136
139};
140
142{
143 protected:
146
149
154
156
158
160
161
162 std::vector<EpochDataChannelDecryptContext> future_keys;
163
164
167
170
172
174
175 public:
179 void iterate_send_key();
180
181
186 {
187 return future_keys_count;
188 }
189
190
195 {
196 return send.epoch > 0xFF00;
197 }
198
199 DataChannelEpoch() = default;
200
201 DataChannelEpoch(decltype(cipher) cipher, openvpn::StaticKey e1send, openvpn::StaticKey e1recv, SSLLib::Ctx libctx = nullptr, uint16_t future_key_count = 16);
202
203 void replace_update_recv_key(std::uint16_t new_epoch, const SessionStats::Ptr &stats_arg);
204
208 void check_send_iterate();
209
217
225};
226
227
228
229}; // namespace openvpn
230
231#endif // CRYPTO_DATA_EPOCH_H
EpochDataChannelDecryptContext retiring_decrypt_ctx
EpochDataChannelDecryptContext * lookup_decrypt_key(uint16_t epoch)
EpochDataChannelEncryptContext encrypt_ctx
EpochDataChannelDecryptContext decrypt_ctx
void replace_update_recv_key(std::uint16_t new_epoch, const SessionStats::Ptr &stats_arg)
EpochDataChannelEncryptContext & encrypt()
std::vector< EpochDataChannelDecryptContext > future_keys
openvpn::CryptoAlgs::Type cipher
EpochDataChannelCryptoContext key_context(openvpn::SSLLib::Ctx libctx, openvpn::CryptoAlgs::Type cipher, int mode)
std::uint16_t epoch
static constexpr int SECRET_SIZE
EpochKey(decltype(keydata) keydata, uint16_t epoch)
std::array< uint8_t, SECRET_SIZE > keydata
EpochKey()=default
std::pair< StaticKey, StaticKey > data_key(openvpn::CryptoAlgs::Type cipher)
#define OPENVPN_EXCEPTION(C)
void ovpn_expand_label(const uint8_t *secret, size_t secret_len, const uint8_t *label, size_t label_len, const uint8_t *context, size_t context_len, uint8_t *out, size_t out_len)
void ovpn_hkdf_expand(const uint8_t *secret, const uint8_t *info, int info_len, uint8_t *out, int out_len)
void calculate_iv(uint8_t *packet_id, std::array< uint8_t, IV_SIZE > &iv_dest)
openvpn::SSLLib::CryptoAPI::CipherContextAEAD cipher
std::array< uint8_t, IV_SIZE > implicit_iv
openvpn::PacketIDDataReceive pid
static std::stringstream out
Definition test_path.cpp:10