Search in sources :

Example 1 with HeldCertificate

use of okhttp3.internal.tls.HeldCertificate in project okhttp by square.

the class CertificateChainCleanerTest method normalizeUnknownSelfSignedCertificate.

@Test
public void normalizeUnknownSelfSignedCertificate() throws Exception {
    HeldCertificate root = new HeldCertificate.Builder().serialNumber("1").build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get();
    try {
        cleaner.clean(list(root), "hostname");
        fail();
    } catch (SSLPeerUnverifiedException expected) {
    }
}
Also used : SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Example 2 with HeldCertificate

use of okhttp3.internal.tls.HeldCertificate in project okhttp by square.

the class CertificateChainCleanerTest method normalizeSingleSelfSignedCertificate.

@Test
public void normalizeSingleSelfSignedCertificate() throws Exception {
    HeldCertificate root = new HeldCertificate.Builder().serialNumber("1").build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate);
    assertEquals(list(root), cleaner.clean(list(root), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Example 3 with HeldCertificate

use of okhttp3.internal.tls.HeldCertificate in project okhttp by square.

the class CertificateChainCleanerTest method equalsFromCertificate.

@Test
public void equalsFromCertificate() throws Exception {
    HeldCertificate rootA = new HeldCertificate.Builder().serialNumber("1").build();
    HeldCertificate rootB = new HeldCertificate.Builder().serialNumber("2").build();
    assertEquals(CertificateChainCleaner.get(rootA.certificate, rootB.certificate), CertificateChainCleaner.get(rootB.certificate, rootA.certificate));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) Test(org.junit.Test)

Example 4 with HeldCertificate

use of okhttp3.internal.tls.HeldCertificate in project okhttp by square.

the class CertificateChainCleanerTest method orderedChainOfCertificatesWithRoot.

@Test
public void orderedChainOfCertificatesWithRoot() throws Exception {
    HeldCertificate root = new HeldCertificate.Builder().serialNumber("1").build();
    HeldCertificate certA = new HeldCertificate.Builder().serialNumber("2").issuedBy(root).build();
    HeldCertificate certB = new HeldCertificate.Builder().serialNumber("3").issuedBy(certA).build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate);
    assertEquals(list(certB, certA, root), cleaner.clean(list(certB, certA, root), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Example 5 with HeldCertificate

use of okhttp3.internal.tls.HeldCertificate in project okhttp by square.

the class CertificateChainCleanerTest method chainTooLong.

@Test
public void chainTooLong() throws Exception {
    List<HeldCertificate> heldCertificates = chainOfLength(11);
    List<Certificate> certificates = new ArrayList<>();
    for (HeldCertificate heldCertificate : heldCertificates) {
        certificates.add(heldCertificate.certificate);
    }
    X509Certificate root = heldCertificates.get(heldCertificates.size() - 1).certificate;
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(root);
    try {
        cleaner.clean(certificates, "hostname");
        fail();
    } catch (SSLPeerUnverifiedException expected) {
    }
}
Also used : SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) HeldCertificate(okhttp3.internal.tls.HeldCertificate) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) X509Certificate(java.security.cert.X509Certificate) HeldCertificate(okhttp3.internal.tls.HeldCertificate) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 HeldCertificate (okhttp3.internal.tls.HeldCertificate)14 CertificateChainCleaner (okhttp3.internal.tls.CertificateChainCleaner)11 Call (okhttp3.Call)5 OkHttpClient (okhttp3.OkHttpClient)5 Request (okhttp3.Request)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)4 CertificatePinner (okhttp3.CertificatePinner)4 RecordingHostnameVerifier (okhttp3.RecordingHostnameVerifier)4 Certificate (java.security.cert.Certificate)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 Response (okhttp3.Response)2 SocketException (java.net.SocketException)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1 DelegatingSSLSocketFactory (okhttp3.DelegatingSSLSocketFactory)1 SslClient (okhttp3.internal.tls.SslClient)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1