use of org.jboss.resteasy.security.doseta.DKIMSignature in project resteasy by resteasy.
the class SigningTest method testSigningManual.
@Test
public void testSigningManual() throws Exception {
// ResteasyClientImpl client = new ResteasyClientImpl();
WebTarget target = client.target(TestPortProvider.generateURL("/signed"));
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
MarshalledEntity<String> marshalledEntity = response.readEntity(new GenericType<MarshalledEntity<String>>() {
});
Assert.assertEquals("hello world", marshalledEntity.getEntity());
String signatureHeader = response.getHeaderString(DKIMSignature.DKIM_SIGNATURE);
// System.out.println(DKIMSignature.DKIM_SIGNATURE + ": " + signatureHeader);
Assert.assertNotNull(signatureHeader);
DKIMSignature contentSignature = new DKIMSignature(signatureHeader);
contentSignature.verify(response.getStringHeaders(), marshalledEntity.getMarshalledBytes(), keys.getPublic());
response.close();
}
use of org.jboss.resteasy.security.doseta.DKIMSignature in project resteasy by resteasy.
the class SigningDnsTest method testBasicVerificationRepository.
@Test
public void testBasicVerificationRepository() throws Exception {
WebTarget target = client.target(TestPortProvider.generateURL("/signed"));
DKIMSignature contentSignature = new DKIMSignature();
contentSignature.setSelector("test1");
contentSignature.setDomain("samplezone.org");
target.property(KeyRepository.class.getName(), clientRepository);
Builder request = target.request();
request.header(DKIMSignature.DKIM_SIGNATURE, contentSignature);
Response response = request.post(Entity.entity("hello world", "text/plain"));
Assert.assertEquals(204, response.getStatus());
response.close();
}
use of org.jboss.resteasy.security.doseta.DKIMSignature in project resteasy by resteasy.
the class SigningTest method testRequestOnly.
/**
* @tpTestDetails Test for "DKIM-Signature" header attribute
* @tpSince RESTEasy 3.0.16
*/
@Test
public void testRequestOnly() throws Exception {
WebTarget target = client.target(generateURL("/signed/request-only"));
DKIMSignature contentSignature = new DKIMSignature();
contentSignature.setDomain("samplezone.org");
contentSignature.setSelector("test");
contentSignature.setPrivateKey(keys.getPrivate());
contentSignature.setBodyHashRequired(false);
contentSignature.setAttribute("method", "GET");
contentSignature.setAttribute("uri", "/signed/request-only");
contentSignature.setAttribute("token", "1122");
Response response = target.request().header(DKIMSignature.DKIM_SIGNATURE, contentSignature).delete();
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
String signatureHeader = response.getHeaderString(DKIMSignature.DKIM_SIGNATURE);
contentSignature = new DKIMSignature(signatureHeader);
Verification verification = new Verification(keys.getPublic());
verification.setBodyHashRequired(false);
verification.getRequiredAttributes().put("token", "1122");
verification.verify(contentSignature, response.getStringHeaders(), null, keys.getPublic());
response.close();
}
use of org.jboss.resteasy.security.doseta.DKIMSignature in project resteasy by resteasy.
the class SigningTest method testManualVerification.
/**
* @tpTestDetails Manual verification test
* @tpSince RESTEasy 3.0.16
*/
@Test
public void testManualVerification() throws Exception {
WebTarget target = client.target(generateURL("/signed/verify-manual"));
DKIMSignature contentSignature = new DKIMSignature();
contentSignature.setDomain("samplezone.org");
contentSignature.setSelector("test");
contentSignature.setAttribute("code", "hello");
contentSignature.setPrivateKey(keys.getPrivate());
Response response = target.request().header(DKIMSignature.DKIM_SIGNATURE, contentSignature).post(Entity.text("hello world"));
Assert.assertEquals(HttpResponseCodes.SC_NO_CONTENT, response.getStatus());
response.close();
}
use of org.jboss.resteasy.security.doseta.DKIMSignature in project resteasy by resteasy.
the class SigningTest method testSigningManual.
/**
* @tpTestDetails Test for manual signing
* @tpSince RESTEasy 3.0.16
*/
@Test
public void testSigningManual() throws Exception {
WebTarget target = client.target(generateURL("/signed"));
Response response = target.request().get();
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
MarshalledEntity<String> marshalledEntity = response.readEntity(new GenericType<MarshalledEntity<String>>() {
});
Assert.assertEquals(RESPONSE_ERROR_MSG, "hello world", marshalledEntity.getEntity());
String signatureHeader = response.getHeaderString(DKIMSignature.DKIM_SIGNATURE);
logger.info(DKIMSignature.DKIM_SIGNATURE + ": " + signatureHeader);
Assert.assertNotNull("Missing DKIM_SIGNATURE header", signatureHeader);
DKIMSignature contentSignature = new DKIMSignature(signatureHeader);
contentSignature.verify(response.getStringHeaders(), marshalledEntity.getMarshalledBytes(), keys.getPublic());
response.close();
}
Aggregations