cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
ssl.h
Go to the documentation of this file.
1
29#ifndef CWIST_SHIM_OPENSSL_SSL_H
30#define CWIST_SHIM_OPENSSL_SSL_H
31
32#include <stddef.h>
33#include <stdint.h>
34
35#include <openssl/evp.h>
36#include <openssl/hmac.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/* Opaque backend objects. Definitions live in backend_mbedtls.c. */
43typedef struct cwist_mtls_ctx SSL_CTX;
44typedef struct cwist_mtls_ssl SSL;
45typedef struct cwist_mtls_method SSL_METHOD;
46
47/* Protocol version codes (wire values, as in OpenSSL). */
48#define TLS1_2_VERSION 0x0303
49#define TLS1_3_VERSION 0x0304
50
51/* SSL_get_error() result codes (values match OpenSSL). */
52#define SSL_ERROR_NONE 0
53#define SSL_ERROR_SSL 1
54#define SSL_ERROR_WANT_READ 2
55#define SSL_ERROR_WANT_WRITE 3
56#define SSL_ERROR_SYSCALL 5
57#define SSL_ERROR_ZERO_RETURN 6
58
59/* SSL_CTX_set_options() flags. Compression and renegotiation are always off
60 * in the mbedTLS backend, so the corresponding flags are accepted as no-ops;
61 * SSL_OP_NO_TICKET is honoured (session tickets are disabled). */
62#define SSL_OP_NO_COMPRESSION 0x0001UL
63#define SSL_OP_NO_RENEGOTIATION 0x0002UL
64#define SSL_OP_CIPHER_SERVER_PREFERENCE 0x0004UL
65#define SSL_OP_NO_TICKET 0x0008UL
66#define SSL_OP_NO_TLSv1 0x0010UL
67#define SSL_OP_NO_TLSv1_1 0x0020UL
68#define SSL_OP_NO_TLSv1_2 0x0040UL
69
70/* SSL_CTX_set_mode() flags; AUTO_RETRY is the mbedTLS default behaviour. */
71#define SSL_MODE_AUTO_RETRY 0x0001UL
72
73/* SSL_CTX_set_session_cache_mode() flags. */
74#define SSL_SESS_CACHE_SERVER 0x0002L
75
76/* Certificate file types. */
77#define SSL_FILETYPE_PEM 1
78
79/* SSL_CTX_set_verify() modes. */
80#define SSL_VERIFY_NONE 0x00
81#define SSL_VERIFY_PEER 0x01
82
83/* ALPN select-callback return codes (values match OpenSSL). */
84#define SSL_TLSEXT_ERR_OK 0
85#define SSL_TLSEXT_ERR_NOACK 3
86
87/* SSL_select_next_proto() return code (value matches OpenSSL). */
88#define OPENSSL_NPN_NEGOTIATED 1
89
90/* --- Library lifecycle (no-ops; mbedTLS needs no global init) --- */
91#define SSL_load_error_strings() ((void)0)
92#define OpenSSL_add_ssl_algorithms() ((void)0)
93#define EVP_cleanup() ((void)0)
94
95/* --- SSL_METHOD / SSL_CTX lifecycle --- */
96#define TLS_server_method cwist_mtls_TLS_server_method
97#define TLS_client_method cwist_mtls_TLS_client_method
98#define SSL_CTX_new cwist_mtls_SSL_CTX_new
99#define SSL_CTX_free cwist_mtls_SSL_CTX_free
104
105/* --- SSL_CTX configuration --- */
106#define SSL_CTX_set_min_proto_version cwist_mtls_SSL_CTX_set_min_proto_version
107#define SSL_CTX_set_options cwist_mtls_SSL_CTX_set_options
108#define SSL_CTX_set_mode cwist_mtls_SSL_CTX_set_mode
109#define SSL_CTX_set_cipher_list cwist_mtls_SSL_CTX_set_cipher_list
110#define SSL_CTX_set_ciphersuites cwist_mtls_SSL_CTX_set_ciphersuites
111#define SSL_CTX_use_certificate_chain_file cwist_mtls_SSL_CTX_use_certificate_chain_file
112#define SSL_CTX_use_PrivateKey_file cwist_mtls_SSL_CTX_use_PrivateKey_file
113#define SSL_CTX_check_private_key cwist_mtls_SSL_CTX_check_private_key
114#define SSL_CTX_set_session_cache_mode cwist_mtls_SSL_CTX_set_session_cache_mode
115#define SSL_CTX_sess_set_cache_size cwist_mtls_SSL_CTX_sess_set_cache_size
116#define SSL_CTX_set_session_id_context cwist_mtls_SSL_CTX_set_session_id_context
117#define SSL_CTX_set_timeout cwist_mtls_SSL_CTX_set_timeout
118#define SSL_CTX_set_alpn_select_cb cwist_mtls_SSL_CTX_set_alpn_select_cb
119#define SSL_CTX_set_alpn_protos cwist_mtls_SSL_CTX_set_alpn_protos
120#define SSL_CTX_set_tlsext_ticket_key_cb cwist_mtls_SSL_CTX_set_tlsext_ticket_key_cb
121#define SSL_CTX_get_ex_new_index cwist_mtls_SSL_CTX_get_ex_new_index
122#define SSL_CTX_set_ex_data cwist_mtls_SSL_CTX_set_ex_data
123#define SSL_CTX_get_ex_data cwist_mtls_SSL_CTX_get_ex_data
124#define SSL_CTX_set_verify cwist_mtls_SSL_CTX_set_verify
125#define SSL_CTX_set_default_verify_paths cwist_mtls_SSL_CTX_set_default_verify_paths
126#define SSL_CTX_set1_groups_list cwist_mtls_SSL_CTX_set1_groups_list
128long cwist_mtls_SSL_CTX_set_options(SSL_CTX *ctx, unsigned long options);
129long cwist_mtls_SSL_CTX_set_mode(SSL_CTX *ctx, long mode);
130int cwist_mtls_SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *list);
133int cwist_mtls_SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *path, int type);
136long cwist_mtls_SSL_CTX_sess_set_cache_size(SSL_CTX *ctx, unsigned long size);
137int cwist_mtls_SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx,
138 unsigned int sid_ctx_len);
141 int (*cb)(SSL *ssl, const unsigned char **out,
142 unsigned char *outlen, const unsigned char *in,
143 unsigned int inlen, void *arg),
144 void *arg);
145int cwist_mtls_SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
146 unsigned int protos_len);
147#define SSL_set_alpn_protos cwist_mtls_SSL_set_alpn_protos
148int cwist_mtls_SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos, unsigned int protos_len);
149#define SSL_CTX_use_certificate_file cwist_mtls_SSL_CTX_use_certificate_file
150int cwist_mtls_SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *path, int type);
151#define SSL_CTX_get_min_proto_version cwist_mtls_SSL_CTX_get_min_proto_version
154 int (*cb)(SSL *ssl, unsigned char *key_name,
155 unsigned char *iv, EVP_CIPHER_CTX *ectx,
156 HMAC_CTX *hctx, int enc));
158 void *free_func);
159int cwist_mtls_SSL_CTX_set_ex_data(SSL_CTX *ctx, int idx, void *data);
160void *cwist_mtls_SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx);
161void cwist_mtls_SSL_CTX_set_verify(SSL_CTX *ctx, int mode, void *callback);
164
165/* --- Per-connection API --- */
166#define SSL_new cwist_mtls_SSL_new
167#define SSL_free cwist_mtls_SSL_free
168#define SSL_set_fd cwist_mtls_SSL_set_fd
169#define SSL_accept cwist_mtls_SSL_accept
170#define SSL_connect cwist_mtls_SSL_connect
171#define SSL_read cwist_mtls_SSL_read
172#define SSL_write cwist_mtls_SSL_write
173#define SSL_pending cwist_mtls_SSL_pending
174#define SSL_shutdown cwist_mtls_SSL_shutdown
175#define SSL_get_error cwist_mtls_SSL_get_error
176#define SSL_get_SSL_CTX cwist_mtls_SSL_get_SSL_CTX
177#define SSL_session_reused cwist_mtls_SSL_session_reused
178#define SSL_version cwist_mtls_SSL_version
179#define SSL_get_cipher_name cwist_mtls_SSL_get_cipher_name
180#define SSL_get0_alpn_selected cwist_mtls_SSL_get0_alpn_selected
181#define SSL_set_tlsext_host_name cwist_mtls_SSL_set_tlsext_host_name
183void cwist_mtls_SSL_free(SSL *ssl);
184int cwist_mtls_SSL_set_fd(SSL *ssl, int fd);
185int cwist_mtls_SSL_accept(SSL *ssl);
187int cwist_mtls_SSL_read(SSL *ssl, void *buf, int num);
188int cwist_mtls_SSL_write(SSL *ssl, const void *buf, int num);
189int cwist_mtls_SSL_pending(const SSL *ssl);
191int cwist_mtls_SSL_get_error(const SSL *ssl, int ret);
193int cwist_mtls_SSL_session_reused(const SSL *ssl);
194int cwist_mtls_SSL_version(const SSL *ssl);
195const char *cwist_mtls_SSL_get_cipher_name(const SSL *ssl);
196void cwist_mtls_SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
197 unsigned int *len);
198int cwist_mtls_SSL_set_tlsext_host_name(SSL *ssl, const char *name);
199
200/* --- ALPN helpers --- */
201#define SSL_select_next_proto cwist_mtls_SSL_select_next_proto
202int cwist_mtls_SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
203 const unsigned char *server, unsigned int server_len,
204 const unsigned char *client, unsigned int client_len);
205
206#ifdef __cplusplus
207}
208#endif
209
210#endif /* CWIST_SHIM_OPENSSL_SSL_H */
mbedTLS TLS backend: EVP subset (HMAC digest tags, AES-256-CBC).
struct cwist_mtls_cipher_ctx EVP_CIPHER_CTX
Definition evp.h:21
mbedTLS TLS backend: HMAC subset (HMAC-SHA256, one-shot + streaming).
struct cwist_mtls_hmac_ctx HMAC_CTX
Definition hmac.h:19
size_t cap
Definition otel.c:56
const SSL_METHOD * cwist_mtls_TLS_client_method(void)
int cwist_mtls_SSL_read(SSL *ssl, void *buf, int num)
void cwist_mtls_SSL_free(SSL *ssl)
int cwist_mtls_SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *path, int type)
void cwist_mtls_SSL_CTX_set_tlsext_ticket_key_cb(SSL_CTX *ctx, int(*cb)(SSL *ssl, unsigned char *key_name, unsigned char *iv, EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc))
int cwist_mtls_SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *path)
struct cwist_mtls_ssl SSL
Definition ssl.h:44
void cwist_mtls_SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data, unsigned int *len)
int cwist_mtls_SSL_select_next_proto(unsigned char **out, unsigned char *outlen, const unsigned char *server, unsigned int server_len, const unsigned char *client, unsigned int client_len)
int cwist_mtls_SSL_CTX_check_private_key(const SSL_CTX *ctx)
int cwist_mtls_SSL_CTX_get_min_proto_version(const SSL_CTX *ctx)
int cwist_mtls_SSL_CTX_set_ciphersuites(SSL_CTX *ctx, const char *list)
void cwist_mtls_SSL_CTX_set_verify(SSL_CTX *ctx, int mode, void *callback)
int cwist_mtls_SSL_set_fd(SSL *ssl, int fd)
int cwist_mtls_SSL_CTX_set_ex_data(SSL_CTX *ctx, int idx, void *data)
int cwist_mtls_SSL_write(SSL *ssl, const void *buf, int num)
long cwist_mtls_SSL_CTX_set_mode(SSL_CTX *ctx, long mode)
int cwist_mtls_SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *list)
int cwist_mtls_SSL_set_tlsext_host_name(SSL *ssl, const char *name)
const SSL_METHOD * cwist_mtls_TLS_server_method(void)
int cwist_mtls_SSL_CTX_set1_groups_list(SSL_CTX *ctx, const char *groups)
SSL_CTX * cwist_mtls_SSL_get_SSL_CTX(const SSL *ssl)
const char * cwist_mtls_SSL_get_cipher_name(const SSL *ssl)
void * cwist_mtls_SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx)
int cwist_mtls_SSL_CTX_set_min_proto_version(SSL_CTX *ctx, uint16_t version)
int cwist_mtls_SSL_version(const SSL *ssl)
int cwist_mtls_SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)
int cwist_mtls_SSL_CTX_get_ex_new_index(long argl, void *argp, void *new_func, void *dup_func, void *free_func)
SSL_CTX * cwist_mtls_SSL_CTX_new(const SSL_METHOD *method)
int cwist_mtls_SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *path, int type)
int cwist_mtls_SSL_get_error(const SSL *ssl, int ret)
long cwist_mtls_SSL_CTX_set_session_cache_mode(SSL_CTX *ctx, long mode)
void cwist_mtls_SSL_CTX_free(SSL_CTX *ctx)
int cwist_mtls_SSL_shutdown(SSL *ssl)
struct cwist_mtls_method SSL_METHOD
Definition ssl.h:45
SSL * cwist_mtls_SSL_new(SSL_CTX *ctx)
long cwist_mtls_SSL_CTX_sess_set_cache_size(SSL_CTX *ctx, unsigned long size)
int cwist_mtls_SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos, unsigned int protos_len)
long cwist_mtls_SSL_CTX_set_options(SSL_CTX *ctx, unsigned long options)
int cwist_mtls_SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx, unsigned int sid_ctx_len)
int cwist_mtls_SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos, unsigned int protos_len)
int cwist_mtls_SSL_connect(SSL *ssl)
int cwist_mtls_SSL_session_reused(const SSL *ssl)
struct cwist_mtls_ctx SSL_CTX
Definition ssl.h:43
int cwist_mtls_SSL_pending(const SSL *ssl)
int cwist_mtls_SSL_accept(SSL *ssl)
long cwist_mtls_SSL_CTX_set_timeout(SSL_CTX *ctx, long seconds)
void cwist_mtls_SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, int(*cb)(SSL *ssl, const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg), void *arg)