use of org.jboss.resteasy.security.doseta.DKIMSignature in project resteasy by resteasy.
the class LocalTest method testBadAttributes.
@Test
public void testBadAttributes() throws Exception {
DKIMSignature signed = new DKIMSignature();
signed.setAttribute("path", "/hello/world");
signed.setTimestamp();
signed.addHeader("Visa");
signed.addHeader("Visa");
MultivaluedMapImpl<String, String> headers = new MultivaluedMapImpl<String, String>();
headers.add("Visa", "v1");
headers.add("Visa", "v2");
headers.add("Visa", "v3");
signed.sign(headers, null, keys.getPrivate());
String signedHeader = signed.toString();
logger.info(signedHeader);
DKIMSignature verified = new DKIMSignature(signedHeader);
HashMap<String, String> requiredAttributes = new HashMap<String, String>();
requiredAttributes.put("path", "/hello/world");
Verification verification = new Verification();
verification.getRequiredAttributes().put("path", "/hello");
try {
verification.verify(verified, headers, null, keys.getPublic());
Assert.fail("Verification was successful, but it shoudn't be");
} catch (SignatureException e) {
}
}
use of org.jboss.resteasy.security.doseta.DKIMSignature in project resteasy by resteasy.
the class LocalTest method testAttributes.
@Test
public void testAttributes() throws Exception {
DKIMSignature signed = new DKIMSignature();
signed.setAttribute("path", "/hello/world");
signed.setTimestamp();
signed.addHeader("Visa");
signed.addHeader("Visa");
MultivaluedMapImpl<String, String> headers = new MultivaluedMapImpl<String, String>();
headers.add("Visa", "v1");
headers.add("Visa", "v2");
headers.add("Visa", "v3");
signed.sign(headers, null, keys.getPrivate());
String signedHeader = signed.toString();
logger.info(signedHeader);
DKIMSignature verified = new DKIMSignature(signedHeader);
HashMap<String, String> requiredAttributes = new HashMap<String, String>();
requiredAttributes.put("path", "/hello/world");
Verification verification = new Verification();
verification.getRequiredAttributes().put("path", "/hello/world");
MultivaluedMap<String, String> verifiedHeaders = verification.verify(verified, headers, null, keys.getPublic());
Assert.assertEquals(verifiedHeaders.size(), 1);
List<String> visas = verifiedHeaders.get("Visa");
Assert.assertNotNull(ERROR_MSG, visas);
Assert.assertEquals(ERROR_MSG, visas.size(), 2);
logger.info(visas);
Assert.assertEquals(ERROR_MSG, visas.get(0), "v3");
Assert.assertEquals(ERROR_MSG, visas.get(1), "v2");
}
use of org.jboss.resteasy.security.doseta.DKIMSignature in project resteasy by resteasy.
the class SigningTest method testManualVerification.
@Test
public void testManualVerification() throws Exception {
// ResteasyClientImpl client = new ResteasyClientImpl();
WebTarget target = client.target(TestPortProvider.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(204, response.getStatus());
response.close();
}
use of org.jboss.resteasy.security.doseta.DKIMSignature in project resteasy by resteasy.
the class SigningTest method testBasicVerification.
@Test
public void testBasicVerification() throws Exception {
// ResteasyClientImpl client = new ResteasyClientImpl();
WebTarget target = client.target(TestPortProvider.generateURL("/signed"));
DKIMSignature contentSignature = new DKIMSignature();
contentSignature.setDomain("samplezone.org");
contentSignature.setSelector("test");
contentSignature.setPrivateKey(keys.getPrivate());
Response response = target.request().header(DKIMSignature.DKIM_SIGNATURE, contentSignature).post(Entity.text("hello world"));
Assert.assertEquals(204, response.getStatus());
response.close();
}
use of org.jboss.resteasy.security.doseta.DKIMSignature in project resteasy by resteasy.
the class SigningTest method testBasicVerificationBadSignature.
@Test
public void testBasicVerificationBadSignature() throws Exception {
// ResteasyClientImpl client = new ResteasyClientImpl();
WebTarget target = client.target(TestPortProvider.generateURL("/signed"));
DKIMSignature contentSignature = new DKIMSignature();
contentSignature.setSelector("test");
contentSignature.setDomain("samplezone.org");
contentSignature.setPrivateKey(badKey);
Response response = target.request().header(DKIMSignature.DKIM_SIGNATURE, contentSignature).post(Entity.text("hello world"));
Assert.assertEquals(401, response.getStatus());
response.close();
}
Aggregations