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 {
11 class logger_interface;
12 
16 class x509_certificate final
17 {
18 public:
20  class subject_name final
21  {
22  public:
23  std::string name;
24  bool is_dns{};
25  };
26 
27  x509_certificate() = default;
28  ~x509_certificate() noexcept = default;
29  x509_certificate(x509_certificate const&) = default;
30  x509_certificate(x509_certificate&&) noexcept = default;
31  x509_certificate& operator=(x509_certificate const&) = default;
32  x509_certificate& operator=(x509_certificate&&) noexcept = default;
33 
35  std::vector<uint8_t> const& rawData,
36  fz::datetime const& activation_time, fz::datetime const& expiration_time,
37  std::string const& serial,
38  std::string const& pkalgoname, unsigned int bits,
39  std::string const& signalgoname,
40  std::string const& fingerprint_sha256,
41  std::string const& fingerprint_sha1,
42  std::string const& issuer,
43  std::string const& subject,
44  std::vector<subject_name> const& alt_subject_names,
45  bool const self_signed);
46 
48  std::vector<uint8_t> && rawdata,
49  fz::datetime const& activation_time, fz::datetime const& expiration_time,
50  std::string const& serial,
51  std::string const& pkalgoname, unsigned int bits,
52  std::string const& signalgoname,
53  std::string const& fingerprint_sha256,
54  std::string const& fingerprint_sha1,
55  std::string const& issuer,
56  std::string const& subject,
57  std::vector<subject_name> && alt_subject_names,
58  bool const self_Signed);
59 
60 
62  std::vector<uint8_t> get_raw_data() const { return raw_cert_; }
63 
64  fz::datetime const& get_activation_time() const { return activation_time_; }
65  fz::datetime const& get_expiration_time() const { return expiration_time_; }
66 
67  std::string const& get_serial() const { return serial_; }
68 
70  std::string const& get_pubkey_algorithm() const { return pkalgoname_; }
71 
73  unsigned int get_pubkey_bits() const { return pkalgobits_; }
74 
76  std::string const& get_signature_algorithm() const { return signalgoname_; }
77 
79  std::string const& get_fingerprint_sha256() const { return fingerprint_sha256_; }
80 
82  std::string const& get_fingerprint_sha1() const { return fingerprint_sha1_; }
83 
88  std::string const& get_subject() const { return subject_; }
89 
91  std::string const& get_issuer() const { return issuer_; }
92 
94  std::vector<subject_name> const& get_alt_subject_names() const { return alt_subject_names_; }
95 
96  explicit operator bool() const { return !raw_cert_.empty(); }
97 
99  bool self_signed() const { return self_signed_; }
100 
101 private:
102  fz::datetime activation_time_;
103  fz::datetime expiration_time_;
104 
105  std::vector<uint8_t> raw_cert_;
106 
107  std::string serial_;
108  std::string pkalgoname_;
109  unsigned int pkalgobits_{};
110 
111  std::string signalgoname_;
112 
113  std::string fingerprint_sha256_;
114  std::string fingerprint_sha1_;
115 
116  std::string issuer_;
117  std::string subject_;
118 
119  std::vector<subject_name> alt_subject_names_;
120 
121  bool self_signed_{};
122 };
123 
131 std::vector<x509_certificate> FZ_PUBLIC_SYMBOL load_certificates_file(native_string const& certsfile, bool pem, bool sort, logger_interface * logger = nullptr);
132 std::vector<x509_certificate> FZ_PUBLIC_SYMBOL load_certificates(std::string_view const& certdata, bool pem, bool sort, logger_interface * logger = nullptr);
133 
143 class tls_session_info final
144 {
145 public:
146  tls_session_info() = default;
147  ~tls_session_info() = default;
148  tls_session_info(tls_session_info const&) = default;
149  tls_session_info(tls_session_info&&) noexcept = default;
150  tls_session_info& operator=(tls_session_info const&) = default;
151  tls_session_info& operator=(tls_session_info&&) noexcept = default;
152 
153  tls_session_info(std::string const& host, unsigned int port,
154  std::string const& protocol,
155  std::string const& key_exchange,
156  std::string const& session_cipher,
157  std::string const& session_mac,
158  int algorithm_warnings,
159  std::vector<x509_certificate>&& certificates,
160  bool system_trust,
161  bool hostname_mismatch);
162 
164  std::string const& get_host() const { return host_; }
165 
167  unsigned int get_port() const { return port_; }
168 
170  std::string const& get_session_cipher() const { return session_cipher_; }
171 
173  std::string const& get_session_mac() const { return session_mac_; }
174 
182  std::vector<fz::x509_certificate> const& get_certificates() const { return certificates_; }
183 
185  std::string const& get_protocol() const { return protocol_; }
186 
188  std::string const& get_key_exchange() const { return key_exchange_; }
189 
190  enum algorithm_warnings_t
191  {
192  tlsver = 1,
193  cipher = 2,
194  mac = 4,
195  kex = 8
196  };
197 
199  int get_algorithm_warnings() const { return algorithm_warnings_; }
200 
203  bool system_trust() const { return system_trust_; }
204 
206  bool mismatched_hostname() const { return hostname_mismatch_; }
207 
208 private:
209  std::string host_;
210  unsigned int port_{};
211 
212  std::string protocol_;
213  std::string key_exchange_;
214  std::string session_cipher_;
215  std::string session_mac_;
216  int algorithm_warnings_{};
217 
218  std::vector<x509_certificate> certificates_;
219 
220  bool system_trust_{};
221  bool hostname_mismatch_{};
222 };
223 }
224 
225 #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:76
Represents all relevant information of a X.509 certificate as used by TLS.
Definition: tls_info.hpp:16
std::string const & get_subject() const
Gets the subject of the certificate as RDN as described in RFC4514.
Definition: tls_info.hpp:88
std::vector< fz::x509_certificate > const & get_certificates() const
The server&#39;s certificate chain.
Definition: tls_info.hpp:182
Information about a TLS session.
Definition: tls_info.hpp:143
std::string const & get_pubkey_algorithm() const
The public key algorithm used by the certificate.
Definition: tls_info.hpp:70
std::string const & get_session_cipher() const
The symmetric algorithm used to encrypt all exchanged application data.
Definition: tls_info.hpp:170
std::string const & get_protocol() const
TLS version.
Definition: tls_info.hpp:185
std::string const & get_session_mac() const
The MAC used for integrity-protect and authenticate the exchanged application data.
Definition: tls_info.hpp:173
std::string const & get_fingerprint_sha256() const
Gets fingerprint as hex-encoded sha256.
Definition: tls_info.hpp:79
std::vector< x509_certificate > load_certificates_file(native_string const &certsfile, bool pem, bool sort, logger_interface *logger=nullptr)
Gets the certificate information for the certificates in the file.
unsigned int get_pubkey_bits() const
The number of bits of the public key algorithm.
Definition: tls_info.hpp:73
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:94
bool system_trust() const
Definition: tls_info.hpp:203
std::string const & get_fingerprint_sha1() const
Gets fingerprint as hex-encoded sha1.
Definition: tls_info.hpp:82
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:188
A subject name, typically a DNS hostname.
Definition: tls_info.hpp:20
std::vector< uint8_t > get_raw_data() const
The raw, DER-encoded X.509 certificate.
Definition: tls_info.hpp:62
int get_algorithm_warnings() const
Warnings about old algorithms used, which are considered weak.
Definition: tls_info.hpp:199
unsigned int get_port() const
The server&#39;s port.
Definition: tls_info.hpp:167
std::wstring native_string
A string in the system&#39;s native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:33
std::string const & get_issuer() const
Gets the issuer of the certificate as RDN as described in RFC4514.
Definition: tls_info.hpp:91
The namespace used by libfilezilla.
Definition: apply.hpp:17
std::string const & get_host() const
The server&#39;s hostname used to connect.
Definition: tls_info.hpp:164
bool self_signed() const
Indicates whether the certificate is self-signed.
Definition: tls_info.hpp:99
bool mismatched_hostname() const
True if the hostname in the SANs does not match the requested hostname.
Definition: tls_info.hpp:206