Search in sources :

Example 86 with CertificateFactory

use of java.security.cert.CertificateFactory in project robovm by robovm.

the class myCertificateFactory method testCertificateFactory15.

/**
     * Test for <code>generateCertPath(List certificates)</code> method
     * Assertion: returns empty CertPath if certificates is empty
     */
public void testCertificateFactory15() throws CertificateException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    List<Certificate> list = new Vector<Certificate>();
    for (int i = 0; i < certFs.length; i++) {
        CertPath cp = certFs[i].generateCertPath(list);
        List<? extends Certificate> list1 = cp.getCertificates();
        assertTrue("List should be empty", list1.isEmpty());
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) CertPath(java.security.cert.CertPath) CertificateFactory(java.security.cert.CertificateFactory) Vector(java.util.Vector) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate)

Example 87 with CertificateFactory

use of java.security.cert.CertificateFactory in project robovm by robovm.

the class myCertificateFactory method testCertificateFactory08.

/**
     * Test for <code>getInstance(String type, Provider provider)</code>
     * method
     * Assertion: returns CertificateFactorythrows when type and provider
     * have valid values
     */
public void testCertificateFactory08() throws CertificateException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactory certF;
    for (int i = 0; i < validValues.length; i++) {
        certF = CertificateFactory.getInstance(validValues[i], defaultProvider);
        assertEquals("Incorrect provider", certF.getProvider(), defaultProvider);
        assertEquals("Incorrect type", certF.getType(), validValues[i]);
    }
}
Also used : CertificateFactory(java.security.cert.CertificateFactory)

Example 88 with CertificateFactory

use of java.security.cert.CertificateFactory in project robovm by robovm.

the class myCertificateFactory method testCertificateFactory18.

/**
     * Test for <code>getType()</code> method
     */
public void testCertificateFactory18() throws CertificateException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    for (int i = 0; i < validValues.length; i++) {
        try {
            CertificateFactory certF = CertificateFactory.getInstance(validValues[i]);
            assertEquals("Incorrect type: ", validValues[i], certF.getType());
            certF = CertificateFactory.getInstance(validValues[i], defaultProviderName);
            assertEquals("Incorrect type", certF.getType(), validValues[i]);
            certF = CertificateFactory.getInstance(validValues[i], defaultProvider);
            assertEquals("Incorrect provider", certF.getProvider(), defaultProvider);
            assertEquals("Incorrect type", certF.getType(), validValues[i]);
        } catch (NoSuchProviderException e) {
            fail("Unexpected NoSuchProviderException " + e.getMessage());
        }
    }
}
Also used : NoSuchProviderException(java.security.NoSuchProviderException) CertificateFactory(java.security.cert.CertificateFactory)

Example 89 with CertificateFactory

use of java.security.cert.CertificateFactory in project robovm by robovm.

the class CertificateTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    TestUtils.initCertPathSSCertChain();
    cert = TestUtils.rootCertificateSS;
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    wrongProvider = cf.getProvider();
    usefulProvider = Signature.getInstance("SHA1WithRSA").getProvider();
}
Also used : CertificateFactory(java.security.cert.CertificateFactory)

Example 90 with CertificateFactory

use of java.security.cert.CertificateFactory in project dbeaver by serge-rider.

the class DefaultCertificateStorage method addCertificate.

@Override
public void addCertificate(DBPDataSourceContainer dataSource, String certType, byte[] caCertData, byte[] clientCertData, byte[] keyData) throws DBException {
    final KeyStore keyStore = getKeyStore(dataSource, certType);
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        List<Certificate> certChain = new ArrayList<>();
        if (caCertData != null) {
            Certificate caCert = cf.generateCertificate(new ByteArrayInputStream(caCertData));
            keyStore.setCertificateEntry("ca-cert", caCert);
        //certChain.add(caCert);
        }
        if (clientCertData != null) {
            Certificate clientCert = cf.generateCertificate(new ByteArrayInputStream(clientCertData));
            keyStore.setCertificateEntry("client-cert", clientCert);
            certChain.add(clientCert);
        }
        if (keyData != null) {
            PrivateKey privateKey = loadPrivateKeyFromPEM(keyData);
            keyStore.setKeyEntry("key-cert", privateKey, DEFAULT_PASSWORD, certChain.toArray(new Certificate[certChain.size()]));
        }
        saveKeyStore(dataSource, certType, keyStore);
    } catch (Throwable e) {
        throw new DBException("Error adding certificate to keystore", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) PrivateKey(java.security.PrivateKey) ArrayList(java.util.ArrayList) KeyStore(java.security.KeyStore) CertificateFactory(java.security.cert.CertificateFactory) Certificate(java.security.cert.Certificate)

Aggregations

CertificateFactory (java.security.cert.CertificateFactory)550 X509Certificate (java.security.cert.X509Certificate)409 ByteArrayInputStream (java.io.ByteArrayInputStream)372 Certificate (java.security.cert.Certificate)272 CertificateException (java.security.cert.CertificateException)120 KeyFactory (java.security.KeyFactory)103 PrivateKey (java.security.PrivateKey)93 InputStream (java.io.InputStream)92 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)86 IOException (java.io.IOException)80 KeyStore (java.security.KeyStore)77 PrivateKeyEntry (java.security.KeyStore.PrivateKeyEntry)67 Entry (java.security.KeyStore.Entry)59 TrustedCertificateEntry (java.security.KeyStore.TrustedCertificateEntry)59 KeyStoreException (java.security.KeyStoreException)49 ArrayList (java.util.ArrayList)49 FileInputStream (java.io.FileInputStream)47 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)35 File (java.io.File)23 HashSet (java.util.HashSet)21