use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.
the class JAXRSHTTPSignatureTest method testNonMatchingSignatureAlgorithm.
//
// Negative tests
//
@Test
public void testNonMatchingSignatureAlgorithm() throws Exception {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor();
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray());
PrivateKey privateKey = (PrivateKey) keyStore.getKey("alice", "password".toCharArray());
assertNotNull(privateKey);
MessageSigner messageSigner = new MessageSigner("rsa-sha512", keyId -> privateKey, "alice-key-id");
signatureFilter.setMessageSigner(messageSigner);
String address = "http://localhost:" + PORT + "/httpsig/bookstore/books";
WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString());
client.type("application/xml").accept("application/xml");
Response response = client.post(new Book("CXF", 126L));
assertEquals(400, response.getStatus());
}
use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.
the class JAXRSHTTPSignatureTest method testEmptyDigest.
@Test
public void testEmptyDigest() throws Exception {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
CreateDigestTestInterceptor signatureFilter = new CreateDigestTestInterceptor();
signatureFilter.setEmptyDigestValue(true);
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray());
PrivateKey privateKey = (PrivateKey) keyStore.getKey("alice", "password".toCharArray());
assertNotNull(privateKey);
MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id");
signatureFilter.setMessageSigner(messageSigner);
String address = "http://localhost:" + PORT + "/httpsig/bookstore/books";
WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString());
client.type("application/xml").accept("application/xml");
Response response = client.post(new Book("CXF", 126L));
assertEquals(400, response.getStatus());
}
use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.
the class AbstractSignatureOutFilter method createMessageSigner.
private MessageSigner createMessageSigner() {
Properties props = KeyManagementUtils.loadSignatureOutProperties();
if (props == null) {
throw new SignatureException("Signature properties are not configured correctly");
}
Message m = PhaseInterceptorChain.getCurrentMessage();
KeyProvider keyProvider = keyId -> KeyManagementUtils.loadPrivateKey(m, props);
String signatureAlgorithm = (String) m.getContextualProperty(HTTPSignatureConstants.RSSEC_SIGNATURE_ALGORITHM);
if (signatureAlgorithm == null) {
signatureAlgorithm = DefaultSignatureConstants.SIGNING_ALGORITHM;
}
String keyId = (String) m.getContextualProperty(HTTPSignatureConstants.RSSEC_HTTP_SIGNATURE_KEY_ID);
if (keyId == null) {
keyId = props.getProperty(HTTPSignatureConstants.RSSEC_HTTP_SIGNATURE_KEY_ID);
if (keyId == null) {
throw new SignatureException("The signature key id is a required configuration property");
}
}
List<String> signedHeaders = CastUtils.cast((List<?>) m.getContextualProperty(HTTPSignatureConstants.RSSEC_HTTP_SIGNATURE_OUT_HEADERS));
if (signedHeaders == null) {
signedHeaders = Collections.emptyList();
}
return new MessageSigner(signatureAlgorithm, keyProvider, keyId, signedHeaders);
}
use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.
the class JAXRSHTTPSignatureTest method testMissingDigestHeader.
@Test
public void testMissingDigestHeader() throws Exception {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor();
signatureFilter.setAddDigest(false);
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray());
PrivateKey privateKey = (PrivateKey) keyStore.getKey("alice", "password".toCharArray());
assertNotNull(privateKey);
List<String> headerList = Arrays.asList("accept", "(request-target)");
MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id", headerList);
signatureFilter.setMessageSigner(messageSigner);
String address = "http://localhost:" + PORT + "/httpsigprops/bookstore/books";
WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString());
client.type("application/xml").accept("application/xml");
Response response = client.post(new Book("CXF", 126L));
assertEquals(400, response.getStatus());
}
use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.
the class JAXRSHTTPSignatureTest method testIncorrectDigestAlgorithm.
@Test
public void testIncorrectDigestAlgorithm() throws Exception {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
CreateDigestTestInterceptor signatureFilter = new CreateDigestTestInterceptor("SHA-1");
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray());
PrivateKey privateKey = (PrivateKey) keyStore.getKey("alice", "password".toCharArray());
assertNotNull(privateKey);
MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id");
signatureFilter.setMessageSigner(messageSigner);
String address = "http://localhost:" + PORT + "/httpsig/bookstore/books";
WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString());
client.type("application/xml").accept("application/xml");
Response response = client.post(new Book("CXF", 126L));
assertEquals(400, response.getStatus());
}
Aggregations