Artifact 2595a63a1b0a45dd02d08fa247568d0e16b8ec314d3a216717b48a5623183fcb:
- File
src/store.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: 7691) [annotate] [blame] [check-ins using]
#ifndef SUIT_STORE_H #define SUIT_STORE_H #include "upstream.h" constexpr int EXIT_LOCAL_CHANGES = 12; constexpr int EXIT_CONFLICT = 13; constexpr int EXIT_NOTHING_TO_UNDO = 14; constexpr int EXIT_NEEDS_REPAIR = 15; constexpr int EXIT_SYMLINK = 16; constexpr int EXIT_NETWORK = 17; constexpr int EXIT_TLS = 18; // the secure connection failed constexpr int EXIT_REFUSED = 19; constexpr int EXIT_EXISTS = 20; constexpr int EXIT_LINT = 3; constexpr int EXIT_HELD = 4; // The store of wardrobe NAME: a working copy in $SUIT_HOME/store/NAME of the // repository $SUIT_HOME/wardrobes/NAME.fossil. Each command returns an exit // code and reports on stderr (errors) or stdout (what changed). // While an update is in progress, or was interrupted, $SUIT_HOME/NAME.journal // names the version it is leaving and the version it is going to. Every // command but repair refuses with EXIT_NEEDS_REPAIR while it exists. // // Symlinks are not supported: libfossil's checkout writes them as regular // files. open and update refuse a version that holds one and commit refuses to // check one in, each with EXIT_SYMLINK and a message naming the path. // Open the wardrobe and create the working copy at trunk's tip if there is // none. Idempotent. int store_open(const char *name); // One line per local change: "edited PATH", "added PATH" or "deleted PATH". // Nothing when clean. Changes nothing. int store_status(const char *name); // How many local changes `suit store status NAME` would list, into *COUNT (0 on any failure). Changes // nothing. int store_changes(const char *name, unsigned *count); // Run the lint (docs/store.md, "The lint") on the local changes: nothing when // clean, else one "PATH:LINE: what" per problem on stderr and EXIT_LINT. It // changes no file. int store_lint(const char *name); // Check in every local change as the current user. Exit 0, and no check-in, // when there are none. EXIT_LINT, with the report and nothing checked in, when // the lint finds a problem. EXIT_HELD when the changes delete many files, // unless CONFIRM_DELETIONS. int store_commit(const char *name, const char *message, bool confirm_deletions); // What a timer calls: check in the local changes with a message saying how // many files, or leave what needs the user in $SUIT_HOME/attention // (docs/store.md, "suit tend"). EXIT_LINT or EXIT_HELD then. int store_tend(const char *name); // Pull from the wardrobe's remote, bring the working copy forward, merge a // fork if it merges cleanly, and push (docs/store.md, "suit sync"). Exit 0 // with nothing done when no remote is set. EXIT_LOCAL_CHANGES after the pull // when the working copy has changes; EXIT_CONFLICT when a fork would conflict // (nothing in the working copy changes; the local check-ins are still pushed); // EXIT_NETWORK when the remote cannot be reached or fails; EXIT_TLS when the // secure connection to an https remote fails (no trusted certificates, the // handshake, the certificate or its host name); EXIT_REFUSED when the remote // refuses the login. int store_sync(const char *name); // Make the wardrobe NAME on this machine from the repository at URL: clone it // to $SUIT_HOME/wardrobes/NAME.fossil, record URL as NAME's remote, and open // the store at trunk's tip. Uses the login saved for NAME, if any. EXIT_EXISTS // when NAME is already a wardrobe or a store here; 2 for a bad name or // address or CA file; EXIT_TLS, EXIT_NETWORK and EXIT_REFUSED as for sync. A // failure at any point leaves nothing behind. CA, when not null, is an https // remote's own CA file, recorded with the remote. int store_clone(const char *name, const char *url, const char *ca); // Tend every wardrobe on this machine, in name order, one after another. One // that fails does not stop the others; each that did not end clean gets a // line. Exit 0 when all were clean, else the highest exit code of any. int store_tend_all(void); // Bring the working copy to trunk's tip. EXIT_LOCAL_CHANGES, listing the // files, if tracked files have changes. EXIT_CONFLICT, listing "conflict // PATH", if the update would conflict; nothing is changed then. int store_update(const char *name); // Bring every managed file back to the checked-in content of the version the // working copy records, using suit's file writer. EXIT_LOCAL_CHANGES, listing // them, if that would destroy local edits, unless an interrupted update left // a journal: then the files it partly replaced go back to the version it was // leaving. Clears the journal. Nothing to do is not an error. int store_repair(const char *name); // Say which version the working copy is at: "store NAME at UUID12". int store_show_version(const char *name); // EXIT_NEEDS_REPAIR, with a message, if an update of NAME did not finish; else 0. int store_check_journal(const char *name); // Undo the last update. EXIT_NOTHING_TO_UNDO if there is nothing to undo or // the store has moved on since. int store_back(const char *name); // ---- upstreams (docs/upstreams.md) ---------------------------------------------- // Check the files F in on the branch upstream-NAME of wardrobe WARDROBE, as // one check-in whose parent is the branch's tip, or trunk's first check-in // for the first take, without touching the working copy. Says // "upstream NAME: no change" and checks nothing in when F is the tip's tree. // Otherwise leaves "upstream NAME: update waiting for review" in the attention // file and sets *TAKEN. EXIT_LINT, with the report, when the lint finds a // problem; 1 when a file of F is already trunk's own or another upstream's. int store_upstream_take(const char *wardrobe, const UpstreamSpec *spec, const UpstreamFiles *f, bool *taken); // Merge the tip of upstream-NAME into the working copy of WARDROBE and check it // in (docs/upstreams.md, "accept"). EXIT_LOCAL_CHANGES with local changes; // EXIT_CONFLICT, with "conflict PATH" lines and the attention item, when files // conflict that SETTLE does not settle; 2 when SETTLE names a path that is not // such a conflict. int store_upstream_accept(const char *wardrobe, const char *upstream, const UpstreamSettle *settle); // Say what accept would change in trunk, one "add|change|remove|conflict PATH" // a line in byte order of path. Changes nothing. int store_upstream_diff(const char *wardrobe, const char *upstream); // Reverse the newest accept of the upstream not yet undone, by a new check-in // on trunk (docs/upstreams.md, "Undo"). "upstream NAME: nothing to undo", 0, // when there is none. EXIT_LOCAL_CHANGES with local changes; 1 when the working // copy is not at trunk's tip; EXIT_CONFLICT, with "conflict PATH" lines, when a // file the accept changed has changed since. Leaves the upstream waiting for review. int store_upstream_undo(const char *wardrobe, const char *upstream); // Where the upstream stands, and the pin it was last taken at (empty when // never taken), copied to PIN (CAP bytes). int store_upstream_state(const char *wardrobe, const char *upstream, UpstreamState *state, char *pin, size_t cap); // Call SINK(STATE, ENTRY) once for each top-level entry (a file or a folder name) under INTO in // the check-in that the record upstreams/NAME of WARDROBE names: what the upstream's // last accept brought into trunk (docs/upstreams.md, "The record"). A record that is // missing, not whole, or names no check-in of the branch means nothing is called. Reads the // repository and changes no file. 1 after a message, naming the wardrobe, when it cannot be read. typedef void (*UpstreamEntrySink)(void *state, const char *entry); int store_upstream_entries(const char *wardrobe, const char *upstream, const char *into, UpstreamEntrySink sink, void *state); #endif