mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-28 14:08:42 -08:00
Merge pull request #2701 from storytold/fix/2342-system-trust-store
M9: wss:// connections also trust the operating system's certificate store (#2342)
This commit is contained in:
6 files changed
+35
-15
No files matched your search
Generated
+1
@@ -2705,6 +2705,7 @@ dependencies = [
|
||||
"log",
|
||||
"proptest",
|
||||
"rustls",
|
||||
"rustls-native-certs",
|
||||
"rustls-pki-types",
|
||||
"serde_json",
|
||||
"tungstenite",
|
||||
|
||||
@@ -19,12 +19,13 @@ web-time = "1"
|
||||
# Native transport: blocking tungstenite with a reader and a writer thread per connection.
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
tungstenite = { version = "0.30", default-features = false, features = ["handshake"] }
|
||||
# `wss://`: TLS with ring as the crypto provider and Mozilla's root certificates compiled in (no
|
||||
# OS certificate store, no OpenSSL). Over our own split reader/writer stream (`tls.rs`), so not
|
||||
# tungstenite's single-owner TLS stream.
|
||||
# `wss://`: TLS with ring as the crypto provider, the public root certificates of webpki-roots
|
||||
# compiled in and the operating system's certificate store read (no OpenSSL). Over our own split
|
||||
# reader/writer stream (`tls.rs`), so not tungstenite's single-owner TLS stream.
|
||||
rustls = { version = "0.23", default-features = false, features = ["std", "ring", "tls12", "logging"] }
|
||||
rustls-pki-types = { version = "1", features = ["std"] }
|
||||
webpki-roots = "1"
|
||||
rustls-native-certs = "0.8"
|
||||
getrandom = "0.4"
|
||||
base64 = { workspace = true }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! TLS for `wss://` addresses (native): rustls with ring, trusting Mozilla's root certificates
|
||||
//! (compiled in) plus any in the PEM file `FIGCRAFT_CA_FILE` names (a private authority or a
|
||||
//! self-signed server). Certificates are always verified.
|
||||
//! TLS for `wss://` addresses (native): rustls with ring, trusting the public root certificates of
|
||||
//! webpki-roots (compiled in), the authorities this computer trusts (its certificate store, unless
|
||||
//! `FIGCRAFT_NO_SYSTEM_ROOTS` is set) and any in the PEM file `FIGCRAFT_CA_FILE` names (a private
|
||||
//! authority or a self-signed server). Certificates are always verified.
|
||||
//!
|
||||
//! A connection's reader and writer threads share one TLS session ([`Tls`]), each holding it only
|
||||
//! to decrypt or encrypt: the reader waits for bytes on its own socket handle without it, and a
|
||||
@@ -20,6 +21,9 @@ use rustls::{CertificateError, ClientConfig, ClientConnection, RootCertStore};
|
||||
/// The variable naming a PEM file of extra certificate authorities to trust.
|
||||
pub const CA_FILE: &str = "FIGCRAFT_CA_FILE";
|
||||
|
||||
/// The variable that, set, leaves the operating system's certificate store out.
|
||||
pub const NO_SYSTEM_ROOTS: &str = "FIGCRAFT_NO_SYSTEM_ROOTS";
|
||||
|
||||
/// One connection's TLS session, shared by its reader and writer.
|
||||
pub type Tls = Arc<Mutex<ClientConnection>>;
|
||||
|
||||
@@ -44,7 +48,7 @@ pub fn handshake(stream: &TcpStream, host: &str) -> Result<Tls, String> {
|
||||
fn explain(host: &str, e: &io::Error) -> String {
|
||||
let why = |c: &CertificateError| match c {
|
||||
CertificateError::UnknownIssuer => format!(
|
||||
"isn't signed by an authority this app trusts (for a private or self-signed certificate, set {CA_FILE} to its authority's PEM file)"
|
||||
"isn't signed by an authority this app trusts (for a private or self-signed certificate, add its authority to this computer's trusted certificates, or set {CA_FILE} to its authority's PEM file)"
|
||||
),
|
||||
CertificateError::NotValidForName | CertificateError::NotValidForNameContext { .. } => "is for another name".into(),
|
||||
CertificateError::Expired | CertificateError::ExpiredContext { .. } => "has expired".into(),
|
||||
@@ -67,6 +71,15 @@ fn config() -> Result<Arc<ClientConfig>, String> {
|
||||
|
||||
fn make_config() -> Result<Arc<ClientConfig>, String> {
|
||||
let mut roots = RootCertStore::from_iter(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
|
||||
// A private authority an administrator installed (a company's, a proxy's) is trusted as the
|
||||
// computer's other apps trust it (#2342). An unreadable store adds nothing.
|
||||
if std::env::var_os(NO_SYSTEM_ROOTS).is_none() {
|
||||
let system = rustls_native_certs::load_native_certs();
|
||||
for e in &system.errors {
|
||||
log::warn!("system certificate store: {e}");
|
||||
}
|
||||
roots.add_parsable_certificates(system.certs);
|
||||
}
|
||||
if let Some(path) = std::env::var_os(CA_FILE) {
|
||||
let shown = std::path::Path::new(&path).display().to_string();
|
||||
let certs: Vec<CertificateDer> = CertificateDer::pem_file_iter(&path)
|
||||
|
||||
@@ -799,7 +799,8 @@ resuming with its offline edits, and leaving the session going back to snapshot
|
||||
plain `ws://` endpoint at `/`, `figcraft://join?server=<ws(s)://host[:port][/path]>&file=…&token=…`
|
||||
for any endpoint (TLS, a path behind a proxy), or `ws(s)://…?file=…&token=…`. The desktop app,
|
||||
`figcraft-cli` and the browser all open `wss://`: natively through rustls (ring, Mozilla's root
|
||||
certificates compiled in, plus any authority in the PEM file `FIGCRAFT_CA_FILE` names), always
|
||||
certificates compiled in, the operating system's certificate store unless
|
||||
`FIGCRAFT_NO_SYSTEM_ROOTS` is set, plus any authority in the PEM file `FIGCRAFT_CA_FILE` names), always
|
||||
verifying the certificate; the browser through its own WebSocket.
|
||||
- **Managing files.** A connection that opens with `Manage {key}` instead of `Hello` sends
|
||||
`Admin` requests: publish a document (its snapshot) as a new file, which returns an edit link
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Collaboration parity
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-26 · **Change:** minor (legacy welcomes without a reconnect secret are accepted with their explicit access level, and reconnects re-authenticate with the share link (#2365); a shared file's opening page can be set (`page.setOpening`, Set as opening page in the pages list) and syncs to everyone who joins afterwards (#1817); shared branches sync across live sessions and survive `figcraft-server` restarts, capability-gated on `branches`; numbers unchanged) · **Target:** Figma Design (desktop app 126.10.7); M9: a joined live session reconnects until you leave and says when it is disconnected, and joining it again merges what you did while disconnected; ; a file shared on the local network can be shared to look at only: a view-only code next to the edit code, picked in the Share popover before or while sharing)
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-28 · **Change:** minor (`wss://` connections also trust the authorities in the operating system's certificate store, so a private authority added there works without `FIGCRAFT_CA_FILE` (#2342); legacy welcomes without a reconnect secret are accepted with their explicit access level, and reconnects re-authenticate with the share link (#2365); a shared file's opening page can be set (`page.setOpening`, Set as opening page in the pages list) and syncs to everyone who joins afterwards (#1817); shared branches sync across live sessions and survive `figcraft-server` restarts, capability-gated on `branches`; numbers unchanged) · **Target:** Figma Design (desktop app 126.10.7); M9: a joined live session reconnects until you leave and says when it is disconnected, and joining it again merges what you did while disconnected; ; a file shared on the local network can be shared to look at only: a view-only code next to the edit code, picked in the Share popover before or while sharing)
|
||||
|
||||
Figma is multiplayer first; FigCraft is local first. **Ready ~13% (estimated):** comments, version
|
||||
history and branches (review and merge) work inside one file; the real-time collaboration core landed in #103 (sync model,
|
||||
@@ -27,6 +27,7 @@ cursors, selections, text carets, cursor chat and spotlights shown live ([`colla
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-28 | minor | #2342: the desktop app and `figcraft-cli` checked a `wss://` server's certificate against the compiled-in public roots and `FIGCRAFT_CA_FILE` only, so a server behind a proxy with a private authority needed that variable on every computer, which a signed desktop app started from the dock or the start menu doesn't see. They now also trust the authorities in the operating system's certificate store, read once per process, so adding the private authority to the computer's trusted certificates is enough. `FIGCRAFT_NO_SYSTEM_ROOTS=1` leaves the store out. Certificates are still always verified; an unknown authority's error names both ways to trust it. Not tested against a real private authority in the store here. |
|
||||
| 2026-11-28 | patch | M9, #2495: Stop sharing failed on a private server for a file shared with the server key typed under Advanced ("that owner token doesn't manage a file of that id here"). Such a file has no owner token, and the key went only with the publish. `collab.share {key}` now keeps the key with the share in this session, in the address as `collab.share {server: "…?key=…"}` would give it, so Stop sharing and sharing again ask as the server's operator. The key is never in a command result. Test: `live_share_tests::stopping_a_file_shared_with_a_separate_key_asks_with_that_key`. Numbers unchanged |
|
||||
| 2026-11-26 | minor | M10, gap 17: shared branches sync across live sessions. Capability-gated on `branches` in `Hello::client_version` (`ServerMsg::Branches` / `Branch`, `ClientMsg::Branch` with `Create`, `Edit`, `UpdateFromMain`, `SetState`), persisted in `SessionState::branches` and the server journal (with fallback decoding for pre-branch `figcraft-server` snapshots). Any editor can open, co-edit, update from main, review, archive and merge another peer's branch (remote merges/archives close open branch tabs on peers and switch back to main); view and comment links are refused; node/entry id spaces, geometry and image entries are validated on every branch mutation; older clients and servers stay compatible (local-only branches). Tests: `collab::branch_tests`, `engine::branch_live_tests`, `figcraft-server::server_tests::shared_branches_sync_and_survive_a_server_restart`, `figcraft-server::disk::tests::decode_snapshot_reads_pre_branch_v1_snapshots`. Numbers unchanged. |
|
||||
| 2026-11-16 | patch | M9, #2365: a server predating reconnect secrets sends a complete `Welcome` ending at `access`; postcard does not honor a missing trailing field through `serde(default)`. The client reads that exact legacy layout, preserves access, and keeps strict size, version and message-boundary checks. Native and browser transports use this reader; reconnects without a secret send a fresh authenticated hello. Covered by codec and connection-driver regressions. A patched 0.15.1 desktop build was also checked against the public service with separate view-only access and annotation reads; writes remained denied. The public server still needs upgrading. Numbers unchanged. |
|
||||
|
||||
+9
-6
@@ -454,12 +454,15 @@ gives people `wss://` links (and browsers the `wss://` they need on an `https://
|
||||
so the proxy's access logs don't record them.
|
||||
|
||||
The desktop app, `figcraft-cli` (and so agents through MCP) and the browser build all open
|
||||
`wss://` links. The desktop app and the CLI check the certificate against Mozilla's list of root
|
||||
authorities built into them (not the operating system's store), so a certificate from a public
|
||||
authority such as Let's Encrypt just works. For a certificate from a private authority (or a
|
||||
self-signed one, such as Caddy's `tls internal`), set the environment variable `FIGCRAFT_CA_FILE`
|
||||
to that authority's certificate (a PEM file) before starting the app: it is trusted in addition
|
||||
to the built-in list. There is no way to skip the check: a certificate that has expired, is for
|
||||
`wss://` links. The desktop app and the CLI check the certificate against a list of public root
|
||||
authorities built into them and the authorities the operating system trusts (its certificate
|
||||
store), so a
|
||||
certificate from a public authority such as Let's Encrypt just works, and so does one from a
|
||||
private authority once it is added to the computer's trusted certificates. Without that (or for a
|
||||
self-signed certificate, such as Caddy's `tls internal`), set the environment variable
|
||||
`FIGCRAFT_CA_FILE` to that authority's certificate (a PEM file) before starting the app: it is
|
||||
trusted in addition to the others. `FIGCRAFT_NO_SYSTEM_ROOTS=1` leaves the operating system's
|
||||
store out. There is no way to skip the check: a certificate that has expired, is for
|
||||
another name or comes from an unknown authority is refused, and the app says which.
|
||||
|
||||
## Running a public server
|
||||
|
||||
Reference in new issue
Block a user