Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/transport/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions docs/transport/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
17 changes: 14 additions & 3 deletions internal/tlsct/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +262 to +267
if pkErr != nil {
verifyErrs = append(verifyErrs, "parse log public key: "+pkErr.Error())
continue
Expand All @@ -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()
Expand Down
113 changes: 113 additions & 0 deletions internal/tlsct/tiled_logs_test.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading