Search in sources :

Example 16 with HeldCertificate

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

the class CertificateChainCleanerTest method orderedChainOfCertificatesWithoutRoot.

@Test
public void orderedChainOfCertificatesWithoutRoot() 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), // Root is added!
    cleaner.clean(list(certB, certA), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Example 17 with HeldCertificate

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

the class CertificateChainCleanerTest method unorderedChainOfCertificatesWithRoot.

@Test
public void unorderedChainOfCertificatesWithRoot() 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();
    HeldCertificate certC = new HeldCertificate.Builder().serialNumber("4").issuedBy(certB).build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate);
    assertEquals(list(certC, certB, certA, root), cleaner.clean(list(certC, certA, root, certB), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) Test(org.junit.Test)

Example 18 with HeldCertificate

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

the class CertificateChainCleanerTest method trustedRootNotSelfSigned.

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

Example 19 with HeldCertificate

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

the class CertificateChainCleanerTest method unorderedChainOfCertificatesWithoutRoot.

@Test
public void unorderedChainOfCertificatesWithoutRoot() 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();
    HeldCertificate certC = new HeldCertificate.Builder().serialNumber("4").issuedBy(certB).build();
    CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate);
    assertEquals(list(certC, certB, certA, root), cleaner.clean(list(certC, certA, certB), "hostname"));
}
Also used : HeldCertificate(okhttp3.internal.tls.HeldCertificate) CertificateChainCleaner(okhttp3.internal.tls.CertificateChainCleaner) 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