Botan: Botan::Server_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::Server_Key_Exchange Class Reference

`#include <tls_messages.h>`

Inheritance diagram for Botan::Server_Key_Exchange:

## Public Member Functions
Public_Key * | key () const
void | send (Record_Writer &, HandshakeHash &) const
| Server_Key_Exchange (RandomNumberGenerator &rng, Record_Writer &, const Public_Key *, const Private_Key *, const MemoryRegion< byte > &, const MemoryRegion< byte > &, HandshakeHash &)
| Server_Key_Exchange (const MemoryRegion< byte > &buf)
Handshake_Type | type () const
bool | verify (const X509_Certificate &, const MemoryRegion< byte > &, const MemoryRegion< byte > &) const

## Detailed Description

Server Key Exchange Message

Definition at line 256 of file tls_messages.h.

## Constructor & Destructor Documentation

Botan::Server_Key_Exchange::Server_Key_Exchange | ( | RandomNumberGenerator & | rng,
|  | Record_Writer & | writer,
|  | const Public_Key * | kex_key,
|  | const Private_Key * | priv_key,
|  | const MemoryRegion< byte > & | c_random,
|  | const MemoryRegion< byte > & | s_random,
|  | HandshakeHash & | hash
| ) |  |

Create a new Server Key Exchange message

Definition at line 22 of file s_kex.cpp.

References Botan::Public_Key::algo_name(), Botan::append_tls_length_value(), Botan::copy_mem(), Botan::BigInt::decode(), Botan::DER_SEQUENCE, Botan::BigInt::encode(), Botan::DL_Scheme_PublicKey::get_domain(), Botan::IF_Scheme_PublicKey::get_e(), Botan::DL_Group::get_g(), Botan::IF_Scheme_PublicKey::get_n(), Botan::DL_Group::get_p(), Botan::IEEE_1363, Botan::make_u16bit(), Botan::DH_PublicKey::public_value(), Botan::MemoryRegion< T >::resize(), Botan::HandshakeMessage::send(), and Botan::MemoryRegion< T >::size().

29 {
30 const DH_PublicKey* dh_pub = dynamic_cast<const DH_PublicKey*>(kex_key);
31 const RSA_PublicKey* rsa_pub = dynamic_cast<const RSA_PublicKey*>(kex_key);
32
33 if(dh_pub)
34 {
35 params.push_back(dh_pub->get_domain().get_p());
36 params.push_back(dh_pub->get_domain().get_g());
37 params.push_back(BigInt::decode(dh_pub->public_value()));
38 }
39 else if(rsa_pub)
40 {
41 params.push_back(rsa_pub->get_n());
42 params.push_back(rsa_pub->get_e());
43 }
44 else
45 throw Invalid_Argument("Bad key for TLS key exchange: not DH or RSA");
46
47
48 std::string padding = "";
49 Signature_Format format = IEEE_1363;
50
51 if(priv_key->algo_name() == "RSA")
52 padding = "EMSA3(TLS.Digest.0)";
53 else if(priv_key->algo_name() == "DSA")
54 {
55 padding = "EMSA1(SHA-1)";
56 format = DER_SEQUENCE;
57 }
58 else
59 throw Invalid_Argument(priv_key->algo_name() +
60 " is invalid/unknown for TLS signatures");
61
62 PK_Signer signer(*priv_key, padding, format);
63
64 signer.update(c_random);
65 signer.update(s_random);
66 signer.update(serialize_params());
67 signature = signer.signature(rng);
68
69 send(writer, hash);
70 }
Botan::HandshakeMessage::send
void send(Record_Writer &, HandshakeHash &) const
Definition: hello.cpp:16
Botan::Signature_Format
Signature_Format
Definition: pubkey.h:24
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::IEEE_1363
Definition: pubkey.h:24
Botan::BigInt::decode
static BigInt decode(const byte buf[], size_t length, Base base=Binary)
Definition: big_code.cpp:102
Botan::DER_SEQUENCE
Definition: pubkey.h:24

Botan::Server_Key_Exchange::Server_Key_Exchange | ( | const MemoryRegion< byte > & | buf | ) |
| inline

Definition at line 270 of file tls_messages.h.

270 { deserialize(buf); }

## Member Function Documentation

Public_Key * Botan::Server_Key_Exchange::key | ( |  | ) | const

Return the public key

Definition at line 136 of file s_kex.cpp.

Referenced by verify().

137 {
138 if(params.size() == 2)
139 return new RSA_PublicKey(params[0], params[1]);
140 else if(params.size() == 3)
141 return new DH_PublicKey(DL_Group(params[0], params[1]), params[2]);
142 else
143 throw Internal_Error("Server_Key_Exchange::key: No key set");
144 }

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(), Botan::Client_Key_Exchange::Client_Key_Exchange(), Botan::Finished::Finished(), Botan::Hello_Request::Hello_Request(), Botan::Server_Hello::Server_Hello(), Botan::Server_Hello_Done::Server_Hello_Done(), and 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::Server_Key_Exchange::type | ( |  | ) | const
| inlinevirtual

Implements Botan::HandshakeMessage.

Definition at line 259 of file tls_messages.h.

References Botan::SERVER_KEX.

259 { return SERVER_KEX; }
Botan::SERVER_KEX
Definition: tls_magic.h:46

bool Botan::Server_Key_Exchange::verify | ( | const X509_Certificate & | cert,
|  | const MemoryRegion< byte > & | c_random,
|  | const MemoryRegion< byte > & | s_random
| ) |  | const

Verify a Server Key Exchange message

Definition at line 149 of file s_kex.cpp.

References Botan::Public_Key::algo_name(), Botan::DER_SEQUENCE, Botan::IEEE_1363, key(), and Botan::X509_Certificate::subject_public_key().

152 {
153
154 std::auto_ptr<Public_Key> key(cert.subject_public_key());
155
156 std::string padding = "";
157 Signature_Format format = IEEE_1363;
158
159 if(key->algo_name() == "RSA")
160 padding = "EMSA3(TLS.Digest.0)";
161 else if(key->algo_name() == "DSA")
162 {
163 padding = "EMSA1(SHA-1)";
164 format = DER_SEQUENCE;
165 }
166 else
167 throw Invalid_Argument(key->algo_name() +
168 " is invalid/unknown for TLS signatures");
169
170 PK_Verifier verifier(*key, padding, format);
171
172 SecureVector<byte> params_got = serialize_params();
173 verifier.update(c_random);
174 verifier.update(s_random);
175 verifier.update(params_got);
176
177 return verifier.check_signature(signature);
178 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0
Botan::Server_Key_Exchange::key
Public_Key * key() const
Definition: s_kex.cpp:136
Botan::Signature_Format
Signature_Format
Definition: pubkey.h:24
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::IEEE_1363
Definition: pubkey.h:24
Botan::DER_SEQUENCE
Definition: pubkey.h:24

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

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