diff --git a/docs/transport/README.md b/docs/transport/README.md index 47bf2f7f..f9313000 100644 --- a/docs/transport/README.md +++ b/docs/transport/README.md @@ -41,6 +41,12 @@ the response is too late to protect request data. SPKI comparisons use constant-time operations. TLS-SPKI pools disable session resumption to ensure that each handshake checks the attested peer identity. +CT verification obtains log public keys from Google's +[all-logs list](https://www.gstatic.com/ct/log_list/v3/all_logs_list.json), +cached in memory for 24 hours. SCT log IDs can identify either RFC 6962 logs +or Static CT API logs (`tiled_logs`). Both use SCT signature verification; +an unknown log ID or invalid signature does not authenticate an SCT. + For E2EE routes, every logical request must acquire a valid authorization that binds the backend encryption key through attestation, including requests that reuse relay TLS connections. A cached authorization satisfies this requirement; diff --git a/docs/transport/testing.md b/docs/transport/testing.md index bd547735..d6f4e36a 100644 --- a/docs/transport/testing.md +++ b/docs/transport/testing.md @@ -11,6 +11,7 @@ tests. | Behavior to preserve | Representative coverage | | --- | --- | +| RFC 6962 and tiled CT logs verify signed SCTs during concurrent checks; unknown log IDs, invalid keys, and invalid signatures fail closed | `TestCheckTLSState_LogCollections` in [CT log tests](../../internal/tlsct/tiled_logs_test.go) | | Concurrent KDS retrieval uses TLS 1.3/HTTP2 and verifies signed evidence; retrieval failures are terminal | `TestTinfoilKDS`, `TestTinfoilKDSEmbeddedChains` in [Tinfoil KDS tests](../../internal/provider/tinfoil/kds_test.go) | | Canceled discovery and capture collection do not race | `TestCanceledDiscoveryCapture` in [capture cancellation tests](../../internal/verify/capture_cancellation_test.go) | | Standalone EHBP rejects encrypted provider error events and malformed data without exposing response content | `TestStandaloneEHBPStreamCompletion` in [EHBP completion tests](../../internal/verify/ehbp_completion_test.go) | diff --git a/internal/tlsct/checker.go b/internal/tlsct/checker.go index 2b3372a3..03983f06 100644 --- a/internal/tlsct/checker.go +++ b/internal/tlsct/checker.go @@ -259,12 +259,12 @@ func (c *Checker) checkTLSState( var verifyErrs []string for _, candidate := range scts { - log := logList.FindLogByKeyHash(candidate.sct.LogID.KeyID) - if log == nil { + key, found := ctLogKey(logList, candidate.sct.LogID.KeyID) + if !found { verifyErrs = append(verifyErrs, "SCT log ID not found in trusted log list") continue } - pub, pkErr := ctx509.ParsePKIXPublicKey(log.Key) + pub, pkErr := ctx509.ParsePKIXPublicKey(key) if pkErr != nil { verifyErrs = append(verifyErrs, "parse log public key: "+pkErr.Error()) continue @@ -284,6 +284,17 @@ func (c *Checker) checkTLSState( return fmt.Errorf("no valid SCTs: %s", strings.Join(verifyErrs, "; ")) } +// ctLogKey finds the SCT verification key in either CT log collection. +func ctLogKey(list *loglist3.LogList, id [sha256.Size]byte) ([]byte, bool) { + if log := list.FindLogByKeyHash(id); log != nil { + return log.Key, true + } + if log := list.FindTiledLogByKeyHash(id); log != nil { + return log.Key, true + } + return nil, false +} + func (c *Checker) addCacheEntry(key string) { c.mu.Lock() defer c.mu.Unlock() diff --git a/internal/tlsct/tiled_logs_test.go b/internal/tlsct/tiled_logs_test.go new file mode 100644 index 00000000..e656517e --- /dev/null +++ b/internal/tlsct/tiled_logs_test.go @@ -0,0 +1,113 @@ +package tlsct_test + +import ( + "context" + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/sha256" + "crypto/tls" + "crypto/x509" + "net/http" + "net/http/httptest" + "sync" + "testing" + "time" + + "github.com/13rac1/teep/internal/tlsct" + ct "github.com/google/certificate-transparency-go" + "github.com/google/certificate-transparency-go/loglist3" + cttls "github.com/google/certificate-transparency-go/tls" +) + +func TestCheckTLSState_LogCollections(t *testing.T) { + server := httptest.NewTLSServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) + defer server.Close() + cert := server.Certificate() + sct, key := signedHandshakeSCT(t, cert) + + for _, tiled := range []bool{false, true} { + name := "RFC6962" + if tiled { + name = "tiled" + } + t.Run(name, func(t *testing.T) { + for _, outcome := range []string{"valid", "invalid signature", "unknown log", "invalid key"} { + t.Run(outcome, func(t *testing.T) { + candidate := sct + logKey := key + logID := sct.LogID.KeyID + switch outcome { + case "invalid signature": + candidate.Timestamp++ + case "unknown log": + logID[0] ^= 1 + case "invalid key": + logKey = []byte("invalid public key") + } + op := &loglist3.Operator{} + if tiled { + op.TiledLogs = []*loglist3.TiledLog{{LogID: logID[:], Key: logKey}} + } else { + op.Logs = []*loglist3.Log{{LogID: logID[:], Key: logKey}} + } + checker := tlsct.NewChecker() + checker.InjectLogList(&loglist3.LogList{Operators: []*loglist3.Operator{op}}) + raw, err := cttls.Marshal(candidate) + if err != nil { + t.Fatal(err) + } + state := &tls.ConnectionState{ + PeerCertificates: []*x509.Certificate{cert}, + SignedCertificateTimestamps: [][]byte{raw}, + } + var wg sync.WaitGroup + for range 8 { + wg.Go(func() { + err := checker.CheckTLSState(context.Background(), "example.com", state) + if (err == nil) != (outcome == "valid") { + t.Errorf("CT verification: %v; expected %s", err, outcome) + } + }) + } + wg.Wait() + }) + } + }) + } +} + +func signedHandshakeSCT(t *testing.T, cert *x509.Certificate) (sct ct.SignedCertificateTimestamp, publicKey []byte) { + t.Helper() + key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + t.Fatal(err) + } + pub, err := x509.MarshalPKIXPublicKey(&key.PublicKey) + if err != nil { + t.Fatal(err) + } + sct = ct.SignedCertificateTimestamp{ + SCTVersion: ct.V1, + LogID: ct.LogID{KeyID: sha256.Sum256(pub)}, + Timestamp: uint64(time.Now().UnixMilli()), + } + leaf, err := ct.MerkleTreeLeafFromRawChain([]ct.ASN1Cert{{Data: cert.Raw}}, ct.X509LogEntryType, sct.Timestamp) + if err != nil { + t.Fatal(err) + } + input, err := ct.SerializeSCTSignatureInput(sct, ct.LogEntry{Leaf: *leaf}) + if err != nil { + t.Fatal(err) + } + digest := sha256.Sum256(input) + sig, err := ecdsa.SignASN1(rand.Reader, key, digest[:]) + if err != nil { + t.Fatal(err) + } + sct.Signature = ct.DigitallySigned{ + Algorithm: cttls.SignatureAndHashAlgorithm{Hash: cttls.SHA256, Signature: cttls.ECDSA}, + Signature: sig, + } + return sct, pub +}