Botan 2.13.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
11 namespace Botan {
12
13 namespace TLS {
14
15 std::string Protocol_Version::to_string() const
16 {
17 const uint8_t maj = major_version();
18 const uint8_t min = minor_version();
19
20 if(maj == 3 && min == 0)
21 return "SSL v3";
22
23 if(maj == 3 && min >= 1) // TLS v1.x
24 return "TLS v1." + std::to_string(min-1);
25
26 if(maj == 254) // DTLS 1.x
27 return "DTLS v1." + std::to_string(255 - min);
28
29 // Some very new or very old protocol (or bogus data)
30 return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
31 }
32
33 bool Protocol_Version::is_datagram_protocol() const
34 {
35 return major_version() > 250;
36 }
37
38 bool Protocol_Version::operator>(const Protocol_Version& other) const
39 {
40 if(this->is_datagram_protocol() != other.is_datagram_protocol())
41 throw TLS_Exception(Alert::PROTOCOL_VERSION,
42 "Version comparing " + to_string() +
43 " with " + other.to_string());
44
45 if(this->is_datagram_protocol())
46 return m_version < other.m_version; // goes backwards
47
48 return m_version > other.m_version;
49 }
50
51 bool Protocol_Version::known_version() const
52 {
53 return (m_version == Protocol_Version::TLS_V10 ||
54 m_version == Protocol_Version::TLS_V11 ||
55 m_version == Protocol_Version::TLS_V12 ||
56 m_version == Protocol_Version::DTLS_V10 ||
57 m_version == Protocol_Version::DTLS_V12);
58 }
59
60 bool Protocol_Version::supports_negotiable_signature_algorithms() const
61 {
62 return (m_version != Protocol_Version::TLS_V10 &&
63 m_version != Protocol_Version::TLS_V11 &&
64 m_version != Protocol_Version::DTLS_V10);
65 }
66
67 bool Protocol_Version::supports_explicit_cbc_ivs() const
68 {
69 return (m_version != Protocol_Version::TLS_V10);
70 }
71
72 bool Protocol_Version::supports_ciphersuite_specific_prf() const
73 {
74 return (m_version != Protocol_Version::TLS_V10 &&
75 m_version != Protocol_Version::TLS_V11 &&
76 m_version != Protocol_Version::DTLS_V10);
77 }
78
79 bool Protocol_Version::supports_aead_modes() const
80 {
81 return (m_version != Protocol_Version::TLS_V10 &&
82 m_version != Protocol_Version::TLS_V11 &&
83 m_version != Protocol_Version::DTLS_V10);
84 }
85
86 }
87
88 }
Botan::TLS::Protocol_Version::minor_version
uint8_t minor_version() const
Definition: tls_version.h:84
Botan::TLS::Protocol_Version::to_string
std::string to_string() const
Definition: tls_version.cpp:15
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
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:79
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:51
Botan::TLS::Protocol_Version::operator>
bool operator>(const Protocol_Version &other) const
Definition: tls_version.cpp:38
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:72
Botan::TLS::Protocol_Version::supports_aead_modes
bool supports_aead_modes() const
Definition: tls_version.cpp:79
Botan::TLS::Protocol_Version::supports_negotiable_signature_algorithms
bool supports_negotiable_signature_algorithms() const
Definition: tls_version.cpp:60
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:33
Botan::TLS::TLS_Exception
Definition: tls_exceptn.h:21