Search in sources :

Example 6 with TlsCertificateAuthorityRequest

use of org.apache.nifi.toolkit.tls.service.dto.TlsCertificateAuthorityRequest in project nifi by apache.

the class TlsCertificateAuthorityServiceHandlerTest method testNoHmac.

@Test
public void testNoHmac() throws IOException, ServletException {
    tlsCertificateAuthorityRequest = new TlsCertificateAuthorityRequest(null, testPemEncodedCsr);
    tlsCertificateAuthorityServiceHandler.handle(null, baseRequest, httpServletRequest, httpServletResponse);
    assertEquals(Response.SC_BAD_REQUEST, statusCode);
    assertEquals(TlsCertificateAuthorityServiceHandler.HMAC_FIELD_MUST_BE_SET, getResponse().getError());
}
Also used : TlsCertificateAuthorityRequest(org.apache.nifi.toolkit.tls.service.dto.TlsCertificateAuthorityRequest) Test(org.junit.Test)

Example 7 with TlsCertificateAuthorityRequest

use of org.apache.nifi.toolkit.tls.service.dto.TlsCertificateAuthorityRequest in project nifi by apache.

the class TlsCertificateAuthorityServiceHandlerTest method testSuccess.

@Test
public void testSuccess() throws IOException, ServletException, GeneralSecurityException, CRMFException {
    tlsCertificateAuthorityRequest = new TlsCertificateAuthorityRequest(testHmac, testPemEncodedCsr);
    tlsCertificateAuthorityServiceHandler.handle(null, baseRequest, httpServletRequest, httpServletResponse);
    assertEquals(Response.SC_OK, statusCode);
    assertArrayEquals(testCaHmac, getResponse().getHmac());
    X509Certificate certificate = TlsHelper.parseCertificate(new StringReader(getResponse().getPemEncodedCertificate()));
    assertEquals(certificateKeyPair.getPublic(), certificate.getPublicKey());
    assertEquals(new X500Name(requestedDn), new X500Name(certificate.getSubjectDN().toString()));
    certificate.verify(caCert.getPublicKey());
}
Also used : TlsCertificateAuthorityRequest(org.apache.nifi.toolkit.tls.service.dto.TlsCertificateAuthorityRequest) StringReader(java.io.StringReader) X500Name(org.bouncycastle.asn1.x500.X500Name) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Aggregations

TlsCertificateAuthorityRequest (org.apache.nifi.toolkit.tls.service.dto.TlsCertificateAuthorityRequest)7 Test (org.junit.Test)4 X509Certificate (java.security.cert.X509Certificate)3 JcaPKCS10CertificationRequest (org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 HttpHost (org.apache.http.HttpHost)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)2 TlsCertificateAuthorityResponse (org.apache.nifi.toolkit.tls.service.dto.TlsCertificateAuthorityResponse)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Field (java.lang.reflect.Field)1 KeyPair (java.security.KeyPair)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 BoundedInputStream (org.apache.commons.io.input.BoundedInputStream)1