aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenĂ© Meusel <[email protected]>2021-10-28 11:08:34 +0530
committerRenĂ© Meusel <[email protected]>2021-10-28 12:10:45 +0530
commit084cabc9760dfe4ea79cc28f5289669fd20b5a57 (patch)
treea5b7ccb18ee438c35a4e57f92e084318608ca3d2
parentfc980c60d6aa0cf8c853b8c449c241d6deec9274 (diff)
remove default c'tor from TLS::Ciphersuite
-rw-r--r--src/lib/tls/tls_ciphersuite.h20
-rw-r--r--src/lib/tls/tls_handshake_state.cpp19
-rw-r--r--src/lib/tls/tls_handshake_state.h5
-rw-r--r--src/tests/test_tls_messages.cpp2
4 files changed, 23 insertions, 23 deletions
diff --git a/src/lib/tls/tls_ciphersuite.h b/src/lib/tls/tls_ciphersuite.h
index f065763cd..0123d0d4c 100644
--- a/src/lib/tls/tls_ciphersuite.h
+++ b/src/lib/tls/tls_ciphersuite.h
@@ -131,8 +131,6 @@ class BOTAN_PUBLIC_API(2,0) Ciphersuite final
bool operator<(const Ciphersuite& o) const { return ciphersuite_code() < o.ciphersuite_code(); }
bool operator<(const uint16_t c) const { return ciphersuite_code() < c; }
- Ciphersuite() = default;
-
private:
bool is_usable() const;
@@ -167,18 +165,18 @@ class BOTAN_PUBLIC_API(2,0) Ciphersuite final
All of these const char* strings are references to compile time
constants in tls_suite_info.cpp
*/
- const char* m_iana_id = nullptr;
+ const char* m_iana_id;
- Auth_Method m_auth_method = Auth_Method::IMPLICIT;
- Kex_Algo m_kex_algo = Kex_Algo::STATIC_RSA;
- KDF_Algo m_prf_algo = KDF_Algo::SHA_1;
- Nonce_Format m_nonce_format = Nonce_Format::CBC_MODE;
+ Auth_Method m_auth_method;
+ Kex_Algo m_kex_algo;
+ KDF_Algo m_prf_algo;
+ Nonce_Format m_nonce_format;
- const char* m_cipher_algo = nullptr;
- const char* m_mac_algo = nullptr;
+ const char* m_cipher_algo;
+ const char* m_mac_algo;
- size_t m_cipher_keylen = 0;
- size_t m_mac_keylen = 0;
+ size_t m_cipher_keylen;
+ size_t m_mac_keylen;
bool m_usable = false;
};
diff --git a/src/lib/tls/tls_handshake_state.cpp b/src/lib/tls/tls_handshake_state.cpp
index ad2b3bb8b..9f18722d0 100644
--- a/src/lib/tls/tls_handshake_state.cpp
+++ b/src/lib/tls/tls_handshake_state.cpp
@@ -219,15 +219,7 @@ void Handshake_State::client_hello(Client_Hello* client_hello)
void Handshake_State::server_hello(Server_Hello* server_hello)
{
m_server_hello.reset(server_hello);
-
- auto suite = Ciphersuite::by_id(m_server_hello->ciphersuite());
- if (!suite.has_value())
- {
- throw Decoding_Error("Failed to find cipher suite for ID " +
- std::to_string(m_server_hello->ciphersuite()));
- }
-
- m_ciphersuite = suite.value();
+ m_ciphersuite = Ciphersuite::by_id(m_server_hello->ciphersuite());
note_message(*m_server_hello);
}
@@ -297,6 +289,15 @@ void Handshake_State::client_finished(Finished* client_finished)
note_message(*m_client_finished);
}
+const Ciphersuite& Handshake_State::ciphersuite() const
+ {
+ if (!m_ciphersuite.has_value())
+ {
+ throw Decoding_Error("Cipher suite is not set");
+ }
+ return m_ciphersuite.value();
+ }
+
void Handshake_State::set_version(const Protocol_Version& version)
{
m_version = version;
diff --git a/src/lib/tls/tls_handshake_state.h b/src/lib/tls/tls_handshake_state.h
index 558fd0d13..1cc22d029 100644
--- a/src/lib/tls/tls_handshake_state.h
+++ b/src/lib/tls/tls_handshake_state.h
@@ -19,6 +19,7 @@
#include <botan/pk_keys.h>
#include <botan/pubkey.h>
#include <functional>
+#include <optional>
namespace Botan {
@@ -154,7 +155,7 @@ class Handshake_State
const Finished* client_finished() const
{ return m_client_finished.get(); }
- const Ciphersuite& ciphersuite() const { return m_ciphersuite; }
+ const Ciphersuite& ciphersuite() const;
const Session_Keys& session_keys() const { return m_session_keys; }
@@ -178,7 +179,7 @@ class Handshake_State
uint32_t m_hand_expecting_mask = 0;
uint32_t m_hand_received_mask = 0;
Protocol_Version m_version;
- Ciphersuite m_ciphersuite;
+ std::optional<Ciphersuite> m_ciphersuite;
Session_Keys m_session_keys;
Handshake_Hash m_handshake_hash;
diff --git a/src/tests/test_tls_messages.cpp b/src/tests/test_tls_messages.cpp
index 937a9f100..052e9a83e 100644
--- a/src/tests/test_tls_messages.cpp
+++ b/src/tests/test_tls_messages.cpp
@@ -101,7 +101,7 @@ class TLS_Message_Parsing_Test final : public Text_Based_Test
{
const std::string extensions = vars.get_req_str("AdditionalData");
Botan::TLS::Protocol_Version pv(protocol[0], protocol[1]);
- Botan::TLS::Ciphersuite cs = Botan::TLS::Ciphersuite::by_id(Botan::make_uint16(ciphersuite[0], ciphersuite[1])).value_or(Botan::TLS::Ciphersuite());
+ Botan::TLS::Ciphersuite cs = Botan::TLS::Ciphersuite::by_id(Botan::make_uint16(ciphersuite[0], ciphersuite[1])).value();
Botan::TLS::Server_Hello message(buffer);
result.test_eq("Protocol version", message.version().to_string(), pv.to_string());
result.confirm("Ciphersuite", (message.ciphersuite() == cs.ciphersuite_code()));