Search in sources :

Example 96 with X509Certificate

use of java.security.cert.X509Certificate in project nutz by nutzam.

the class Http method nopSSLSocketFactory.

public static SSLSocketFactory nopSSLSocketFactory() throws Exception {
    SSLContext sc = SSLContext.getInstance("SSL");
    TrustManager[] tmArr = { new X509TrustManager() {

        public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException {
        }

        public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException {
        }

        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    } };
    sc.init(null, tmArr, new SecureRandom());
    return sc.getSocketFactory();
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) SecureRandom(java.security.SecureRandom) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) X509Certificate(java.security.cert.X509Certificate) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 97 with X509Certificate

use of java.security.cert.X509Certificate in project android by owncloud.

the class SsoWebViewClient method getX509CertificateFromError.

/**
     * Obtain the X509Certificate from SslError
     * @param   error     SslError
     * @return  X509Certificate from error
     */
public X509Certificate getX509CertificateFromError(SslError error) {
    Bundle bundle = SslCertificate.saveState(error.getCertificate());
    X509Certificate x509Certificate;
    byte[] bytes = bundle.getByteArray("x509-certificate");
    if (bytes == null) {
        x509Certificate = null;
    } else {
        try {
            CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
            Certificate cert = certFactory.generateCertificate(new ByteArrayInputStream(bytes));
            x509Certificate = (X509Certificate) cert;
        } catch (CertificateException e) {
            x509Certificate = null;
        }
    }
    return x509Certificate;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Bundle(android.os.Bundle) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) SslCertificate(android.net.http.SslCertificate)

Example 98 with X509Certificate

use of java.security.cert.X509Certificate in project android by owncloud.

the class SsoWebViewClient method onReceivedSslError.

@Override
public void onReceivedSslError(final WebView view, final SslErrorHandler handler, SslError error) {
    Log_OC.e(TAG, "onReceivedSslError : " + error);
    // Test 1
    X509Certificate x509Certificate = getX509CertificateFromError(error);
    boolean isKnownServer = false;
    if (x509Certificate != null) {
        try {
            isKnownServer = NetworkUtils.isCertInKnownServersStore((Certificate) x509Certificate, mContext);
        } catch (Exception e) {
            Log_OC.e(TAG, "Exception: " + e.getMessage());
        }
    }
    if (isKnownServer) {
        handler.proceed();
    } else {
        ((AuthenticatorActivity) mContext).showUntrustedCertDialog(x509Certificate, error, handler);
    }
}
Also used : X509Certificate(java.security.cert.X509Certificate) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) SslCertificate(android.net.http.SslCertificate)

Example 99 with X509Certificate

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

the class PinningTrustManagerImpl method checkServerTrusted.

@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
    Log.d(TAG, "Checking if server is trusted");
    for (final TrustManager systemTrustManager : systemTrustManagers) {
        ((X509TrustManager) systemTrustManager).checkServerTrusted(chain, authType);
    }
    Log.d(TAG, "Getting trust root");
    final X509Certificate anchor = systemKeyStore.getTrustRoot(chain);
    Log.d(TAG, "checking certs for valid pin");
    for (final X509Certificate certificate : chain) {
        if (isValidPin(certificate)) {
            Log.d(TAG, "Success!");
            return;
        }
    }
    Log.d(TAG, "checking anchor for valid pin");
    if (anchor != null && isValidPin(anchor)) {
        Log.d(TAG, "Success!");
        return;
    }
    throw new CertificateException("No valid Pins found in Certificate Chain!");
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 100 with X509Certificate

use of java.security.cert.X509Certificate in project platformlayer by platformlayer.

the class PkiServiceImpl method signCsr.

@Override
public List<X509Certificate> signCsr(ProjectEntity project, String csr) throws OpsException {
    CertificateAndKey projectPki;
    try {
        projectPki = repository.getProjectPki(project);
    } catch (RepositoryException e) {
        throw new OpsException("Error getting project PKI info", e);
    }
    SimpleCertificateAuthority ca = new SimpleCertificateAuthority();
    ca.caCertificate = projectPki.getCertificateChain();
    ca.caPrivateKey = projectPki.getPrivateKey();
    X509Certificate certificate = ca.signCsr(csr);
    List<X509Certificate> chain = Lists.newArrayList();
    chain.add(certificate);
    for (X509Certificate cert : projectPki.getCertificateChain()) {
        chain.add(cert);
    }
    return chain;
}
Also used : OpsException(org.platformlayer.ops.OpsException) SimpleCertificateAuthority(org.platformlayer.crypto.SimpleCertificateAuthority) RepositoryException(org.platformlayer.RepositoryException) CertificateAndKey(com.fathomdb.crypto.CertificateAndKey) X509Certificate(java.security.cert.X509Certificate)

Aggregations

X509Certificate (java.security.cert.X509Certificate)1706 IOException (java.io.IOException)336 CertificateException (java.security.cert.CertificateException)272 ByteArrayInputStream (java.io.ByteArrayInputStream)260 CertificateFactory (java.security.cert.CertificateFactory)251 ArrayList (java.util.ArrayList)232 Certificate (java.security.cert.Certificate)227 KeyStore (java.security.KeyStore)177 PrivateKey (java.security.PrivateKey)150 InputStream (java.io.InputStream)134 File (java.io.File)112 KeyStoreException (java.security.KeyStoreException)112 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)111 GeneralSecurityException (java.security.GeneralSecurityException)100 Test (org.junit.Test)90 List (java.util.List)89 PublicKey (java.security.PublicKey)88 X509TrustManager (javax.net.ssl.X509TrustManager)80 X500Principal (javax.security.auth.x500.X500Principal)76 HashSet (java.util.HashSet)64