Botan 3.9.0
Crypto and TLS for C&
Botan::TLS::Certificate_Verify_13 Class Referencefinal

#include <tls_messages.h>

Inheritance diagram for Botan::TLS::Certificate_Verify_13:
Botan::TLS::Certificate_Verify Botan::TLS::Handshake_Message

Public Member Functions

 Certificate_Verify_13 (const Certificate_13 &certificate_message, const std::vector< Signature_Scheme > &peer_allowed_schemes, std::string_view hostname, const Transcript_Hash &hash, Connection_Side whoami, Credentials_Manager &creds_mgr, const Policy &policy, Callbacks &callbacks, RandomNumberGenerator &rng)
 Certificate_Verify_13 (const std::vector< uint8_t > &buf, Connection_Side side)
std::vector< uint8_t > serialize () const override
Signature_Scheme signature_scheme () const
Handshake_Type type () const override
std::string type_string () const
bool verify (const Public_Key &public_key, Callbacks &callbacks, const Transcript_Hash &transcript_hash) const
virtual Handshake_Type wire_type () const

Protected Attributes

Signature_Scheme m_scheme
std::vector< uint8_t > m_signature

Detailed Description

Certificate Verify Message

Definition at line 801 of file tls_messages.h.

Constructor & Destructor Documentation

◆ Certificate_Verify_13() [1/2]

Botan::TLS::Certificate_Verify_13::Certificate_Verify_13 ( const std::vector< uint8_t > & buf,
Connection_Side side )

Deserialize a Certificate message

Parameters
bufthe serialized message
sideis this a Connection_Side::Server or Connection_Side::Client certificate message

Definition at line 170 of file msg_cert_verify.cpp.

170 :
171 Certificate_Verify(buf), m_side(side) {
172 if(!m_scheme.is_available()) {
173 throw TLS_Exception(Alert::IllegalParameter, "Peer sent unknown signature scheme");
174 }
175
176 if(!m_scheme.is_compatible_with(Protocol_Version::TLS_V13)) {
177 throw TLS_Exception(Alert::IllegalParameter, "Peer sent signature algorithm that is not suitable for TLS 1.3");
178 }
179}

References Botan::TLS::Certificate_Verify::Certificate_Verify(), and Botan::TLS::Certificate_Verify::m_scheme.

◆ Certificate_Verify_13() [2/2]

Botan::TLS::Certificate_Verify_13::Certificate_Verify_13 ( const Certificate_13 & certificate_message,
const std::vector< Signature_Scheme > & peer_allowed_schemes,
std::string_view hostname,
const Transcript_Hash & hash,
Connection_Side whoami,
Credentials_Manager & creds_mgr,
const Policy & policy,
Callbacks & callbacks,
RandomNumberGenerator & rng )

Definition at line 140 of file msg_cert_verify.cpp.

148 :
149 m_side(whoami) {
150 BOTAN_ASSERT_NOMSG(!certificate_msg.empty());
151
152 const std::string op_type((m_side == Connection_Side::Client) ? "tls-client" : "tls-server");
153 const auto context = std::string(hostname);
154
155 const auto private_key = (certificate_msg.has_certificate_chain())
156 ? creds_mgr.private_key_for(certificate_msg.leaf(), op_type, context)
157 : creds_mgr.private_key_for(*certificate_msg.public_key(), op_type, context);
158 if(!private_key) {
159 throw TLS_Exception(Alert::InternalError, "Application did not provide a private key for its credential");
160 }
161
162 m_scheme = choose_signature_scheme(*private_key, policy.allowed_signature_schemes(), peer_allowed_schemes);
163 BOTAN_ASSERT_NOMSG(m_scheme.is_available());
164 BOTAN_ASSERT_NOMSG(m_scheme.is_compatible_with(Protocol_Version::TLS_V13));
165
166 m_signature = callbacks.tls_sign_message(
167 *private_key, rng, m_scheme.padding_string(), m_scheme.format().value(), message(m_side, hash));
168}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75
std::vector< uint8_t > m_signature

References Botan::TLS::Policy::allowed_signature_schemes(), BOTAN_ASSERT_NOMSG, Botan::TLS::Client, Botan::TLS::Certificate_13::empty(), Botan::TLS::Certificate_13::has_certificate_chain(), Botan::TLS::Certificate_13::leaf(), Botan::TLS::Certificate_Verify::m_scheme, Botan::TLS::Certificate_Verify::m_signature, Botan::Credentials_Manager::private_key_for(), Botan::TLS::Certificate_13::public_key(), and Botan::TLS::Callbacks::tls_sign_message().

Member Function Documentation

◆ serialize()

std::vector< uint8_t > Botan::TLS::Certificate_Verify::serialize ( ) const
overridevirtualinherited
Returns
DER representation of this message

Implements Botan::TLS::Handshake_Message.

Definition at line 61 of file msg_cert_verify.cpp.

61 {
63 std::vector<uint8_t> buf;
64 buf.reserve(2 + 2 + m_signature.size()); // work around GCC warning
65
66 const auto code = m_scheme.wire_code();
67 buf.push_back(get_byte<0>(code));
68 buf.push_back(get_byte<1>(code));
69
70 if(m_signature.size() > 0xFFFF) {
71 throw Encoding_Error("Certificate_Verify signature too long to encode");
72 }
73
74 const uint16_t sig_len = static_cast<uint16_t>(m_signature.size());
75 buf.push_back(get_byte<0>(sig_len));
76 buf.push_back(get_byte<1>(sig_len));
77 buf += m_signature;
78
79 return buf;
80}
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79

References BOTAN_ASSERT_NOMSG, Botan::get_byte(), m_scheme, and m_signature.

Referenced by Certificate_Verify().

◆ signature_scheme()

Signature_Scheme Botan::TLS::Certificate_Verify::signature_scheme ( ) const
inlineinherited

Definition at line 762 of file tls_messages.h.

762{ return m_scheme; }

References m_scheme.

◆ type()

Handshake_Type Botan::TLS::Certificate_Verify::type ( ) const
inlineoverridevirtualinherited
Returns
the message type

Implements Botan::TLS::Handshake_Message.

Definition at line 760 of file tls_messages.h.

References Botan::TLS::CertificateVerify.

◆ type_string()

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

Definition at line 19 of file tls_handshake_state.cpp.

19 {
21}
virtual Handshake_Type type() const =0
const char * handshake_type_to_string(Handshake_Type type)

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

◆ verify()

bool Botan::TLS::Certificate_Verify_13::verify ( const Public_Key & public_key,
Callbacks & callbacks,
const Transcript_Hash & transcript_hash ) const

Definition at line 184 of file msg_cert_verify.cpp.

186 {
187 BOTAN_ASSERT_NOMSG(m_scheme.is_available());
188
189 // RFC 8446 4.2.3
190 // The keys found in certificates MUST [...] be of appropriate type for
191 // the signature algorithms they are used with.
192 if(m_scheme.key_algorithm_identifier() != public_key.algorithm_identifier()) {
193 throw TLS_Exception(Alert::IllegalParameter, "Signature algorithm does not match certificate's public key");
194 }
195
196 const bool signature_valid = callbacks.tls_verify_message(
197 public_key, m_scheme.padding_string(), m_scheme.format().value(), message(m_side, transcript_hash), m_signature);
198
199 #if defined(BOTAN_UNSAFE_FUZZER_MODE)
200 BOTAN_UNUSED(signature_valid);
201 return true;
202 #else
203 return signature_valid;
204 #endif
205}
#define BOTAN_UNUSED
Definition assert.h:144

References Botan::Public_Key::algorithm_identifier(), BOTAN_ASSERT_NOMSG, BOTAN_UNUSED, Botan::TLS::Certificate_Verify::m_scheme, Botan::TLS::Certificate_Verify::m_signature, and Botan::TLS::Callbacks::tls_verify_message().

◆ wire_type()

virtual Handshake_Type Botan::TLS::Handshake_Message::wire_type ( ) const
inlinevirtualinherited
Returns
the wire representation of the message's type

Reimplemented in Botan::TLS::Hello_Retry_Request.

Definition at line 39 of file tls_handshake_msg.h.

39 {
40 // Usually equal to the Handshake_Type enum value,
41 // with the exception of TLS 1.3 Hello Retry Request.
42 return type();
43 }

References type().

Referenced by Botan::TLS::Stream_Handshake_IO::send().

Member Data Documentation

◆ m_scheme

◆ m_signature


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