mirror of
http://git.haproxy.org/git/haproxy.git
synced 2026-02-15 10:41:58 +02:00
MINOR: quic: QUIC openssl wrapper implementation
Highly inspired from nginx openssl wrapper code. This wrapper implement this list of functions: SSL_set_quic_method(), SSL_quic_read_level(), SSL_quic_write_level(), SSL_set_quic_transport_params(), SSL_provide_quic_data(), SSL_process_quic_post_handshake() and SSL_QUIC_METHOD QUIC specific bio method which are also implemented by quictls to support QUIC from OpenSSL. So, its aims is to support QUIC from a standard OpenSSL stack without QUIC support. It relies on the OpenSSL keylog feature to retreive the secrets derived by the OpenSSL stack during a handshake and to pass them to the ->set_encryption_secrets() callback as this is done by quictls. It makes usage of a callback (quic_tls_compat_msg_callback()) to handle some TLS messages only on the receipt path. Some of them must be passed to the ->add_handshake_data() callback as this is done with quictls to be sent to the peer as CRYPTO data. quic_tls_compat_msg_callback() callback also sends the received TLS alert with ->send_alert() callback. AES 128-bits with CCM mode is not supported at this time. It is often disabled by the OpenSSL stack, but as it can be enabled by "ssl-default-bind-ciphersuites", the wrapper will send a TLS alerts (Handhshake failure) if this algorithm is negotiated between the client and the server. 0rtt is also not supported by this wrapper.
This commit is contained in:
@@ -231,6 +231,7 @@ enum quic_pkt_type {
|
||||
#define QUIC_EV_CONN_RCV (1ULL << 48)
|
||||
#define QUIC_EV_CONN_KILL (1ULL << 49)
|
||||
#define QUIC_EV_CONN_KP (1ULL << 50)
|
||||
#define QUIC_EV_CONN_SSL_COMPAT (1ULL << 51)
|
||||
#define QUIC_EV_CONN_SET_AFFINITY (1ULL << 52)
|
||||
|
||||
/* Similar to kernel min()/max() definitions. */
|
||||
|
||||
64
include/haproxy/quic_openssl_compat-t.h
Normal file
64
include/haproxy/quic_openssl_compat-t.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef _HAPROXY_QUIC_OPENSSL_COMPAT_T_H_
|
||||
#define _HAPROXY_QUIC_OPENSSL_COMPAT_T_H_
|
||||
|
||||
#ifdef USE_QUIC_OPENSSL_COMPAT
|
||||
#ifndef USE_OPENSSL
|
||||
#error "Must define USE_OPENSSL"
|
||||
#endif
|
||||
|
||||
#define QUIC_OPENSSL_COMPAT_TLS_SECRET_LEN 48
|
||||
#define QUIC_OPENSSL_COMPAT_TLS_IV_LEN 12
|
||||
|
||||
/* Highly inspired from nginx QUIC TLS compatibilty code */
|
||||
|
||||
enum ssl_encryption_level_t {
|
||||
ssl_encryption_initial = 0,
|
||||
ssl_encryption_early_data,
|
||||
ssl_encryption_handshake,
|
||||
ssl_encryption_application
|
||||
};
|
||||
|
||||
typedef struct ssl_quic_method_st {
|
||||
int (*set_encryption_secrets)(SSL *ssl, enum ssl_encryption_level_t level,
|
||||
const uint8_t *rsecret, const uint8_t *wsecret,
|
||||
size_t secret_len);
|
||||
int (*add_handshake_data)(SSL *ssl, enum ssl_encryption_level_t level,
|
||||
const uint8_t *data, size_t len);
|
||||
int (*flush_flight)(SSL *ssl);
|
||||
int (*send_alert)(SSL *ssl, enum ssl_encryption_level_t level,
|
||||
uint8_t alert);
|
||||
} SSL_QUIC_METHOD;
|
||||
|
||||
struct quic_tls_md {
|
||||
unsigned char data[QUIC_OPENSSL_COMPAT_TLS_SECRET_LEN];
|
||||
size_t len;
|
||||
};
|
||||
|
||||
struct quic_tls_iv {
|
||||
unsigned char data[QUIC_OPENSSL_COMPAT_TLS_IV_LEN];
|
||||
size_t len;
|
||||
};
|
||||
|
||||
struct quic_tls_secret {
|
||||
struct quic_tls_md secret;
|
||||
struct quic_tls_md key;
|
||||
struct quic_tls_iv iv;
|
||||
};
|
||||
|
||||
struct quic_tls_compat_keys {
|
||||
struct quic_tls_secret secret;
|
||||
const EVP_CIPHER *cipher;
|
||||
};
|
||||
|
||||
struct quic_openssl_compat {
|
||||
BIO *rbio;
|
||||
BIO *wbio;
|
||||
const SSL_QUIC_METHOD *method;
|
||||
enum ssl_encryption_level_t write_level;
|
||||
enum ssl_encryption_level_t read_level;
|
||||
uint64_t read_record;
|
||||
struct quic_tls_compat_keys keys;
|
||||
};
|
||||
|
||||
#endif /* USE_QUIC_OPENSSL_COMPAT */
|
||||
#endif /* _HAPROXY_QUIC_OPENSSL_COMPAT_T_H_ */
|
||||
30
include/haproxy/quic_openssl_compat.h
Normal file
30
include/haproxy/quic_openssl_compat.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef _HAPROXY_QUIC_OPENSSL_COMPAT_H_
|
||||
#define _HAPROXY_QUIC_OPENSSL_COMPAT_H_
|
||||
|
||||
#ifdef USE_QUIC_OPENSSL_COMPAT
|
||||
|
||||
/* Highly inspired from nginx QUIC TLS compatibilty code */
|
||||
#include <haproxy/listener-t.h>
|
||||
#include <haproxy/quic_openssl_compat-t.h>
|
||||
|
||||
#define QUIC_OPENSSL_COMPAT_SSL_TP_EXT 0x39
|
||||
|
||||
/* Used by keylog */
|
||||
#define QUIC_OPENSSL_COMPAT_CLIENT_HANDSHAKE "CLIENT_HANDSHAKE_TRAFFIC_SECRET"
|
||||
#define QUIC_OPENSSL_COMPAT_SERVER_HANDSHAKE "SERVER_HANDSHAKE_TRAFFIC_SECRET"
|
||||
#define QUIC_OPENSSL_COMPAT_CLIENT_APPLICATION "CLIENT_TRAFFIC_SECRET_0"
|
||||
#define QUIC_OPENSSL_COMPAT_SERVER_APPLICATION "SERVER_TRAFFIC_SECRET_0"
|
||||
|
||||
int quic_tls_compat_init(struct bind_conf *bind_conf, SSL_CTX *ctx);
|
||||
void quic_tls_compat_keylog_callback(const SSL *ssl, const char *line);
|
||||
|
||||
int SSL_set_quic_method(SSL *ssl, const SSL_QUIC_METHOD *quic_method);
|
||||
enum ssl_encryption_level_t SSL_quic_read_level(const SSL *ssl);
|
||||
enum ssl_encryption_level_t SSL_quic_write_level(const SSL *ssl);
|
||||
int SSL_set_quic_transport_params(SSL *ssl, const uint8_t *params, size_t params_len);
|
||||
int SSL_provide_quic_data(SSL *ssl, enum ssl_encryption_level_t level,
|
||||
const uint8_t *data, size_t len);
|
||||
int SSL_process_quic_post_handshake(SSL *ssl);
|
||||
|
||||
#endif /* USE_QUIC_OPENSSL_COMPAT */
|
||||
#endif /* _HAPROXY_QUIC_OPENSSL_COMPAT_H_ */
|
||||
Reference in New Issue
Block a user