diff options
author | lloyd <[email protected]> | 2012-01-28 15:41:22 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-01-28 15:41:22 +0000 |
commit | e2e9105071f2d0a1360603f06c2acf68865ff072 (patch) | |
tree | 42f5bb0f689c2221b63ff20628e130552735ef9f /src | |
parent | ee7f6c030776c17a47e9d4f12e59aad86366e0da (diff) |
Support getting ciphersuites by name as well as suite ID
Diffstat (limited to 'src')
-rw-r--r-- | src/tls/tls_ciphersuite.cpp | 18 | ||||
-rw-r--r-- | src/tls/tls_ciphersuite.h | 4 | ||||
-rw-r--r-- | src/tls/tls_client.cpp | 2 | ||||
-rw-r--r-- | src/tls/tls_policy.cpp | 9 | ||||
-rw-r--r-- | src/tls/tls_server.cpp | 4 | ||||
-rw-r--r-- | src/tls/tls_session.h | 2 |
6 files changed, 29 insertions, 10 deletions
diff --git a/src/tls/tls_ciphersuite.cpp b/src/tls/tls_ciphersuite.cpp index 01c35a55a..82e2cdd28 100644 --- a/src/tls/tls_ciphersuite.cpp +++ b/src/tls/tls_ciphersuite.cpp @@ -18,7 +18,7 @@ namespace TLS { /** * Convert an SSL/TLS ciphersuite to algorithm fields */ -Ciphersuite Ciphersuite::lookup_ciphersuite(u16bit suite) +Ciphersuite Ciphersuite::by_id(u16bit suite) { switch(static_cast<Ciphersuite_Code>(suite)) { @@ -255,6 +255,22 @@ Ciphersuite Ciphersuite::lookup_ciphersuite(u16bit suite) return Ciphersuite(); // some unknown ciphersuite } +Ciphersuite Ciphersuite::by_name(const std::string& name) + { + for(size_t i = 0; i != 65536; ++i) + { + Ciphersuite suite = Ciphersuite::by_id(i); + + if(!suite.valid()) + continue; // not a ciphersuite we know, skip + + if(suite.to_string() == name) + return suite; + } + + return Ciphersuite(); // some unknown ciphersuite + } + std::string Ciphersuite::to_string() const { if(m_cipher_keylen == 0) diff --git a/src/tls/tls_ciphersuite.h b/src/tls/tls_ciphersuite.h index f0acc1497..e5d8c967b 100644 --- a/src/tls/tls_ciphersuite.h +++ b/src/tls/tls_ciphersuite.h @@ -21,7 +21,9 @@ namespace TLS { class BOTAN_DLL Ciphersuite { public: - static Ciphersuite lookup_ciphersuite(u16bit suite); + static Ciphersuite by_id(u16bit suite); + + static Ciphersuite by_name(const std::string& name); /** * Formats the ciphersuite back to an RFC-style ciphersuite string diff --git a/src/tls/tls_client.cpp b/src/tls/tls_client.cpp index 5c7b50abc..2bcdf7457 100644 --- a/src/tls/tls_client.cpp +++ b/src/tls/tls_client.cpp @@ -180,7 +180,7 @@ void Client::process_handshake_msg(Handshake_Type type, secure_renegotiation.update(state->server_hello); - state->suite = Ciphersuite::lookup_ciphersuite(state->server_hello->ciphersuite()); + state->suite = Ciphersuite::by_id(state->server_hello->ciphersuite()); if(!state->server_hello->session_id().empty() && (state->server_hello->session_id() == state->client_hello->session_id())) diff --git a/src/tls/tls_policy.cpp b/src/tls/tls_policy.cpp index 805e0ca38..49f74975b 100644 --- a/src/tls/tls_policy.cpp +++ b/src/tls/tls_policy.cpp @@ -11,6 +11,8 @@ #include <botan/tls_exceptn.h> #include <botan/internal/stl_util.h> +#include <assert.h> + namespace Botan { namespace TLS { @@ -182,10 +184,9 @@ std::vector<u16bit> Policy::ciphersuite_list(bool have_srp) const std::map<Ciphersuite, u16bit, Ciphersuite_Preference_Ordering> ciphersuites(order); - // When in doubt use brute force :) - for(u32bit i = 0; i != 65536; ++i) + for(size_t i = 0; i != 65536; ++i) { - Ciphersuite suite = Ciphersuite::lookup_ciphersuite(i); + Ciphersuite suite = Ciphersuite::by_id(i); if(!suite.valid()) continue; // not a ciphersuite we know, skip @@ -247,7 +248,7 @@ u16bit Policy::choose_suite(const std::vector<u16bit>& client_suites, for(size_t i = 0; i != ciphersuites.size(); ++i) { const u16bit suite_id = ciphersuites[i]; - Ciphersuite suite = Ciphersuite::lookup_ciphersuite(suite_id); + Ciphersuite suite = Ciphersuite::by_id(suite_id); if(!have_shared_ecc_curve) { diff --git a/src/tls/tls_server.cpp b/src/tls/tls_server.cpp index 30983f48f..d186ddac4 100644 --- a/src/tls/tls_server.cpp +++ b/src/tls/tls_server.cpp @@ -221,7 +221,7 @@ void Server::process_handshake_msg(Handshake_Type type, writer.set_maximum_fragment_size(session_info.fragment_size()); } - state->suite = Ciphersuite::lookup_ciphersuite(state->server_hello->ciphersuite()); + state->suite = Ciphersuite::by_id(state->server_hello->ciphersuite()); state->keys = Session_Keys(state, session_info.master_secret(), true); @@ -277,7 +277,7 @@ void Server::process_handshake_msg(Handshake_Type type, writer.set_maximum_fragment_size(state->client_hello->fragment_size()); } - state->suite = Ciphersuite::lookup_ciphersuite(state->server_hello->ciphersuite()); + state->suite = Ciphersuite::by_id(state->server_hello->ciphersuite()); const std::string sig_algo = state->suite.sig_algo(); const std::string kex_algo = state->suite.kex_algo(); diff --git a/src/tls/tls_session.h b/src/tls/tls_session.h index f8b94133b..96b6d6daf 100644 --- a/src/tls/tls_session.h +++ b/src/tls/tls_session.h @@ -90,7 +90,7 @@ class BOTAN_DLL Session /** * Get the ciphersuite info of the saved session */ - Ciphersuite ciphersuite() const { return Ciphersuite::lookup_ciphersuite(m_ciphersuite); } + Ciphersuite ciphersuite() const { return Ciphersuite::by_id(m_ciphersuite); } /** * Get the compression method used in the saved session |