Botan: Botan::Client_Key_Exchange Class Reference

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::Client_Key_Exchange Class Reference

`#include <tls_messages.h>`

Inheritance diagram for Botan::Client_Key_Exchange:

## Public Member Functions
| Client_Key_Exchange (RandomNumberGenerator &rng, Record_Writer &output, HandshakeHash &hash, const Public_Key *my_key, Version_Code using_version, Version_Code pref_version)
| Client_Key_Exchange (const MemoryRegion< byte > &buf, const CipherSuite &suite, Version_Code using_version)
SecureVector< byte > | pre_master_secret () const
SecureVector< byte > | pre_master_secret (RandomNumberGenerator &rng, const Private_Key *key, Version_Code version)
void | send (Record_Writer &, HandshakeHash &) const
Handshake_Type | type () const

## Detailed Description

Client Key Exchange Message

Definition at line 86 of file tls_messages.h.

## Constructor & Destructor Documentation

Botan::Client_Key_Exchange::Client_Key_Exchange | ( | RandomNumberGenerator & | rng,
|  | Record_Writer & | writer,
|  | HandshakeHash & | hash,
|  | const Public_Key * | pub_key,
|  | Version_Code | using_version,
|  | Version_Code | pref_version
| ) |  |

Create a new Client Key Exchange message

Definition at line 22 of file c_kex.cpp.

References Botan::PK_Encryptor::encrypt(), Botan::RandomNumberGenerator::random_vec(), Botan::HandshakeMessage::send(), and Botan::SSL_V3.

28 {
29 include_length = true;
30
31 if(const DH_PublicKey* dh_pub = dynamic_cast<const DH_PublicKey*>(pub_key))
32 {
33 DH_PrivateKey priv_key(rng, dh_pub->get_domain());
34
35 PK_Key_Agreement ka(priv_key, "Raw");
36
37 pre_master = ka.derive_key(0, dh_pub->public_value()).bits_of();
38
39 key_material = priv_key.public_value();
40 }
41 else if(const RSA_PublicKey* rsa_pub = dynamic_cast<const RSA_PublicKey*>(pub_key))
42 {
43 pre_master = rng.random_vec(48);
44 pre_master[0] = (pref_version >> 8) & 0xFF;
45 pre_master[1] = (pref_version ) & 0xFF;
46
47 PK_Encryptor_EME encryptor(*rsa_pub, "PKCS1v15");
48
49 key_material = encryptor.encrypt(pre_master, rng);
50
51 if(using_version == SSL_V3)
52 include_length = false;
53 }
54 else
55 throw Invalid_Argument("Client_Key_Exchange: Key not RSA or DH");
56
57 send(writer, hash);
58 }
Botan::HandshakeMessage::send
void send(Record_Writer &, HandshakeHash &) const
Definition: hello.cpp:16
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::SSL_V3
Definition: tls_magic.h:24

Botan::Client_Key_Exchange::Client_Key_Exchange | ( | const MemoryRegion< byte > & | contents,
|  | const CipherSuite & | suite,
|  | Version_Code | using_version
| ) |  |

Read a Client Key Exchange message

Definition at line 63 of file c_kex.cpp.

References Botan::append_tls_length_value(), Botan::TLS_Data_Reader::get_range(), Botan::CipherSuite::kex_type(), Botan::SSL_V3, and Botan::TLS_ALGO_KEYEXCH_RSA.

66 {
67 include_length = true;
68
69 if(using_version == SSL_V3 && (suite.kex_type() == TLS_ALGO_KEYEXCH_RSA))
70 include_length = false;
71
72 deserialize(contents);
73 }
Botan::SSL_V3
Definition: tls_magic.h:24
Botan::TLS_ALGO_KEYEXCH_RSA
Definition: tls_magic.h:154

## Member Function Documentation

SecureVector< byte > Botan::Client_Key_Exchange::pre_master_secret | ( |  | ) | const

Return the pre_master_secret

Definition at line 160 of file c_kex.cpp.

161 {
162 return pre_master;
163 }

SecureVector< byte > Botan::Client_Key_Exchange::pre_master_secret | ( | RandomNumberGenerator & | rng,
|  | const Private_Key * | priv_key,
|  | Version_Code | version
| ) |  |

Return the pre_master_secret

Definition at line 108 of file c_kex.cpp.

References Botan::OctetString::bits_of(), Botan::PK_Decryptor::decrypt(), Botan::PK_Key_Agreement::derive_key(), Botan::make_u16bit(), Botan::RandomNumberGenerator::random_vec(), and Botan::MemoryRegion< T >::size().

111 {
112
113 if(const DH_PrivateKey* dh_priv = dynamic_cast<const DH_PrivateKey*>(priv_key))
114 {
115 try {
116 PK_Key_Agreement ka(*dh_priv, "Raw");
117
118 pre_master = ka.derive_key(0, key_material).bits_of();
119 }
120 catch(...)
121 {
122 /*
123 * Something failed in the DH computation. To avoid possible
124 * timing attacks, randomize the pre-master output and carry
125 * on, allowing the protocol to fail later in the finished
126 * checks.
127 */
128 pre_master = rng.random_vec(dh_priv->public_value().size());
129 }
130
131 return pre_master;
132 }
133 else if(const RSA_PrivateKey* rsa_priv = dynamic_cast<const RSA_PrivateKey*>(priv_key))
134 {
135 PK_Decryptor_EME decryptor(*rsa_priv, "PKCS1v15");
136
137 try {
138 pre_master = decryptor.decrypt(key_material);
139
140 if(pre_master.size() != 48 ||
141 make_u16bit(pre_master[0], pre_master[1]) != version)
142 throw Decoding_Error("Client_Key_Exchange: Secret corrupted");
143 }
144 catch(...)
145 {
146 pre_master = rng.random_vec(48);
147 pre_master[0] = (version >> 8) & 0xFF;
148 pre_master[1] = (version ) & 0xFF;
149 }
150
151 return pre_master;
152 }
153 else
154 throw Invalid_Argument("Client_Key_Exchange: Bad key for decrypt");
155 }
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::make_u16bit
u16bit make_u16bit(byte i0, byte i1)
Definition: loadstor.h:47

void Botan::HandshakeMessage::send | ( | Record_Writer & | writer,
|  | HandshakeHash & | hash
| ) |  | const
| inherited

Definition at line 16 of file hello.cpp.

References Botan::Record_Writer::flush(), Botan::HANDSHAKE, Botan::Record_Writer::send(), Botan::MemoryRegion< T >::size(), Botan::HandshakeMessage::type(), and Botan::HandshakeHash::update().

Referenced by Botan::Certificate::Certificate(), Botan::Certificate_Req::Certificate_Req(), Botan::Certificate_Verify::Certificate_Verify(), Botan::Client_Hello::Client_Hello(), Client_Key_Exchange(), Botan::Finished::Finished(), Botan::Hello_Request::Hello_Request(), Botan::Server_Hello::Server_Hello(), Botan::Server_Hello_Done::Server_Hello_Done(), and Botan::Server_Key_Exchange::Server_Key_Exchange().

17 {
18 SecureVector<byte> buf = serialize();
19 SecureVector<byte> send_buf(4);
20
21 const size_t buf_size = buf.size();
22
23 send_buf[0] = type();
24
25 for(size_t i = 1; i != 4; ++i)
26 send_buf[i] = get_byte<u32bit>(i, buf_size);
27
28 send_buf += buf;
29
30 hash.update(send_buf);
31
32 writer.send(HANDSHAKE, &send_buf[0], send_buf.size());
33 writer.flush();
34 }
Botan::HANDSHAKE
Definition: tls_magic.h:36
Botan::HandshakeMessage::type
virtual Handshake_Type type() const =0

Handshake_Type Botan::Client_Key_Exchange::type | ( |  | ) | const
| inlinevirtual

Implements Botan::HandshakeMessage.

Definition at line 89 of file tls_messages.h.

References Botan::CLIENT_KEX.

89 { return CLIENT_KEX; }
Botan::CLIENT_KEX
Definition: tls_magic.h:50

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

- src/ssl/tls_messages.h
- src/ssl/c_kex.cpp