Skip to content

Commit fddecf3

Browse files
tonibergholmclaude
andauthored
feat(repo,cli): close the four P32 TLS follow-ons (#208)
* feat(repo,cli): close the four P32 TLS follow-ons - sc serve fingerprint and --tls auto-mint refuse a root with no .sc/. - Warn when an SC_HTTPS_* knob is set but the URL is plaintext sc+http://. - Bound the sc+http(s) client's connect, TLS handshake, opening and wire handshake (30 s) so a silent peer fails the connect; lift it afterwards. - sc remote add parse-validates sc+http(s):// URLs at add time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(repo,cli,tlsio): type every client timeout, one connect deadline, discover the repo Codex: a timeout in the TLS handshake or wire handshake now surfaces as ConnectionLost like the opening read; the connect shares one deadline across resolved addresses; an empty CA knob counts as set for the downgrade warning; sc serve fingerprint finds the repo from a subdirectory; and the reserved sc+http:/sc+https: prefix, not just the exact form, is parse-validated at add. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(repo): give the wire handshake its own bound; test the lift for real Reviewer: the lift test passed with the lift removed, so it now inspects the live socket options (and fails without the lift). A bucket-backed server opens its bucket before answering HELLO, so the wire handshake gets 300 s while the connect, TLS and opening keep 30 s. Docs say these are inactivity bounds. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(repo): print the plaintext-URL knob warning once per process Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(repo): bound name resolution in the connect; see non-UTF-8 HTTPS knobs Codex: to_socket_addrs ran before the deadline could apply, so a stalled resolver defeated the connect bound; and var() hid a non-UTF-8 SC_HTTPS_* value from the downgrade warning. Resolve on a helper thread under the deadline and read the knobs with var_os. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(repo): report an opening-write timeout as ConnectionLost Codex: write_client_opening turned every write failure into InvalidArgument, so a peer that never reads (opening larger than the socket buffers) hit the new write bound but got the wrong typed error. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(repo): give each connect attempt an even share of the deadline Codex: with one shared deadline, a first address that silently drops packets could use all of it and starve a reachable later address. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 512536a commit fddecf3

10 files changed

Lines changed: 625 additions & 28 deletions

File tree

‎.claude/skills/sc-cli-reference/SKILL.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ cargo run --bin sc -- serve --http <addr> <path> --tls [--tls-cert <pem> --tls-k
345345
# --tls now — plaintext public needs
346346
# --allow-public (or --read-only)
347347
cargo run --bin sc -- serve fingerprint [<path>] # print (minting if absent) the serve-TLS
348-
# SPKI fingerprint (sha256:<hex>)
348+
# SPKI fingerprint (sha256:<hex>); needs a repo
349+
# (.sc/) — found from the cwd, or <path>
349350
cargo run --bin sc -- clone sc+https://host[:port]/repo <dst> # TLS clone (P32); accept-new
350351
# TOFU: first connect pins into
351352
# ~/.config/sc/known_hosts (SC_HTTPS_KNOWN_HOSTS

‎ROADMAP.md‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -906,19 +906,16 @@ scale-&-reach horizon):
906906
today; and a one-line fix to `SignatureObj.snapshot`'s now-stale doc
907907
comment, which still describes the field as always a snapshot id even
908908
though signing a transcript stores a transcript id there instead.
909-
- **P32 follow-ons.** Four items named but not closed by the P32 TLS work,
910-
deferred rather than silently dropped: (1) a `.sc`-existence check before
911-
`sc serve fingerprint`/`--tls` auto-mint — today it happily mints
912-
`~/.sc/serve-tls` even when run outside a repo; (2) a stderr warning when
913-
an `SC_HTTPS_*` env knob (`SC_HTTPS_STRICT`/`SC_HTTPS_FINGERPRINT`/
914-
`SC_HTTPS_KNOWN_HOSTS`) is set but the target URL is plaintext
915-
`sc+http://` — a scheme-downgrade footgun where the knob silently does
916-
nothing; (3) a client-side TLS handshake/read timeout — the server bounds
917-
its side at 30s (the opening read), but the `sc+https://` client is
918-
unbounded, so this folds into the existing deferred hostile-peer pass
919-
alongside `read_frame_inner`'s unbounded frame-length allocation; (4)
920-
`sc remote add` parse-validating `sc+http(s)://` URLs at add time, the
921-
way `ssh://` already does, instead of deferring the parse to first use.
909+
- **P32 follow-ons — shipped.** The four items the TLS work named: (1) `sc serve
910+
fingerprint` and `--tls` auto-mint refuse a root with no `.sc/` instead of
911+
minting there; (2) a stderr warning when an `SC_HTTPS_*` knob is set but the
912+
URL is plaintext `sc+http://`; (3) the `sc+http(s)://` client bounds the connect, TLS handshake, opening and
913+
status line (30 s inactivity) and the wire handshake (300 s, for a bucket
914+
server's slow open), so a silent peer fails the connect as `ConnectionLost`,
915+
and lifts both afterwards; (4) `sc remote add` parse-validates `sc+http(s)://` URLs
916+
at add time like `ssh://` and the bucket schemes. The client bounds are not
917+
configurable, and `read_frame_inner`'s frame-length allocation (covered by the
918+
`MAX_OBJECT_SIZE` cap since P28) is unchanged.
922919

923920
- **P34 follow-ons (private branches, ADR-0044).** Deferred rather than
924921
built: (1) `sc branch publish --squash` — collapse the sealed history into

‎crates/cli/src/main.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,8 @@ fn main() -> Result<()> {
10331033
Some(ServeSub::Fingerprint { path }) => {
10341034
let root = match path {
10351035
Some(p) => p,
1036-
None => std::env::current_dir()?,
1036+
// Like every repo command, find the repo from a subdirectory.
1037+
None => scl_repo::layout::Layout::discover(std::env::current_dir()?)?.root,
10371038
};
10381039
println!(
10391040
"{}",
@@ -3912,6 +3913,12 @@ fn run_remote(op: RemoteOp) -> Result<()> {
39123913
if url.starts_with("ssh://") {
39133914
scl_repo::SshUrl::parse(&url)?; // fail fast on malformed URLs
39143915
}
3916+
// The reserved scheme prefix, not just the exact `://` form: a
3917+
// near miss such as `sc+https:/host/repo` would otherwise be
3918+
// recorded and later read as a local path.
3919+
if url.starts_with("sc+http:") || url.starts_with("sc+https:") {
3920+
scl_repo::ScHttpUrl::parse(&url)?; // fail fast on malformed URLs
3921+
}
39153922
if url.starts_with("sc+wal://") || url.starts_with("sc+s3://") {
39163923
scl_repo::BucketUrl::parse(&url)?; // fail fast on malformed URLs
39173924
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//! `sc remote add` parse-validates the native network URL schemes at add time,
2+
//! so a typo fails here and not at the first fetch (P32 follow-on).
3+
4+
use std::process::Command;
5+
6+
fn sc(dir: &std::path::Path, args: &[&str]) -> std::process::Output {
7+
Command::new(env!("CARGO_BIN_EXE_sc"))
8+
.args(args)
9+
.current_dir(dir)
10+
.output()
11+
.expect("sc runs")
12+
}
13+
14+
fn repo(tag: &str) -> std::path::PathBuf {
15+
let root =
16+
std::env::temp_dir().join(format!("scl-cli-remote-add-{tag}-{}", std::process::id()));
17+
let _ = std::fs::remove_dir_all(&root);
18+
std::fs::create_dir_all(&root).unwrap();
19+
assert!(sc(&root, &["init"]).status.success());
20+
root
21+
}
22+
23+
#[test]
24+
fn malformed_http_urls_are_refused_at_add_time_and_good_ones_recorded() {
25+
let root = repo("http");
26+
for bad in [
27+
"sc+http://",
28+
"sc+http:///repo",
29+
"sc+https://host:notaport/repo",
30+
"sc+http://host:99999/repo",
31+
"sc+https:/host/repo", // near-miss scheme: one slash
32+
"sc+http:host/repo",
33+
] {
34+
let out = sc(&root, &["remote", "add", "origin", bad]);
35+
assert!(!out.status.success(), "{bad} should be refused");
36+
let list = sc(&root, &["remote", "list"]);
37+
assert!(
38+
String::from_utf8_lossy(&list.stdout).trim().is_empty(),
39+
"{bad} must not be recorded"
40+
);
41+
}
42+
43+
for (name, good) in [
44+
("plain", "sc+http://127.0.0.1:7777/repo"),
45+
("secure", "sc+https://example.com/repo"),
46+
] {
47+
let out = sc(&root, &["remote", "add", name, good]);
48+
assert!(
49+
out.status.success(),
50+
"{good}: {}",
51+
String::from_utf8_lossy(&out.stderr)
52+
);
53+
}
54+
let list = String::from_utf8_lossy(&sc(&root, &["remote", "list"]).stdout).into_owned();
55+
assert!(list.contains("sc+http://127.0.0.1:7777/repo"), "{list}");
56+
assert!(list.contains("sc+https://example.com/repo"), "{list}");
57+
58+
std::fs::remove_dir_all(&root).unwrap();
59+
assert!(!root.exists(), "test must leave no residue");
60+
}
61+
62+
/// With no path, `sc serve fingerprint` finds the repo from a subdirectory,
63+
/// and outside any repo it refuses instead of minting.
64+
#[test]
65+
fn serve_fingerprint_discovers_the_repo_and_refuses_outside_one() {
66+
let root = repo("fingerprint");
67+
let sub = root.join("a/b");
68+
std::fs::create_dir_all(&sub).unwrap();
69+
let out = sc(&sub, &["serve", "fingerprint"]);
70+
assert!(
71+
out.status.success(),
72+
"{}",
73+
String::from_utf8_lossy(&out.stderr)
74+
);
75+
assert!(String::from_utf8_lossy(&out.stdout).starts_with("sha256:"));
76+
assert!(
77+
root.join(".sc/serve-tls").is_dir(),
78+
"minted in the repo root"
79+
);
80+
assert!(!sub.join(".sc").exists(), "never in the subdirectory");
81+
82+
let bare =
83+
std::env::temp_dir().join(format!("scl-cli-fingerprint-bare-{}", std::process::id()));
84+
let _ = std::fs::remove_dir_all(&bare);
85+
std::fs::create_dir_all(&bare).unwrap();
86+
let out = sc(&bare, &["serve", "fingerprint"]);
87+
assert!(!out.status.success());
88+
assert!(!bare.join(".sc").exists(), "nothing may be created");
89+
90+
std::fs::remove_dir_all(&root).unwrap();
91+
std::fs::remove_dir_all(&bare).unwrap();
92+
assert!(
93+
!root.exists() && !bare.exists(),
94+
"test must leave no residue"
95+
);
96+
}

0 commit comments

Comments
 (0)