/* * TinyBlocks - tb_ssl.h * Library tinyblocks-ssl: TLS (dependencia de terceiros: OpenSSL). Registra * a categoria "SSL". * * Embrulha um TbStream TCP (tinyblocks-socket) num TbStream TLS: ler e * escrever passam a ser cifrados, e quem usa o fluxo (ex.: a * tinyblocks-http, para o https://) nao muda nada. O certificado do * servidor e conferido com os certificados do sistema e com o nome do host * (SNI + verificacao do nome). * * Tabela TbSslApi no lib_userdata da library (tb_ssl_api(rt)). */ #ifndef TINYBLOCKS_SSL_H #define TINYBLOCKS_SSL_H #include #include #include #include "tb_socket.h" #define TB_SSL_LIB "tinyblocks-ssl" #define TB_SSL_API_VERSION 1 typedef struct TbSslApi { int version; /* TB_SSL_API_VERSION */ /* Faz o aperto de mao TLS sobre tcp (fica dono dele: fecha junto). NULL em erro (tcp ja fechado; mensagem em err). */ TbStream* (*wrap)(TbStream* tcp, const char* host, char* err, size_t cap); const char* (*version_text)(void); /* "OpenSSL 3.0.13 ..." */ } TbSslApi; TB_API const TinyBlocks_LibraryDescriptor* tb_ssl_get_library(void); static inline const TbSslApi* tb_ssl_api(TinyBlocks* rt) { TinyBlocks_LibraryBlock* lib = tb_rt_find_library(rt, TB_SSL_LIB); const TbSslApi* api = lib ? (const TbSslApi*)lib->lib_userdata : NULL; return api && api->version == TB_SSL_API_VERSION ? api : NULL; } #endif /* TINYBLOCKS_SSL_H */