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

#include <tls_messages.h>

Inheritance diagram for Botan::TLS::Certificate_Req:
Botan::TLS::Handshake_Message

Public Member Functions

std::vector< X509_DNacceptable_CAs () const
 
const std::vector< std::string > & acceptable_cert_types () const
 
 Certificate_Req (Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, const std::vector< X509_DN > &allowed_cas, Protocol_Version version)
 
 Certificate_Req (const std::vector< uint8_t > &buf, Protocol_Version version)
 
std::vector< std::pair< std::string, std::string > > supported_algos () const
 
Handshake_Type type () const override
 
std::string type_string () const
 

Detailed Description

Certificate Request Message

Definition at line 475 of file tls_messages.h.

Constructor & Destructor Documentation

Botan::TLS::Certificate_Req::Certificate_Req ( Handshake_IO io,
Handshake_Hash hash,
const Policy policy,
const std::vector< X509_DN > &  ca_certs,
Protocol_Version  version 
)

Create a new Certificate Request message

Definition at line 55 of file msg_cert_req.cpp.

59  :
60  m_names(ca_certs),
61  m_cert_key_types({ "RSA", "DSA", "ECDSA" })
62  {
63  if(version.supports_negotiable_signature_algorithms())
64  {
65  std::vector<std::string> hashes = policy.allowed_signature_hashes();
66  std::vector<std::string> sigs = policy.allowed_signature_methods();
67 
68  for(size_t i = 0; i != hashes.size(); ++i)
69  for(size_t j = 0; j != sigs.size(); ++j)
70  m_supported_algos.push_back(std::make_pair(hashes[i], sigs[j]));
71  }
72 
73  hash.update(io.send(*this));
74  }
MechanismType hash
Botan::TLS::Certificate_Req::Certificate_Req ( const std::vector< uint8_t > &  buf,
Protocol_Version  version 
)

Deserialize a Certificate Request message

Definition at line 79 of file msg_cert_req.cpp.

References Botan::TLS::TLS_Data_Reader::get_range_vector(), Botan::TLS::TLS_Data_Reader::get_uint16_t(), Botan::TLS::TLS_Data_Reader::has_remaining(), hash, Botan::TLS::Signature_Algorithms::hash_algo_name(), Botan::TLS::TLS_Data_Reader::remaining_bytes(), Botan::TLS::Signature_Algorithms::sig_algo_name(), and Botan::TLS::Protocol_Version::supports_negotiable_signature_algorithms().

81  {
82  if(buf.size() < 4)
83  throw Decoding_Error("Certificate_Req: Bad certificate request");
84 
85  TLS_Data_Reader reader("CertificateRequest", buf);
86 
87  std::vector<uint8_t> cert_type_codes = reader.get_range_vector<uint8_t>(1, 1, 255);
88 
89  for(size_t i = 0; i != cert_type_codes.size(); ++i)
90  {
91  const std::string cert_type_name = cert_type_code_to_name(cert_type_codes[i]);
92 
93  if(cert_type_name.empty()) // something we don't know
94  continue;
95 
96  m_cert_key_types.push_back(cert_type_name);
97  }
98 
99  if(version.supports_negotiable_signature_algorithms())
100  {
101  std::vector<uint8_t> sig_hash_algs = reader.get_range_vector<uint8_t>(2, 2, 65534);
102 
103  if(sig_hash_algs.size() % 2 != 0)
104  throw Decoding_Error("Bad length for signature IDs in certificate request");
105 
106  for(size_t i = 0; i != sig_hash_algs.size(); i += 2)
107  {
108  std::string hash = Signature_Algorithms::hash_algo_name(sig_hash_algs[i]);
109  std::string sig = Signature_Algorithms::sig_algo_name(sig_hash_algs[i+1]);
110  m_supported_algos.push_back(std::make_pair(hash, sig));
111  }
112  }
113 
114  const uint16_t purported_size = reader.get_uint16_t();
115 
116  if(reader.remaining_bytes() != purported_size)
117  throw Decoding_Error("Inconsistent length in certificate request");
118 
119  while(reader.has_remaining())
120  {
121  std::vector<uint8_t> name_bits = reader.get_range_vector<uint8_t>(2, 0, 65535);
122 
123  BER_Decoder decoder(name_bits.data(), name_bits.size());
124  X509_DN name;
125  decoder.decode(name);
126  m_names.push_back(name);
127  }
128  }
static std::string sig_algo_name(uint8_t code)
MechanismType hash
static std::string hash_algo_name(uint8_t code)

Member Function Documentation

std::vector<X509_DN> Botan::TLS::Certificate_Req::acceptable_CAs ( ) const
inline

Definition at line 483 of file tls_messages.h.

483 { return m_names; }
const std::vector<std::string>& Botan::TLS::Certificate_Req::acceptable_cert_types ( ) const
inline

Definition at line 480 of file tls_messages.h.

481  { return m_cert_key_types; }
std::vector<std::pair<std::string, std::string> > Botan::TLS::Certificate_Req::supported_algos ( ) const
inline

Definition at line 485 of file tls_messages.h.

Referenced by Botan::TLS::Handshake_State::parse_sig_format().

486  { return m_supported_algos; }
Handshake_Type Botan::TLS::Certificate_Req::type ( ) const
inlineoverridevirtual
Returns
the message type

Implements Botan::TLS::Handshake_Message.

Definition at line 478 of file tls_messages.h.

References Botan::TLS::CERTIFICATE_REQUEST.

std::string Botan::TLS::Handshake_Message::type_string ( ) const
inherited
Returns
string representation of this message type

Definition at line 17 of file tls_handshake_state.cpp.

References Botan::TLS::handshake_type_to_string(), and Botan::TLS::Handshake_Message::type().

18  {
20  }
virtual Handshake_Type type() const =0
const char * handshake_type_to_string(Handshake_Type type)

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