diff options
Diffstat (limited to 'src/lib/tls')
-rw-r--r-- | src/lib/tls/msg_cert_req.cpp | 15 | ||||
-rw-r--r-- | src/lib/tls/msg_certificate.cpp | 4 | ||||
-rw-r--r-- | src/lib/tls/msg_client_hello.cpp | 9 | ||||
-rw-r--r-- | src/lib/tls/tls_extensions.cpp | 4 | ||||
-rw-r--r-- | src/lib/tls/tls_policy.cpp | 24 | ||||
-rw-r--r-- | src/lib/tls/tls_session.cpp | 8 |
6 files changed, 36 insertions, 28 deletions
diff --git a/src/lib/tls/msg_cert_req.cpp b/src/lib/tls/msg_cert_req.cpp index a621c9c39..dc009651a 100644 --- a/src/lib/tls/msg_cert_req.cpp +++ b/src/lib/tls/msg_cert_req.cpp @@ -72,11 +72,11 @@ Certificate_Req::Certificate_Req(const std::vector<uint8_t>& buf) TLS_Data_Reader reader("CertificateRequest", buf); - std::vector<uint8_t> cert_type_codes = reader.get_range_vector<uint8_t>(1, 1, 255); + const auto cert_type_codes = reader.get_range_vector<uint8_t>(1, 1, 255); - for(size_t i = 0; i != cert_type_codes.size(); ++i) + for(const auto cert_type_code : cert_type_codes) { - const std::string cert_type_name = cert_type_code_to_name(cert_type_codes[i]); + const std::string cert_type_name = cert_type_code_to_name(cert_type_code); if(cert_type_name.empty()) // something we don't know continue; @@ -119,8 +119,8 @@ std::vector<uint8_t> Certificate_Req::serialize() const std::vector<uint8_t> cert_types; - for(size_t i = 0; i != m_cert_key_types.size(); ++i) - cert_types.push_back(cert_type_name_to_code(m_cert_key_types[i])); + for(const auto& cert_key_type : m_cert_key_types) + cert_types.push_back(cert_type_name_to_code(cert_key_type)); append_tls_length_value(buf, cert_types, 1); @@ -129,11 +129,10 @@ std::vector<uint8_t> Certificate_Req::serialize() const std::vector<uint8_t> encoded_names; - for(size_t i = 0; i != m_names.size(); ++i) + for(const auto& name : m_names) { DER_Encoder encoder; - encoder.encode(m_names[i]); - + encoder.encode(name); append_tls_length_value(encoded_names, encoder.get_contents(), 2); } diff --git a/src/lib/tls/msg_certificate.cpp b/src/lib/tls/msg_certificate.cpp index 3815c981a..db6f2ce9e 100644 --- a/src/lib/tls/msg_certificate.cpp +++ b/src/lib/tls/msg_certificate.cpp @@ -86,9 +86,9 @@ std::vector<uint8_t> Certificate::serialize() const { std::vector<uint8_t> buf(3); - for(size_t i = 0; i != m_certs.size(); ++i) + for(const auto& cert : m_certs) { - std::vector<uint8_t> raw_cert = m_certs[i].BER_encode(); + const auto raw_cert = cert.BER_encode(); const size_t cert_size = raw_cert.size(); for(size_t j = 0; j != 3; ++j) { diff --git a/src/lib/tls/msg_client_hello.cpp b/src/lib/tls/msg_client_hello.cpp index 9d7b09f61..bbc75a7de 100644 --- a/src/lib/tls/msg_client_hello.cpp +++ b/src/lib/tls/msg_client_hello.cpp @@ -299,9 +299,14 @@ Client_Hello::Client_Hello(const std::vector<uint8_t>& buf) */ bool Client_Hello::offered_suite(uint16_t ciphersuite) const { - for(size_t i = 0; i != m_suites.size(); ++i) - if(m_suites[i] == ciphersuite) + for(const auto suite : m_suites) + { + if(suite == ciphersuite) + { return true; + } + } + return false; } diff --git a/src/lib/tls/tls_extensions.cpp b/src/lib/tls/tls_extensions.cpp index 6b0d8f550..77ae608ae 100644 --- a/src/lib/tls/tls_extensions.cpp +++ b/src/lib/tls/tls_extensions.cpp @@ -135,8 +135,8 @@ bool Extensions::remove_extension(Handshake_Extension_Type typ) std::set<Handshake_Extension_Type> Extensions::extension_types() const { std::set<Handshake_Extension_Type> offers; - for(auto i = m_extensions.begin(); i != m_extensions.end(); ++i) - offers.insert(i->first); + for(const auto& extension : m_extensions) + offers.insert(extension.first); return offers; } diff --git a/src/lib/tls/tls_policy.cpp b/src/lib/tls/tls_policy.cpp index 38c91c069..eea1eb871 100644 --- a/src/lib/tls/tls_policy.cpp +++ b/src/lib/tls/tls_policy.cpp @@ -339,22 +339,22 @@ class Ciphersuite_Preference_Ordering final { if(a.kex_method() != b.kex_method()) { - for(size_t i = 0; i != m_kex.size(); ++i) + for(const auto & i : m_kex) { - if(a.kex_algo() == m_kex[i]) + if(a.kex_algo() == i) return true; - if(b.kex_algo() == m_kex[i]) + if(b.kex_algo() == i) return false; } } if(a.cipher_algo() != b.cipher_algo()) { - for(size_t i = 0; i != m_ciphers.size(); ++i) + for(const auto & m_cipher : m_ciphers) { - if(a.cipher_algo() == m_ciphers[i]) + if(a.cipher_algo() == m_cipher) return true; - if(b.cipher_algo() == m_ciphers[i]) + if(b.cipher_algo() == m_cipher) return false; } } @@ -369,22 +369,22 @@ class Ciphersuite_Preference_Ordering final if(a.auth_method() != b.auth_method()) { - for(size_t i = 0; i != m_sigs.size(); ++i) + for(const auto & m_sig : m_sigs) { - if(a.sig_algo() == m_sigs[i]) + if(a.sig_algo() == m_sig) return true; - if(b.sig_algo() == m_sigs[i]) + if(b.sig_algo() == m_sig) return false; } } if(a.mac_algo() != b.mac_algo()) { - for(size_t i = 0; i != m_macs.size(); ++i) + for(const auto & m_mac : m_macs) { - if(a.mac_algo() == m_macs[i]) + if(a.mac_algo() == m_mac) return true; - if(b.mac_algo() == m_macs[i]) + if(b.mac_algo() == m_mac) return false; } } diff --git a/src/lib/tls/tls_session.cpp b/src/lib/tls/tls_session.cpp index 8eb03712b..593987d51 100644 --- a/src/lib/tls/tls_session.cpp +++ b/src/lib/tls/tls_session.cpp @@ -141,9 +141,13 @@ Session::Session(const uint8_t ber[], size_t ber_len) secure_vector<uint8_t> Session::DER_encode() const { + // TODO note for anyone making an incompatible change to the + // encodings of TLS sessions. The peer cert list should have been a + // SEQUENCE not a concatenation: + std::vector<uint8_t> peer_cert_bits; - for(size_t i = 0; i != m_peer_certs.size(); ++i) - peer_cert_bits += m_peer_certs[i].BER_encode(); + for(const auto& peer_cert : m_peer_certs) + peer_cert_bits += peer_cert.BER_encode(); return DER_Encoder() .start_sequence() |