Search in sources :

Example 6 with CertificateBuilder

use of com.adaptris.security.certificate.CertificateBuilder in project interlok by adaptris.

the class TestCertificateGeneration method testCertificateToKeystore.

@Test
public void testCertificateToKeystore() throws Exception {
    String commonName = String.valueOf(random.nextInt(1000));
    CertificateBuilder builder = Config.getInstance().getBuilder(commonName);
    Certificate selfCert = builder.createSelfSignedCertificate();
    builder.getPrivateKey();
    ksp = KeystoreFactory.getDefault().create(ksc);
    try {
        ksp.load();
    } catch (Exception e) {
        ;
    }
    ksp.setCertificate(commonName, selfCert);
    ksp.commit();
}
Also used : CertificateBuilder(com.adaptris.security.certificate.CertificateBuilder) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Example 7 with CertificateBuilder

use of com.adaptris.security.certificate.CertificateBuilder in project interlok by adaptris.

the class TestPassword method specificMicrosoftSetup.

/*
   * Ensure that the Windows-MY keystore actually has a certificate
   * chain and a private key
   */
private void specificMicrosoftSetup() throws Exception {
    String username = System.getProperty("user.name");
    KeyStore ks = KeyStore.getInstance("Windows-MY");
    ks.load(null, null);
    if (!ks.containsAlias(username)) {
        CertificateBuilder builder = Config.getInstance().getBuilder(username);
        X509Certificate[] chain = new X509Certificate[1];
        chain[0] = (X509Certificate) builder.createSelfSignedCertificate();
        ks.setKeyEntry(username, builder.getPrivateKey(), username.toCharArray(), chain);
    }
}
Also used : CertificateBuilder(com.adaptris.security.certificate.CertificateBuilder) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate)

Example 8 with CertificateBuilder

use of com.adaptris.security.certificate.CertificateBuilder in project interlok by adaptris.

the class TestCertificateGeneration method testEncodedCertificateToKeystore.

@Test
public void testEncodedCertificateToKeystore() throws Exception {
    String commonName = String.valueOf(random.nextInt(1000));
    CertificateBuilder builder = Config.getInstance().getBuilder(commonName);
    Certificate selfCert = builder.createSelfSignedCertificate();
    builder.getPrivateKey();
    ksp = KeystoreFactory.getDefault().create(ksc);
    try {
        ksp.load();
    } catch (Exception e) {
        ;
    }
    ksp.setCertificate(commonName, new ByteArrayInputStream(selfCert.getEncoded()));
    ksp.commit();
}
Also used : CertificateBuilder(com.adaptris.security.certificate.CertificateBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Example 9 with CertificateBuilder

use of com.adaptris.security.certificate.CertificateBuilder in project interlok by adaptris.

the class TestCertificateGeneration method testCreateCertificateRequest.

@Test
public void testCreateCertificateRequest() {
    try {
        String commonName = String.valueOf(random.nextInt(1000));
        CertificateBuilder builder = Config.getInstance().getBuilder(commonName);
        Certificate selfCert = builder.createSelfSignedCertificate();
        PrivateKey privkey = builder.getPrivateKey();
        String s = CertRequestHandler.createRequest(selfCert, privkey);
        logR.trace(s);
    } catch (Exception e) {
        logR.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : CertificateBuilder(com.adaptris.security.certificate.CertificateBuilder) PrivateKey(java.security.PrivateKey) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Example 10 with CertificateBuilder

use of com.adaptris.security.certificate.CertificateBuilder in project interlok by adaptris.

the class TestCertificateGeneration method testCertificateGeneration.

@Test
public void testCertificateGeneration() throws Exception {
    String commonName = String.valueOf(random.nextInt(1000));
    CertificateBuilder builder = Config.getInstance().getBuilder(commonName);
    Certificate selfCert = builder.createSelfSignedCertificate();
    CertificateHandler ch = CertificateHandlerFactory.getInstance().generateHandler(selfCert);
    String signatureAlgorithm = ch.getSignatureAlgorithm();
    String property = cfg.getProperty(Config.CERTIFICATE_SIGALG);
    // AlgorithmID algorithmID = SecurityUtil.getAlgorithmID(signatureAlgorithm);
    // AlgorithmID configID = SecurityUtil.getAlgorithmID(property);
    assertEquals("Signature Algorithm", signatureAlgorithm, property);
    assertEquals("Key Algorithm", cfg.getProperty(Config.CERTIFICATE_KEYALG), ch.getKeyAlgorithm());
}
Also used : CertificateBuilder(com.adaptris.security.certificate.CertificateBuilder) CertificateHandler(com.adaptris.security.certificate.CertificateHandler) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Aggregations

CertificateBuilder (com.adaptris.security.certificate.CertificateBuilder)10 Certificate (java.security.cert.Certificate)7 Test (org.junit.Test)5 PrivateKey (java.security.PrivateKey)4 CertificateParameter (com.adaptris.security.certificate.CertificateParameter)2 KeystoreLocation (com.adaptris.security.keystore.KeystoreLocation)2 KeystoreProxy (com.adaptris.security.keystore.KeystoreProxy)2 X500NameBuilder (org.bouncycastle.asn1.x500.X500NameBuilder)2 CertificateHandler (com.adaptris.security.certificate.CertificateHandler)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 KeyStore (java.security.KeyStore)1 X509Certificate (java.security.cert.X509Certificate)1