use of okhttp3.tls.HeldCertificate in project okhttp by square.
the class ClientAuthTest method buildClient.
private OkHttpClient buildClient(HeldCertificate heldCertificate, X509Certificate... intermediates) {
HandshakeCertificates.Builder builder = new HandshakeCertificates.Builder().addTrustedCertificate(serverRootCa.certificate());
if (heldCertificate != null) {
builder.heldCertificate(heldCertificate, intermediates);
}
HandshakeCertificates handshakeCertificates = builder.build();
return clientTestRule.newClientBuilder().sslSocketFactory(handshakeCertificates.sslSocketFactory(), handshakeCertificates.trustManager()).build();
}
use of okhttp3.tls.HeldCertificate in project okhttp by square.
the class CertificatePinnerTest method sameKeypairSamePin.
/**
* Multiple certificates generated from the same keypair have the same pin.
*/
@Test
public void sameKeypairSamePin() throws Exception {
HeldCertificate heldCertificateA2 = new HeldCertificate.Builder().keyPair(certA1.keyPair()).serialNumber(101L).build();
String keypairACertificate2Pin = CertificatePinner.pin(heldCertificateA2.certificate());
HeldCertificate heldCertificateB2 = new HeldCertificate.Builder().keyPair(certB1.keyPair()).serialNumber(201L).build();
String keypairBCertificate2Pin = CertificatePinner.pin(heldCertificateB2.certificate());
assertThat(keypairACertificate2Pin).isEqualTo(certA1Sha256Pin);
assertThat(keypairBCertificate2Pin).isEqualTo(certB1Sha256Pin);
assertThat(certB1Sha256Pin).isNotEqualTo(certA1Sha256Pin);
}
use of okhttp3.tls.HeldCertificate in project okhttp by square.
the class CertificateChainCleanerTest method unorderedChainOfCertificatesWithoutRoot.
@Test
public void unorderedChainOfCertificatesWithoutRoot() throws Exception {
HeldCertificate root = new HeldCertificate.Builder().serialNumber(1L).certificateAuthority(2).build();
HeldCertificate certA = new HeldCertificate.Builder().serialNumber(2L).certificateAuthority(1).signedBy(root).build();
HeldCertificate certB = new HeldCertificate.Builder().serialNumber(3L).certificateAuthority(0).signedBy(certA).build();
HeldCertificate certC = new HeldCertificate.Builder().serialNumber(4L).signedBy(certB).build();
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
assertThat(cleaner.clean(list(certC, certA, certB), "hostname")).isEqualTo(list(certC, certB, certA, root));
}
use of okhttp3.tls.HeldCertificate in project okhttp by square.
the class CertificateChainCleanerTest method chainMaxLength.
@Test
public void chainMaxLength() throws Exception {
List<HeldCertificate> heldCertificates = chainOfLength(10);
List<Certificate> certificates = new ArrayList<>();
for (HeldCertificate heldCertificate : heldCertificates) {
certificates.add(heldCertificate.certificate());
}
X509Certificate root = heldCertificates.get(heldCertificates.size() - 1).certificate();
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root);
assertThat(cleaner.clean(certificates, "hostname")).isEqualTo(certificates);
assertThat(cleaner.clean(certificates.subList(0, 9), "hostname")).isEqualTo(certificates);
}
use of okhttp3.tls.HeldCertificate in project okhttp by square.
the class CertificateChainCleanerTest method unrelatedCertificatesAreOmitted.
@Test
public void unrelatedCertificatesAreOmitted() throws Exception {
HeldCertificate root = new HeldCertificate.Builder().serialNumber(1L).certificateAuthority(1).build();
HeldCertificate certA = new HeldCertificate.Builder().serialNumber(2L).certificateAuthority(0).signedBy(root).build();
HeldCertificate certB = new HeldCertificate.Builder().serialNumber(3L).signedBy(certA).build();
HeldCertificate certUnnecessary = new HeldCertificate.Builder().serialNumber(4L).build();
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
assertThat(cleaner.clean(list(certB, certUnnecessary, certA, root), "hostname")).isEqualTo(list(certB, certA, root));
}
Aggregations