diff --git a/server/attester_trust.go b/server/attester_trust.go index 850f54a9..3ca20736 100644 --- a/server/attester_trust.go +++ b/server/attester_trust.go @@ -267,9 +267,13 @@ const ( // only while it can't put that identity in a certificate: with // anchors shared between attesters — a trust list, one anchor pool // for every client — any attester that runs a CA under any of the - // anchors (or holds an intermediate without name constraints) can - // issue itself a certificate naming another attester, and attest for - // that attester's clients. Choose AttesterIssuerBoundToAnchor for + // anchors can issue itself a certificate naming another attester, + // and attest for that attester's clients. Name constraints confine + // that only if they are uniformResourceIdentifier constraints, on the + // attester's CA or one above it, and then only a URI's host: RFC 5280 + // §4.2.1.10 applies each constraint to names of its own type, so a + // CA constrained to the dNSName attester-a.example can still certify + // https://attester-b.example. Choose AttesterIssuerBoundToAnchor for // shared trust lists; this mode suits anchors that issue only to // attesters they have vetted for every identifier they certify. AttesterIssuerInCertificate diff --git a/server/attester_trust_test.go b/server/attester_trust_test.go index 441d69f9..10bbcb7c 100644 --- a/server/attester_trust_test.go +++ b/server/attester_trust_test.go @@ -43,6 +43,8 @@ type certOptions struct { keyUsage x509.KeyUsage key crypto.Signer // nil: fresh P-256 uris []string // URI subject alternative names + permittedDNS []string // dNSName name constraints + permittedURI []string // uniformResourceIdentifier name constraints extKeyUsage []x509.ExtKeyUsage unknownExtKeyUsage []asn1.ObjectIdentifier } @@ -82,6 +84,8 @@ func newTestCert(t *testing.T, name string, o certOptions) testCert { IsCA: o.isCA, ExtKeyUsage: o.extKeyUsage, UnknownExtKeyUsage: o.unknownExtKeyUsage, + PermittedDNSDomains: o.permittedDNS, + PermittedURIDomains: o.permittedURI, } for _, raw := range o.uris { u, err := url.Parse(raw) @@ -511,6 +515,48 @@ func TestX5CAttesterChainIssuerInCertificate(t *testing.T) { } } +// TestX5CAttesterChainIssuerInCertificateNameConstraints pins what name +// constraints do for AttesterIssuerInCertificate under a shared anchor: +// attester A's CA, constrained to A's host, issues a certificate naming +// the client's attester. A dNSName constraint doesn't confine a URI SAN +// (RFC 5280 §4.2.1.10), so A attests for the client; only a +// uniformResourceIdentifier constraint stops it. +func TestX5CAttesterChainIssuerInCertificateNameConstraints(t *testing.T) { + sharedRoot := newTestCert(t, "trust list CA", certOptions{isCA: true}) + cases := map[string]struct { + constraints certOptions + wantOK bool + }{ + "dNSName constraint doesn't confine a URI SAN": {certOptions{permittedDNS: []string{"attester-a.example"}}, true}, + "uniformResourceIdentifier constraint does": {certOptions{permittedURI: []string{"attester-a.example"}}, false}, + } + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + opts := tc.constraints + opts.parent, opts.isCA = &sharedRoot, true + attesterACA := newTestCert(t, "attester A CA", opts) + leaf := newTestCert(t, "attester", certOptions{parent: &attesterACA, uris: []string{testAttesterIssuer}}) + h := newHarnessWithAttesterTrust(t, nil, server.X5CAttesterChain{ + Revocation: server.NoClientCertificateRevocationCheck{}, + TrustAnchors: server.StaticAttesterTrustAnchors{Roots: poolOf(sharedRoot)}, + IssuerBinding: server.AttesterIssuerInCertificate, + }) + instanceKey := generateKey(t) + attestation := createX5CAttestation(t, leaf.key, x5cOf(leaf, attesterACA), "", &instanceKey.PublicKey, h.now) + err := requestWithAttestation(t, h, attestation, instanceKey) + if tc.wantOK { + if err != nil { + t.Fatalf("RequestClientCredentialsToken: %v", err) + } + return + } + if code := serverErrorCode(t, err); code != server.ErrorInvalidClient { + t.Fatalf("error code = %q, want %q", code, server.ErrorInvalidClient) + } + }) + } +} + // TestRegisteredAttesterKeysIgnoresClientKeys proves an attestation // verifies only against the attester's own key source: a client whose // own key is in Dependencies.ClientKeys — as keys/ephemeral or diff --git a/storage/client_repository.go b/storage/client_repository.go index d16c3261..5327576e 100644 --- a/storage/client_repository.go +++ b/storage/client_repository.go @@ -129,7 +129,11 @@ const ( // of ExpectedSANURI against one of the presented certificate's // subjectAltName uniformResourceIdentifier entries — RFC 8705 // §2.1's "tls_client_auth_san_uri". Same chain-trust posture as - // ClientAuthMethodTLSClientAuth — see its own doc comment. + // ClientAuthMethodTLSClientAuth — see its own doc comment. Where the + // trusted CAs are shared, any CA under them that may issue a URI SAN + // can name this client's value: only uniformResourceIdentifier name + // constraints confine URI SANs (RFC 5280 §4.2.1.10), dNSName ones + // don't. ClientAuthMethodTLSClientAuthSANURI // ClientAuthMethodTLSClientAuthSANIP authenticates by match of