Skip to content

feat(client): add identity.v1 claim signing and verification - #2223

Merged
ramizpolic merged 5 commits into
mainfrom
feat/identity-02-claim-crypto
Oct 1, 2026
Merged

ramizpolic merged 5 commits into
mainfrom
feat/identity-02-claim-crypto

Conversation

@ramizpolic

@ramizpolic ramizpolic commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Second PR in the identity/ownership claims epic (#2212), following #2221 (claim types, merged). Adds the cryptographic proof for a Claim: signing and verification, as two small packages under client/utils with no server, CLI, reconciler, or key-resolution awareness.

The split mirrors how sign.v1 already works here: api/sign/v1 has no crypto, and the logic lives in client/utils/cosign and client/utils/verify. api/identity/v1 keeps the same shape (proto types, payload, referrer marshaling) and imports no crypto library.

client/utils/jws: payload-agnostic detached JWS (RFC 7515)

  • Sign(signer, payload) and Verify(jws, payload, keys...). The algorithm is derived from the key's own type (ES256, ES384, EdDSA, RS256), never from the token's self-declared alg header, so a token can't pick its own verification algorithm.
  • Verify takes variadic keys and succeeds if any one validates, so a resolver can hand over a whole key set (a DNS TXT record set, a JWKS). An unusable key is skipped rather than aborting, and no keys is an explicit error.
  • RSA keys under 2048 bits are rejected for both signing and verification.
  • KeySigner loads a PEM key: EC PRIVATE KEY, RSA PRIVATE KEY, PRIVATE KEY, and password-protected ENCRYPTED PRIVATE KEY (PKCS#8 PBES2, including Ed25519). jws takes bytes and does no I/O of its own: the password is passed in by the caller (nil for an unencrypted key), and reading key files, prompting, and the environment (COSIGN_PASSWORD / --password-stdin) stay with the CLI. Decryption uses github.com/youmark/pkcs8, already in the module graph through cosign, so go.mod only loses its // indirect marker.
  • The Signer interface is Sign(payload) plus Public(), so callers can check a certificate against the signer's key without a second type.

client/utils/identity: claim-level glue on top of jws

  • Sign(claim, recordCID, signer, opts...) sets RecordCid, SignedAt, and Signature. It signs a copy and writes the fields back only once signing has succeeded, so a failed Sign leaves the caller's claim exactly as it was, and re-signing replaces a stale Certificate rather than leaving it behind.
  • WithCertificate(cert) embeds an X.509 certificate (PEM or DER) in the claim, for subjects whose proof is a certificate rather than a published key (SPIFFE X.509-SVIDs). Before signing, Sign checks that the certificate belongs to the signer's key (a mismatched pair fails here instead of producing signatures every verifier rejects) and that it names the claim's subject as a URI SAN. An unparsable or empty certificate is an error, never a claim whose optional Certificate is present but empty.
  • Verify(claim, recordCID, expectedSubject, keys...) checks record_cid, subject, and expiry (a malformed expires_at is an error, not silently ignored), then verifies the signature against the given keys. It returns (bool, error).

Signed payload

(*Claim).GetPayload() in api/identity/v1 returns a canonical JSON encoding of record_cid, role, subject, signed_at, and expires_at, excluding signature and certificate, which don't exist yet at signing time. role is part of it, so a signature made for one role can never be replayed as the other, regardless of which referrer type the claim is stored under. Note that role is the proto enum name (CLAIM_ROLE_IDENTITY), so that string is what gets signed.

Verify takes already-resolved public keys and does no resolution itself, so it needs no network or resolver mocking to test. Resolving keys (DNS, DID, JWKS, SPIFFE trust bundle) is a separate follow-up.

Contains

  • api/identity/v1/claim.go (+ test): Claim.GetPayload
  • client/utils/jws/{jws,signer}.go (+ tests)
  • client/utils/identity/{sign,verify}.go (+ tests)
  • client/go.mod, client/go.sum: lestrrat-go/jwx/v2, and youmark/pkcs8 as a direct dependency

Nothing outside these packages calls any of this yet.

Verification

go build, go vet, go test, and golangci-lint (CI-pinned 2.13.2, diff-only and over the full packages) pass for the api and client modules; go mod tidy leaves no drift. Statement coverage is 95.5% for jws and 97.6% for identity.

  • jws: sign/verify round-trips for ES256, ES384, EdDSA, and RS256; tampered payload, wrong key, wrong key type, and unsupported key type are rejected; multi-key verification; key loading from PEM (PKCS#8, legacy EC and RSA), bad key material; encrypted-key loading (missing password, wrong password, password ignored for an unencrypted key); RSA keys under 2048 bits rejected.
  • identity: round-trips for both roles, and with a certificate (PEM and raw DER); a tampered payload, a wrong subject, a mismatched role (a claim signed as identity must not verify as owner), an expired claim, a malformed expiry, and a wrong record_cid each fail distinctly; Sign leaves the claim untouched when the signer fails, the subject isn't covered by the certificate, the certificate belongs to another key (same or different type), or the certificate is empty or garbage; re-signing clears a stale certificate; invalid-input errors.
  • api/identity/v1: GetPayload output for all three roles (unspecified, identity, owner), asserting exact bytes and field order.

Resolves #2222

@ramizpolic
ramizpolic requested a review from a team as a code owner September 29, 2026 16:36
@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Sep 29, 2026
@ramizpolic
ramizpolic force-pushed the feat/identity-02-claim-crypto branch from 65ec3ee to 5ef8955 Compare September 29, 2026 16:43
@ramizpolic
ramizpolic force-pushed the feat/identity-01-claim-types branch from 79099c3 to c7cf7c5 Compare September 30, 2026 08:05
@ramizpolic
ramizpolic marked this pull request as draft September 30, 2026 08:23
@ramizpolic
ramizpolic force-pushed the feat/identity-02-claim-crypto branch from 5ef8955 to fbd816b Compare September 30, 2026 08:58
@ramizpolic
ramizpolic force-pushed the feat/identity-01-claim-types branch from c7cf7c5 to 6c6ff45 Compare September 30, 2026 11:08
@ramizpolic
ramizpolic force-pushed the feat/identity-02-claim-crypto branch from fbd816b to 47d8a8a Compare September 30, 2026 11:09
Base automatically changed from feat/identity-01-claim-types to main September 30, 2026 11:43
@ramizpolic
ramizpolic force-pushed the feat/identity-02-claim-crypto branch from 47d8a8a to bd56a05 Compare September 30, 2026 12:37
@github-actions github-actions Bot added size/L Denotes a PR that changes 1000-1999 lines and removed size/M Denotes a PR that changes 200-999 lines labels Sep 30, 2026
@ramizpolic ramizpolic changed the title feat(api): add identity.v1 claim signing and verification feat(client): add identity.v1 claim signing and verification Sep 30, 2026
@ramizpolic
ramizpolic marked this pull request as ready for review September 30, 2026 12:37
@ramizpolic
ramizpolic force-pushed the feat/identity-02-claim-crypto branch from bd56a05 to c16a3ec Compare September 30, 2026 12:52
@ramizpolic ramizpolic linked an issue Sep 30, 2026 that may be closed by this pull request
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.94595% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
client/utils/jws/jws.go 93.8% 2 Missing ⚠️
api/identity/v1/claim.go 90.0% 1 Missing ⚠️
client/utils/identity/sign.go 98.1% 1 Missing ⚠️
client/utils/identity/verify.go 95.0% 1 Missing ⚠️
client/utils/jws/signer.go 97.0% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

lgecse
lgecse previously approved these changes Sep 30, 2026
@ramizpolic
ramizpolic force-pushed the feat/identity-02-claim-crypto branch from c16a3ec to d1af0ab Compare September 30, 2026 13:48
@ramizpolic
ramizpolic enabled auto-merge (squash) September 30, 2026 13:57
Comment thread client/utils/identity/verify.go Resolved
Comment thread client/utils/jws/signer.go Resolved
Comment thread client/utils/jws/signer.go Resolved
Comment thread client/utils/identity/sign.go Resolved
Comment thread client/utils/identity/sign.go Resolved
ramizpolic added a commit that referenced this pull request Oct 1, 2026
Adds client/utils/identity/resolvers: one resolver per key-discovery
scheme, each returning the candidate public keys for a claim's subject.
A resolver only finds keys; it never checks a signature. Pass the result
to identity.Verify, which does all of the cryptography and accepts the
claim if any one key validates.

  Resolve(ctx, subject, certificate) ([]crypto.PublicKey, error)

- DNS: "_agntcy-key.<domain>" TXT records, "v=akv1;key=<base64 SPKI>".
- WellKnown: https subjects, the host's /.well-known/jwks.json. Skips
  encryption-only and symmetric keys.
- DID: did:web (document over HTTPS, whose id must equal the subject) and
  did:key (self-certifying, no network) for ed25519, P-256, P-384, RSA.
  did:web segments are validated so an escaped "/" or ".." can't steer
  the request to another path or host.
- SPIFFE: the key comes from the claim's X.509-SVID, trusted only after
  x509svid.ParseAndVerify validates it against the subject's trust-domain
  bundle and its SPIFFE ID equals the subject. A trust domain with no
  bundle fails closed.

Each resolver is built with an explicit constructor; there is no registry
or self-registration. Network access goes through a small Fetcher
interface, so resolvers are tested against fakes with no live network.
Every resolver caps the number of keys it will return.

utils/safefetch is the SSRF-guarded HTTPS client did and wellknown use by
default: https only, non-public addresses refused at dial time after DNS
resolution (loopback, RFC 1918, link-local, shared address space, IPv4-
mapped IPv6), redirects bounded and unable to downgrade to http, and a
response size cap.

Stacked on #2223; nothing outside these packages calls any of this yet.

Closes #2214

Signed-off-by: Ramiz Polic <[email protected]>
lgecse
lgecse previously approved these changes Oct 1, 2026
ramizpolic added a commit that referenced this pull request Oct 1, 2026
Adds client/utils/identity/resolvers: one resolver per key-discovery
scheme, each returning the candidate public keys for a claim's subject.
A resolver only finds keys; it never checks a signature. Pass the result
to identity.Verify, which does all of the cryptography and accepts the
claim if any one key validates.

  Resolve(ctx, subject, certificate) ([]crypto.PublicKey, error)

- DNS: "_agntcy-key.<domain>" TXT records, "v=akv1;key=<base64 SPKI>".
- WellKnown: https subjects, the host's /.well-known/jwks.json. Skips
  encryption-only and symmetric keys.
- DID: did:web (document over HTTPS, whose id must equal the subject) and
  did:key (self-certifying, no network) for ed25519, P-256, P-384, RSA.
  did:web segments are validated so an escaped "/" or ".." can't steer
  the request to another path or host.
- SPIFFE: the key comes from the claim's X.509-SVID, trusted only after
  x509svid.ParseAndVerify validates it against the subject's trust-domain
  bundle and its SPIFFE ID equals the subject. A trust domain with no
  bundle fails closed.

Each resolver is built with an explicit constructor; there is no registry
or self-registration. Network access goes through a small Fetcher
interface, so resolvers are tested against fakes with no live network.
Every resolver caps the number of keys it will return.

utils/safefetch is the SSRF-guarded HTTPS client did and wellknown use by
default: https only, non-public addresses refused at dial time after DNS
resolution (loopback, RFC 1918, link-local, shared address space, IPv4-
mapped IPv6), redirects bounded and unable to downgrade to http, and a
response size cap.

Stacked on #2223; nothing outside these packages calls any of this yet.

Closes #2214

Signed-off-by: Ramiz Polic <[email protected]>
ramizpolic added a commit that referenced this pull request Oct 1, 2026
Adds client/utils/identity/resolvers: one resolver per key-discovery
scheme, each returning the candidate public keys for a claim's subject.
A resolver only finds keys; it never checks a signature. Pass the result
to identity.Verify, which does all of the cryptography and accepts the
claim if any one key validates.

  Resolve(ctx, subject, certificate) ([]crypto.PublicKey, error)

- DNS: "_agntcy-key.<domain>" TXT records, "v=akv1;key=<base64 SPKI>".
- WellKnown: https subjects, the host's /.well-known/jwks.json. Skips
  encryption-only and symmetric keys.
- DID: did:web (document over HTTPS, whose id must equal the subject) and
  did:key (self-certifying, no network) for ed25519, P-256, P-384, RSA.
  did:web segments are validated so an escaped "/" or ".." can't steer
  the request to another path or host.
- SPIFFE: the key comes from the claim's X.509-SVID, trusted only after
  x509svid.ParseAndVerify validates it against the subject's trust-domain
  bundle and its SPIFFE ID equals the subject. A trust domain with no
  bundle fails closed.

Each resolver is built with an explicit constructor; there is no registry
or self-registration. Network access goes through a small Fetcher
interface, so resolvers are tested against fakes with no live network.
Every resolver caps the number of keys it will return.

utils/safefetch is the SSRF-guarded HTTPS client did and wellknown use by
default: https only, non-public addresses refused at dial time after DNS
resolution (loopback, RFC 1918, link-local, shared address space, IPv4-
mapped IPv6), redirects bounded and unable to downgrade to http, and a
response size cap.

Stacked on #2223; nothing outside these packages calls any of this yet.

Closes #2214

Signed-off-by: Ramiz Polic <[email protected]>
Adds the cryptographic proof for a Claim, split into two packages under
client/utils, mirroring how sign.v1 keeps api/sign/v1 free of crypto and
puts the logic in client/utils/cosign and client/utils/verify:

- client/utils/jws: payload-agnostic detached JWS (RFC 7515) signing and
  verification. The algorithm is derived from the key's own type (ES256,
  ES384, EdDSA, RS256), never from the token's self-declared alg header.
  RSA keys under 2048 bits are rejected. Verify takes variadic keys and
  succeeds if any one validates. KeySigner and KeyCertSigner load PEM
  keys, including password-protected PKCS#8 (ENCRYPTED PRIVATE KEY), with
  the password passed in by the caller; jws never prompts or reads env.
- client/utils/identity: claim-level Sign and Verify on top of jws. Sign
  takes WithSubjectChecker and WithCertificateProvider options (e.g. a
  KeyCertSigner's SubjectMatchesCertificate and CertificateDER for SPIFFE)
  instead of discovering interfaces on the signer. Verify checks
  record_cid, subject, and expiry, then verifies against the given keys.

A claim is signed over Claim.GetPayload, a canonical JSON encoding of
record_cid, role, subject, signed_at, and expires_at, excluding signature
and certificate. role is part of the payload, so a signature made for one
role cannot be replayed as the other.

Verify takes already-resolved public keys and does no key resolution
itself, so it has no server, CLI, reconciler, or network awareness.
Resolving keys (DNS, DID, JWKS, SPIFFE trust bundle) is a follow-up.

Closes #2222

Signed-off-by: Ramiz Polic <[email protected]>
Signed-off-by: Ramiz Polic <[email protected]>
- KeyCertSigner now keeps the parsed certificate instead of re-parsing
  its DER on every SubjectMatchesCertificate call, which also stops a
  parse failure from silently reading as "subject does not match".
- NewKeyCertSigner refuses a private key that does not belong to the
  certificate. Before, a mismatched pair signed fine and every
  verification then failed far from the cause.
- identity.Sign no longer mutates the caller's claim on failure: it
  signs a copy and writes RecordCid, SignedAt, Signature and Certificate
  back only once signing has succeeded. Re-signing also clears a stale
  Certificate rather than leaving it behind.
- A certificate provider that returns nothing is now an error. Before,
  it produced a claim whose optional Certificate was present but empty,
  which claims to carry a certificate and carries none.

Adds tests for each of the above, and for previously uncovered paths: the
file loaders, the legacy EC and RSA PEM formats, bad key material, a raw
DER certificate, and Verify's guard branches (including a malformed
expiry).

Signed-off-by: Ramiz Polic <[email protected]>
NewKeySignerFromFile and NewKeyCertSignerFromFile were thin wrappers over
os.ReadFile and the byte-based constructors, and nothing called them.
jws otherwise does no I/O: it takes bytes, and leaves prompts, the
environment and files to the caller. The CLI will decide how it loads
keys (path, inline PEM or KMS), so a file loader here was a guess about
its needs. Callers read the files themselves and use NewKeySigner or
NewKeyCertSigner.

Signed-off-by: Ramiz Polic <[email protected]>
…ate option

Drop KeyCertSigner, WithSubjectChecker and WithCertificateProvider. Sign now
takes a single WithCertificate(cert) option and checks, before signing, that
the certificate belongs to the signer's key and names the claim subject as a
URI SAN. jws.Signer exposes Public() so the check needs no extra type.

Signed-off-by: Ramiz Polic <[email protected]>
@ramizpolic
ramizpolic force-pushed the feat/identity-02-claim-crypto branch from 3e7cce7 to 56b1729 Compare October 1, 2026 09:19
ramizpolic added a commit that referenced this pull request Oct 1, 2026
Adds client/utils/identity/resolvers: one resolver per key-discovery
scheme, each returning the candidate public keys for a claim's subject.
A resolver only finds keys; it never checks a signature. Pass the result
to identity.Verify, which does all of the cryptography and accepts the
claim if any one key validates.

  Resolve(ctx, subject, certificate) ([]crypto.PublicKey, error)

- DNS: "_agntcy-key.<domain>" TXT records, "v=akv1;key=<base64 SPKI>".
- WellKnown: https subjects, the host's /.well-known/jwks.json. Skips
  encryption-only and symmetric keys.
- DID: did:web (document over HTTPS, whose id must equal the subject) and
  did:key (self-certifying, no network) for ed25519, P-256, P-384, RSA.
  did:web segments are validated so an escaped "/" or ".." can't steer
  the request to another path or host.
- SPIFFE: the key comes from the claim's X.509-SVID, trusted only after
  x509svid.ParseAndVerify validates it against the subject's trust-domain
  bundle and its SPIFFE ID equals the subject. A trust domain with no
  bundle fails closed.

Each resolver is built with an explicit constructor; there is no registry
or self-registration. Network access goes through a small Fetcher
interface, so resolvers are tested against fakes with no live network.
Every resolver caps the number of keys it will return.

utils/safefetch is the SSRF-guarded HTTPS client did and wellknown use by
default: https only, non-public addresses refused at dial time after DNS
resolution (loopback, RFC 1918, link-local, shared address space, IPv4-
mapped IPv6), redirects bounded and unable to downgrade to http, and a
response size cap.

Stacked on #2223; nothing outside these packages calls any of this yet.

Closes #2214

Signed-off-by: Ramiz Polic <[email protected]>

@tkircsi tkircsi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvements! One nit.

Comment thread client/utils/identity/sign.go Resolved

@tkircsi tkircsi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@ramizpolic
ramizpolic added this pull request to the merge queue Oct 1, 2026
Merged via the queue into main with commit 68f65f7 Oct 1, 2026
34 checks passed
@ramizpolic
ramizpolic deleted the feat/identity-02-claim-crypto branch October 1, 2026 12:27
ramizpolic added a commit that referenced this pull request Oct 1, 2026
Adds client/utils/identity/resolvers: one resolver per key-discovery
scheme, each returning the candidate public keys for a claim's subject.
A resolver only finds keys; it never checks a signature. Pass the result
to identity.Verify, which does all of the cryptography and accepts the
claim if any one key validates.

  Resolve(ctx, subject, certificate) ([]crypto.PublicKey, error)

- DNS: "_agntcy-key.<domain>" TXT records, "v=akv1;key=<base64 SPKI>".
- WellKnown: https subjects, the host's /.well-known/jwks.json. Skips
  encryption-only and symmetric keys.
- DID: did:web (document over HTTPS, whose id must equal the subject) and
  did:key (self-certifying, no network) for ed25519, P-256, P-384, RSA.
  did:web segments are validated so an escaped "/" or ".." can't steer
  the request to another path or host.
- SPIFFE: the key comes from the claim's X.509-SVID, trusted only after
  x509svid.ParseAndVerify validates it against the subject's trust-domain
  bundle and its SPIFFE ID equals the subject. A trust domain with no
  bundle fails closed.

Each resolver is built with an explicit constructor; there is no registry
or self-registration. Network access goes through a small Fetcher
interface, so resolvers are tested against fakes with no live network.
Every resolver caps the number of keys it will return.

utils/safefetch is the SSRF-guarded HTTPS client did and wellknown use by
default: https only, non-public addresses refused at dial time after DNS
resolution (loopback, RFC 1918, link-local, shared address space, IPv4-
mapped IPv6), redirects bounded and unable to downgrade to http, and a
response size cap.

Stacked on #2223; nothing outside these packages calls any of this yet.

Closes #2214

Signed-off-by: Ramiz Polic <[email protected]>
vijit-vishnoi pushed a commit to vijit-vishnoi/agntcy-dir that referenced this pull request Oct 10, 2026
* feat(client): add identity key resolvers and safefetch

Adds client/utils/identity/resolvers: one resolver per key-discovery
scheme, each returning the candidate public keys for a claim's subject.
A resolver only finds keys; it never checks a signature. Pass the result
to identity.Verify, which does all of the cryptography and accepts the
claim if any one key validates.

  Resolve(ctx, subject, certificate) ([]crypto.PublicKey, error)

- DNS: "_agntcy-key.<domain>" TXT records, "v=akv1;key=<base64 SPKI>".
- WellKnown: https subjects, the host's /.well-known/jwks.json. Skips
  encryption-only and symmetric keys.
- DID: did:web (document over HTTPS, whose id must equal the subject) and
  did:key (self-certifying, no network) for ed25519, P-256, P-384, RSA.
  did:web segments are validated so an escaped "/" or ".." can't steer
  the request to another path or host.
- SPIFFE: the key comes from the claim's X.509-SVID, trusted only after
  x509svid.ParseAndVerify validates it against the subject's trust-domain
  bundle and its SPIFFE ID equals the subject. A trust domain with no
  bundle fails closed.

Each resolver is built with an explicit constructor; there is no registry
or self-registration. Network access goes through a small Fetcher
interface, so resolvers are tested against fakes with no live network.
Every resolver caps the number of keys it will return.

utils/safefetch is the SSRF-guarded HTTPS client did and wellknown use by
default: https only, non-public addresses refused at dial time after DNS
resolution (loopback, RFC 1918, link-local, shared address space, IPv4-
mapped IPv6), redirects bounded and unable to downgrade to http, and a
response size cap.

Stacked on agntcy#2223; nothing outside these packages calls any of this yet.

Closes agntcy#2214

Signed-off-by: Ramiz Polic <[email protected]>

* refactor(client): split identity resolvers into one package per scheme

Each resolver now lives in its own package under resolvers/, with a
package name that reads at the call site:

  didresolver.New(fetch)        resolvers/did
  dnsresolver.New(opts...)      resolvers/dns
  wellknownresolver.New(fetch)  resolvers/wellknown
  spifferesolver.New(bundles)   resolvers/spiffe

The type in each is Resolver, and spifferesolver.LoadBundles replaces
LoadSPIFFEBundles. The parent resolvers package keeps only the public
contract: the Resolver and Fetcher interfaces and ErrNoKeys.

Code the schemes share moves to resolvers/internal/keyutil (key
normalization, host parsing, the key-count cap, JWK conversion), and the
test fixtures to resolvers/internal/testutil, so neither is importable
from outside resolvers/. dnsresolver gains a WithLookupTXT option, since
the end-to-end test now lives outside the package.

Each scheme wraps the shared key-count error with its own name, so a
failure reads "dns: no usable public keys found at ...".

No behavior change: the same 21 test functions and 39 subtests pass.

Signed-off-by: Ramiz Polic <[email protected]>

* refactor(client): move key helpers into jws and drop the shared keyutil

- ToPublicKey and PublicKeyFromJWK move to client/utils/jws, where the set
  of usable key types is already decided. ToPublicKey now reuses
  jwsAlgorithmFor, so it accepts exactly what jws can verify with (and
  refuses unsupported curves and RSA keys under 2048 bits up front)
  instead of keeping a second, separate type switch.
- Finish and the per-subject key cap are removed: a resolver returns every
  key it finds. Each resolver still returns ErrNoKeys rather than an
  empty result with a nil error.
- ParseHost is removed. It only mattered where a URL is built from the
  subject: wellknown now parses the subject as a URL and refuses
  userinfo (in "https://[email protected]" the host is evil.com), and
  did:web validates its host inline. dns builds a TXT name, not a URL,
  so it only rejects an empty subject.
- internal/keyutil is deleted.

Signed-off-by: Ramiz Polic <[email protected]>

* test(client): share crypto fixtures across jws, identity and resolvers

The jws and identity tests each carried a byte-identical generateKey, and
PKCS#8 encoding, key generation and self-signed certificates were written
out in four places. The resolvers' testutil added a third copy.

- client/utils/internal/testutil is now the one shared package, importable
  by jws, identity and the resolvers and by nothing outside client/utils:
  key generators (including a NewKey(kind) that replaces both generateKey
  copies), PKCS#8 and certificate PEM helpers, a self-signed certificate,
  JWKS, a fake fetcher, and RequireSameKeys. It imports none of this
  repo's packages, so it cannot form an import cycle with their tests.
- Fixtures only one scheme uses move into that scheme's tests: the DID
  document and did:key builders, the DNS TXT key encoding, a JWK with a
  "use", and the test CA, SVID issuer and trust bundle.
- The parent-package end-to-end test splits into each scheme's package, so
  a scheme's sign -> resolve -> verify test uses only its own fixtures.
  The shared flow lives in resolvers/internal/claimtest, kept apart from
  testutil because it imports identity and jws. The compile-time contract
  assertions become a TestResolver_SatisfiesContract per package.
- The two 1024-bit RSA key generations in the jws tests share one helper.

No production code changes. Every previous test still runs: the five
end-to-end tests are now TestEndToEnd* in their own packages, and the
security mutations (SPIFFE ID, DID id and host, userinfo, key/cert match,
RSA floor and others) are all still caught.

Signed-off-by: Ramiz Polic <[email protected]>

* fix(client): address review feedback on identity resolvers

- safefetch: also refuse the IPv6 transition ranges (NAT64, 6to4, Teredo,
  discard, documentation, deprecated IPv4-compatible) and the IPv4
  documentation and relay ranges, which can reach a blocked IPv4 target
- did:web: build the document path from the decoded segments so an escaped
  segment is not escaped a second time
- did:key: apply the shared jws key filter, so an RSA key below the minimum
  size is no longer returned as a usable key
- jws: refuse typed-nil and incomplete ECDSA/RSA keys instead of panicking
- jws: honor key_ops on a JWK and require verify when it is present

Signed-off-by: Ramiz Polic <[email protected]>

* test(client): merge claimtest into testutil

Move the sign-resolve-verify claim helpers into client/utils/internal/testutil
so the shared test code is one package. testutil now imports jws and
identity, so their tests become external (package jws_test, identity_test).

Signed-off-by: Ramiz Polic <[email protected]>

* fix(client): address second round of review feedback on resolvers

- did:web: only accept keys authorized by assertionMethod (by reference or
  embedded) instead of every verificationMethod
- jws: refuse Ed25519 keys of the wrong length instead of panicking
- safefetch: also refuse deprecated site-local fec0::/10
- safefetch: try every validated address in order rather than only the first

Signed-off-by: Ramiz Polic <[email protected]>

* test(client): build the small RSA fixture from primes

CodeQL flags rsa.GenerateKey with 1024 bits. The key is deliberately weak, to
test the 2048-bit floor, so assemble it from two random primes instead.

Signed-off-by: Ramiz Polic <[email protected]>

* Revert "test(client): build the small RSA fixture from primes"

The 1024-bit key is deliberately weak, to test the 2048-bit floor. The CodeQL
finding is a false positive and will be dismissed rather than worked around.

This reverts commit dad0d7b.

Signed-off-by: Ramiz Polic <[email protected]>

---------

Signed-off-by: Ramiz Polic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 1000-1999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add identity/ownership claim signing and verification

4 participants