scorpiox-bot-plugin-webhook
←wh_tls.hc
39 lines · 1 KBHEADBlameDownload
1/*
2 * wh_tls.h - TLS over an already-connected, already-validated socket.
3 *
4 * POSIX only. _WIN32 uses WinHTTP (which does its own TLS against the system
5 * root store) so this module is an empty translation unit there.
6 *
7 * Policy: TLS 1.2 minimum, VERIFY_PEER always, hostname checked against the
8 * certificate, trust anchors from WEBHOOK_TLS_CA_FILE or the first readable
9 * system bundle. There is deliberately NO insecure bypass anywhere in this
10 * plugin: a webhook that carries a bearer token must not be sendable over a
11 * channel that cannot prove who it is talking to.
12 *
13 * MIT License. Copyright (c) 2026 SCORPIOX INC.
14 */
15#ifndef SX_WH_TLS_H
16#define SX_WH_TLS_H
17
18#include <stddef.h>
19
20#if !defined(_WIN32)
21
22typedef struct wh_tls wh_tls;
23
24/* Takes ownership of `fd` on success (closed by wh_tls_close) and on failure.
25 * `hostname` is used for SNI and certificate verification. NULL + err on
26 * failure. */
27wh_tls *wh_tls_connect_fd(int fd, const char *hostname, char *err, size_t errsz);
28
29/* bytes read, 0 at EOF, -1 on error. */
30int wh_tls_read(wh_tls *t, char *buf, size_t n);
31
32/* bytes written, -1 on error. */
33int wh_tls_write(wh_tls *t, const char *buf, size_t n);
34
35void wh_tls_close(wh_tls *t);
36
37#endif /* !_WIN32 */
38
39#endif /* SX_WH_TLS_H */