Botan 3.4.0
Crypto and TLS for C&
Public Member Functions | Protected Attributes | List of all members
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 169 of file msg_cert_verify.cpp.

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

References Botan::TLS::Signature_Scheme::is_available(), Botan::TLS::Signature_Scheme::is_compatible_with(), 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 139 of file msg_cert_verify.cpp.

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

References Botan::TLS::Policy::allowed_signature_schemes(), BOTAN_ASSERT_NOMSG, Botan::TLS::Client, Botan::TLS::Certificate_13::empty(), Botan::TLS::Signature_Scheme::format(), Botan::TLS::Certificate_13::has_certificate_chain(), Botan::TLS::Signature_Scheme::is_available(), Botan::TLS::Signature_Scheme::is_compatible_with(), Botan::TLS::Certificate_13::leaf(), Botan::TLS::Certificate_Verify::m_scheme, Botan::TLS::Certificate_Verify::m_signature, Botan::TLS::Signature_Scheme::padding_string(), 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 60 of file msg_cert_verify.cpp.

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

References BOTAN_ASSERT_NOMSG, Botan::TLS::Signature_Scheme::is_set(), Botan::TLS::Certificate_Verify::m_scheme, Botan::TLS::Certificate_Verify::m_signature, and Botan::TLS::Signature_Scheme::wire_code().

◆ 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; }

◆ 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.

◆ 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 Botan::TLS::Handshake_Message::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 183 of file msg_cert_verify.cpp.

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

References Botan::Public_Key::algorithm_identifier(), BOTAN_ASSERT_NOMSG, BOTAN_UNUSED, Botan::TLS::Signature_Scheme::format(), Botan::TLS::Signature_Scheme::is_available(), Botan::TLS::Signature_Scheme::key_algorithm_identifier(), Botan::TLS::Certificate_Verify::m_scheme, Botan::TLS::Certificate_Verify::m_signature, Botan::TLS::Signature_Scheme::padding_string(), 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 }

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

Member Data Documentation

◆ m_scheme

Signature_Scheme Botan::TLS::Certificate_Verify::m_scheme
protectedinherited

◆ m_signature

std::vector<uint8_t> Botan::TLS::Certificate_Verify::m_signature
protectedinherited

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