Search in sources :

Example 1 with DKIMSignature

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) {
    }
}
Also used : HashMap(java.util.HashMap) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Verification(org.jboss.resteasy.security.doseta.Verification) DKIMSignature(org.jboss.resteasy.security.doseta.DKIMSignature) SignatureException(java.security.SignatureException) Test(org.junit.Test)

Example 2 with DKIMSignature

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");
}
Also used : HashMap(java.util.HashMap) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Verification(org.jboss.resteasy.security.doseta.Verification) DKIMSignature(org.jboss.resteasy.security.doseta.DKIMSignature) Test(org.junit.Test)

Example 3 with DKIMSignature

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();
}
Also used : Response(jakarta.ws.rs.core.Response) WebTarget(jakarta.ws.rs.client.WebTarget) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) DKIMSignature(org.jboss.resteasy.security.doseta.DKIMSignature) Test(org.junit.Test)

Example 4 with DKIMSignature

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();
}
Also used : Response(jakarta.ws.rs.core.Response) WebTarget(jakarta.ws.rs.client.WebTarget) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) DKIMSignature(org.jboss.resteasy.security.doseta.DKIMSignature) Test(org.junit.Test)

Example 5 with DKIMSignature

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();
}
Also used : Response(jakarta.ws.rs.core.Response) WebTarget(jakarta.ws.rs.client.WebTarget) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) DKIMSignature(org.jboss.resteasy.security.doseta.DKIMSignature) Test(org.junit.Test)

Aggregations

DKIMSignature (org.jboss.resteasy.security.doseta.DKIMSignature)28 Test (org.junit.Test)23 Response (jakarta.ws.rs.core.Response)21 WebTarget (jakarta.ws.rs.client.WebTarget)18 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)17 SignatureException (java.security.SignatureException)6 MarshalledEntity (org.jboss.resteasy.spi.MarshalledEntity)6 Path (jakarta.ws.rs.Path)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Verification (org.jboss.resteasy.security.doseta.Verification)5 GET (jakarta.ws.rs.GET)4 Produces (jakarta.ws.rs.Produces)4 HashMap (java.util.HashMap)4 UnauthorizedSignatureException (org.jboss.resteasy.security.doseta.UnauthorizedSignatureException)4 DosetaKeyRepository (org.jboss.resteasy.security.doseta.DosetaKeyRepository)3 KeyRepository (org.jboss.resteasy.security.doseta.KeyRepository)3 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)2 Builder (jakarta.ws.rs.client.Invocation.Builder)2 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)2 DELETE (jakarta.ws.rs.DELETE)1