62#include "xtc_export.h"
75#if defined(XTC_TLS_BACKEND_OPENSSL) || \
76 defined(XTC_TLS_BACKEND_MBEDTLS) || \
77 defined(XTC_TLS_BACKEND_GNUTLS) || \
78 defined(XTC_TLS_BACKEND_WOLFSSL) || \
79 defined(XTC_TLS_BACKEND_SCHANNEL)
80#define XTC_TLS_ENABLED 1
99typedef struct xtc_tls_ctx xtc_tls_ctx_t;
107typedef struct xtc_tls xtc_tls_t;
113typedef enum xtc_tls_role {
122#define XTC_TLS_VER_12 0x0303
123#define XTC_TLS_VER_13 0x0304
136typedef enum xtc_tls_verify_mode {
137 XTC_TLS_VERIFY_DEFAULT = 0,
139 XTC_TLS_VERIFY_REQUEST,
140 XTC_TLS_VERIFY_REQUIRE
141} xtc_tls_verify_mode_t;
153typedef int (*xtc_tls_passphrase_cb_t)(
char *buf,
int size,
void *userdata);
222typedef struct xtc_tls_opts {
223 const char *cert_file;
224 const char *key_file;
227 const char *alpn_protos;
234 xtc_tls_verify_mode_t verify_peer_mode;
235 const char *cipher_list;
236 const char *ciphersuites_13;
238 const char *crl_file;
240 int prefer_server_ciphers;
241 xtc_tls_passphrase_cb_t passphrase_cb;
242 void *passphrase_userdata;
270XTC_API
int xtc_tls_ctx_create(xtc_tls_role_t role,
272 xtc_tls_ctx_t **out);
287XTC_API
void xtc_tls_ctx_destroy(xtc_tls_ctx_t *ctx);
316XTC_API
int xtc_tls_create(xtc_tls_ctx_t *ctx,
int fd, xtc_tls_t **out);
347typedef xtc_tls_ctx_t *(*xtc_tls_sni_cb_t)(xtc_tls_t *tls,
348 const char *server_name,
355XTC_API
int xtc_tls_ctx_set_sni_cb(xtc_tls_ctx_t *ctx,
356 xtc_tls_sni_cb_t cb,
void *userdata);
386typedef struct xtc_tls_transport {
387 int (*read_cb)(
void *userdata,
void *buf,
size_t len);
388 int (*write_cb)(
void *userdata,
const void *buf,
size_t len);
397XTC_API
int xtc_tls_create_transport(xtc_tls_ctx_t *ctx,
416XTC_API
int xtc_tls_set_hostname(xtc_tls_t *tls,
const char *name);
425XTC_API
void xtc_tls_destroy(xtc_tls_t *tls);
451XTC_API
int xtc_tls_handshake(xtc_tls_t *tls);
471XTC_API
int xtc_tls_read(xtc_tls_t *tls,
void *buf,
size_t buflen,
size_t *out_n);
482XTC_API
int xtc_tls_write(xtc_tls_t *tls,
const void *buf,
size_t buflen,
495XTC_API
int xtc_tls_wants_read(
const xtc_tls_t *tls);
503XTC_API
int xtc_tls_wants_write(
const xtc_tls_t *tls);
524XTC_API
int xtc_tls_shutdown(xtc_tls_t *tls);
555XTC_API
const char *xtc_tls_get_version(
const xtc_tls_t *tls);
558XTC_API
const char *xtc_tls_get_cipher(
const xtc_tls_t *tls);
561XTC_API
int xtc_tls_get_cipher_bits(
const xtc_tls_t *tls);
570XTC_API
int xtc_tls_get_alpn_selected(
const xtc_tls_t *tls,
571 const unsigned char **out,
unsigned int *len);
574XTC_API
int xtc_tls_has_peer_cert(
const xtc_tls_t *tls);
588XTC_API
int xtc_tls_get_verify_error(
const xtc_tls_t *tls,
long *x509_err,
589 char *buf,
size_t len);
601XTC_API
int xtc_tls_get_peer_subject_dn(
const xtc_tls_t *tls,
char *buf,
size_t len);
602XTC_API
int xtc_tls_get_peer_common_name(
const xtc_tls_t *tls,
char *buf,
size_t len);
603XTC_API
int xtc_tls_get_peer_issuer_dn(
const xtc_tls_t *tls,
char *buf,
size_t len);
606XTC_API
int xtc_tls_get_peer_serial(
const xtc_tls_t *tls,
char *buf,
size_t len);
618XTC_API
int xtc_tls_get_server_cert_hash(
const xtc_tls_t *tls,
619 unsigned char *buf,
size_t buflen,
size_t *out_len);