libfilezilla
tls_info.hpp
Go to the documentation of this file.
1 #ifndef LIBFILEZILLA_TLS_INFO_HEADER
2 #define LIBFILEZILLA_TLS_INFO_HEADER
3 
8 #include "time.hpp"
9 
10 namespace fz {
14 class x509_certificate final
15 {
16 public:
18  class subject_name final
19  {
20  public:
21  std::string name;
22  bool is_dns{};
23  };
24 
25  x509_certificate() = default;
26  ~x509_certificate() noexcept = default;
27  x509_certificate(x509_certificate const&) = default;
28  x509_certificate(x509_certificate&&) noexcept = default;
29  x509_certificate& operator=(x509_certificate const&) = default;
30  x509_certificate& operator=(x509_certificate&&) noexcept = default;
31 
33  std::vector<uint8_t> const& rawData,
34  fz::datetime const& activation_time, fz::datetime const& expiration_time,
35  std::string const& serial,
36  std::string const& pkalgoname, unsigned int bits,
37  std::string const& signalgoname,
38  std::string const& fingerprint_sha256,
39  std::string const& fingerprint_sha1,
40  std::string const& issuer,
41  std::string const& subject,
42  std::vector<subject_name> const& alt_subject_names,
43  bool const self_signed);
44 
46  std::vector<uint8_t> && rawdata,
47  fz::datetime const& activation_time, fz::datetime const& expiration_time,
48  std::string const& serial,
49  std::string const& pkalgoname, unsigned int bits,
50  std::string const& signalgoname,
51  std::string const& fingerprint_sha256,
52  std::string const& fingerprint_sha1,
53  std::string const& issuer,
54  std::string const& subject,
55  std::vector<subject_name> && alt_subject_names,
56  bool const self_Signed);
57 
58 
60  std::vector<uint8_t> get_raw_data() const { return raw_cert_; }
61 
62  fz::datetime const& get_activation_time() const { return activation_time_; }
63  fz::datetime const& get_expiration_time() const { return expiration_time_; }
64 
65  std::string const& get_serial() const { return serial_; }
66 
68  std::string const& get_pubkey_algorithm() const { return pkalgoname_; }
69 
71  unsigned int get_pubkey_bits() const { return pkalgobits_; }
72 
74  std::string const& get_signature_algorithm() const { return signalgoname_; }
75 
77  std::string const& get_fingerprint_sha256() const { return fingerprint_sha256_; }
78 
80  std::string const& get_fingerprint_sha1() const { return fingerprint_sha1_; }
81 
86  std::string const& get_subject() const { return subject_; }
87 
89  std::string const& get_issuer() const { return issuer_; }
90 
92  std::vector<subject_name> const& get_alt_subject_names() const { return alt_subject_names_; }
93 
94  explicit operator bool() const { return !raw_cert_.empty(); }
95 
97  bool self_signed() const { return self_signed_; }
98 
99 private:
100  fz::datetime activation_time_;
101  fz::datetime expiration_time_;
102 
103  std::vector<uint8_t> raw_cert_;
104 
105  std::string serial_;
106  std::string pkalgoname_;
107  unsigned int pkalgobits_{};
108 
109  std::string signalgoname_;
110 
111  std::string fingerprint_sha256_;
112  std::string fingerprint_sha1_;
113 
114  std::string issuer_;
115  std::string subject_;
116 
117  std::vector<subject_name> alt_subject_names_;
118 
119  bool self_signed_{};
120 };
121 
131 class tls_session_info final
132 {
133 public:
134  tls_session_info() = default;
135  ~tls_session_info() = default;
136  tls_session_info(tls_session_info const&) = default;
137  tls_session_info(tls_session_info&&) noexcept = default;
138  tls_session_info& operator=(tls_session_info const&) = default;
139  tls_session_info& operator=(tls_session_info&&) noexcept = default;
140 
141  tls_session_info(std::string const& host, unsigned int port,
142  std::string const& protocol,
143  std::string const& key_exchange,
144  std::string const& session_cipher,
145  std::string const& session_mac,
146  int algorithm_warnings,
147  std::vector<x509_certificate>&& certificates,
148  bool system_trust,
149  bool hostname_mismatch);
150 
152  std::string const& get_host() const { return host_; }
153 
155  unsigned int get_port() const { return port_; }
156 
158  std::string const& get_session_cipher() const { return session_cipher_; }
159 
161  std::string const& get_session_mac() const { return session_mac_; }
162 
170  std::vector<fz::x509_certificate> const& get_certificates() const { return certificates_; }
171 
173  std::string const& get_protocol() const { return protocol_; }
174 
176  std::string const& get_key_exchange() const { return key_exchange_; }
177 
178  enum algorithm_warnings_t
179  {
180  tlsver = 1,
181  cipher = 2,
182  mac = 4,
183  kex = 8
184  };
185 
187  int get_algorithm_warnings() const { return algorithm_warnings_; }
188 
191  bool system_trust() const { return system_trust_; }
192 
194  bool mismatched_hostname() const { return hostname_mismatch_; }
195 
196 private:
197  std::string host_;
198  unsigned int port_{};
199 
200  std::string protocol_;
201  std::string key_exchange_;
202  std::string session_cipher_;
203  std::string session_mac_;
204  int algorithm_warnings_{};
205 
206  std::vector<x509_certificate> certificates_;
207 
208  bool system_trust_{};
209  bool hostname_mismatch_{};
210 };
211 }
212 
213 #endif
std::string const & get_signature_algorithm() const
The algorithm used for signing, typically the public key algorithm combined with a hash.
Definition: tls_info.hpp:74
Represents all relevant information of a X.509 certificate as used by TLS.
Definition: tls_info.hpp:14
std::string const & get_subject() const
Gets the subject of the certificate as RDN as described in RFC4514.
Definition: tls_info.hpp:86
std::vector< fz::x509_certificate > const & get_certificates() const
The server's certificate chain.
Definition: tls_info.hpp:170
Information about a TLS session.
Definition: tls_info.hpp:131
std::string const & get_pubkey_algorithm() const
The public key algorithm used by the certificate.
Definition: tls_info.hpp:68
std::string const & get_session_cipher() const
The symmetric algorithm used to encrypt all exchanged application data.
Definition: tls_info.hpp:158
std::string const & get_protocol() const
TLS version.
Definition: tls_info.hpp:173
std::string const & get_session_mac() const
The MAC used for integrity-protect and authenticate the exchanged application data.
Definition: tls_info.hpp:161
std::string const & get_fingerprint_sha256() const
Gets fingerprint as hex-encoded sha256.
Definition: tls_info.hpp:77
unsigned int get_pubkey_bits() const
The number of bits of the public key algorithm.
Definition: tls_info.hpp:71
std::vector< subject_name > const & get_alt_subject_names() const
Gets the alternative subject names (SANSs) of the certificated, usually hostnames.
Definition: tls_info.hpp:92
bool system_trust() const
Definition: tls_info.hpp:191
std::string const & get_fingerprint_sha1() const
Gets fingerprint as hex-encoded sha1.
Definition: tls_info.hpp:80
Represents a point of time in wallclock, tracking the timestamps accuracy/precision.
Definition: time.hpp:40
Assorted classes dealing with time.
std::string const & get_key_exchange() const
Key exchange algorithm.
Definition: tls_info.hpp:176
A subject name, typically a DNS hostname.
Definition: tls_info.hpp:18
std::vector< uint8_t > get_raw_data() const
The raw, DER-encoded X.509 certificate.
Definition: tls_info.hpp:60
int get_algorithm_warnings() const
Warnings about old algorithms used, which are considered weak.
Definition: tls_info.hpp:187
unsigned int get_port() const
The server's port.
Definition: tls_info.hpp:155
std::string const & get_issuer() const
Gets the issuer of the certificate as RDN as described in RFC4514.
Definition: tls_info.hpp:89
The namespace used by libfilezilla.
Definition: apply.hpp:17
std::string const & get_host() const
The server's hostname used to connect.
Definition: tls_info.hpp:152
bool self_signed() const
Indicates whether the certificate is self-signed.
Definition: tls_info.hpp:97
bool mismatched_hostname() const
True if the hostname in the SANs does not match the requested hostname.
Definition: tls_info.hpp:194