Search in sources :

Example 36 with X509TrustManager

use of javax.net.ssl.X509TrustManager in project k-9 by k9mail.

the class TrustManagerFactoryTest method testLocallyTrustedCertificateChain.

@Test
public void testLocallyTrustedCertificateChain() throws Exception {
    mKeyStore.addCertificate(MATCHING_HOST, PORT1, mCert3);
    X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1);
    trustManager.checkServerTrusted(new X509Certificate[] { mCert3, mCaCert }, "authType");
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) Test(org.junit.Test)

Example 37 with X509TrustManager

use of javax.net.ssl.X509TrustManager in project k-9 by k9mail.

the class TrustManagerFactoryTest method testCertificateOfOtherHost.

@Test
public void testCertificateOfOtherHost() throws Exception {
    mKeyStore.addCertificate(MATCHING_HOST, PORT1, mCert1);
    mKeyStore.addCertificate(MATCHING_HOST, PORT2, mCert2);
    X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1);
    assertCertificateRejection(trustManager, new X509Certificate[] { mCert2 });
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) Test(org.junit.Test)

Example 38 with X509TrustManager

use of javax.net.ssl.X509TrustManager in project k-9 by k9mail.

the class TrustManagerFactoryTest method testLocallyTrustedCertificateChainNotMatchingHost.

@Test
public void testLocallyTrustedCertificateChainNotMatchingHost() throws Exception {
    mKeyStore.addCertificate(NOT_MATCHING_HOST, PORT1, mCert3);
    X509TrustManager trustManager = TrustManagerFactory.get(NOT_MATCHING_HOST, PORT1);
    trustManager.checkServerTrusted(new X509Certificate[] { mCert3, mCaCert }, "authType");
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) Test(org.junit.Test)

Example 39 with X509TrustManager

use of javax.net.ssl.X509TrustManager in project k-9 by k9mail.

the class TrustManagerFactoryTest method testGloballyTrustedCertificateNotMatchingHost.

@Test
public void testGloballyTrustedCertificateNotMatchingHost() throws Exception {
    X509TrustManager trustManager = TrustManagerFactory.get(NOT_MATCHING_HOST, PORT1);
    assertCertificateRejection(trustManager, new X509Certificate[] { mLinuxComCert, mLinuxComFirstParentCert });
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) Test(org.junit.Test)

Example 40 with X509TrustManager

use of javax.net.ssl.X509TrustManager 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)

Aggregations

X509TrustManager (javax.net.ssl.X509TrustManager)183 TrustManager (javax.net.ssl.TrustManager)114 X509Certificate (java.security.cert.X509Certificate)96 SSLContext (javax.net.ssl.SSLContext)88 CertificateException (java.security.cert.CertificateException)54 IOException (java.io.IOException)50 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)45 SecureRandom (java.security.SecureRandom)44 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)32 KeyManagementException (java.security.KeyManagementException)28 Test (org.junit.Test)21 HostnameVerifier (javax.net.ssl.HostnameVerifier)19 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)19 KeyStore (java.security.KeyStore)17 GeneralSecurityException (java.security.GeneralSecurityException)15 SSLSession (javax.net.ssl.SSLSession)15 KeyStoreException (java.security.KeyStoreException)14 SSLException (javax.net.ssl.SSLException)14 URL (java.net.URL)11 OkHttpClient (okhttp3.OkHttpClient)10