Skip to content

C02 - Streams, TLS, and the Inspection CA

Purpose: The test cases for the streams wb-proxyd takes over: the hand-off from wb-netd, the first-byte and TLS checks, upstream addresses, the HTTP request form, and the inspection CA’s leaves, rotation, and keys.

Verifies: S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach., S07-07-hosts-and-modesS07-07-hosts-and-modes: Hosts and ModesHow wb-proxyd binds a stream to its name, which upstream addresses it refuses, and the inspect, pass and audit modes. (“Upstream address”), S07-15-non-http-streamsS07-15-non-http-streams: Non-HTTP StreamsHow wb-proxyd checks the protocol of each stream, and what it does with SSH, other protocols and raw TCP., S07-08-requests-and-credentialsS07-08-requests-and-credentials: Requests and CredentialsThe form of each request wb-proxyd sends upstream, and how it removes the guest's credentials and injects bound ones. (“Request form”), S07-16-tls-and-tunnelsS07-16-tls-and-tunnels: TLS and TunnelsWhat wb-proxyd does with client certificates, encrypted ClientHello and tunnels, and which refusals no mode or approval relaxes. (“Method overrides”), S09-06-ca-keysS09-06-ca-keys: CA KeysHow the key of each TLS inspection certificate authority is made, stored and restored, and when a CA is valid. (“Valid CA”), S09-07-ca-certificatesS09-07-ca-certificates: CA CertificatesThe profile and scope of each TLS inspection CA, the leaf certificates it signs, and its rotation. (“Lifetimes”), S09-08-guest-trustS09-08-guest-trust: Guest TrustHow wb-guestd makes the guest's clients trust the VM's CAs.

Spec: S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach..

Two VMs at different generations. On VM A’s hand-off socket the test sends these streams:

  • one whose generation field is VM B’s;
  • one to an address only VM B’s copy holds, and one to an address with no entry;
  • one on a port the name’s policy doesn’t allow;
  • one to a name that a policy change removed after its report;
  • one with no descriptor, one with two, and one with three, which the channel refuses with fdchan-fd-count;
  • one with a datagram socket, and one with a socket that isn’t a Unix domain socket, as the stream;
  • one sent right behind a report that waits on wb-hostd for the wildcard budget, which passes once the report is accepted;
  • one in a message over 4 KiB;
  • streams past the per-socket cap, while VM B’s streams still pass.

On the same socket it sends name reports with:

  • a name only VM B’s policy allows;
  • a name that fails the name form rule;
  • a name with a capital letter or a trailing dot;
  • an address outside the synthetic range;
  • new names under a wildcard past the wildcard budget.

Each is refused and logged with its rule and check, a refused stream gets a StreamReset, and the stream handler sees none of them, so wb-proxyd doesn’t resolve a name upstream, open an upstream connection or fetch a binding. The malformed ones also close VM A’s hand-off socket and its streams, and wb-proxyd sends HandoffSocketClosed: a name not in canonical form, an address outside the range, a stream of the wrong form (no descriptor, two, three or over 4 KiB), and a record that doesn’t decode. wb-hostd ends VM A’s wb-netd and counts the exit.

On macOS, internal/proxyd/handoff runs the wb-proxyd cases over socketpairs (receiver_darwin_test.go), and the reset that can’t be sent with a fake channel (TestResetSendFails).

TestMalformedReportEndsOneNetd in internal/hostd/egress (crossvm_darwin_test.go) runs wb-hostd’s side with a real wb-proxyd receiver over socketpairs. VM A’s wb-netd sends a name with a capital letter. wb-proxyd closes A’s hand-off socket, and wb-hostd ends A’s wb-netd with name-report-malformed. VM B’s streams still pass, wb-hostd keeps B’s wildcard name, and wb-proxyd isn’t ended (SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another.).

Spec: S07-07-hosts-and-modesS07-07-hosts-and-modes: Hosts and ModesHow wb-proxyd binds a stream to its name, which upstream addresses it refuses, and the inspect, pass and audit modes., “Upstream address”. The tests are in internal/proxyd/upstream.

  • One address inside and one just outside each range, with 169.254.169.254, 192.0.0.8, ::ffff:127.0.0.1, ::127.0.0.1, 64:ff9b::a00:1, 6to4 and Teredo addresses that embed a public IPv4 address, and public addresses that pass (TestRefused).
  • With a fake reader of the host’s networks, an address assigned to an interface, an address in an on-link IPv4 prefix, a global IPv6 address in an on-link prefix and the IPv4-mapped form of an interface address are refused, and nothing is dialed (TestDialHostNetworks). The networks are read at each connect (TestDialReadsNetworksEachTime).
  • With a fake resolver, a name with one bad address among good ones is refused, nothing is dialed, and the refusal is logged with the host, the address and upstream-address-refused (TestDialRefusesOneBadAddress). A good name is dialed at the checked address after one lookup (TestDialGoodName), and its addresses are tried in order (TestDialInOrder). A failed lookup and one with no address give upstream-resolve-failed (TestDialResolveFailed).
  • A name that resolves to 127.0.0.1 reaches no listener there (TestDialLoopback).

Spec: S07-15-non-http-streamsS07-15-non-http-streams: Non-HTTP StreamsHow wb-proxyd checks the protocol of each stream, and what it does with SSH, other protocols and raw TCP., S07-07-hosts-and-modesS07-07-hosts-and-modes: Hosts and ModesHow wb-proxyd binds a stream to its name, which upstream addresses it refuses, and the inspect, pass and audit modes. (“Name binding”), S07-16-tls-and-tunnelsS07-16-tls-and-tunnels: TLS and TunnelsWhat wb-proxyd does with client certificates, encrypted ClientHello and tunnels, and which refusals no mode or approval relaxes. (“Pass”). The tests are in internal/proxyd/stream, with a fake hand-off side for each stream and loopback upstream servers, and in internal/proxyd/tlsparse. Each reset is logged with its rule, its check and what the first bytes looked like, and reaches the audit hook.

  • Send a ClientHello whose SNI differs from the stream’s name, one without an SNI, one with an IP address and one with a trailing dot, and see each reset with tls-sni-mismatch and nothing dialed. An SNI in upper case goes to the Inspector, with its bytes to read again (TestC02SNIBinding).
  • Send SSH, a PostgreSQL startup message, an SSLRequest, a cleartext HTTP/2 preface and an HTTP request line to a TLS port, and an HTTP/2 preface, a ClientHello, SSH and an HTTP/0.9 request line to port 80. See each reset with stream-protocol-mismatch and the protocol it looked like, and nothing dialed (TestC02FirstBytesMismatch). HTTP/1.1 and HTTP/1.0 request lines sent a byte at a time go to the Inspector (TestC02PlainHTTP). A port with no protocol is reset (TestC02NoProtocol).
  • Open a stream and don’t send, and send a ClientHello a byte at a time, and see each reset with stream-first-bytes-timeout (TestC02FirstBytesTimeout).
  • Send a ClientHello split over three records, and a flight of exactly the byte cap, and see each taken. A flight one byte past the cap is reset (TestC02ClientHelloRecords).
  • Send an ALPN list of only ftp, and one of only h2, and see each reset. A list that names http/1.1, alone or with others, and no list go to the Inspector (TestC02ALPN). A host in audit goes to the Inspector in audit mode, after the same checks (TestC02AuditMode).
  • To a pass host, send ClientHellos that hold an encrypted_client_hello or encrypted SNI extension (tls-ech-pass), early_data, an unknown extension (tls-extension-unknown), or another SNI. See each reset before any dial (TestC02PassHello).
  • To a pass host, before the ServerHello, send application data, a handshake record that isn’t a ClientHello, a second ClientHello without a HelloRetryRequest, a second change cipher spec, one that isn’t the byte 0x01, and after a HelloRetryRequest a second ClientHello with another SNI or with ECH. See each reset with its rule, and the server get only the records that passed (TestC02PassRecords). A ServerHello after a HelloRetryRequest and before the second ClientHello (TestC02PassServerHelloEarly), and a server’s application data, second HelloRetryRequest or bytes that aren’t TLS (TestC02PassServerRecords), are reset too.
  • See one change cipher spec relayed, and the bytes after the ServerHello relayed unchanged both ways (TestC02PassOneCCS). See an alert close both ways with tls-client-alert, its level and description logged, and the alert not relayed (TestC02PassAlert).
  • Run a full TLS 1.3 handshake of crypto/tls, with a HelloRetryRequest, through a pass relay (TestC02PassHandshake).
  • Relay a server-first protocol through a raw TCP entry (TestC02RawRelay). A pass and a raw TCP stream to a name that resolves to 127.0.0.1 are reset with upstream-address-refused (TestC02UpstreamRefused).
  • Remove the raw TCP entry of an open relay, and take an open pass relay’s host out of the pass list, and see each relay end both ways with policy-recomputed (TestC02PolicyRecomputed). Each logs its one allowed record and no refusal of its own.
  • Reset a stream from the hand-off’s side while its first bytes are read, during its dial, and as its dial opens. See no refusal and no allowed record logged by the handler, and nothing reach the upstream server (TestC02EndedByHandoff). Reset a pass stream after its dial opened and passed its end check, before its ClientHello is sent, and see the same (TestC02ResetBeforeHelloSend).
  • Stall a pass relay’s ClientHello write upstream. See the write end at its deadline, the relay end with first-send-timeout, and a hand-off reset during the write wait no longer than that (TestC02FirstSendTimeout).
  • Close wb-netd’s end of a raw and a pass relay’s socket while upstream sends nothing. See the stream and the upstream connection close, with stream-peer-closed in the relay’s end record (TestC02NetdClosedRaw, TestC02NetdClosedPass). Half-close it instead, and see upstream half-closed and the server’s later answer reach the guest (TestC02NetdHalfClosedRaw). On the receiver’s sockets, a read sees a half-close as an end of file and a later close as ErrPeerClosed. The stream keeps its place under the stream cap until it’s closed (TestStreamPeerClosed). A relay reads only to the first end of file, so it waits for the later close instead. wb-netd closes its end after its half-close while upstream is silent (TestC02NetdClosedAfterHalfCloseRaw), or once the relay blocks toward an upstream that doesn’t read (TestC02NetdClosedUpstreamNotReading). The stream and upstream close with stream-peer-closed. On the receiver’s sockets the wait sees the close with no read, and the closed stream frees its place under the cap (TestStreamWaitPeerClosed). The wait ends with the stream and once wb-proxyd’s own end shut down its writes (TestStreamWaitEnds), and doesn’t leave a descriptor or goroutine behind (TestWaitLeavesNothing). The stream’s end frees its place only once the wait returned (TestStreamEndWaitsForWait), and a raw relay holds DescriptorsPerStream descriptors (TestDescriptorsPerStream). A failed wait resets the stream with stream-hangup-wait-failed (TestC02HangUpWaitFailedRaw), and on Windows the wait refuses (TestWaitUnsupported). A reset on the socket reads as ErrPeerClosed too (TestHangUpReset), and the hang-up check answers under a deny-all Seatbelt profile (TestHungUpConfined).
  • tlsparse refuses each malformed record and ClientHello with its check (TestReadClientHelloRefuses), and reads a server’s records only to its ServerHello (TestServerFlight).

Spec: S07-15-non-http-streamsS07-15-non-http-streams: Non-HTTP StreamsHow wb-proxyd checks the protocol of each stream, and what it does with SSH, other protocols and raw TCP. (“Inside TLS on an inspected host”), S07-07-hosts-and-modesS07-07-hosts-and-modes: Hosts and ModesHow wb-proxyd binds a stream to its name, which upstream addresses it refuses, and the inspect, pass and audit modes. (“inspect”), S07-16-tls-and-tunnelsS07-16-tls-and-tunnels: TLS and TunnelsWhat wb-proxyd does with client certificates, encrypted ClientHello and tunnels, and which refusals no mode or approval relaxes.. The tests are in internal/proxyd/inspect, with Go test clients and servers on loopback, a CA made in the test, and fakes for the leaves, the stream’s control and the HTTP handler. Each refusal is checked in inspect and in audit mode, and is the same in both.

  • A client that trusts the CA completes the handshake with TLS 1.2 and 1.3, offering http/1.1, h2 and http/1.1, or no ALPN. It gets HTTP/1.1, its first request reaches the HTTP handler, the leaf is asked for the stream’s VM, generation, name, port and policy, and nothing is dialed (TestC02InspectHandshake). A plain HTTP stream goes to the HTTP handler with no leaf (TestC02InspectPlainHTTP).
  • See that the client doesn’t hold a session ticket after the handshake, with TLS 1.2 and 1.3 (TestC02InspectNoSessionTickets).
  • A refusal from the leaf interface resets the stream with its rule (TestC02InspectLeafRefused). An h2-only client’s handshake fails (TestC02InspectALPN).
  • A Go client with an ECH configuration aborts with ech_required, and the stream is reset with tls-ech-refused (TestC02InspectECH).
  • A Go client that distrusts the CA, with TLS 1.2 and 1.3, or that expects another name, aborts. The stream is reset with tls-client-rejected-leaf, the alert’s description and the known gap of FR08-no-proxy-configFR08-no-proxy-config: No per-tool proxy settingsAllowlisted network destinations work for every tool without per-tool proxy configuration. (TestC02InspectRejectedLeaf). A client that closes after the server’s flight, during the handshake or after it with no request byte, is logged the same way with closed (TestC02InspectClientClosed). Every alert code classifies by its structure, never by its text alone, and a reset after the server’s flight is closed as a close is (TestHandshakeErrorRule).
  • After the handshake, send SSH, the HTTP/2 preface, a line past the cap, a partial line and then the end, nothing, and a partial line. See each reset with stream-protocol-mismatch or stream-first-bytes-timeout and its check, and nothing dialed (TestC02InspectAfterHandshake). A client that stalls in the handshake meets the same deadline (TestC02InspectDeadlineCoversHandshake).
  • Upstream, see the server verified for the stream’s name, offered http/1.1 only, and that it doesn’t get a client certificate when it asks for one (TestC02UpstreamTLS). A plain HTTP stream gets the dialed connection (TestC02UpstreamPlain), and a dialer’s refusal comes back with its rule (TestC02UpstreamDialRefused). Both connections count the bytes unread in the dialed socket (TestC02UpstreamUnread).
  • An upstream that requires a client certificate gives tls-client-cert-unsupported, with TLS 1.2 in the handshake and with TLS 1.3 on the first read (TestC02UpstreamClientCert). One whose CA the roots don’t trust, or whose certificate names another host, gives upstream-tls-verify (TestC02UpstreamVerify). One that isn’t TLS gives upstream-tls-failed (TestC02UpstreamFailed).
  • An upstream that asks for a client certificate with TLS 1.3 and then closes with no alert gives upstream-tls-failed, and a first read past its deadline returns the timeout with no refusal (TestC02UpstreamCertAskedThenFailed). A timeout or a canceled stream is upstream-tls-failed after a request, and only handshake_failure, bad_certificate and certificate_required count as a refused certificate on the first read (TestUpstreamRule).
  • A stream that ends while the upstream handshake waits on the server gives handoff.ErrEnded, and no upstream-tls-failed is logged, though the end closed the connection before Done closed (TestC02UpstreamEndDuringHandshake).
  • New refuses a configuration without leaves, a dialer or an HTTP handler (TestNew), and a leaf interface that returns neither a leaf nor a refusal resets the stream with ca-leaf-refused (TestC02InspectLeafRefused).

Spec: S09-06-ca-keysS09-06-ca-keys: CA KeysHow the key of each TLS inspection certificate authority is made, stored and restored, and when a CA is valid..

  • Ask wb-proxyd for a leaf for a host the policy doesn’t inspect, a host in pass mode, a stream whose SNI differs from its hostname, a hostname on another VM’s stream, and a VM whose only CA has expired. In every case wb-proxyd doesn’t sign a leaf. The pass-mode stream is relayed unchanged, and each other stream is reset and logged with its rule.
  • In internal/proxyd/ca, over the fake key store and the fake secret store (S09-07-ca-certificatesS09-07-ca-certificates: CA CertificatesThe profile and scope of each TLS inspection CA, the leaf certificates it signs, and its rotation., “Leaf issuance”):
    • Ask for a leaf for a wildcard, an IP address, a name not in canonical form, a VM with no CA set, an older generation, a VM with no signing CA, and an expired CA with a leaf cached. See each refused with ca-leaf-refused and its reason, or ca-not-installed, and logged (TestC02LeafRefusals).
    • Ask for a leaf for a pass host, plain HTTP, a raw TCP entry, a port outside every endpoint and a stream with no policy. See each refused with ca-leaf-refused, logged, and nothing signed (TestC02LeafNotInspected).
    • Ask for one new hostname’s leaf from 8 calls at once, and see it signed once and each call get it (TestLeafSingleflight).
    • Make the first signature of a new hostname’s leaf fail, then panic. See the flight end each time, with ca-leaf-refused when it fails, and the next call sign the leaf (TestLeafFlightFails).
    • See a leaf with exactly the leaf profile, a chain of the leaf only, and a validity cut to the CA’s end, that verifies against its CA (TestC02LeafProfile).
    • See the cache return the same leaf for the same VM, CA and hostname, a new one an hour before its end and after a signing CA change, and drop the least recently used leaf at its cap (TestC02LeafCache).
    • See a leaf signed for one VM fail to verify against another VM’s CA (TestC02VMScope), and the package’s API give or take no x509.CertPool (TestNoCertPool).
    • See a VM’s streams refused until wb-hostd accepts the CA set’s generation, and a CA set of an older generation end the control channel (TestC02AcceptGating).
    • See wb-proxyd’s hand-off receiver, which has no CA handler yet, refuse a CA message and end the control channel (TestCAMessageRefused).

On a fake clock, with each step checking its 5019 event:

  • Day 30 issues and installs the successor.
  • Day 58 switches only after the install is recorded, and otherwise refuses the VM’s streams with ca-not-installed.
  • Day 60 removes the old CA and destroys its key.
  • A restore and a host wake each follow this order: clock set, expired CAs removed, the current CAs installed from the host’s record, and only then streams accepted, signed with the CA wb-proxyd signed with before the save or the sleep.
  • A save on day 40 and a restore on day 45 keep signing with the old CA.
  • A host that sleeps from day 50 to day 61 removes the old CA before it accepts a stream.
  • In internal/hostd/carecord, over a fake wb-proxyd, a fake guest and a fake clock, each with its 5019 events:
    • Day 30 issues the successor, sends both in the CA set and records the install (TestC02RotationDay30).
    • Day 58 switches once the install is recorded (TestC02RotationDay58), and otherwise leaves the VM without a signer and logs ca-not-installed (TestC02RotationDay58NotInstalled).
    • Day 60 drops the old CA and puts its item on the removal list (TestC02RotationDay60).
    • A boot runs the seven steps in order (TestC02RotationBootOrder). A restore and a wake keep the old signer (TestC02RotationRestoreAndWakeKeepSigner), also from a save on day 40 to a restore on day 45 (TestC02RotationSaveDay40RestoreDay45).
    • A sleep from day 50 to day 61 drops the old CA before the accept (TestC02RotationSleepDay50To61).
    • An install the guest doesn’t report in time refuses the VM’s streams with ca-install-unreported (TestC02RotationInstallUnreported).

Spec: S09-06-ca-keysS09-06-ca-keys: CA KeysHow the key of each TLS inspection certificate authority is made, stored and restored, and when a CA is valid., “Valid CA”.

  • Hand wb-proxyd a token object ID of another key, random bytes, a missing item, and a restore that returns an error. See each VM start refused with ca-key-restore, and no new CA issued until wb vm reset-ca.
  • Fail an issue’s read-back or restore, and see the record unchanged and its item deleted.
  • Through the cgo shim, read back a new CA key and its item, and check that a keychain search for the key finds nothing, kSecAccessControlPrivateKeyUsage as the only access control flag, kSecAttrAccessibleWhenUnlockedThisDeviceOnly, and kSecAttrSynchronizable false.
  • On Linux, record “software” on a host with a TPM, and “TPM” on one without, and see each CA issue and restore refused with ca-key-store-mismatch.
  • Run wb vm reset-ca and wb setup --ca-key-store, and see each write a 5019 event with the command and each dropped CA’s fingerprint.
  • In internal/proxyd/ca, over the fakes:
    • Restore from the wrapped form of another key, a token of another key, random bytes, a missing item, and a restore error. See each CA set fail with ca-key-restore, the VM get no leaf, and no key made or left open (TestC02RestoreFails). A CA set whose certificate isn’t the item’s fails the same way (TestC02RestoreBadCertificate).
    • Fail an issue’s read-back and restore, and see its item deleted (TestC02IssueRoundTripFails). An issue for a CA id in use, for either VM and also after a CA set that failed to restore, fails with ca-issue-refused and no store call (TestC02IssueRefused). After a restart, an issue for an id whose item the store holds fails with ca-issue-refused and leaves the item, and a failed write deletes nothing (TestC02IssueStored).
    • See a locked store wait, log the wait once and continue at the unlock (TestC02StoreLockedWaits), and fail closed when the wait ends (TestC02StoreLockedCancel). See an ad-hoc signed build fail with keychain-needs-team (TestC02AdHocStore).
    • See a new CA with exactly the CA profile (TestC02IssueProfile).
  • In internal/platform/hwkey, on a Mac VM such as CI’s macOS runners, run the real shim unsigned against the VM’s virtual Secure Enclave (S09-06-ca-keysS09-06-ca-keys: CA KeysHow the key of each TLS inspection certificate authority is made, stored and restored, and when a CA is valid., “macOS, every build”). Generate a key, and sign a SHA-256 digest that Go verifies. Restore the key from its wrapped form, and see the same public key and a signature that verifies, and a closed key refuses to sign (TestC02VMRoundTrip). It makes no Keychain call and stores nothing, and it skips on a Mac that isn’t a VM. A Mac without a Secure Enclave, whose generate and restore give the framework’s error, has no test: CI has no such Mac.
  • In internal/platform/hwkey, in pure Go on every OS, feed the reader of the wrapped form a form generate gave, and see it pass. See the reader refuse each form whose structure or encoding differs: a length one short or long at each level, a long-form or indefinite length, a wrong tag or name, fields out of order, a field more or less, a size or fixed value changed, a changed ed, bytes after an element, and the form cut short (TestWrappedGenerated, TestWrappedRefused). Any bytes in the key fields are taken (TestWrappedKeyBytes). These tests pass their changed forms to the reader only, never to the Secure Enclave or the Keychain. So a form with changed key-field bytes is deliberately not tested on hardware.
  • In internal/platform/hwkey on darwin, see Restore refuse a form with one changed ed byte and a live context, with the shim’s call replaced by a stub that fails the test when called (TestRestoreRefusesForm).
  • In internal/platform/hwkey, see the check that each restore runs refuse a key whose signature doesn’t verify with its public key, and one that fails to sign (TestCheckPossession, S09-06-ca-keysS09-06-ca-keys: CA KeysHow the key of each TLS inspection certificate authority is made, stored and restored, and when a CA is valid., “kSecAttrTokenOID is undocumented”).
  • On the maintainer’s Mac, with the real store and Secure Enclave, in the bundles of mise run store:host-test (C05-credentials-and-storeC05-credentials-and-store: Credentials and the Secret StoreThe test cases for the secret store and its callers, the signing setup that gives development builds their Keychain groups, and the credential checks wb-proxyd makes on guest requests and server responses., “Host tests”). The run skips them on a Mac VM, and the maintainer watches for a dialog or a Touch ID prompt, which fails them.
  • In internal/hostd/carecord, see a restore failure refuse the start with ca-key-restore and issue nothing, and after wb vm reset-ca the next boot issue a new CA and remove the old one’s item (TestC02CAKeyRestoreFailed).
  • In internal/vmcmd, against the real service and CA record, see wb vm reset-ca refused without a terminal, on a wrong answer and while the VM runs, each leaving the record as it was (TestResetCARefusals). On success see the record empty, both items on the removal list and one 5019 event with the command (TestResetCAAccepted).

Spec: S09-07-ca-certificatesS09-07-ca-certificates: CA CertificatesThe profile and scope of each TLS inspection CA, the leaf certificates it signs, and its rotation., “Lifetimes”.

  • Hand wb-proxyd batches with binding/x, wbadmin/build/x, a name with a part outside the fixed form, and an entry whose CA is still in the record, each next to a valid entry. See each batch refused with ca-removal-refused and nothing deleted. Then see wb-hostd drop an entry refused for its form and log it, keep one refused because its CA is in the record until the VM’s next CA set, and the next batch delete the valid one.
  • Report an entry whose item is gone, and see it counted as deleted.
  • internal/proxyd/ca covers the wb-proxyd side: the refused batches, each entry before and after the valid one, an entry of another VM’s CA set and one of a CA set that failed to restore among them (TestC02RemovalRefused), and the deletes, an item already gone and a failed delete (TestC02RemovalDeletes).
  • internal/hostd/carecord covers the wb-hostd side: a list of 3 entries, and one of 70 sent as batches of 64 and 6, with deleted entries dropped, entries refused for their form dropped and logged, and the rest sent next (TestC02CARemovalList). An entry refused because its CA is in the record stays, logged, and goes out after the VM’s next CA set (TestC02CARemovalHeldBack).

Spec: S09-08-guest-trustS09-08-guest-trust: Guest TrustHow wb-guestd makes the guest's clients trust the VM's CAs.. The tests are in internal/guestd/trust, in a temporary directory, unless named otherwise.

  • Install one CA, then two, then one of the two. See ca.pem hold the CAs in order, bundle.pem the public roots then the CAs, and java-truststore.p12 parse back without a password to the bundle’s certificates, each file mode 0644 and the directory and its parent 0755 under a umask of 077 (TestC02TrustFiles).
  • Send an empty list, four certificates, a leaf, an RSA CA, a P-384 CA, garbage and the same CA twice. See each refused with trust-install-refused, logged with the rule, and the directory unchanged (TestC02TrustRefused).
  • Make the directory a symlink, a file, mode 0777, 0700 or setgid, or owned by another user (as root only). Make its parent a symlink, writable by its group or by others, or owned by another user (as root only). See each refused with trust-dir-unsafe and nothing written (TestC02TrustDirUnsafe).
  • Make the public roots missing, a directory, a FIFO, empty of certificates or over 4 MiB, and see each fail with trust-install-failed and nothing written (TestInstallRootsFailed). Cancel the call’s context, and see the same (TestInstallCanceled).
  • Install a CA that wb-proxyd’s CA authority issued with the fake key, then a new one. A Go tls.Client in a child process with SSL_CERT_FILE set to the bundle accepts the new CA’s leaf, and one with the first install’s bundle refuses it (TestC02TrustTLSClient).
  • When a JDK’s keytool is on PATH, it lists the Java trust store without a password, every entry trusted (TestC02TrustKeytool).
  • The trust variables have their exact values (TestC02TrustEnv), and internal/guestd/shell puts them after the account’s variables (TestEnvironment) and refuses a host value of any of their names (TestRefusals).
  • No Go file of wb-guestd names a call that adds a CA to the system trust store (TestC02NoSystemTrustStore).
  • In internal/guestd, InstallTrust hands the certificates on in order and answers each rule with its code and ErrorInfo (TestC02InstallTrustRPC).

TestC02GuestTrustVM in cmd/wb-hostd, needs-vm, as TestC11HostdVM in C11-host-daemonsC11-host-daemons: Host Daemons, Audit, and DisksThe test cases for the host daemons' own checks: wb-vmd's device set and slots, the image build bundle, supervision, the accounting and event channels, the daemon log pipes, the audit writer, free space, and the data…: it runs under a test data root the same way. It runs with the variables and the go test command of mise run go:test-vm, with -run '^TestC02GuestTrustVM$'. wb-proxyd doesn’t run. The child wb-hostd gets a fake wb-proxyd end of the control channel, wb-proxyd’s CA authority over the fake secret store and the software fake key, so no Keychain item is made. The boot time call runs the CA record’s boot order (S09-07-ca-certificatesS09-07-ca-certificates: CA CertificatesThe profile and scope of each TLS inspection CA, the leaf certificates it signs, and its rotation., “Boot, restore and host wake”), until I583I583 (closed): wb-hostd: run the CA keeper: boot order at VM start, ProxydStarted, the rotation tick and host wakeNamed by the code review of #581 (finding 1), which builds #507. wires it in wb-hostd. The fake writes a leaf for wbtest.invalid to .scratch/go-test-vm/trust for each accepted CA set. In wb shells of a project it adds, the test checks:

  • the project user’s environment holds the six trust variables with their values;
  • /etc/wraithbox/trust is mode 0755 and holds exactly the three files, each owned by root with mode 0644, and its parent is owned by root and not writable by its group or others;
  • ca.pem is the record’s CAs in order, bundle.pem ends with them after the public roots, and java-truststore.p12 holds the bundle’s certificates;
  • security find-certificate -a -Z over the system keychains lists certificates, and none is a CA of the record or names Wraith Box;
  • a TLS server (testdata/tlsserver, built for darwin/arm64) on the guest’s loopback, with the leaf, is accepted by curl, git ls-remote (dumb HTTP), python3 with urllib, node with https.get, and, when the image has a JDK, Java with only JAVA_TOOL_OPTIONS. Each client runs with the shell’s environment and nothing the test adds, and is told the server’s address. curl is in the base system and must run. Any other client the script marks missing is logged as not run, and a client with no whole block in the output fails the test;
  • URLSession, from osascript -l JavaScript through the server’s CONNECT proxy, refuses the leaf with NSURLError -1202 or -1203, and the server logs a failed handshake after that tunnel;
  • after wb vm stop, wb vm reset-ca work and a new start, the record holds one new CA, no trust file holds the old one, every client refuses the old leaf with its certificate error and accepts the new one.

The test sends the server, the leaf and its key to the guest only on the shell’s standard input (SEC02-no-host-fs-shareSEC02-no-host-fs-share: No host filesystem sharingNo host directory is mounted into the guest, read-only or otherwise.), and logs each client’s outcome with result:. Unit tests of the same package check the fake against the CA record, a reset included (TestFakeCABootWritesLeaf, TestFakeCAResetWritesNewLeaf, TestFakeCABootHook), the server (TestTLSServer), the script and its output (TestParseClients, TestClientsScriptCarriesServerAndLeaf), and the judgment of each client’s outcome (TestJudgeProbeFailsClosed).

Runs: none yet.

  • Upstream addresses: arbitrary 16-byte addresses, checked against a second reading of the ranges (FuzzUpstreamAddress).
  • TLS ClientHello parsing, a ClientHello split across TLS records included: FuzzClientHello feeds any bytes, whole and split into records at any points. The parser doesn’t panic, decides the same on the bytes cut at the cap, so it doesn’t read past it, and a server name it accepts is in the name form. FuzzServerFlight checks that the server’s records are read within the cap with at most one HelloRetryRequest.
  • The first-byte protocol check of S07-15-non-http-streamsS07-15-non-http-streams: Non-HTTP StreamsHow wb-proxyd checks the protocol of each stream, and what it does with SSH, other protocols and raw TCP.: FuzzFirstBytes checks that a TLS port takes nothing the ClientHello parser refuses, that port 80 never takes the HTTP/2 preface, and that a decision on a prefix holds for the whole. FuzzPassClientRecords checks that before the ServerHello a pass relay sends upstream at most one change cipher spec and, after a HelloRetryRequest, one ClientHello that passes the pass checks. FuzzPassInterleaved steps the relay’s client and server directions in any order, and checks that the checks end only when no second ClientHello is owed.
  • The guest handshake’s errors: FuzzHandshakeErrorRule feeds any error text, plain, wrapped or in a *net.OpError with any Op. It never classifies as tls-ech-refused or tls-client-rejected-leaf for anything but a received alert, and gives one of them for every received alert.
  • HTTP/1.1 and HTTP/2 request handling, and request path canonicalization. FuzzHTTP1RequestHead, FuzzCanonicalPath and FuzzHTTP1Conn cover HTTP/1.1.
  • The name reports, releases and stream messages wb-proxyd reads from wb-netd, and the hand-off messages it reads from wb-hostd (S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach.). FuzzNetdMessage checks that an accepted message has a canonical name, an address inside 198.18.0.0/15, a stream’s generation, id and port of at least 1, and a descriptor on a stream and no other message. The message encodes again within 4 KiB. FuzzProxydMessage does the same for the StreamReset that wb-netd reads, and FuzzControlMessage for wb-hostd’s messages. FuzzHandoffDecision drives wb-proxyd’s decisions on them and checks its copy of the name mapping after each.
  • The CA messages of the control channel: FuzzCAControlMessage feeds any bytes through the decoder to wb-proxyd’s CA authority over the fakes. A message that parses has a VM slot and CA ids of the fixed form, and each reply has the form control.proto gives it.
  • Leaf hostnames: FuzzLeafName feeds any hostname to wb-proxyd’s leaf signing over the fakes. A leaf it signs has exactly one dNSName, equal to the input and neither a wildcard nor an IP address. It is CA:FALSE, signed by the VM’s CA, and valid within the CA’s validity.
  • wb-proxyd’s CA replies as wb-hostd reads them: FuzzProxydCAReply feeds any bytes to the check of a CA issued reply. It never panics, and a reply that passes has a certificate of the CA profile: a P-256 key, self-signed, and 60 days of validity.
  • Guest trust: FuzzCheckCAs feeds any certificates to the request check, and a set it accepts has 1 to 3 P-256 CAs. FuzzParseRoots feeds any bytes as the public roots file, and sees a root or an error.
  • The wrapped form of the CA key: FuzzWrappedForm feeds any bytes to the reader the restore runs before it calls the Secure Enclave, in pure Go. It never panics or changes its input, and a form it takes has the length, the ed element, and every byte outside the key fields of a form generate gave.
  • Present an SNI that differs from the resolved name.
  • Send SSH, a PostgreSQL startup message and a cleartext HTTP/2 preface to an allowed TLS port, and SSH to port 22 of a git forge. Open a stream to an allowed port and don’t send. Send an HTTP CONNECT and an Upgrade: h2c to an inspected host. Send a ClientHello with an encrypted_client_hello extension to a pass host. See each reset or refused with its rule from S07-15-non-http-streamsS07-15-non-http-streams: Non-HTTP StreamsHow wb-proxyd checks the protocol of each stream, and what it does with SSH, other protocols and raw TCP., and no connection opened upstream for a stream reset on its first bytes.
  • Send a ClientHello with a real ECH configuration to an inspected host, and see the client abort and tls-ech-refused logged.
  • After a HelloRetryRequest from a pass host, send a second ClientHello with another SNI, and see it reset.
  • To a pass host, send client application data, or a handshake record that isn’t a ClientHello, before the server’s ServerHello, and see it reset.
  • Try to add a raw TCP entry on a guarded host (github.com, ssh.github.com, a host with a credential binding), at load and at a recompute, and see it refused with the host named.
  • With an allowed name that resolves to 127.0.0.1, an RFC 1918 address, 169.254.169.254 or an IPv4-mapped form of one, open an inspected, a pass and a raw TCP stream to it, and see each refused with upstream-address-refused and no upstream connection.
  • Do the same for a name that resolves to an address of one of the host’s interfaces, to an address in an on-link prefix of the host (a global IPv6 LAN address included), to 192.0.0.8, and to IPv4-compatible, 6to4, and Teredo addresses.
  • Load a policy whose host is 127.0.0.1 or 0x7f000001, and see it refused.

Spec: S07-08-requests-and-credentialsS07-08-requests-and-credentials: Requests and CredentialsThe form of each request wb-proxyd sends upstream, and how it removes the guest's credentials and injects bound ones., “Request form”.

  • On an inspected host, send Transfer-Encoding: gzip, chunked, chunked, chunked, identity, two Transfer-Encoding lines, Transfer-Encoding with Content-Length, and any Transfer-Encoding over HTTP/2. See each get a 400 with http-transfer-coding and nothing sent upstream.
  • Send a chunked body with a bad chunk size, and see the request end with the same rule and the upstream request aborted.
  • Send a request head over 64 KiB over HTTP/1.1, and a header list over the announced SETTINGS_MAX_HEADER_LIST_SIZE over HTTP/2, and see a 431 with http-header-size and nothing sent upstream.
  • To a path whose policy allows POST and not DELETE, send a POST with X-HTTP-Method-Override: DELETE, then with X-HTTP-Method and X-Method-Override, and see each get a 403 with http-method-override and nothing sent upstream (S07-16-tls-and-tunnelsS07-16-tls-and-tunnels: TLS and TunnelsWhat wb-proxyd does with client certificates, encrypted ClientHello and tunnels, and which refusals no mode or approval relaxes., “Method overrides”).

Unit tests in internal/proxyd/httpreq, below the HTTP/1.1 connection loop:

  • Each head form the parser refuses gets a 400 with http-request-form (TestC02RequestHeadRefusals). A head over 64 KiB gets a 431 with http-header-size, and the parser takes no byte past the cap (TestC02HeadOverCap).
  • Origin form, absolute form with its userinfo dropped, and Host: example.com:443 on port 443 pass (TestC02RequestFormAccepted).
  • The canonical path: /a/./b/../c becomes /a/c, /@scope%2fname stays one segment, and %2e%2e and wget%2F..%2Fcurl are refused with http-path-form (TestC02CanonicalPath).
  • The transfer codings above get a 400 with http-transfer-coding before the HTTP policy step (TestC02TransferCoding). A chunked framing that fails to decode ends the body with the same rule (TestC02ChunkedFraming).
  • CONNECT and Upgrade: h2c get a 403 with http-tunnel before any step (TestC02Tunnels). TRACE and TRACK get a 403 with http-trace, and trace reaches the policy step’s own check (TestC02Trace). Without the credential removal step or the HTTP policy step, a request gets http-step-missing (TestC02StepMissing).
  • Each method-override field, in any case, with any other separator such as X.HTTP.Method.Override, empty, repeated, and named in Connection, gets a 403 with http-method-override before any step, and a field whose name only resembles one passes (TestC02MethodOverride). The request steps refuse it again when the reader didn’t check it (TestC02MethodOverrideInSteps).
  • FuzzHTTP1RequestHead and FuzzCanonicalPath fuzz the head parser and the canonicalize step. A head the parser accepts has no method-override field that net/http reads.

Unit tests in internal/proxyd/http1, the HTTP/1.1 connection loop. Tests check each refusal in inspect mode and in audit mode. Its answer is text/plain with Connection: close and names the rule and the host, and its log record names the rule:

  • The transfer codings above get a 400 with http-transfer-coding, and no upstream connection opens (TestC02HTTP1TransferCoding). A chunked body with a bad chunk size gets the same, and the upstream gets an incomplete request (TestC02HTTP1ChunkedAbort). A head over 64 KiB gets a 431 with http-header-size (TestC02HTTP1HeadOverCap).
  • A method that isn’t a token, a Host other than the stream’s name (the name its SNI gave), a field name with an _, %2e%2e, TRACE, TRACK, CONNECT, Upgrade: h2c and each method-override field, in lower and upper case, with other separators, repeated and named in Connection, are refused with their rules before the HTTP policy step. No upstream connection opens for them (TestC02HTTP1Refusals).
  • The request upstream is in origin form with the canonical path, userinfo dropped and Host from the binding (TestC02HTTP1RequestForm), with no hop-by-hop field (TestC02HTTP1HopByHop). Bodies with a length and chunked go whole, Expect: 100-continue is answered by wb-proxyd, and the response step removes Set-Cookie (TestC02HTTP1Bodies).
  • The upstream gets the stream’s requests on one connection, which opens once (TestC02HTTP1KeepAlive). A refused first request opens none (TestC02HTTP1RefusedOpensNothing). A missing step, or a policy step with no recompute check, gets a 500 with http-step-missing (TestC02HTTP1StepMissing). A request after a policy change that refuses it never reaches the upstream, and its refusal is logged with the current mode (TestC02HTTP1PolicyChange).
  • A head past its deadline resets with http-header-timeout, on the first request and on a later one (TestC02HTTP1HeaderTimeout).
  • A refused upstream connection gets a 502 that names its rule, and the answer leaves out the certificate names in the error (TestC02HTTP1UpstreamRefused). A refusal on the response’s first read gets the refusal’s own rule (TestC02HTTP1UpstreamReadRefusal). When the upstream closes without a response, the guest gets a 502 with upstream-request-failed (TestC02HTTP1UpstreamBroken). A kept upstream connection that the server closed between requests closes the guest’s stream with no answer and upstream-idle-close, before the guest’s next request (TestC02HTTP1UpstreamIdleClose), and so does one the server closes after it read the next request (TestC02HTTP1UpstreamCloseAfterRequest). A close while the steps decide the next request leaves a refusal its answer and its record, and sends a request that passed nowhere (TestC02HTTP1StepAtIdleClose, TestC02HTTP1PipelinedRefusalAtIdleClose). Bytes the server sent after a response, in the socket before the next request goes, get that request a 502 with upstream-request-failed and never reach the guest. The tests send junk before a close, a whole response, bytes a while after the response, and a response in TLS records of its own behind the answer to a pipelined guest (TestC02HTTP1UpstreamJunkAfterResponse, TestC02HTTP1UnsolicitedResponse, TestC02HTTP1LateUnsolicitedResponse, TestC02HTTP1PipelinedLateBytes). A last read before a request that stalled past its deadline with bytes in the socket is made again, and the request gets that 502 when each try stalls (TestC02HTTP1ProbeStall). Bytes the next read takes without data pass (TestC02HTTP1ProbeRecordWithoutData), and a failed count of the socket’s bytes fails closed (TestC02HTTP1ProbeUnreadFails). A response head past its bound gets a 502, and a response body that pauses past its bound resets (TestC02HTTP1ResponseTimeouts). A stream reset while it waits for a response head ends with the reset alone, with no 502 (TestC02HTTP1ResetWaitingForHead).
  • An HTTP/1.0 guest that asked to keep the stream gets a body of unknown length unframed, and the stream closes after it (TestC02HTTP1HTTP10Unframed). A body that the body step made longer than its length resets with http-transfer-coding before the upstream has a whole request (TestC02HTTP1BodyLength). A body step’s read that returns bytes with a refusal sends none of them (TestC02HTTP1BodyRefusalSendsNothing).
  • Each stream registers one recompute check. A recompute that no longer allows the request in flight resets the stream inside its response, and one between requests doesn’t (TestC02HTTP1Recompute). A check that fails at its registration resets with nothing sent upstream (TestC02HTTP1OpenCheckRefuses). That covers a recompute between the steps and the registration on a first request (TestC02HTTP1RecomputeBeforeAddCheck) and a nil check from the policy step (TestC02HTTP1NilOpenCheck).
  • A recompute that lands between the steps of a later request and its going in flight resets the stream with the failed check in its log record. The origin gets the earlier request only (TestC02HTTP1RecomputeBeforeWatch).
  • An allowed WebSocket upgrade relays (TestC02HTTP1WebSocket). An upstream 101 to another request, or one answered with another Upgrade, resets with http-tunnel (TestC02HTTP1Unexpected101).
  • FuzzHTTP1Conn feeds the loop any guest bytes and any upstream bytes under a policy step that passes or refuses every request. It checks that the loop returns with the stream ended. The upstream connection may open only after a request passed the steps, and no more requests may go upstream than passed. Each of them has the binding’s Host. A byte after them is a fault unless it belongs to a WebSocket.

Status: Draft