63#include "xtc_export.h"
76#if defined(XTC_TLS_BACKEND_OPENSSL) || \
77 defined(XTC_TLS_BACKEND_MBEDTLS) || \
78 defined(XTC_TLS_BACKEND_GNUTLS) || \
79 defined(XTC_TLS_BACKEND_WOLFSSL) || \
80 defined(XTC_TLS_BACKEND_SCHANNEL)
81#define XTC_TLS_ENABLED 1
100typedef struct xtc_tls_ctx xtc_tls_ctx_t;
108typedef struct xtc_tls xtc_tls_t;
114typedef enum xtc_tls_role {
123#define XTC_TLS_VER_12 0x0303
124#define XTC_TLS_VER_13 0x0304
155typedef enum xtc_tls_verify_mode {
156 XTC_TLS_VERIFY_DEFAULT = 0,
158 XTC_TLS_VERIFY_REQUEST,
159 XTC_TLS_VERIFY_REQUIRE
160} xtc_tls_verify_mode_t;
172typedef int (*xtc_tls_passphrase_cb_t)(
char *buf,
int size,
void *userdata);
256typedef struct xtc_tls_opts {
258 const char *cert_file;
259 const char *key_file;
261 const char *alpn_protos;
263 xtc_tls_verify_mode_t verify_peer_mode;
266 const char *cipher_list;
267 const char *ciphersuites_13;
269 const char *crl_file;
271 int prefer_server_ciphers;
272 xtc_tls_passphrase_cb_t passphrase_cb;
273 void *passphrase_userdata;
277#define XTC_TLS_OPTS_INIT { .size = sizeof(xtc_tls_opts_t) }
307XTC_API
int xtc_tls_ctx_create(xtc_tls_role_t role,
309 xtc_tls_ctx_t **out);
324XTC_API
void xtc_tls_ctx_destroy(xtc_tls_ctx_t *ctx);
353XTC_API
int xtc_tls_create(xtc_tls_ctx_t *ctx,
int fd, xtc_tls_t **out);
384typedef xtc_tls_ctx_t *(*xtc_tls_sni_cb_t)(xtc_tls_t *tls,
385 const char *server_name,
392XTC_API
int xtc_tls_ctx_set_sni_cb(xtc_tls_ctx_t *ctx,
393 xtc_tls_sni_cb_t cb,
void *userdata);
431typedef struct xtc_tls_transport {
433 int (*read_cb)(
void *userdata,
void *buf,
size_t len);
434 int (*write_cb)(
void *userdata,
const void *buf,
size_t len);
438#define XTC_TLS_TRANSPORT_INIT { .size = sizeof(xtc_tls_transport_t) }
445XTC_API
int xtc_tls_create_transport(xtc_tls_ctx_t *ctx,
470XTC_API
int xtc_tls_set_hostname(xtc_tls_t *tls,
const char *name);
519#define XTC_TLS_KTLS_TX 1
520#define XTC_TLS_KTLS_RX 2
522XTC_API
int xtc_tls_enable_ktls(xtc_tls_t *tls);
523XTC_API
int xtc_tls_ktls_active(
const xtc_tls_t *tls);
524XTC_API
int xtc_tls_sendfile(xtc_tls_t *tls,
int fd, int64_t off,
525 size_t len,
size_t *out_n);
534XTC_API
void xtc_tls_destroy(xtc_tls_t *tls);
570XTC_API
int xtc_tls_handshake(xtc_tls_t *tls);
594XTC_API
int xtc_tls_read(xtc_tls_t *tls,
void *buf,
size_t buflen,
size_t *out_n);
606XTC_API
int xtc_tls_write(xtc_tls_t *tls,
const void *buf,
size_t buflen,
619XTC_API
int xtc_tls_wants_read(
const xtc_tls_t *tls);
627XTC_API
int xtc_tls_wants_write(
const xtc_tls_t *tls);
648XTC_API
int xtc_tls_shutdown(xtc_tls_t *tls);
679XTC_API
const char *xtc_tls_get_version(
const xtc_tls_t *tls);
682XTC_API
const char *xtc_tls_get_cipher(
const xtc_tls_t *tls);
685XTC_API
int xtc_tls_get_cipher_bits(
const xtc_tls_t *tls);
694XTC_API
int xtc_tls_get_alpn_selected(
const xtc_tls_t *tls,
695 const unsigned char **out,
unsigned int *len);
698XTC_API
int xtc_tls_has_peer_cert(
const xtc_tls_t *tls);
712XTC_API
int xtc_tls_get_verify_error(
const xtc_tls_t *tls,
long *x509_err,
713 char *buf,
size_t len);
725XTC_API
int xtc_tls_get_peer_subject_dn(
const xtc_tls_t *tls,
char *buf,
size_t len);
726XTC_API
int xtc_tls_get_peer_common_name(
const xtc_tls_t *tls,
char *buf,
size_t len);
727XTC_API
int xtc_tls_get_peer_issuer_dn(
const xtc_tls_t *tls,
char *buf,
size_t len);
730XTC_API
int xtc_tls_get_peer_serial(
const xtc_tls_t *tls,
char *buf,
size_t len);
742XTC_API
int xtc_tls_get_server_cert_hash(
const xtc_tls_t *tls,
743 unsigned char *buf,
size_t buflen,
size_t *out_len);