Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

tls_version.cpp
Go to the documentation of this file.
1 /*
2 * TLS Protocol Version Management
3 * (C) 2012 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/tls_version.h>
9 #include <botan/tls_exceptn.h>
10 #include <botan/parsing.h>
11
12 namespace Botan {
13
14 namespace TLS {
15
16 std::string Protocol_Version::to_string() const
17 {
18 const uint8_t maj = major_version();
19 const uint8_t min = minor_version();
20
21 if(maj == 3 && min == 0)
22 return "SSL v3";
23
24 if(maj == 3 && min >= 1) // TLS v1.x
25 return "TLS v1." + std::to_string(min-1);
26
27 if(maj == 254) // DTLS 1.x
28 return "DTLS v1." + std::to_string(255 - min);
29
30 // Some very new or very old protocol (or bogus data)
31 return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
32 }
33
34 bool Protocol_Version::is_datagram_protocol() const
35 {
36 return major_version() == 254;
37 }
38
39 bool Protocol_Version::operator>(const Protocol_Version& other) const
40 {
41 if(this->is_datagram_protocol() != other.is_datagram_protocol())
42 throw TLS_Exception(Alert::PROTOCOL_VERSION,
43 "Version comparing " + to_string() +
44 " with " + other.to_string());
45
46 if(this->is_datagram_protocol())
47 return m_version < other.m_version; // goes backwards
48
49 return m_version > other.m_version;
50 }
51
52 bool Protocol_Version::known_version() const
53 {
54 return (m_version == Protocol_Version::TLS_V10 ||
55 m_version == Protocol_Version::TLS_V11 ||
56 m_version == Protocol_Version::TLS_V12 ||
57 m_version == Protocol_Version::DTLS_V10 ||
58 m_version == Protocol_Version::DTLS_V12);
59 }
60
61 bool Protocol_Version::supports_negotiable_signature_algorithms() const
62 {
63 return (m_version == Protocol_Version::TLS_V12 ||
64 m_version == Protocol_Version::DTLS_V12);
65 }
66
67 bool Protocol_Version::supports_explicit_cbc_ivs() const
68 {
69 return (m_version == Protocol_Version::TLS_V11 ||
70 m_version == Protocol_Version::TLS_V12 ||
71 m_version == Protocol_Version::DTLS_V10 ||
72 m_version == Protocol_Version::DTLS_V12);
73 }
74
75 bool Protocol_Version::supports_ciphersuite_specific_prf() const
76 {
77 return (m_version == Protocol_Version::TLS_V12 ||
78 m_version == Protocol_Version::DTLS_V12);
79 }
80
81 bool Protocol_Version::supports_aead_modes() const
82 {
83 return (m_version == Protocol_Version::TLS_V12 ||
84 m_version == Protocol_Version::DTLS_V12);
85 }
86
87 }
88
89 }
Botan::TLS::Protocol_Version::minor_version
uint8_t minor_version() const
Definition: tls_version.h:82
Botan::TLS::Protocol_Version::to_string
std::string to_string() const
Definition: tls_version.cpp:16
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
Botan::TLS::Protocol_Version
Definition: tls_version.h:21
Botan::TLS::Protocol_Version::DTLS_V12
Definition: tls_version.h:30
Botan::TLS::Protocol_Version::supports_explicit_cbc_ivs
bool supports_explicit_cbc_ivs() const
Definition: tls_version.cpp:67
Botan::TLS::Protocol_Version::DTLS_V10
Definition: tls_version.h:29
Botan::TLS::Protocol_Version::major_version
uint8_t major_version() const
Definition: tls_version.h:77
Botan::TLS::Protocol_Version::TLS_V11
Definition: tls_version.h:26
Botan::TLS::Protocol_Version::known_version
bool known_version() const
Definition: tls_version.cpp:52
Botan::TLS::Protocol_Version::operator>
bool operator>(const Protocol_Version &other) const
Definition: tls_version.cpp:39
Botan
Definition: alg_id.cpp:13
Botan::TLS::Protocol_Version::TLS_V12
Definition: tls_version.h:27
Botan::TLS::Protocol_Version::TLS_V10
Definition: tls_version.h:25
Botan::TLS::Protocol_Version::supports_ciphersuite_specific_prf
bool supports_ciphersuite_specific_prf() const
Definition: tls_version.cpp:75
Botan::CT::min
T min(T a, T b)
Definition: ct_utils.h:180
Botan::TLS::Protocol_Version::supports_aead_modes
bool supports_aead_modes() const
Definition: tls_version.cpp:81
Botan::TLS::Protocol_Version::supports_negotiable_signature_algorithms
bool supports_negotiable_signature_algorithms() const
Definition: tls_version.cpp:61
Botan::TLS::Alert::PROTOCOL_VERSION
Definition: tls_alert.h:47
Botan::TLS::Protocol_Version::is_datagram_protocol
bool is_datagram_protocol() const
Definition: tls_version.cpp:34
Botan::TLS::TLS_Exception
Definition: tls_exceptn.h:21