diff --git a/robot-docs/provider-requests.md b/robot-docs/provider-requests.md index d04dadd62..a0e6e9f58 100644 --- a/robot-docs/provider-requests.md +++ b/robot-docs/provider-requests.md @@ -108,7 +108,7 @@ combinations. There is no new raw-request retention or periodic writer. `openai_api` speaks HTTP/1.1 itself (`albedo_openai_transport.erl`) over a socket the process streaming the call owns: plain TCP for `http`, and for `https` TLS verified against `albedo_trust:cacerts()` with HTTPS hostname matching, SNI for named hosts, and ALPN offering only `http/1.1`. Each packet wakes only that process; no connection process sits between the socket and the reducer. The socket closes when its owner exits, and a host header the caller passes (Bedrock signs its own) replaces the one the transport would add. -`albedo_trust` owns the roots every daemon TLS client trusts (this transport, `albedo_http`, and https MCP servers, which go through this transport): the OTP system store without the roots on its block list, matched by the SHA-256 of their public key. A platform can distrust a root in its own verifier and still leave it in the store OTP reads (macOS revokes in trust evaluation, so `cacerts_get` keeps returning it), so an incident's roots go on that list; today it holds emSign ECC Root CA - G3 and AAA Certificate Services, which signed eMudhra's leaked intermediates (2026-10). Model tools and the discord bot get the same roots through `SSL_CERT_FILE`: `albedo_trust:environment/0`, which `albedo_python:clean_environment/0` and `albedo_discord` add to the environments they start, points it at a PEM under `$ALBEDO_HOME/cache/`, built from the store, or from the bundle the daemon's own `SSL_CERT_FILE` names with the same roots left out, so OpenSSL in the kernel and its jobs (Python's `ssl`, curl) refuses those chains too. +`albedo_trust` owns the roots every daemon TLS client trusts (this transport, `albedo_http`, and https MCP servers, which go through this transport): the OTP system store without the roots on its block list, matched by the SHA-256 of their public key. A platform can distrust a root in its own verifier and still leave it in the store OTP reads (macOS revokes in trust evaluation, so `cacerts_get` keeps returning it), so an incident's roots go on that list; today it holds emSign ECC Root CA - G3 and AAA Certificate Services, which signed eMudhra's leaked intermediates (2026-10). Keys are read with OTP's lenient decoder, the one TLS uses, so malformed certs are matched too. Model tools and the discord bot get the same roots through `SSL_CERT_FILE`: `albedo_trust:environment/0`, which `albedo_python:clean_environment/0` and `albedo_discord` add to the environments they start, points it at a PEM under `$ALBEDO_HOME/cache/`, built from the store, or from the bundle the daemon's own `SSL_CERT_FILE` names with the same roots left out, so OpenSSL in the kernel and its jobs (Python's `ssl`, curl) refuses those chains too. An exchange's `timeout_ms` bounds connecting and each wait for data. A provider that sets `first_event_timeout_ms` gives its headers and first streamed event a shared deadline instead, counted from when the request went out; keepalive comments do not move it, and `timeout_ms` bounds the waits after the first event. Only Antigravity sets one: 300 s for both, as oh-my-pi allows Cloud Code Assist, because argon streams no thought parts, so its thinking is a silent socket. Everyone else keeps one per-wait budget (60 s for the OpenAI clients, 120 s for Claude, Bedrock, Vertex). `ALBEDO_PROVIDER_TIMEOUT_MS` holds every budget to at most that many ms, so tests can reach a timeout in seconds. diff --git a/src/albedo/harness/albedo_trust.erl b/src/albedo/harness/albedo_trust.erl index 76f16e8bd..c838f71d7 100644 --- a/src/albedo/harness/albedo_trust.erl +++ b/src/albedo/harness/albedo_trust.erl @@ -62,9 +62,13 @@ cached(Key, Make) -> spki_hash(#cert{der = Der}) -> spki_hash(Der); spki_hash(Der) -> - #'Certificate'{tbsCertificate = Tbs} = public_key:pkix_decode_cert(Der, plain), - Spki = Tbs#'TBSCertificate'.subjectPublicKeyInfo, - crypto:hash(sha256, public_key:der_encode('SubjectPublicKeyInfo', Spki)). + %% The lenient decoder TLS uses, so malformed certs are matched too. + try public_key:pkix_decode_cert(Der, otp) of + #'OTPCertificate'{tbsCertificate = Tbs} -> + Spki = Tbs#'OTPTBSCertificate'.subjectPublicKeyInfo, + crypto:hash(sha256, public_key:pkix_encode('OTPSubjectPublicKeyInfo', Spki, otp)) + catch _:_ -> undecodable + end. bundle() -> try diff --git a/test/harness/trust_test.gleam b/test/harness/trust_test.gleam index 368f371be..19f28ef0f 100644 --- a/test/harness/trust_test.gleam +++ b/test/harness/trust_test.gleam @@ -59,6 +59,35 @@ const emsign_c3 = <> "WEBaLd4gTCKDypOofu4SQMfWh0/434UCMBwUZOR8loMRnLDRWmFLpg9J0wD8ofzkpf9/rdcw" <> "0Md3f76BB1UwUCAU9Vc4CqgxUQ==" +// emSign C3 with its issuer countryName re-tagged as a UTF8String, which +// the strict PKIX decoder rejects. +const emsign_c3_utf8_country = + "MIICKzCCAbGgAwIBAgIKe3G2gla4EnycqDAKBggqhkjOPQQDAzBaMQswCQYDVQQGDAJVUzET" + <> "MBEGA1UECxMKZW1TaWduIFBLSTEUMBIGA1UEChMLZU11ZGhyYSBJbmMxIDAeBgNVBAMTF2Vt" + <> "U2lnbiBFQ0MgUm9vdCBDQSAtIEMzMB4XDTE4MDIxODE4MzAwMFoXDTQzMDIxODE4MzAwMFow" + <> "WjELMAkGA1UEBhMCVVMxEzARBgNVBAsTCmVtU2lnbiBQS0kxFDASBgNVBAoTC2VNdWRocmEg" + <> "SW5jMSAwHgYDVQQDExdlbVNpZ24gRUNDIFJvb3QgQ0EgLSBDMzB2MBAGByqGSM49AgEGBSuB" + <> "BAAiA2IABP2lYa57JhAd6bciMK4G9IGzsUJxlTm801Ljr6/58pc1kjZGDoeVjbk5Wum739D+" + <> "yAdBPLtVb4OjavtisIGJAnB9SMVK4+kiVCJNk7tCDK93nCOmfddhEc5lx/h//vXyqaNCMEAw" + <> "HQYDVR0OBBYEFPtaSNCAIEDyqOkAB2kZd6fmw/TPMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB" + <> "Af8EBTADAQH/MAoGCCqGSM49BAMDA2gAMGUCMQC02C8Cif22TGK6Q04ThHK1rt0c3ta13FaP" + <> "WEBaLd4gTCKDypOofu4SQMfWh0/434UCMBwUZOR8loMRnLDRWmFLpg9J0wD8ofzkpf9/rdcw" + <> "0Md3f76BB1UwUCAU9Vc4CqgxUQ==" + +// emSign G3, blocked, with the same re-tag. +const emsign_g3_utf8_country = + "MIICTjCCAdOgAwIBAgIKPPYHqWhwDtqLhDAKBggqhkjOPQQDAzBrMQswCQYDVQQGDAJJTjET" + <> "MBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGlt" + <> "aXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0gRzMwHhcNMTgwMjE4MTgzMDAw" + <> "WhcNNDMwMjE4MTgzMDAwWjBrMQswCQYDVQQGEwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTEl" + <> "MCMGA1UEChMcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWdu" + <> "IEVDQyBSb290IENBIC0gRzMwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAQjpQy4LRL1KPOxst3i" + <> "AhKAnjlfSU2fySU0WXTsuwYc58Byr+iuL+FBVIcUqEqy6HyC5ltqtdyzdc6LBtCGI79G1Y4P" + <> "PwT01xySfvalY8L1X44uT6EYGQIrMgqCZH0Wk9GjQjBAMB0GA1UdDgQWBBR8XQKEE9TMipuB" + <> "zhccLikenEhjQjAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQD" + <> "AwNpADBmAjEAvvNhzwIQHWSVB7gYboiFBS+DCBeQyh+KTOgNG3qxrdWBCUfvO6wIBHxcmbHt" + <> "RwfSAjEAnbpV/KlK6O3t5nYBQnvI+GDZjVGLVTv7jHvrZQnD+JbNR6iC8hZVdyR+EhCVBCyj" + fn der(base64: String) -> BitArray { let assert Ok(der) = bit_array.base64_decode(base64) der @@ -75,3 +104,14 @@ pub fn store_records_are_matched_by_their_der_test() -> Nil { without_blocked([record(emsign_g3), record(emsign_c3)]) |> should.equal([record(emsign_c3)]) } + +// One store cert the strict decoder rejects must not fail every TLS client. +pub fn malformed_store_certs_are_kept_test() -> Nil { + let certs = [der(emsign_c3_utf8_country), der(emsign_g3)] + without_blocked(certs) |> should.equal([der(emsign_c3_utf8_country)]) +} + +pub fn malformed_blocked_roots_are_dropped_test() -> Nil { + without_blocked([der(emsign_g3_utf8_country), der(emsign_c3)]) + |> should.equal([der(emsign_c3)]) +}