CXF-8811: Use request JWS signing key to encrypt JWE response#1303
CXF-8811: Use request JWS signing key to encrypt JWE response#1303mjhaugsdal wants to merge 20 commits intoapache:mainfrom
Conversation
…te (x5c header) to sign the response JWE.
- Remove unused Certificate import - Remove static import, use qualified JoseConstants.RSSEC_KEY_STORE_ALIAS - Replace var with explicit PublicKey type - Extract local variable to avoid repeated instanceof casts - Fix brace placement to match CXF conventions - Remove meaningless includeKeyId for useReqSigCert case - Remove extra blank line Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove broken cert/sha header code from the useReqSigCert path in JweUtils: when alias is "useReqSigCert", the cert headers tried to look up a certificate with that alias in the keystore, which would fail at runtime since no such alias exists. - Improve USE_REQ_SIG_CERT Javadoc to clarify it is a magic alias value, not a boolean flag. - Add missing throws Exception on useReqSigCert test methods. - Extract common helper createUseReqSigCertBookStore() to reduce duplicated test boilerplate. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Review findings and fixesI've performed an in-depth review of this PR and pushed a fix commit (771d279) addressing the following issues: Fixed issues
Review notes (no action needed)
|
|
@gnodet thank you for the feedback. This was a wanted feature on my team years ago but I never got confirmed if this is an actual wanted feature or not in CXF, so I have not looked at it for years now. |
Add required ASF license header prefix (#\n#\n) to properties files to satisfy the CXF RegexpHeader checkstyle rule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Adds support for using the client's JWS request signing public key to encrypt the server's JWE response. This is the JOSE equivalent of the existing
useReqSigCertfeature in CXF's WS-Security/XML Security module.Use case
In JWS+JWE request-response flows, the server may not have the client's public key pre-configured. With this feature, the server can extract the public key from the verified JWS request signature and use it to encrypt the JWE response — ensuring only the original requester can decrypt it.
Configuration
Set
rs.security.keystore.aliastouseReqSigCertin the server's encryption output properties:The server must also have
rs.security.accept.public.key=trueto accept client-provided public keys for JWS verification.Changes
JwsContainerRequestFilter: Stores the verified JWS signature'sPublicKeyon theExchangeso it's available during response encryptionJweUtils.loadKeyEncryptionProvider(): When alias isuseReqSigCert, retrieves the stored public key from the exchange instead of loading from keystorePublicKeyJwsSignatureVerifier: AddsgetPublicKey()accessorJoseConstants: AddsUSE_REQ_SIG_CERTconstant (matches existing WS-Security convention)testJweJwsRsaUseReqSigCertandtestJweJwsJwkRsaUseReqSigCert) with JKS and JWK keystore variantsSecurity note
This feature requires
rs.security.accept.public.key=true, which means the server trusts public keys provided in JWS headers. In production, this should be combined with additional trust mechanisms (e.g., mTLS at the transport layer, or certificate chain validation against a trusted CA).🤖 Generated with Claude Code