Search in sources :

Example 6 with DKIMSignature

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();
}
Also used : Response(jakarta.ws.rs.core.Response) MarshalledEntity(org.jboss.resteasy.spi.MarshalledEntity) 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 7 with DKIMSignature

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

Example 8 with DKIMSignature

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

Example 9 with DKIMSignature

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

Example 10 with DKIMSignature

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();
}
Also used : Response(jakarta.ws.rs.core.Response) MarshalledEntity(org.jboss.resteasy.spi.MarshalledEntity) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) WebTarget(jakarta.ws.rs.client.WebTarget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) 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