Search in sources :

Example 21 with PKCS10CertificationRequest

use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project athenz by yahoo.

the class CryptoTest method testGetPKCS10CertRequest.

@Test
public void testGetPKCS10CertRequest() throws IOException {
    Path path = Paths.get("src/test/resources/valid.csr");
    String certStr = new String(Files.readAllBytes(path));
    PKCS10CertificationRequest req = Crypto.getPKCS10CertRequest(certStr);
    assertNotNull(req);
    assertEquals(req.getSubject().toString(), "C=US,ST=CA,L=Sunnyvale,O=My Test Company,CN=athenz.syncer");
    Crypto.extractX509CSRPublicKey(req);
}
Also used : Path(java.nio.file.Path) PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) DERIA5String(org.bouncycastle.asn1.DERIA5String) Test(org.testng.annotations.Test)

Example 22 with PKCS10CertificationRequest

use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project athenz by yahoo.

the class CryptoTest method testExtractX509IPAddressesMultipleAddresses.

@Test
public void testExtractX509IPAddressesMultipleAddresses() throws IOException {
    Path path = Paths.get("src/test/resources/multiple_ips.csr");
    String csr = new String(Files.readAllBytes(path));
    PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(csr);
    assertNotNull(certReq);
    List<String> ips = Crypto.extractX509CSRIPAddresses(certReq);
    assertEquals(2, ips.size());
    assertEquals(ips.get(0), "10.11.12.13");
    assertEquals(ips.get(1), "10.11.12.14");
}
Also used : Path(java.nio.file.Path) PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) DERIA5String(org.bouncycastle.asn1.DERIA5String) Test(org.testng.annotations.Test)

Example 23 with PKCS10CertificationRequest

use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project athenz by yahoo.

the class CryptoTest method testGenerateX509CertificateAltNames.

@Test
public void testGenerateX509CertificateAltNames() throws IOException {
    Path path = Paths.get("src/test/resources/csr_altnames.csr");
    String certStr = new String(Files.readAllBytes(path));
    PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(certStr);
    X509Certificate caCertificate = Crypto.loadX509Certificate(ecPublicX509Cert);
    PrivateKey caPrivateKey = Crypto.loadPrivateKey(privateEncryptedKey, encryptedKeyPassword);
    X509Certificate cert = Crypto.generateX509Certificate(certReq, caPrivateKey, caCertificate, 600, true);
    assertNotNull(cert);
}
Also used : Path(java.nio.file.Path) PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) PrivateKey(java.security.PrivateKey) DERIA5String(org.bouncycastle.asn1.DERIA5String) X509Certificate(java.security.cert.X509Certificate) Test(org.testng.annotations.Test)

Example 24 with PKCS10CertificationRequest

use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project athenz by yahoo.

the class CryptoTest method testExtractX509IPAddressesNoAddresses.

@Test
public void testExtractX509IPAddressesNoAddresses() throws IOException {
    Path path = Paths.get("src/test/resources/valid.csr");
    String csr = new String(Files.readAllBytes(path));
    PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(csr);
    assertNotNull(certReq);
    List<String> ips = Crypto.extractX509CSRIPAddresses(certReq);
    assertTrue(ips.isEmpty());
}
Also used : Path(java.nio.file.Path) PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) DERIA5String(org.bouncycastle.asn1.DERIA5String) Test(org.testng.annotations.Test)

Example 25 with PKCS10CertificationRequest

use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project athenz by yahoo.

the class CryptoTest method testExtractX509CSRSubjectFieldNull.

@Test
public void testExtractX509CSRSubjectFieldNull() {
    PKCS10CertificationRequest certReq = mock(PKCS10CertificationRequest.class);
    when(certReq.getSubject()).thenReturn(null);
    assertNull(Crypto.extractX509CSRSubjectField(certReq, null));
    X500Name x500Name = mock(X500Name.class);
    when(certReq.getSubject()).thenReturn(x500Name);
    RDN[] rdns = new RDN[2];
    when(x500Name.getRDNs(null)).thenReturn(rdns);
    assertThrows(CryptoException.class, () -> Crypto.extractX509CSRSubjectField(certReq, null));
}
Also used : PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) X500Name(org.bouncycastle.asn1.x500.X500Name) RDN(org.bouncycastle.asn1.x500.RDN) Test(org.testng.annotations.Test)

Aggregations

PKCS10CertificationRequest (org.bouncycastle.pkcs.PKCS10CertificationRequest)79 Test (org.testng.annotations.Test)39 Path (java.nio.file.Path)34 DERIA5String (org.bouncycastle.asn1.DERIA5String)19 X509Certificate (java.security.cert.X509Certificate)17 IOException (java.io.IOException)14 X500Name (org.bouncycastle.asn1.x500.X500Name)13 PrivateKey (java.security.PrivateKey)12 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)11 JcaPKCS10CertificationRequestBuilder (org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder)11 KeyPair (java.security.KeyPair)9 X500Principal (javax.security.auth.x500.X500Principal)9 KeyPairGenerator (java.security.KeyPairGenerator)8 ContentSigner (org.bouncycastle.operator.ContentSigner)8 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)8 File (java.io.File)7 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)7 JcaPKCS10CertificationRequest (org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest)7 PemObject (org.bouncycastle.util.io.pem.PemObject)6 CryptoException (org.kse.crypto.CryptoException)6