Skip to content

Authorized exchange purposes per subscriber; bulk revocation by exchange purpose - #78

Draft
JoeShook wants to merge 2 commits into
mainfrom
feature/66-exchange-purpose-authorization
Draft

JoeShook wants to merge 2 commits into
mainfrom
feature/66-exchange-purpose-authorization

Conversation

@JoeShook

@JoeShook JoeShook commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Closes #66

What changed

Subscriber authorizations (portal)

  • New table OrganizationExchangePurposes (portal Flyway V4__organization_exchange_purposes.sql): exchange purpose code per organization, with ApprovedBy / ApprovedAt. Withdrawing deletes the row, and the audit trail keeps the history.
  • ExchangePurposeService authorizes, withdraws, lists and checks exchange purposes. Each authorize and withdraw is recorded in the portal audit trail (organization.exchange-purpose-authorized / -withdrawn).
  • New RA page Exchange Purposes (/ra/exchange-purposes, roles RA / PortalAdmin). Per organization it can authorize or withdraw a code, find the organization's issued certificates whose SANs carry a code, and revoke them all.

Issuance and RA approval

  • On submit, URI SANs carrying an exchange purpose the subscriber is not authorized for are flagged: a note in the policy reason, which the RA queue shows, plus an ExchangePurposeFlagged request event.
  • RA approval is blocked while such a SAN remains. The request stays in the queue with an ApprovalBlocked event, and the RA can approve it once the authorization is recorded, or reject it.
  • Defense in depth: the portal sends AuthorizedExchangePurposes on POST /api/ra/issue, and the CA refuses (403) a SAN carrying any other exchange purpose. The field is optional; null skips the check, so older callers are unaffected.
  • A requester who belongs to exactly one enabled organization now submits for it (OrganizationId was always null before). This ties requests to a subscriber.

Bulk revocation

  • New CA endpoint POST /api/ra/revoke-by-exchange-purpose calls CertificateManagementService.RevokeByExchangePurposeAsync. Each listed serial is revoked with reason privilegeWithdrawn (9), and only when one of the stored certificate's URI SANs carries the exchange purpose. Unknown serials, already-revoked certificates and certificates without a matching SAN are skipped and reported.
  • Audit: one certificate.revoked event per certificate and one certificate.bulk-revoked summary event in the CA audit trail. The portal records certificate.bulk-revoked (including failures) and marks the requests Revoked (new RequestStatus.Revoked = 12).
  • CRL: a new CRL is generated and published once for each issuing CA involved. CRL problems are reported back, and the revocations stand.
  • The RA client identity gains a new Permission.RevokeFromRa. It allows this revocation and GenerateCrlAsync, and nothing else. Ordinary RevokeAsync is still refused, and a test covers that.

SAN format (HL7 SSRAA URI rules)

  • All exchange purpose parsing is in ExchangePurposeSan.Parse / Extract / Scan (Sigyll.Contracts, shared by the CA and the portal). When the TEFCA client SAN format is published, this is the only place to change.
  • SAN URIs are handled as SSRAA requires: case-sensitive strings, never normalized, percent-decoded or re-encoded (no System.Uri). The raw string is split by hand: fragment = after the first #; query = after the first ? up to the #; path = from the end of the authority (or the scheme, for a URN) to ?/#.
  • Three places are recognised, and each value must equal a code exactly (T- plus upper-case segments; t-trtmnt or T%2DTRTMNT do not count):
    • the fragment (urn:oid:...#T-TRTMNT)
    • the last path segment (https://example.org/fhir/T-TRTMNT; with a trailing slash the last segment is empty, so nothing matches)
    • a query parameter, only when ExchangePurposeSan:QueryParameterName is configured (?<name>=T-TRTMNT). The name is matched ordinal (case-sensitive). There is no default. Unset, the query form is not recognised at all. The setting lives in the ExchangePurposeSan section of both the CA and the portal configuration, and the two must agree.
  • Precedence: no place outranks another. If several places carry a code, they must agree. Different codes in different places, or the query parameter repeated with different values, make the SAN ambiguous: it carries no exchange purpose and is flagged. Ambiguous SANs are flagged at submit, block RA approval, are refused by the CA on issuance, and are skipped by bulk revocation (the skip reason says why).
  • Codes typed into the RA page are trimmed but not case-folded.
  • Sigyll.Common now references Sigyll.Contracts, which has no dependencies of its own. CertificateManagementService takes an optional IOptions<ExchangePurposeSanOptions>.

Testing

  • dotnet test _tests/Sigyll.Signing.Tests: 602 passed, 17 skipped (the existing SoftHSM token tests), 0 failed. New tests:
    • ExchangePurposeSanTests: fragment and path forms work without configuration; an unconfigured name ignores the query form; a wrong-case name does not match; percent-encoded values are not decoded; repeated parameters with different values and conflicting places are ambiguous; trailing slash and lower-case codes do not match; reading SAN URIs from a certificate.
    • RevokeByExchangePurposeTests: only matching certificates revoked with reason 9; skips; CRL generated; audit events; the RA client cannot use ordinary revocation.
    • ExchangePurposeServiceTests: authorize/withdraw plus audit; unauthorized detection; bulk revocation sends only matching serials of that organization; requests marked Revoked; a failed CA call is audited as failed.
    • The existing ServiceBoundaryTests covers the new service method's permission check.
  • dotnet test _tests/Sigyll.Portal.Integration.Tests: 40/40 passed, PostgreSQL in Docker with the Flyway scripts including V4.
  • dotnet test _tests/Sigyll.Integration.Tests: 18/18 passed.
  • python tools/sql-lint/check_sql.py: 16 files, 0 problems.
  • The UI page was not exercised in a browser.

Migration numbering

Portal schema V4 was the next free number when this branch was cut. Other open TEFCA work (#63, #64) adds Flyway migrations in parallel. Those are probably in the sigil schema, but if any of them also lands a portal V4 first, this file needs renumbering to the next free version before merge.

Open questions

  1. Who is the "subscriber"? I used the portal Organization, since the CA core has no subscriber concept. Certificates issued directly by an operator in the CA UI are not tied to an organization, so bulk revocation does not reach them. Should the CA core get its own subscriber record?
  2. Flag vs. block. Submit flags and approval blocks. Should submit deny outright instead?
  3. Withdrawal history. Withdrawal deletes the row, so the history lives only in the audit trail. Would you prefer soft-delete columns (WithdrawnBy / WithdrawnAt) instead?
  4. Sole-organization resolution. Requests from users in several organizations still carry no organization, and any exchange purpose SAN on them is blocked. Should NewRequest get an organization picker?
  5. Query parameter name. The setting is a single app-level value, shared by every trust domain. Should it move to per-trust-domain TEFCA settings once those exist?
  6. Codes allowed. The code pattern accepts any T-... code. Should authorization be limited to the Exchange Purposes SOP list (overlaps TEFCA SAN builder #65)?

🤖 Generated with Claude Code

…n by exchange purpose

Subscriber organizations in the portal now carry the exchange purposes (TEFCA XP
codes such as T-TRTMNT) they are authorized for, with who recorded each and when
(portal Flyway V4, OrganizationExchangePurposes).

- Submitting a request whose URI SANs carry an exchange purpose the subscriber is
  not authorized for flags it in the policy reason; RA approval is blocked until
  the authorization is recorded. The CA re-checks the list it is sent on
  /api/ra/issue (AuthorizedExchangePurposes, optional, null skips the check).
- A requester in exactly one enabled organization now submits for it, so the
  request is tied to its subscriber.
- New RA page "Exchange Purposes": authorize or withdraw an exchange purpose per
  organization, list the organization's issued certificates that carry one, and
  revoke them all. The CA (POST /api/ra/revoke-by-exchange-purpose) revokes each
  with reason privilegeWithdrawn only when a URI SAN carries that exchange
  purpose, records each revocation plus a summary event in its audit trail, and
  generates and publishes a new CRL per issuing CA. The portal marks the requests
  Revoked and records authorize, withdraw and revoke in its own audit trail.
- The RA client gains RevokeFromRa, which allows this revocation and the CRL
  generation that follows it, but not ordinary revocation.
- Which SAN carries which exchange purpose is decided in one place,
  ExchangePurposeSan.Extract (Sigyll.Contracts), which accepts the code as the
  URI fragment, the last path segment or an xp query parameter, because the
  TEFCA client SAN format is not settled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… parameter name is configuration

ExchangePurposeSan no longer assumes a query parameter name. The name comes from
the ExchangePurposeSan:QueryParameterName setting (CA and portal, which must
agree) and has no default; unset, the query form is not recognised and only the
fragment and last-path-segment forms are.

The SAN string is split by hand, never through System.Uri or percent-decoding:
fragment after the first '#', query after the first '?' before it, path from
the end of the authority (or scheme, for a URN) to either. Parameter names match
ordinal; values and codes are compared verbatim and case-sensitively. A query
parameter repeated with different values, or different codes in different
places, makes the SAN ambiguous: it carries no exchange purpose and is flagged.
Ambiguous SANs block RA approval, are refused by the CA on issuance, and are
not matched by bulk revocation (reported in the skip reason).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JoeShook
JoeShook force-pushed the feature/66-exchange-purpose-authorization branch from e6f1b6c to 71e1ff3 Compare November 22, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authorized exchange purposes per subscriber; bulk revocation by exchange purpose

1 participant