34 typedef std::unique_ptr<TLSSessionTicketBase>
UPtr;
48 static constexpr size_t SIZE = 16;
55 explicit Name(
const std::string &name_b64)
82 return "TLSTicketName[" +
b64() +
']';
85 std::string
b64()
const
90 template <
typename HASH>
96#ifdef USE_OPENVPN_HASH
97 std::uint64_t hashval()
const
129 explicit Key(
const std::string &cipher_key_b64,
const std::string &hmac_key_b64)
167 template <
typename KEY_TRANSFORM>
170 unsigned char out[KEY_TRANSFORM::MAX_HMAC_SIZE];
174 t.cipher_transform.reset();
176 const size_t size = t.cipher_transform.final(
out);
178 throw sess_ticket_error(
"insufficient key material for cipher transform");
184 t.hmac_transform.reset();
186 const size_t size = t.hmac_transform.final(
out);
188 throw sess_ticket_error(
"insufficient key material for hmac transform");
218 static void b64_to_key(
const std::string &b64,
const char *title,
unsigned char *
out,
const size_t outlen)
225 catch (
const std::exception &e)
227 throw sess_ticket_error(std::string(
"base64 decode for ") + title +
": " + std::string(e.what()));
229 if (srcbuf.
size() != outlen)
230 throw sess_ticket_error(std::string(
"wrong input size for ") + title +
", actual=" + std::to_string(srcbuf.
size()) +
" expected=" + std::to_string(outlen));
235#ifdef USE_OPENVPN_HASH
std::string encode(const V &data) const
size_t decode(void *data, size_t len, const std::string &str) const
size_t size() const
Returns the size of the buffer in T objects.
virtual void rand_bytes(unsigned char *buf, size_t size)=0
Fill a buffer with random bytes.
Abstract base class for cryptographically strong random number generators.
unsigned char hmac_value_[HMAC_KEY_SIZE]
Key(StrongRandomAPI &rng)
unsigned char cipher_value_[CIPHER_KEY_SIZE]
bool operator!=(const Key &rhs) const
static constexpr size_t CIPHER_KEY_SIZE
bool operator==(const Key &rhs) const
void key_transform(KEY_TRANSFORM &t)
std::string to_string() const
std::string hmac_b64() const
static constexpr size_t HMAC_KEY_SIZE
Key(const std::string &cipher_key_b64, const std::string &hmac_key_b64)
std::string cipher_b64() const
bool operator==(const Name &rhs) const
std::string to_string() const
bool operator!=(const Name &rhs) const
Name(const unsigned char name[SIZE])
Name(StrongRandomAPI &rng)
unsigned char value_[SIZE]
bool operator<(const Name &rhs) const
static constexpr size_t SIZE
Name(const std::string &name_b64)
static void b64_to_key(const std::string &b64, const char *title, unsigned char *out, const size_t outlen)
virtual std::string session_id_context() const =0
virtual Status create_session_ticket_key(Name &name, Key &key) const =0
std::unique_ptr< TLSSessionTicketBase > UPtr
virtual ~TLSSessionTicketBase()=default
virtual Status lookup_session_ticket_key(const Name &name, Key &key) const =0
OPENVPN_EXCEPTION(sess_ticket_error)
#define OPENVPN_HASH_METHOD(T, meth)
Implementation of the base classes for random number generators.
static std::stringstream out