Botan  2.6.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::TLS::Session_Keys Class Referencefinal

#include <tls_session_key.h>

Public Member Functions

const SymmetricKeyclient_cipher_key () const
 
const InitializationVectorclient_iv () const
 
const SymmetricKeyclient_mac_key () const
 
const secure_vector< uint8_t > & master_secret () const
 
const SymmetricKeyserver_cipher_key () const
 
const InitializationVectorserver_iv () const
 
const SymmetricKeyserver_mac_key () const
 
 Session_Keys ()=default
 
 Session_Keys (const Handshake_State *state, const secure_vector< uint8_t > &pre_master_secret, bool resuming)
 

Detailed Description

TLS Session Keys

Definition at line 22 of file tls_session_key.h.

Constructor & Destructor Documentation

◆ Session_Keys() [1/2]

Botan::TLS::Session_Keys::Session_Keys ( )
default

◆ Session_Keys() [2/2]

Botan::TLS::Session_Keys::Session_Keys ( const Handshake_State state,
const secure_vector< uint8_t > &  pre_master_secret,
bool  resuming 
)
Parameters
statestate the handshake state
pre_master_secretthe pre-master secret
resumingwhether this TLS session is resumed

Session_Keys Constructor

Definition at line 20 of file tls_session_key.cpp.

References Botan::OctetString::begin(), Botan::TLS::Ciphersuite::cipher_keylen(), Botan::TLS::Handshake_State::ciphersuite(), Botan::TLS::Handshake_State::client_hello(), Botan::TLS::Handshake_Hash::final(), Botan::TLS::Handshake_State::hash(), Botan::TLS::Ciphersuite::mac_keylen(), Botan::TLS::Ciphersuite::nonce_bytes_from_handshake(), Botan::TLS::Ciphersuite::prf_algo(), Botan::TLS::Handshake_State::protocol_specific_prf(), Botan::TLS::Handshake_State::server_hello(), and Botan::TLS::Handshake_State::version().

23  {
24  const size_t cipher_keylen = state->ciphersuite().cipher_keylen();
25  const size_t mac_keylen = state->ciphersuite().mac_keylen();
26  const size_t cipher_nonce_bytes = state->ciphersuite().nonce_bytes_from_handshake();
27 
28  const bool extended_master_secret = state->server_hello()->supports_extended_master_secret();
29 
30  const size_t prf_gen = 2 * (mac_keylen + cipher_keylen + cipher_nonce_bytes);
31 
32  const uint8_t MASTER_SECRET_MAGIC[] = {
33  0x6D, 0x61, 0x73, 0x74, 0x65, 0x72, 0x20, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74 };
34 
35  const uint8_t EXT_MASTER_SECRET_MAGIC[] = {
36  0x65, 0x78, 0x74, 0x65, 0x6E, 0x64, 0x65, 0x64, 0x20,
37  0x6D, 0x61, 0x73, 0x74, 0x65, 0x72, 0x20, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74 };
38 
39  const uint8_t KEY_GEN_MAGIC[] = {
40  0x6B, 0x65, 0x79, 0x20, 0x65, 0x78, 0x70, 0x61, 0x6E, 0x73, 0x69, 0x6F, 0x6E };
41 
42  std::unique_ptr<KDF> prf(state->protocol_specific_prf());
43 
44  if(resuming)
45  {
46  // This is actually the master secret saved as part of the session
47  m_master_sec = pre_master_secret;
48  }
49  else
50  {
51  secure_vector<uint8_t> salt;
52  secure_vector<uint8_t> label;
53  if(extended_master_secret)
54  {
55  label += std::make_pair(EXT_MASTER_SECRET_MAGIC, sizeof(EXT_MASTER_SECRET_MAGIC));
56  salt += state->hash().final(state->version(),
57  state->ciphersuite().prf_algo());
58  }
59  else
60  {
61  label += std::make_pair(MASTER_SECRET_MAGIC, sizeof(MASTER_SECRET_MAGIC));
62  salt += state->client_hello()->random();
63  salt += state->server_hello()->random();
64  }
65 
66  m_master_sec = prf->derive_key(48, pre_master_secret, salt, label);
67  }
68 
69  secure_vector<uint8_t> salt;
70  secure_vector<uint8_t> label;
71  label += std::make_pair(KEY_GEN_MAGIC, sizeof(KEY_GEN_MAGIC));
72  salt += state->server_hello()->random();
73  salt += state->client_hello()->random();
74 
75  SymmetricKey keyblock = prf->derive_key(prf_gen, m_master_sec, salt, label);
76 
77  const uint8_t* key_data = keyblock.begin();
78 
79  m_c_mac = SymmetricKey(key_data, mac_keylen);
80  key_data += mac_keylen;
81 
82  m_s_mac = SymmetricKey(key_data, mac_keylen);
83  key_data += mac_keylen;
84 
85  m_c_cipher = SymmetricKey(key_data, cipher_keylen);
86  key_data += cipher_keylen;
87 
88  m_s_cipher = SymmetricKey(key_data, cipher_keylen);
89  key_data += cipher_keylen;
90 
91  m_c_iv = InitializationVector(key_data, cipher_nonce_bytes);
92  key_data += cipher_nonce_bytes;
93 
94  m_s_iv = InitializationVector(key_data, cipher_nonce_bytes);
95  }
OctetString InitializationVector
Definition: symkey.h:141
OctetString SymmetricKey
Definition: symkey.h:136
const uint8_t * begin() const
Definition: symkey.h:36

Member Function Documentation

◆ client_cipher_key()

const SymmetricKey& Botan::TLS::Session_Keys::client_cipher_key ( ) const
inline
Returns
client encipherment key

Definition at line 28 of file tls_session_key.h.

Referenced by Botan::TLS::Connection_Cipher_State::Connection_Cipher_State().

28 { return m_c_cipher; }

◆ client_iv()

const InitializationVector& Botan::TLS::Session_Keys::client_iv ( ) const
inline
Returns
client IV

Definition at line 48 of file tls_session_key.h.

Referenced by Botan::TLS::Connection_Cipher_State::Connection_Cipher_State().

48 { return m_c_iv; }

◆ client_mac_key()

const SymmetricKey& Botan::TLS::Session_Keys::client_mac_key ( ) const
inline
Returns
client MAC key

Definition at line 38 of file tls_session_key.h.

Referenced by Botan::TLS::Connection_Cipher_State::Connection_Cipher_State().

38 { return m_c_mac; }

◆ master_secret()

const secure_vector<uint8_t>& Botan::TLS::Session_Keys::master_secret ( ) const
inline
Returns
TLS master secret

Definition at line 58 of file tls_session_key.h.

58 { return m_master_sec; }

◆ server_cipher_key()

const SymmetricKey& Botan::TLS::Session_Keys::server_cipher_key ( ) const
inline
Returns
client encipherment key

Definition at line 33 of file tls_session_key.h.

Referenced by Botan::TLS::Connection_Cipher_State::Connection_Cipher_State().

33 { return m_s_cipher; }

◆ server_iv()

const InitializationVector& Botan::TLS::Session_Keys::server_iv ( ) const
inline
Returns
server IV

Definition at line 53 of file tls_session_key.h.

Referenced by Botan::TLS::Connection_Cipher_State::Connection_Cipher_State().

53 { return m_s_iv; }

◆ server_mac_key()

const SymmetricKey& Botan::TLS::Session_Keys::server_mac_key ( ) const
inline
Returns
server MAC key

Definition at line 43 of file tls_session_key.h.

Referenced by Botan::TLS::Connection_Cipher_State::Connection_Cipher_State().

43 { return m_s_mac; }

The documentation for this class was generated from the following files: