Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TLS 1.3] Preparations for addition of TLS 1.3 #2946

Merged
merged 4 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/authors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Dan Brown
Daniel Neus (Rohde & Schwarz Cybersecurity)
Daniel Seither (Kullo GmbH)
Daniel Wyatt
Elektrobit Automotive GmbH
Eric Cornelius
Erwan Chaussy
etcimon
Expand Down Expand Up @@ -66,6 +67,7 @@ Matthias Gierlings (Hackmanit GmbH)
Matt Johnston
Michael Boric (Rohde & Schwarz Cybersecurity)
Nathan Hourt
neXenio GmbH
Nicolas Sendrier
Nuno Goncalves
Ori Peleg
Expand Down
3 changes: 2 additions & 1 deletion src/bogo_shim/bogo_shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ std::string map_to_bogo_error(const std::string& e)
{ "Certificate key type did not match ciphersuite", ":WRONG_CERTIFICATE_TYPE:" },
{ "Certificate usage constraints do not allow this ciphersuite", ":KEY_USAGE_BIT_INCORRECT:" },
{ "Certificate: Message malformed", ":DECODE_ERROR:" },
{ "Channel::key_material_export cannot export during renegotiation", "failed to export keying material" },
{ "Channel_Impl_12::key_material_export cannot export during renegotiation", "failed to export keying material" },
{ "Client cert verify failed", ":BAD_SIGNATURE:" },
{ "Client certificate does not support signing", ":KEY_USAGE_BIT_INCORRECT:" },
{ "Client did not offer NULL compression", ":INVALID_COMPRESSION_LIST:" },
Expand Down Expand Up @@ -151,6 +151,7 @@ std::string map_to_bogo_error(const std::string& e)
{ "Server downgraded version after renegotiation", ":WRONG_SSL_VERSION:" },
{ "Server policy prohibits renegotiation", ":NO_RENEGOTIATION:" },
{ "Server replied using a ciphersuite not allowed in version it offered", ":WRONG_CIPHER_RETURNED:" },
{ "Server replied with an invalid version", ":UNSUPPORTED_PROTOCOL:" },
{ "Server replied with DTLS-SRTP alg we did not send", ":BAD_SRTP_PROTECTION_PROFILE_LIST:" },
{ "Server replied with ciphersuite we didn't send", ":WRONG_CIPHER_RETURNED:" },
{ "Server replied with later version than client offered", ":UNSUPPORTED_PROTOCOL:" },
Expand Down
6 changes: 3 additions & 3 deletions src/cli/tls_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class TLS_Client_Hello_Reader final : public Command

try
{
Botan::TLS::Client_Hello hello(input);
Botan::TLS::Client_Hello_12 hello(input);

output() << format_hello(hello);
}
Expand All @@ -151,10 +151,10 @@ class TLS_Client_Hello_Reader final : public Command
}

private:
static std::string format_hello(const Botan::TLS::Client_Hello& hello)
static std::string format_hello(const Botan::TLS::Client_Hello_12& hello)
{
std::ostringstream oss;
oss << "Version: " << hello.version().to_string() << "\n"
oss << "Version: " << hello.legacy_version().to_string() << "\n"
<< "Random: " << Botan::hex_encode(hello.random()) << "\n";

if(!hello.session_id().empty())
Expand Down
2 changes: 1 addition & 1 deletion src/configs/pylint.rc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ confidence=
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"

disable=missing-docstring,no-else-return,locally-disabled,import-outside-toplevel,super-with-arguments,raise-missing-from,duplicate-code,consider-using-f-string
disable=missing-docstring,no-else-return,locally-disabled,import-outside-toplevel,super-with-arguments,raise-missing-from,duplicate-code,consider-using-f-string,fixme


[REPORTS]
Expand Down
2 changes: 1 addition & 1 deletion src/fuzzer/tls_client_hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void fuzz(const uint8_t in[], size_t len)
try
{
std::vector<uint8_t> v(in, in + len);
Botan::TLS::Client_Hello ch(v);
Botan::TLS::Client_Hello_12 ch(v); // TODO: We might want to do that for TLS 1.3 as well
}
catch(Botan::Exception& e) {}
}
8 changes: 4 additions & 4 deletions src/lib/pubkey/pubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class BOTAN_PUBLIC_API(2,0) PK_Key_Agreement final

/**
* Perform Key Agreement Operation
* @param key_len the desired key output size
* @param key_len the desired key output size (ignored if "Raw" KDF is used)
* @param in the other parties key
* @param in_len the length of in in bytes
* @param params extra derivation params
Expand All @@ -437,7 +437,7 @@ class BOTAN_PUBLIC_API(2,0) PK_Key_Agreement final

/**
* Perform Key Agreement Operation
* @param key_len the desired key output size
* @param key_len the desired key output size (ignored if "Raw" KDF is used)
* @param in the other parties key
* @param params extra derivation params
* @param params_len the length of params in bytes
Expand All @@ -453,7 +453,7 @@ class BOTAN_PUBLIC_API(2,0) PK_Key_Agreement final

/**
* Perform Key Agreement Operation
* @param key_len the desired key output size
* @param key_len the desired key output size (ignored if "Raw" KDF is used)
* @param in the other parties key
* @param in_len the length of in in bytes
* @param params extra derivation params
Expand All @@ -469,7 +469,7 @@ class BOTAN_PUBLIC_API(2,0) PK_Key_Agreement final

/**
* Perform Key Agreement Operation
* @param key_len the desired key output size
* @param key_len the desired key output size (ignored if "Raw" KDF is used)
* @param in the other parties key
* @param params extra derivation params
*/
Expand Down
10 changes: 3 additions & 7 deletions src/lib/tls/info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@ tls_version.h
</header:public>

<header:internal>
tls_handshake_hash.h
tls_handshake_io.h
tls_handshake_state.h
tls_channel_impl.h
tls_handshake_transitions.h
tls_reader.h
tls_record.h
tls_seq_numbers.h
tls_session_key.h
tls_server_impl.h
</header:internal>

<requires>
Expand All @@ -45,10 +41,10 @@ eme_pkcs1
emsa_pkcs1
gcm
hmac
prf_tls
rng
rsa
sha2_32
sha2_64
tls12
x509
</requires>
24 changes: 23 additions & 1 deletion src/lib/tls/msg_cert_req.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* Certificate Request Message
* (C) 2004-2006,2012 Jack Lloyd
* 2021 Elektrobit Automotive GmbH
* 2022 René Meusel, Hannes Rantzsch - neXenio GmbH
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
Expand All @@ -15,6 +17,11 @@

namespace Botan::TLS {

Handshake_Type Certificate_Req::type() const
{
return CERTIFICATE_REQUEST;
}

namespace {

std::string cert_type_code_to_name(uint8_t code)
Expand Down Expand Up @@ -108,6 +115,21 @@ Certificate_Req::Certificate_Req(const std::vector<uint8_t>& buf)
}
}

const std::vector<std::string>& Certificate_Req::acceptable_cert_types() const
{
return m_cert_key_types;
}

const std::vector<X509_DN>& Certificate_Req::acceptable_CAs() const
{
return m_names;
}

const std::vector<Signature_Scheme>& Certificate_Req::signature_schemes() const
{
return m_schemes;
}

/**
* Serialize a Certificate Request message
*/
Expand All @@ -131,12 +153,12 @@ std::vector<uint8_t> Certificate_Req::serialize() const
{
DER_Encoder encoder;
encoder.encode(name);

append_tls_length_value(encoded_names, encoder.get_contents(), 2);
}

append_tls_length_value(buf, encoded_names, 2);

return buf;
}

reneme marked this conversation as resolved.
Show resolved Hide resolved
}
28 changes: 17 additions & 11 deletions src/lib/tls/msg_cert_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
* Certificate Verify Message
* (C) 2004,2006,2011,2012 Jack Lloyd
* 2017 Harry Reimann, Rohde & Schwarz Cybersecurity
* 2021 Elektrobit Automotive GmbH
* 2022 René Meusel, Hannes Rantzsch - neXenio GmbH
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include <botan/tls_messages.h>
#include <botan/tls_extensions.h>
#include <botan/internal/tls_reader.h>
#include <botan/internal/tls_handshake_io.h>
#include <botan/internal/tls_handshake_state.h>
#include <botan/internal/tls_reader.h>
#include <botan/pk_keys.h>
#include <botan/tls_algos.h>
#include <botan/tls_extensions.h>
#include <botan/tls_messages.h>
reneme marked this conversation as resolved.
Show resolved Hide resolved

namespace Botan::TLS {

Expand Down Expand Up @@ -45,6 +49,10 @@ Certificate_Verify::Certificate_Verify(const std::vector<uint8_t>& buf)
m_scheme = static_cast<Signature_Scheme>(reader.get_uint16_t());
m_signature = reader.get_range<uint8_t>(2, 0, 65535);
reader.assert_done();

if(m_scheme == Signature_Scheme::NONE)
{ throw Decoding_Error("Counterparty did not send hash/sig IDS"); }

}

/*
Expand All @@ -62,7 +70,7 @@ std::vector<uint8_t> Certificate_Verify::serialize() const
}

if(m_signature.size() > 0xFFFF)
throw Encoding_Error("Certificate_Verify signature too long to encode");
{ throw Encoding_Error("Certificate_Verify signature too long to encode"); }

const uint16_t sig_len = static_cast<uint16_t>(m_signature.size());
buf.push_back(get_byte<0>(sig_len));
Expand All @@ -72,19 +80,17 @@ std::vector<uint8_t> Certificate_Verify::serialize() const
return buf;
}

/*
* Verify a Certificate Verify message
*/
bool Certificate_Verify::verify(const X509_Certificate& cert,
const Handshake_State& state,
const Policy& policy) const

bool Certificate_Verify_12::verify(const X509_Certificate& cert,
const Handshake_State& state,
const Policy& policy) const
{
std::unique_ptr<Public_Key> key(cert.subject_public_key());

policy.check_peer_key_acceptable(*key);

std::pair<std::string, Signature_Format> format =
state.parse_sig_format(*key.get(), m_scheme, true, policy);
state.parse_sig_format(*key.get(), m_scheme, state.client_hello()->signature_schemes(), true, policy);

const bool signature_valid =
state.callbacks().tls_verify_message(*key, format.first, format.second,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace Botan::TLS {
/**
* Create a new Certificate message
*/
Certificate::Certificate(Handshake_IO& io,
Handshake_Hash& hash,
const std::vector<X509_Certificate>& cert_list) :
Certificate_12::Certificate_12(Handshake_IO& io,
Handshake_Hash& hash,
const std::vector<X509_Certificate>& cert_list) :
m_certs(cert_list)
{
hash.update(io.send(*this));
Expand All @@ -31,7 +31,7 @@ Certificate::Certificate(Handshake_IO& io,
/**
* Deserialize a Certificate message
*/
Certificate::Certificate(const std::vector<uint8_t>& buf, const Policy& policy)
Certificate_12::Certificate_12(const std::vector<uint8_t>& buf, const Policy& policy)
{
if(buf.size() < 3)
throw Decoding_Error("Certificate: Message malformed");
Expand Down Expand Up @@ -80,7 +80,7 @@ Certificate::Certificate(const std::vector<uint8_t>& buf, const Policy& policy)
/**
* Serialize a Certificate message
*/
std::vector<uint8_t> Certificate::serialize() const
std::vector<uint8_t> Certificate_12::serialize() const
{
std::vector<uint8_t> buf(3);

Expand Down
Loading