11#include <botan/tls_messages.h>
13#include <botan/credentials_manager.h>
14#include <botan/pk_keys.h>
15#include <botan/tls_algos.h>
16#include <botan/tls_extensions.h>
17#include <botan/internal/stl_util.h>
18#include <botan/internal/target_info.h>
19#include <botan/internal/tls_handshake_io.h>
20#include <botan/internal/tls_handshake_state.h>
21#include <botan/internal/tls_reader.h>
63 std::vector<uint8_t> buf;
66 const auto code =
m_scheme.wire_code();
71 throw Encoding_Error(
"Certificate_Verify signature too long to encode");
74 const uint16_t sig_len =
static_cast<uint16_t
>(
m_signature.size());
84 const Policy& policy)
const {
89 std::pair<std::string, Signature_Format> format =
92 const bool signature_valid =
95#if defined(BOTAN_UNSAFE_FUZZER_MODE)
100 return signature_valid;
105#if defined(BOTAN_HAS_TLS_13)
110 std::vector<uint8_t> msg(64, 0x20);
111 msg.reserve(64 + 33 + 1 + hash.size());
114 :
"TLS 1.3, client CertificateVerify";
116 msg.insert(msg.end(), context_string.cbegin(), context_string.cend());
119 msg.insert(msg.end(), hash.cbegin(), hash.cend());
123Signature_Scheme choose_signature_scheme(
const Private_Key& key,
124 const std::vector<Signature_Scheme>& allowed_schemes,
125 const std::vector<Signature_Scheme>& peer_allowed_schemes) {
126 for(Signature_Scheme scheme : allowed_schemes) {
127 if(scheme.is_available() && scheme.is_suitable_for(key) &&
value_exists(peer_allowed_schemes, scheme)) {
132 throw TLS_Exception(Alert::HandshakeFailure,
"Failed to agree on a signature algorithm");
141 const std::vector<Signature_Scheme>& peer_allowed_schemes,
142 std::string_view hostname,
153 const auto context = std::string(hostname);
159 throw TLS_Exception(Alert::InternalError,
"Application did not provide a private key for its credential");
167 *private_key, rng,
m_scheme.padding_string(),
m_scheme.format().value(), message(m_side, hash));
173 throw TLS_Exception(Alert::IllegalParameter,
"Peer sent unknown signature scheme");
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");
193 throw TLS_Exception(Alert::IllegalParameter,
"Signature algorithm does not match certificate's public key");
199 #if defined(BOTAN_UNSAFE_FUZZER_MODE)
203 return signature_valid;
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_ASSERT_NONNULL(ptr)
virtual std::shared_ptr< Private_Key > private_key_for(const X509_Certificate &cert, const std::string &type, const std::string &context)
virtual AlgorithmIdentifier algorithm_identifier() const =0
virtual std::vector< uint8_t > tls_sign_message(const Private_Key &key, RandomNumberGenerator &rng, std::string_view padding, Signature_Format format, const std::vector< uint8_t > &msg)
virtual bool tls_verify_message(const Public_Key &key, std::string_view padding, Signature_Format format, const std::vector< uint8_t > &msg, const std::vector< uint8_t > &sig)
const X509_Certificate & leaf() const
std::shared_ptr< const Public_Key > public_key() const
bool has_certificate_chain() const
bool verify(const X509_Certificate &cert, const Handshake_State &state, const Policy &policy) const
Certificate_Verify_12(Handshake_IO &io, Handshake_State &state, const Policy &policy, RandomNumberGenerator &rng, const Private_Key *key)
bool verify(const Public_Key &public_key, Callbacks &callbacks, const Transcript_Hash &transcript_hash) const
Certificate_Verify_13(const std::vector< uint8_t > &buf, Connection_Side side)
Signature_Scheme m_scheme
Certificate_Verify(const std::vector< uint8_t > &buf)
Certificate_Verify()=default
std::vector< uint8_t > serialize() const override
std::vector< uint8_t > m_signature
const std::vector< uint8_t > & get_contents() const
void update(const uint8_t in[], size_t length)
virtual std::vector< uint8_t > send(const Handshake_Message &msg)=0
std::pair< std::string, Signature_Format > parse_sig_format(const Public_Key &key, Signature_Scheme scheme, const std::vector< Signature_Scheme > &offered_schemes, bool for_client_auth, const Policy &policy) const
void client_hello(std::unique_ptr< Client_Hello_12 > client_hello)
Callbacks & callbacks() const
std::pair< std::string, Signature_Format > choose_sig_format(const Private_Key &key, Signature_Scheme &scheme, bool for_client_auth, const Policy &policy) const
virtual void check_peer_key_acceptable(const Public_Key &public_key) const
virtual std::vector< Signature_Scheme > allowed_signature_schemes() const
std::vector< T > get_range(size_t len_bytes, size_t min_elems, size_t max_elems)
std::unique_ptr< Public_Key > subject_public_key() const
std::vector< uint8_t > Transcript_Hash
constexpr uint8_t get_byte(T input)
bool value_exists(const std::vector< T > &vec, const OT &val)