#ifndef SUIT_TLS_H #define SUIT_TLS_H #include <libfossil.h> // https for the sync and the clone: the four callbacks of libfossil's stream // channel (connect, read, write, close) over a non-blocking TCP socket and // BearSSL. libfossil does all of the HTTP. One transfer at a time. // // Only TLS 1.2 with ECDHE key exchange and AEAD ciphers (AES-GCM, // ChaCha20-Poly1305). The certificate chain and the host name are checked in // connect(), before libfossil writes a byte of the request, so the login goes // only to a verified server. Redirects are libfossil's to refuse. // Seconds a read, a write, a connect or a name lookup may make no progress: // what store.c gives libfossil as socketTimeoutSeconds. constexpr int TLS_IDLE_SECONDS = 30; // The longest one command may spend on the network, pull and push together. A // wardrobe is text: a clone of one from zeitforge takes seconds. Ten minutes // keeps a stuck sync from running into the next hourly tend while leaving a // slow line a hundred times the time it needs. constexpr int TLS_DEADLINE_SECONDS = 600; // The idle limit to use: TLS_IDLE_SECONDS, or in a test build SUIT_NET_TIMEOUT. int tls_idle_seconds(void); // Get ready for https transfers: the trust anchors from CA_FILE (a remote's own // CA file) or the system's bundle, the random seed and the clock for // certificate dates. The total deadline starts at the first connection. // False, with WHY, if any of them fails: the caller exits 18. [[nodiscard]] bool tls_begin(const char *ca_file, char *why, size_t cap); // What BearSSL's error code E means, for a message. void tls_error_text(int e, char *out, size_t cap); // The channel for fsl_xfer_config::channel, after tls_begin. fsl_sc *tls_channel(void); // Whether the transfer that just failed failed in TLS (the handshake, the // certificate, the host name, a TLS protocol error): exit 18, not 17. bool tls_failed(void); #endif