Repository navigation
Conversation
…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
force-pushed
the
feature/66-exchange-purpose-authorization
branch
from
November 22, 2026 14:28
e6f1b6c to
71e1ff3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #66
What changed
Subscriber authorizations (portal)
OrganizationExchangePurposes(portal FlywayV4__organization_exchange_purposes.sql): exchange purpose code per organization, withApprovedBy/ApprovedAt. Withdrawing deletes the row, and the audit trail keeps the history.ExchangePurposeServiceauthorizes, withdraws, lists and checks exchange purposes. Each authorize and withdraw is recorded in the portal audit trail (organization.exchange-purpose-authorized/-withdrawn)./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
ExchangePurposeFlaggedrequest event.ApprovalBlockedevent, and the RA can approve it once the authorization is recorded, or reject it.AuthorizedExchangePurposesonPOST /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.OrganizationIdwas always null before). This ties requests to a subscriber.Bulk revocation
POST /api/ra/revoke-by-exchange-purposecallsCertificateManagementService.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.certificate.revokedevent per certificate and onecertificate.bulk-revokedsummary event in the CA audit trail. The portal recordscertificate.bulk-revoked(including failures) and marks the requestsRevoked(newRequestStatus.Revoked = 12).Permission.RevokeFromRa. It allows this revocation andGenerateCrlAsync, and nothing else. OrdinaryRevokeAsyncis still refused, and a test covers that.SAN format (HL7 SSRAA URI rules)
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.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?/#.T-plus upper-case segments;t-trtmntorT%2DTRTMNTdo not count):urn:oid:...#T-TRTMNT)https://example.org/fhir/T-TRTMNT; with a trailing slash the last segment is empty, so nothing matches)ExchangePurposeSan:QueryParameterNameis 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 theExchangePurposeSansection of both the CA and the portal configuration, and the two must agree.Sigyll.Commonnow referencesSigyll.Contracts, which has no dependencies of its own.CertificateManagementServicetakes an optionalIOptions<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.ServiceBoundaryTestscovers 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.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
sigilschema, but if any of them also lands aportalV4 first, this file needs renumbering to the next free version before merge.Open questions
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?WithdrawnBy/WithdrawnAt) instead?NewRequestget an organization picker?T-...code. Should authorization be limited to the Exchange Purposes SOP list (overlaps TEFCA SAN builder #65)?🤖 Generated with Claude Code