Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1b2c0de
[CXF-8811] add property usereqsigcert for server to use JWS certifica…
mjhaugsdal Jun 13, 2023
ebca316
Merge branch 'main' into feature/CXF-8811
markusavinor Jul 12, 2023
fc1f417
Merge branch 'main' into feature/CXF-8811
mjhaugsdal Jul 17, 2023
b647d2a
Merge branch 'main' into feature/CXF-8811
markusavinor Jul 24, 2023
c697186
Merge branch 'apache:main' into feature/CXF-8811
mjhaugsdal Jul 28, 2023
e0d90eb
Merge branch 'apache:main' into feature/CXF-8811
mjhaugsdal Aug 14, 2023
bd34164
[CXF-8811] changed to public key from sigVerifier
mjhaugsdal Aug 24, 2023
c9b50e7
Merge remote-tracking branch 'origin/feature/CXF-8811' into feature/C…
mjhaugsdal Aug 24, 2023
010d79c
Merge remote-tracking branch 'origin/main' into feature/CXF-8811
mjhaugsdal Aug 24, 2023
aa98f1d
[CXF-8811] fixed exception and added JWK test
mjhaugsdal Aug 25, 2023
ee327a4
Merge remote-tracking branch 'origin/main' into feature/CXF-8811
mjhaugsdal Aug 28, 2023
3c8ff25
[CXF-8811] put public key saving in configureSecurityContext
mjhaugsdal Aug 28, 2023
a5f9b36
Merge remote-tracking branch 'origin/main' into feature/CXF-8811
mjhaugsdal Jul 3, 2024
9f1e678
removed commented lines
mjhaugsdal Jul 3, 2024
c51bf58
Merge branch 'apache:main' into feature/CXF-8811
mjhaugsdal Jul 12, 2024
7a61717
Merge branch 'main' into feature/CXF-8811
mjhaugsdal Mar 1, 2025
b748108
Merge branch 'apache:main' into feature/CXF-8811
mjhaugsdal Oct 29, 2025
a741e67
Clean up code style and fix issues in CXF-8811 implementation
gnodet Mar 11, 2026
771d279
Fix useReqSigCert cert header bug, improve Javadoc and test structure
gnodet Mar 11, 2026
fdbfbc4
Fix checkstyle header format in properties files
gnodet Mar 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.Principal;
import java.security.PublicKey;

import jakarta.annotation.Priority;
import jakarta.ws.rs.HttpMethod;
Expand Down Expand Up @@ -81,24 +82,26 @@ public void filter(ContainerRequestContext context) throws IOException {
}

protected SecurityContext configureSecurityContext(JwsSignatureVerifier sigVerifier) {
if (sigVerifier instanceof PublicKeyJwsSignatureVerifier
&& ((PublicKeyJwsSignatureVerifier)sigVerifier).getX509Certificate() != null) {
final Principal principal =
((PublicKeyJwsSignatureVerifier)sigVerifier).getX509Certificate().getSubjectX500Principal();
return new SecurityContext() {
if (sigVerifier instanceof PublicKeyJwsSignatureVerifier) {
PublicKeyJwsSignatureVerifier pkVerifier = (PublicKeyJwsSignatureVerifier) sigVerifier;
JAXRSUtils.getCurrentMessage().getExchange().put(PublicKey.class, pkVerifier.getPublicKey());
if (pkVerifier.getX509Certificate() != null) {
final Principal principal = pkVerifier.getX509Certificate().getSubjectX500Principal();
return new SecurityContext() {

public Principal getUserPrincipal() {
return principal;
}
public Principal getUserPrincipal() {
return principal;
}

public boolean isUserInRole(String arg0) {
return false;
}
};
public boolean isUserInRole(String arg0) {
return false;
}
};
}
}
return null;
}

protected boolean isMethodWithNoContent(String method) {
return HttpMethod.DELETE.equals(method) || HttpUtils.isMethodWithNoRequestContent(method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ public final class JoseConstants extends RSSecurityConstants {
*/
public static final String ENABLE_UNSIGNED_JWT_PRINCIPAL = "rs.security.enable.unsigned-jwt.principal";

/**
* Magic value for the {@code rs.security.keystore.alias} property that causes the JWE encryption
* to use the public key extracted from the inbound JWS signature verification, instead of loading
* a key from the configured keystore. This mirrors the WS-Security {@code useReqSigCert} convention.
*/
public static final String USE_REQ_SIG_CERT = "useReqSigCert";

/**
* Whether to trace JOSE headers.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,15 @@ public static KeyEncryptionProvider loadKeyEncryptionProvider(Properties props,
boolean includeKeyId =
JoseUtils.checkBooleanProperty(headers, props, m, JoseConstants.RSSEC_ENCRYPTION_INCLUDE_KEY_ID);

if (JoseConstants.HEADER_JSON_WEB_KEY.equals(props.get(JoseConstants.RSSEC_KEY_STORE_TYPE))) {
String alias = props.getProperty(JoseConstants.RSSEC_KEY_STORE_ALIAS);
if (JoseConstants.USE_REQ_SIG_CERT.equals(alias)) {
PublicKey publicKey = (PublicKey)
PhaseInterceptorChain.getCurrentMessage().getExchange().get(PublicKey.class);
if (publicKey == null) {
throw new JweException(JweException.Error.NO_ENCRYPTOR);
}
keyEncryptionProvider = getPublicKeyEncryptionProvider(publicKey, keyAlgo);
} else if (JoseConstants.HEADER_JSON_WEB_KEY.equals(props.get(JoseConstants.RSSEC_KEY_STORE_TYPE))) {
JsonWebKey jwk = JwkUtils.loadJsonWebKey(m, props, KeyOperation.ENCRYPT);
if (jwk != null) {
keyAlgo = getKeyEncryptionAlgorithm(m, props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public SignatureAlgorithm getAlgorithm() {
public X509Certificate getX509Certificate() {
return cert;
}
public PublicKey getPublicKey() {
return key;
}
@Override
public JwsVerificationSignature createJwsVerificationSignature(JwsHeaders headers) {
Signature sig = CryptoUtils.getVerificationSignature(key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,62 @@ private BookStore createJweJwsBookStore(String address,
return bean.create(BookStore.class);
}

@Test
public void testJweJwsJwkRsaUseReqSigCert() throws Exception {
String address = "https://localhost:" + PORT + "/jwejwsjwkreqsigcert";
BookStore bs = createUseReqSigCertBookStore(address,
"org/apache/cxf/systest/jaxrs/security/alice.jwk.enc.out.properties",
"org/apache/cxf/systest/jaxrs/security/alice.jwk.sign.out.properties",
"org/apache/cxf/systest/jaxrs/security/alice.jwk.enc.in.properties",
"org/apache/cxf/systest/jaxrs/security/alice.jwk.sign.in.properties",
"rs.security.signature.include.public.key");
String text = bs.echoText("book");
assertEquals("book", text);
}

@Test
public void testJweJwsRsaUseReqSigCert() throws Exception {
String address = "https://localhost:" + PORT + "/jwejwsreqsigcert";
BookStore bs = createUseReqSigCertBookStore(address,
"org/apache/cxf/systest/jaxrs/security/bob.rs.properties",
"org/apache/cxf/systest/jaxrs/security/alice.rs.properties",
"org/apache/cxf/systest/jaxrs/security/alice.rs.properties",
"org/apache/cxf/systest/jaxrs/security/bob.rs.properties",
"rs.security.signature.include.cert");
String text = bs.echoText("book");
assertEquals("book", text);
}

private BookStore createUseReqSigCertBookStore(String address,
String encOutProps, String sigOutProps,
String encInProps, String sigInProps,
String includeKeyProperty) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
SpringBusFactory bf = new SpringBusFactory();
URL busFile = JAXRSJweJwsTest.class.getResource("client.xml");
Bus springBus = bf.createBus(busFile.toString());
bean.setBus(springBus);
bean.setServiceClass(BookStore.class);
bean.setAddress(address);
List<Object> providers = new LinkedList<>();
JweWriterInterceptor jweWriter = new JweWriterInterceptor();
jweWriter.setUseJweOutputStream(true);
JwsWriterInterceptor jwsWriter = new JwsWriterInterceptor();
jwsWriter.setUseJwsOutputStream(true);
providers.add(jweWriter);
providers.add(jwsWriter);
providers.add(new JweClientResponseFilter());
providers.add(new JwsClientResponseFilter());
bean.setProviders(providers);
bean.getProperties(true).put("rs.security.encryption.out.properties", encOutProps);
bean.getProperties(true).put("rs.security.signature.out.properties", sigOutProps);
bean.getProperties(true).put("rs.security.encryption.in.properties", encInProps);
bean.getProperties(true).put("rs.security.signature.in.properties", sigInProps);
bean.getProperties(true).put("jose.debug", true);
bean.getProperties(true).put(includeKeyProperty, "true");
return bean.create(BookStore.class);
}

@Test
public void testJweAesGcmDirect() throws Exception {
String address = "https://localhost:" + PORT + "/jweaesgcmdirect";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
rs.security.keystore.type=jwk
rs.security.keystore.alias=2011-04-29
rs.security.keystore.file=org/apache/cxf/systest/jaxrs/security/certs/jwkPrivateSet.txt
rs.security.encryption.content.algorithm=A128GCM
rs.security.encryption.key.algorithm=RSA-OAEP
rs.security.signature.algorithm=RS256
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
rs.security.keystore.type=jwk
rs.security.keystore.alias=2011-04-29
rs.security.keystore.file=org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt
rs.security.encryption.content.algorithm=A128GCM
rs.security.encryption.key.algorithm=RSA-OAEP
rs.security.signature.algorithm=RS256
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
rs.security.keystore.type=jwk
rs.security.keystore.alias=2011-04-29
rs.security.keystore.file=org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt
rs.security.encryption.content.algorithm=A128GCM
rs.security.encryption.key.algorithm=RSA-OAEP
rs.security.signature.algorithm=RS256
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
rs.security.keystore.type=jwk
rs.security.keystore.alias=2011-04-29
rs.security.keystore.file=org/apache/cxf/systest/jaxrs/security/certs/jwkPrivateSet.txt
rs.security.encryption.content.algorithm=A128GCM
rs.security.encryption.key.algorithm=RSA-OAEP
rs.security.signature.algorithm=RS256
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
Expand All @@ -16,6 +18,7 @@
# under the License.
rs.security.keystore.type=jks
rs.security.keystore.password=password
rs.security.key.password=password
rs.security.keystore.alias=alice
rs.security.keystore.file=keys/alice.jks
rs.security.encryption.content.algorithm=A128GCM
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
rs.security.keystore.type=jwk
rs.security.keystore.alias=2011-04-29
rs.security.keystore.file=org/apache/cxf/systest/jaxrs/security/certs/jwkPrivateSet.txt
rs.security.encryption.content.algorithm=A128GCM
rs.security.encryption.key.algorithm=RSA-OAEP
rs.security.signature.algorithm=RS256
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
rs.security.keystore.type=jwk
rs.security.keystore.alias=useReqSigCert
rs.security.keystore.file=org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt
rs.security.encryption.content.algorithm=A128GCM
rs.security.encryption.key.algorithm=RSA-OAEP
rs.security.signature.algorithm=RS256
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
rs.security.keystore.type=jwk
rs.security.keystore.alias=2011-04-29
rs.security.keystore.file=org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt
rs.security.encryption.content.algorithm=A128GCM
rs.security.encryption.key.algorithm=RSA-OAEP
rs.security.signature.algorithm=RS256
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
rs.security.keystore.type=jwk
rs.security.keystore.alias=2011-04-29
rs.security.keystore.file=org/apache/cxf/systest/jaxrs/security/certs/jwkPrivateSet.txt
rs.security.encryption.content.algorithm=A128GCM
rs.security.encryption.key.algorithm=RSA-OAEP
rs.security.signature.algorithm=RS256
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
rs.security.keystore.type=jks
rs.security.keystore.password=password
rs.security.key.password=password
rs.security.keystore.alias=useReqSigCert
rs.security.keystore.file=keys/bob.jks
rs.security.encryption.content.algorithm=A128GCM
rs.security.encryption.key.algorithm=RSA-OAEP
rs.security.signature.algorithm=RS256
Loading