Search in sources :

Example 41 with CertificateException

use of java.security.cert.CertificateException in project scdl by passy.

the class PinningTrustManagerImpl method initializeSystemTrustManagers.

private TrustManager[] initializeSystemTrustManagers() throws CertificateException {
    try {
        final TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
        tmf.init((KeyStore) null);
        return tmf.getTrustManagers();
    } catch (final NoSuchAlgorithmException nsae) {
        throw new CertificateException(nsae);
    } catch (final KeyStoreException e) {
        throw new CertificateException(e);
    }
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException)

Example 42 with CertificateException

use of java.security.cert.CertificateException in project scdl by passy.

the class SystemKeyStore method getTrustRoot.

public X509Certificate getTrustRoot(final X509Certificate[] chain) throws CertificateException {
    try {
        final CertPath certPath = certificateFactory.generateCertPath(Arrays.asList(chain));
        final PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult) validator.validate(certPath, parameters);
        if (result == null) {
            return null;
        } else {
            return result.getTrustAnchor().getTrustedCert();
        }
    } catch (final CertPathValidatorException e) {
        return null;
    } catch (final InvalidAlgorithmParameterException e) {
        throw new CertificateException(e);
    }
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) PKIXCertPathValidatorResult(java.security.cert.PKIXCertPathValidatorResult) CertificateException(java.security.cert.CertificateException) CertPath(java.security.cert.CertPath)

Example 43 with CertificateException

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

the class ProvisioningProfile method getCertFingerprint.

private static String getCertFingerprint(byte[] certData) {
    try {
        CertificateFactory x509CertFact = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) x509CertFact.generateCertificate(new ByteArrayInputStream(certData));
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        return toHexString(md.digest(cert.getEncoded()));
    } catch (CertificateException e) {
        throw new RuntimeException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Example 44 with CertificateException

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

the class BcKeyStoreSpi method decodeCertificate.

private Certificate decodeCertificate(DataInputStream dIn) throws IOException {
    String type = dIn.readUTF();
    byte[] cEnc = new byte[dIn.readInt()];
    dIn.readFully(cEnc);
    try {
        CertificateFactory cFact = CertificateFactory.getInstance(type, BouncyCastleProvider.PROVIDER_NAME);
        ByteArrayInputStream bIn = new ByteArrayInputStream(cEnc);
        return cFact.generateCertificate(bIn);
    } catch (NoSuchProviderException ex) {
        throw new IOException(ex.toString());
    } catch (CertificateException ex) {
        throw new IOException(ex.toString());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateFactory(java.security.cert.CertificateFactory)

Example 45 with CertificateException

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

the class X509CertFactoryImpl method engineGenerateCertPath.

/**
     * @see java.security.cert.CertificateFactorySpi#engineGenerateCertPath(InputStream,String)
     * method documentation for more info
     */
public CertPath engineGenerateCertPath(InputStream inStream, String encoding) throws CertificateException {
    if (inStream == null) {
        throw new CertificateException("inStream == null");
    }
    if (!inStream.markSupported()) {
        inStream = new RestoringInputStream(inStream);
    }
    try {
        inStream.mark(1);
        int ch;
        // check if it is PEM encoded form
        if ((ch = inStream.read()) == '-') {
            // decode PEM chunk into ASN.1 form and decode CertPath object
            return X509CertPathImpl.getInstance(decodePEM(inStream, FREE_BOUND_SUFFIX), encoding);
        } else if (ch == 0x30) {
            // ASN.1 Sequence
            inStream.reset();
            // decode ASN.1 form
            return X509CertPathImpl.getInstance(inStream, encoding);
        } else {
            throw new CertificateException("Unsupported encoding");
        }
    } catch (IOException e) {
        throw new CertificateException(e);
    }
}
Also used : CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException)

Aggregations

CertificateException (java.security.cert.CertificateException)456 IOException (java.io.IOException)221 X509Certificate (java.security.cert.X509Certificate)215 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)141 KeyStoreException (java.security.KeyStoreException)123 CertificateFactory (java.security.cert.CertificateFactory)103 ByteArrayInputStream (java.io.ByteArrayInputStream)97 Certificate (java.security.cert.Certificate)75 KeyStore (java.security.KeyStore)58 InputStream (java.io.InputStream)55 UnrecoverableKeyException (java.security.UnrecoverableKeyException)53 ArrayList (java.util.ArrayList)49 InvalidKeyException (java.security.InvalidKeyException)44 X509TrustManager (javax.net.ssl.X509TrustManager)41 SSLContext (javax.net.ssl.SSLContext)36 FileInputStream (java.io.FileInputStream)34 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)34 RemoteException (android.os.RemoteException)33 FileNotFoundException (java.io.FileNotFoundException)30 KeyManagementException (java.security.KeyManagementException)30