Artifact 6521ba4bd3b5f931fb9f1b92bb7d9b42cff18bd260d5a3be15e440ca955a71cc:
- File
src/remote.h
— part of check-in
[27d847f693]
at
2026-11-18 16:19:19
on branch trunk
— suit syncs and clones over https
suit sync, suit clone and suit tend now work with https:// remotes. http:// and file:// keep libfossil's built-in channel.
libfossil is the private byot build 2f20f44ba4 in place of trunk f2983dcd78, approved while suit is being proven; only libfossil.c and libfossil.h differ from trunk's files. Its stream channel does all of the HTTP: request headers, Content-Length, chunked and close-delimited replies (the last only after a clean close), the reply-size limit and the timeout. suit supplies the transport: src/tls.c, over non-blocking TCP and BearSSL 0.6, now vendored.
- TLS 1.2 only, ECDHE key exchange, AES-GCM or ChaCha20-Poly1305. A server offering only TLS 1.3, RSA key exchange or CBC is refused. - The chain is verified against trust anchors and the host name against the certificate. Anchors come from the system's PEM bundle read at run time (SSL_CERT_FILE, then the usual macOS and Linux paths), or from a per-wardrobe CA file set with --ca, which replaces the bundle. No roots are compiled in and there is no way to trust anything. - A certificate file must be a regular file owned by the user or root, writable by no one else, in a folder that passes the same check; --ca refuses a symlink, and a FIFO is refused at once. - Redirects are refused, never followed, and the message names the new address. No proxy support. - Nothing is sent before the handshake has verified. The login goes out only as libfossil's login card. Commands that read the sync secret turn core files off first. - Every connect, read, write and name lookup waits in poll with a 30 s idle limit, and a whole command stops after 10 minutes. getaddrinfo has no deadline, so it runs in a forked child that is killed and reaped. - BearSSL makes no system call of its own: it is built without its own randomness or clock, and suit seeds it and gives it the time through its fault wrappers. - Exit 18 now means the secure connection failed (handshake, certificate, host name). 17 stays the network and 19 a refused login.
A per-wardrobe CA file is kept in cafiles in suit's home folder, one NAME PATH line each. suit-run is built without the network code and is unchanged at 35496 bytes; the speed budget passes. Release suit went from 2291288 to 2490024 bytes.
An independent security review found no critical or high issues. Its one medium finding, a CA file trusted without checking its owner, mode or type, is fixed here, as are its low ones: separate storage for each set of anchors, core files off, and the release check now covering every test-only switch.
Checked against a real server: an anonymous clone of this repository over https from its forge, 8.4 s, verified with stock fossil.
A new suite, test/https.sh, with 170 cases, runs local servers with test certificates made at test time, including servers that misbehave on purpose. It prints skip lines where openssl or nc is missing. A new fuzz target covers the bundle reader.
3788 unit checks (was 3669), 625 shell cases, 1153 store cases, 985 placement cases, 378 project cases, 236 usage cases, 288 curate cases, 376 curate-apply cases and 170 https cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (76 minutes, on a loaded machine). 100% coverage in all 34 source files. Three store cases that expected "cannot use https yet" now expect the refusal for a missing certificate bundle. (user: dmestas, size: 4624) [annotate] [blame] [check-ins using]
#ifndef SUIT_REMOTE_H #define SUIT_REMOTE_H #include <stddef.h> #include <stdint.h> // Two small files in $SUIT_HOME, each parsed strictly (a line that is not // exactly what is described is an error and the whole file is rejected) and // rewritten atomically. // // remotes: one line per wardrobe, "NAME URL". A URL is file://ABSOLUTE/PATH, // http://HOST[:PORT]/PATH or https://HOST[:PORT]/PATH, with no user name or // password in it. // // cafiles: one line per wardrobe whose https remote has a CA file of its own, // "NAME PATH", PATH absolute. Suit trusts that file in place of the system's // bundle for that remote. // // credentials: mode 0600, one line per wardrobe, "NAME USER SECRET". The // secret is printable ASCII with no space. It is never printed or written // anywhere else, and is wiped from memory after use. constexpr size_t REMOTE_FILE_MAX = 65536; constexpr size_t REMOTE_URL_MAX = 1024; constexpr size_t REMOTE_LINE_MAX = 1280; constexpr uint32_t REMOTE_ENTRY_MAX = 256; constexpr size_t CRED_USER_MAX = 64; constexpr size_t CRED_SECRET_MAX = 256; typedef struct { int line; // 0 when the error concerns the whole file char msg[200]; } RemoteError; typedef struct { char name[129]; char url[REMOTE_URL_MAX + 1]; } RemoteEntry; typedef struct { uint32_t n; RemoteEntry e[REMOTE_ENTRY_MAX]; } Remotes; typedef struct { char name[129]; char path[REMOTE_URL_MAX + 1]; } CaEntry; typedef struct { uint32_t n; CaEntry e[REMOTE_ENTRY_MAX]; } CaFiles; typedef struct { char name[129]; char user[CRED_USER_MAX + 1]; char secret[CRED_SECRET_MAX + 1]; } CredEntry; typedef struct { uint32_t n; CredEntry e[REMOTE_ENTRY_MAX]; } Creds; // Nullptr if the LEN bytes are an address suit accepts, else why not. The // reason never repeats the address, which might carry a password. const char *remote_url_check(const char *url, size_t len); // Parse DATA. On failure R is empty and ERR says what and where. [[nodiscard]] bool remotes_parse(Remotes *r, const char *data, size_t len, RemoteError *err); [[nodiscard]] bool creds_parse(Creds *c, const char *data, size_t len, RemoteError *err); [[nodiscard]] bool cafiles_parse(CaFiles *c, const char *data, size_t len, RemoteError *err); // Read PATH. A file that is not there is an empty list. creds_load also // refuses a file that anyone but its owner can use. [[nodiscard]] bool remotes_load(Remotes *r, const char *path, RemoteError *err); [[nodiscard]] bool creds_load(Creds *c, const char *path, RemoteError *err); [[nodiscard]] bool cafiles_load(CaFiles *c, const char *path, RemoteError *err); // Write the entries sorted by name, atomically. Returns 0 or an errno value. int remotes_write(const Remotes *r, const char *path); int creds_write(const Creds *c, const char *path); int cafiles_write(const CaFiles *c, const char *path); RemoteEntry *remotes_find(Remotes *r, const char *name); CredEntry *creds_find(Creds *c, const char *name); CaEntry *cafiles_find(CaFiles *c, const char *name); // The CA file recorded for NAME in OUT, empty when there is none. 0, or 1 // after saying on stderr why the cafiles file cannot be used. int remote_ca(const char *name, char *out, size_t cap); // Before anything reads a secret: turn off core files, which could hold it. // False after saying why on stderr. [[nodiscard]] bool no_core_dumps(void); // Overwrite N bytes at P so the compiler cannot drop it. void secret_wipe(void *p, size_t n); // The host (and port) part of URL, or for file:// its path, for messages. void remote_host(const char *url, char *out, size_t cap); // The commands. Each returns an exit code after reporting on stderr or stdout. // cmd_remote: URL null shows (exit 1 if none), "--none" clears. CA, when not // null, is the https remote's own CA file; setting a remote without one // forgets the old one. int cmd_remote(const char *name, const char *url, const char *ca); // Reads the secret from standard input. int cmd_login(const char *name, const char *user); int cmd_logout(const char *name); // $SUIT_HOME/NAME.syncfail: how many syncs of a wardrobe have failed in a row, // as 1 to 6 decimal digits (no leading zero, at least 1) and a newline. No // such file means none. Rewritten atomically. constexpr unsigned SYNC_FAILS_MAX = 999999; [[nodiscard]] bool syncfail_parse(const char *data, size_t len, unsigned *n); [[nodiscard]] bool syncfail_load(const char *path, unsigned *n, RemoteError *err); int syncfail_write(const char *path, unsigned n); // The files' paths for the sync. int remote_paths(char *remotes, char *creds, size_t cap); #endif