Skip to content

keygen: purpose is a closed Literal, narrower than the spec vocabulary (cannot express response-signing) and narrower than the SDK's own internals #1677

Closed

Description

@KonstantinMirin

Summary

keygen's two public entry points narrow purpose to Literal["request-signing", "webhook-signing"] and reject anything else at runtime. That set is narrower than the spec's own vocabulary — it cannot express response-signing, which AdCP defines as a full signing profile — and it's narrower than the SDK's own internals, which already take adcp_use: str.

Request: validate the purpose syntactically rather than by membership, so the vocabulary is open.

Current behaviour (adcp==6.6.0)

generate_signing_keypair(
    *,
    alg: Literal['ed25519', 'es256'] = 'ed25519',
    kid: str | None = None,
    purpose: Literal['request-signing', 'webhook-signing'] = 'request-signing',
    passphrase: bytes | None = None,
) -> tuple[bytes, dict[str, Any]]

pem_to_adcp_jwk(pem, *, kid, purpose: Literal['request-signing', 'webhook-signing'], password=None)

Both raise:

raise ValueError(f"purpose must be one of {_ADCP_USE_VALUES}, got {purpose!r}")

The vocabulary is already open one layer down

Everything these two wrappers delegate to takes a plain str:

def generate_ed25519(kid: str, passphrase: bytes | None = None, adcp_use: str = "request-signing")
def generate_es256(kid: str, passphrase: bytes | None = None, adcp_use: str = "request-signing")
def _public_jwk_ed25519(public_key: ed25519.Ed25519PublicKey, *, kid: str, adcp_use: str)
def _public_jwk_es256(public_key: ec.EllipticCurvePublicKey, *, kid: str, adcp_use: str)

So the restriction is purely in the public surface, and lifting it is a small change rather than a refactor.

What it blocks

1. response-signing, which the spec defines today. The designated-task response-signing profile is a decoded-payload JWS envelope — schema core/response-payload-jws-envelope.json, verifier checklist at /docs/building/by-layer/L1/security#verifier-checklist-responses, error family SIGNED_RESPONSE_ENVELOPE_EXPIRED / SIGNED_RESPONSE_REQUEST_HASH_MISMATCH / SIGNED_RESPONSE_TENANT_MISMATCH. adcontextprotocol/adcp#5552 names response-signing and governance-signing as purposes that exist and are "never valid for webhooks".

This SDK cannot mint or publish a conformant key for that profile. An implementer has to bypass generate_signing_keypair/pem_to_adcp_jwk and hand-assemble the JWK, or call the private generate_ed25519(..., adcp_use=...).

2. Any surface the vocabulary doesn't yet name. Concrete case: an AdCP agent acting as its own OAuth 2.0 authorization server, signing access tokens for its own MCP resource (prebid/salesagent#2028). A JWT has no RFC 9421 tag, so the tag-based domain separation that #5552 leans on doesn't apply, and adcp_use would be the only purpose discriminator — except it can't be set.

Why opening it is safe

Purpose matching is fail-closed. A conformant verifier requires adcp_use to equal the value defined for the surface it is verifying (request verification requires request-signing exactly; #5552 widened webhooks to accept {webhook-signing, request-signing} and nothing else). An unregistered value therefore satisfies no existing verifier, so widening what a signer may publish cannot weaken any verification path. It only permits keys that existing verifiers decline — which is the desired outcome for a purpose they don't implement.

It's also compatible with the current direction of travel rather than against it. #5552 demoted adcp_use from load-bearing domain separation to blast-radius isolation for the 9421 surfaces, and #5555 tracks removing webhook-signing. Neither implies the set of expressible purposes should stay at two — if anything #5555 item 3 (the JWKS no longer carrying a machine-readable purpose signal) argues the opposite.

Suggested change

_PURPOSE_RE = re.compile(r"^[a-z0-9]+(-[a-z0-9]+)*$")

REQUEST_SIGNING: Final = "request-signing"
WEBHOOK_SIGNING: Final = "webhook-signing"      # deprecated upstream, see adcp#5555
RESPONSE_SIGNING: Final = "response-signing"

def generate_signing_keypair(*, alg=..., kid=None, purpose: str = REQUEST_SIGNING, passphrase=None):
    if not _PURPOSE_RE.match(purpose):
        raise ValueError(f"purpose must be a lowercase hyphenated token, got {purpose!r}")
  • Keep exported constants for the known values, so callers aren't retyping string literals.
  • Literal[...] | str overloads would preserve type-narrowing for the known values if that's valued.
  • Keep raising on empty/malformed input — the ask is open vocabulary, not unvalidated input.
  • Worth a docstring note that purpose matching is fail-closed, since that's the property making an open vocabulary safe.

The docstring on generate_signing_keypair would also want a light touch: it currently says "Request-signing and webhook-signing keys MUST be distinct — a signature from one surface cannot replay as the other, and every conformant verifier enforces the claim", which #5552 has since softened for webhooks.

Spec-side counterpart filed at adcontextprotocol/adcp#8545. The TypeScript SDK's paired change for #5552 was adcontextprotocol/adcp-client#2239, for reference on how the two SDKs were kept in step.

Activity

  1. added a commit that references this issue on Oct 29, 2026
    3bc9d2b
  2. added 2 commits that reference this issue on Oct 29, 2026
    787cfb2
    612f97a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions