Botan 1.10.17
Botan::Server_Key_Exchange Class Reference

#include <tls_messages.h>

Inheritance diagram for Botan::Server_Key_Exchange:
Botan::HandshakeMessage

Public Member Functions

Public_Keykey () const
void send (Record_Writer &, HandshakeHash &) const
 Server_Key_Exchange (const MemoryRegion< byte > &buf)
 Server_Key_Exchange (RandomNumberGenerator &rng, Record_Writer &, const Public_Key *, const Private_Key *, const MemoryRegion< byte > &, const MemoryRegion< byte > &, HandshakeHash &)
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

◆ Server_Key_Exchange() [1/2]

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.

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 = "";
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 }
static BigInt decode(const byte buf[], size_t length, Base base=Binary)
Definition big_code.cpp:102
void send(Record_Writer &, HandshakeHash &) const
Definition hello.cpp:16
std::invalid_argument Invalid_Argument
Definition exceptn.h:20
Signature_Format
Definition pubkey.h:24
@ DER_SEQUENCE
Definition pubkey.h:24
@ IEEE_1363
Definition pubkey.h:24

References Botan::Public_Key::algo_name(), Botan::BigInt::decode(), Botan::DER_SEQUENCE, 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::DH_PublicKey::public_value(), Botan::HandshakeMessage::send(), Botan::PK_Signer::signature(), and Botan::PK_Signer::update().

◆ Server_Key_Exchange() [2/2]

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

◆ key()

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

Return the public key

Definition at line 136 of file s_kex.cpp.

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 }
Internal_Error(const std::string &err)
Definition exceptn.h:47

References Botan::DH_PublicKey::DH_PublicKey(), Botan::DL_Group::DL_Group(), Botan::Internal_Error::Internal_Error(), and Botan::RSA_PublicKey::RSA_PublicKey().

Referenced by verify().

◆ send()

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

Definition at line 16 of file hello.cpp.

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 }
virtual Handshake_Type type() const =0
byte get_byte(size_t byte_num, T input)
Definition get_byte.h:21
@ HANDSHAKE
Definition tls_magic.h:36

References Botan::Record_Writer::flush(), Botan::get_byte(), Botan::HANDSHAKE, Botan::Record_Writer::send(), Botan::MemoryRegion< T >::size(), 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 Botan::Server_Key_Exchange::Server_Key_Exchange().

◆ type()

Handshake_Type Botan::Server_Key_Exchange::type ( ) const
inlinevirtual

Implements Botan::HandshakeMessage.

Definition at line 259 of file tls_messages.h.

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

References Botan::SERVER_KEX.

◆ verify()

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.

152 {
153
154 std::auto_ptr<Public_Key> key(cert.subject_public_key());
155
156 std::string padding = "";
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
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 }
virtual std::string algo_name() const =0
Public_Key * key() const
Definition s_kex.cpp:136

References Botan::PK_Verifier::check_signature(), Botan::DER_SEQUENCE, Botan::IEEE_1363, key(), Botan::X509_Certificate::subject_public_key(), and Botan::PK_Verifier::update().


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