mod_servlet
C++Servlets
 All Classes Files Functions Variables Typedefs Macros Pages
ssl.h
1 /*
2 Copyright (c) 2016 Alexei Novakov
3 https://github.com/novalexei
4 
5 Distributed under the Boost Software License, Version 1.0.
6 http://boost.org/LICENSE_1_0.txt
7 */
8 #ifndef MOD_SERVLET_SSL_H
9 #define MOD_SERVLET_SSL_H
10 
11 #include <vector>
12 #include <chrono>
13 #include <map>
14 #include <experimental/string_view>
15 
16 namespace servlet
17 {
18 
19 using std::experimental::string_view;
20 
29 {
30 public:
34  typedef std::chrono::time_point<std::chrono::system_clock, typename std::chrono::system_clock::duration> time_type;
35 
39  virtual ~certificate() noexcept {};
40 
51  virtual int version() const = 0;
52 
69  virtual string_view serial_number() const = 0;
70 
91  virtual time_type valid_since() const = 0;
92 
113  virtual time_type valid_until() const = 0;
114 
136  virtual bool check_valid() const = 0;
137 
149  virtual bool check_valid(time_type time) const = 0;
150 
172  virtual string_view signature_algorithm_name() const = 0;
173 
179  virtual string_view key_algorithm_name() const = 0;
180 
188  virtual string_view subject_DN() const = 0;
189 
197  virtual const std::map<string_view, string_view, std::less<>>& subject_DN_components() const = 0;
198 
206  virtual string_view issuer_DN() const = 0;
207 
215  virtual const std::map<string_view, string_view, std::less<>>& issuer_DN_components() const = 0;
216 
274  virtual const std::map<string_view, std::vector<string_view>, std::less<>>& subject_alternative_names() const = 0;
275 
284  virtual string_view certificate_exact_assertion() const = 0;
285 
292  virtual const std::vector<string_view>& certificate_chain() const = 0;
293 
299  virtual string_view PEM_encoded() const = 0;
300 };
301 
305 enum class SSL_SESSION_STATE
306 {
310  INITIAL,
314  RESUMED
315 };
316 
325 template<typename CharT, typename Traits>
326 std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& out, SSL_SESSION_STATE ss)
327 {
328  switch (ss)
329  {
330  case SSL_SESSION_STATE::INITIAL: out << "INITIAL"; break;
331  case SSL_SESSION_STATE::RESUMED: out << "RESUMED"; break;
332  }
333  return out;
334 }
335 
355 {
356 public:
360  virtual ~SSL_information() noexcept {}
361 
366  virtual string_view protocol() const = 0;
367 
372  virtual string_view cipher_name() const = 0;
373 
378  virtual bool is_cipher_export() const = 0;
379 
385  virtual int cipher_used_bits() const = 0;
386 
394  virtual int cipher_possible_bits() const = 0;
395 
400  virtual string_view compress_method() const = 0;
401 
406  virtual string_view session_id() const = 0;
407 
414  virtual SSL_SESSION_STATE session_state() const = 0;
415 
422  virtual const certificate& client_certificate() const = 0;
423 
430  virtual const certificate& server_certificate() const = 0;
431 };
432 
433 } // end of servlet namespace
434 
435 #endif // MOD_SERVLET_SSL_H
virtual const certificate & server_certificate() const =0
Returns object containing available information for server certificate.
virtual time_type valid_since() const =0
Gets the notBefore date from the validity period of the certificate.
Class encapsulates availble information about current SSL session.
Definition: ssl.h:354
virtual ~SSL_information() noexcept
Destructor.
Definition: ssl.h:360
virtual string_view certificate_exact_assertion() const =0
Serial number and issuer of the certificate.
virtual const std::map< string_view, string_view, std::less<> > & subject_DN_components() const =0
Returns components of the subject (subject distinguished name) value from the certificate.
virtual const std::map< string_view, std::vector< string_view >, std::less<> > & subject_alternative_names() const =0
Gets an immutable collection of subject alternative names from the SubjectAltName extension...
virtual string_view compress_method() const =0
Returns SSL compression method negotiated.
virtual string_view PEM_encoded() const =0
Returns PEM (Privacy Enhanced Mail) encoded certificate string.
virtual const std::vector< string_view > & certificate_chain() const =0
Returns PEM (Privacy Enhanced Mail) encoded certificates in client certificate chain.
virtual string_view key_algorithm_name() const =0
Gets the public key algorithm name.
virtual bool check_valid() const =0
Checks that the certificate is currently valid.
virtual ~certificate() noexcept
Destructor.
Definition: ssl.h:39
virtual int cipher_used_bits() const =0
Returns number of bits used in the cipher.
virtual string_view serial_number() const =0
Gets the serialNumber value from the certificate.
virtual const std::map< string_view, string_view, std::less<> > & issuer_DN_components() const =0
Returns components of the issuer (subject distinguished name) value from the certificate.
std::chrono::time_point< std::chrono::system_clock, typename std::chrono::system_clock::duration > time_type
time_point type to be used for date representation in this class
Definition: ssl.h:34
Abstract class holding available information regarding client or server security certificate.
Definition: ssl.h:28
virtual string_view cipher_name() const =0
The cipher specification name (e.q.
virtual time_type valid_until() const =0
Gets the notAfter date from the validity period of the certificate.
virtual string_view signature_algorithm_name() const =0
Gets the signature algorithm name for the certificate signature algorithm.
virtual string_view subject_DN() const =0
Returns the subject (subject distinguished name) value from the certificate.
virtual SSL_SESSION_STATE session_state() const =0
Returns the state of the SSL session.
virtual string_view protocol() const =0
The SSL protocol version (e.q.
virtual string_view issuer_DN() const =0
Returns the issuer (subject distinguished name) value from the certificate.
virtual const certificate & client_certificate() const =0
Returns object containing available information for client certificate.
virtual int version() const =0
Gets the version (version number) value from the certificate.
virtual int cipher_possible_bits() const =0
Returns number of bits which could possible be used in the cipher.
virtual string_view session_id() const =0
The hex-encoded SSL session id if any available.
virtual bool is_cipher_export() const =0
Returns true if the cipher is an export cipher.