1 #ifndef LIBFILEZILLA_TLS_LAYER_HEADER
2 #define LIBFILEZILLA_TLS_LAYER_HEADER
11 class logger_interface;
12 class tls_system_trust_store;
13 class tls_session_info;
18 struct certificate_verification_event_type;
46 return (
static_cast<std::underlying_type_t<tls_server_flags>
>(lhs) &
static_cast<std::underlying_type_t<tls_server_flags>
>(rhs)) != 0;
49 return static_cast<tls_server_flags>(
static_cast<std::underlying_type_t<tls_server_flags>
>(lhs) |
static_cast<std::underlying_type_t<tls_server_flags>
>(rhs));
66 return (
static_cast<std::underlying_type_t<tls_client_flags>
>(lhs) &
static_cast<std::underlying_type_t<tls_client_flags>
>(rhs)) != 0;
69 return static_cast<tls_client_flags>(
static_cast<std::underlying_type_t<tls_client_flags>
>(lhs) |
static_cast<std::underlying_type_t<tls_client_flags>
>(rhs));
107 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(),
tls_client_flags flags = {});
142 bool server_handshake(std::vector<uint8_t>
const& session_to_resume = {}, std::string_view
const& preamble = {},
tls_server_flags flags = {});
145 std::vector<uint8_t> get_session_parameters()
const;
148 std::vector<uint8_t> get_raw_certificate()
const;
155 void set_verification_result(
bool trusted);
157 std::string get_protocol()
const;
159 std::string get_key_exchange()
const;
160 std::string get_cipher()
const;
161 std::string get_mac()
const;
162 int get_algorithm_warnings()
const;
165 bool resumed_session()
const;
168 static std::string list_tls_ciphers(std::string
const& priority);
188 bool set_certificate(std::string_view
const& key, std::string_view
const& certs,
native_string const& password,
bool pem =
true);
191 static std::string get_gnutls_version();
209 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, cert_type type = cert_type::any,
bool ecsda =
true);
212 static std::pair<std::string, std::string> generate_ca_certificate(
native_string const& password, std::string
const& distinguished_name,
duration const& lifetime = {},
bool ecdsa =
true);
215 static std::pair<std::string, std::string> generate_csr(
native_string const& password, std::string
const& distinguished_name, std::vector<std::string>
const& hostnames,
bool csr_as_pem =
true, cert_type type = cert_type::any);
222 static std::string generate_cert_from_csr(std::pair<std::string, std::string>
const& issuer,
native_string const& password, std::string
const& csr, std::string
const& distinguished_name = {}, std::vector<std::string>
const& hostnames = {}, duration
const& lifetime = {}, cert_type type = cert_type::any);
236 bool set_alpn(std::string_view
const& alpn);
237 bool set_alpn(std::vector<std::string>
const& alpns,
bool server_priority =
false);
241 void set_min_tls_ver(tls_ver ver);
247 void set_max_tls_ver(tls_ver ver);
250 std::string get_alpn()
const;
255 bool is_server()
const;
265 int new_session_ticket();
280 void set_unexpected_eof_cb(std::function<
bool()>
const& cb);
281 void set_unexpected_eof_cb(std::function<
bool()> && cb);
285 virtual int connect(
native_string const& host,
unsigned int port, address_type family = address_type::unknown)
override;
287 virtual int read(
void *buffer,
unsigned int size,
int&
error)
override;
288 virtual int write(
void const* buffer,
unsigned int size,
int&
error)
override;
290 virtual int shutdown()
override;
292 virtual int shutdown_read()
override;
297 virtual void FZ_PRIVATE_SYMBOL operator()(event_base
const& ev)
override;
299 friend class tls_layer_impl;
300 std::unique_ptr<tls_layer_impl> impl_;
tls_client_flags
Definition: tls_layer.hpp:57
Data has become available.
tls_server_flags
Definition: tls_layer.hpp:34
A Transport Layer Security (TLS) layer.
Definition: tls_layer.hpp:90
Interface for sockets.
Definition: socket.hpp:374
Used in unit tests. Don't use in production.
Simple handler for asynchronous event processing.
Definition: event_handler.hpp:54
This is the recommended event class.
Definition: event.hpp:67
Opaque class to load the system trust store asynchronously.
Definition: tls_system_trust_store.hpp:29
cert_type
Type of certificate to create.
Definition: tls_layer.hpp:194
simple_event< certificate_verification_event_type, tls_layer *, tls_session_info > certificate_verification_event
This event gets sent during the handshake with details about the session and the used certificate...
Definition: tls_layer.hpp:18
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:653
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:34
socket_state
State transitions are monotonically increasing.
Definition: socket.hpp:342
The namespace used by libfilezilla.
Definition: apply.hpp:17
The duration class represents a time interval in milliseconds.
Definition: time.hpp:290
EC key type with P-256 as algorithm.
In TLS 1.3, do not automatically send PSKs after finishing handshake. Ignored if not TLS 1...
Abstract interface for logging strings.
Definition: logger.hpp:50
socket_event_flag
The type of a socket event.
Definition: socket.hpp:34