libfilezilla
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
tls_layer.hpp
Go to the documentation of this file.
1 #ifndef LIBFILEZILLA_TLS_LAYER_HEADER
2 #define LIBFILEZILLA_TLS_LAYER_HEADER
3 
8 #include "socket.hpp"
9 
10 namespace fz {
11 class logger_interface;
12 class tls_system_trust_store;
13 class tls_session_info;
14 
15 class tls_layer;
16 class tls_layer_impl;
17 
18 struct certificate_verification_event_type;
19 typedef simple_event<certificate_verification_event_type, tls_layer*, tls_session_info> certificate_verification_event;
20 
29 class FZ_PUBLIC_SYMBOL tls_layer final : protected event_handler, public socket_layer
30 {
31 public:
32  tls_layer(event_loop& event_loop, event_handler* evt_handler, socket_interface& layer, tls_system_trust_store * system_trust_store, logger_interface& logger);
33  virtual ~tls_layer();
34 
46  bool client_handshake(std::vector<uint8_t> const& required_certificate, std::vector<uint8_t> const& session_to_resume = std::vector<uint8_t>(), native_string const& session_hostname = native_string());
47 
61  bool client_handshake(event_handler *const verification_handler, std::vector<uint8_t> const& session_to_resume = std::vector<uint8_t>(), native_string const& session_hostname = native_string());
62 
73  bool server_handshake();
74 
85  bool server_handshake(std::vector<uint8_t> const& session_to_resume);
86 
88  std::vector<uint8_t> get_session_parameters() const;
89 
91  std::vector<uint8_t> get_raw_certificate() const;
92 
94  void set_verification_result(bool trusted);
95 
96  std::string get_protocol() const;
97 
98  std::string get_key_exchange() const;
99  std::string get_cipher() const;
100  std::string get_mac() const;
101  int get_algorithm_warnings() const;
102 
104  bool resumed_session() const;
105 
107  static std::string list_tls_ciphers(std::string const& priority);
108 
117  bool set_certificate_file(native_string const& keyfile, native_string const& certsfile, native_string const& password, bool pem = true);
118 
127  bool set_certificate(std::string const& key, std::string const& certs, native_string const& password, bool pem = true);
128 
129  static std::string get_gnutls_version();
130 
139  static std::pair<std::string, std::string> generate_selfsigned_certificate(native_string const& password, std::string const& distinguished_name, std::vector<std::string> const& hostnames);
140 
141 
142  virtual socket_state get_state() const override;
143 
144  virtual int connect(native_string const& host, unsigned int port, address_type family = address_type::unknown) override;
145 
146  virtual int read(void *buffer, unsigned int size, int& error) override;
147  virtual int write(void const* buffer, unsigned int size, int& error) override;
148 
149  virtual int shutdown() override;
150 
151  virtual int shutdown_read() override;
152 
153 private:
154  virtual void FZ_PRIVATE_SYMBOL operator()(event_base const& ev) override;
155 
156  friend class tls_layer_impl;
157  std::unique_ptr<tls_layer_impl> impl_;
158 };
159 }
160 
161 #endif
A Transport Layer Security (TLS) layer.
Definition: tls_layer.hpp:29
Interface for sockets.
Definition: socket.hpp:315
Simple handler for asynchronous event processing.
Definition: event_handler.hpp:54
Definition: tls_system_trust_store.hpp:24
Socket classes for networking.
A threaded event loop that supports sending events and timers.
Definition: event_loop.hpp:33
A base class for socket layers.
Definition: socket.hpp:511
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:33
socket_state
State transitions are monotonically increasing.
Definition: socket.hpp:283
The namespace used by libfilezilla.
Definition: apply.hpp:16
The buffer class is a simple buffer where data can be appended at the end and consumed at the front...
Definition: buffer.hpp:23
Definition: logger.hpp:37
Common base class for all events.
Definition: event.hpp:22