public void run() throws Exception { Request request = new Request.Builder() .url("https://publicobject.com/helloworld.txt") .build(); try (Response response = client.newCall(request).execute()) { if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); System.out.println(response.handshake().cipherSuite()); System.out.println(response.body().string()); } }
@Override public List<Certificate> getServerCertificateChain() throws SSLPeerUnverifiedException { if (handshake == null) return null; // Java requires null, not an empty list here. List<Certificate> certificates = handshake.peerCertificates(); return certificates.size() > 0 ? certificates : null; }
@Override public List<Certificate> getLocalCertificateChain() { if (handshake == null) return null; // Java requires null, not an empty list here. List<Certificate> certificates = handshake.localCertificates(); return certificates.size() > 0 ? certificates : null; }
private static void sendRequest(OkHttpClient client, String url) { System.out.printf("%-40s ", url); System.out.flush(); System.out.println(Platform.get()); Request request = new Request.Builder().url(url).build(); try (Response response = client.newCall(request).execute()) { Handshake handshake = response.handshake(); System.out.println(handshake.tlsVersion() + " " + handshake.cipherSuite() + " " + response.protocol() + " " + response.code + " " + response.body.bytes().length + "b"); } catch (IOException ioe) { System.out.println(ioe.toString()); } } }
sink.writeUtf8(handshake.cipherSuite().javaName()) .writeByte('\n'); writeCertList(sink, handshake.peerCertificates()); writeCertList(sink, handshake.localCertificates()); sink.writeUtf8(handshake.tlsVersion().javaName()).writeByte('\n');
Handshake unverifiedHandshake = Handshake.get(sslSocketSession); List<Certificate> peerCertificates = unverifiedHandshake.peerCertificates(); if (!peerCertificates.isEmpty()) { X509Certificate cert = (X509Certificate) peerCertificates.get(0); unverifiedHandshake.peerCertificates());
sink.writeUtf8(handshake.cipherSuite().javaName()); sink.writeByte('\n'); writeCertList(sink, handshake.peerCertificates()); writeCertList(sink, handshake.localCertificates());
if (socket instanceof SSLSocket) { try { this.handshake = Handshake.get(((SSLSocket) socket).getSession()); } catch (IOException e) { throw new IllegalArgumentException(e);
public static Handshake get(TlsVersion tlsVersion, CipherSuite cipherSuite, List<Certificate> peerCertificates, List<Certificate> localCertificates) { if (tlsVersion == null) throw new NullPointerException("tlsVersion == null"); if (cipherSuite == null) throw new NullPointerException("cipherSuite == null"); return new Handshake(tlsVersion, cipherSuite, Util.immutableList(peerCertificates), Util.immutableList(localCertificates)); }
@Override public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { if (handshake == null) return null; return handshake.peerPrincipal(); }
/** Returns the connection's TLS version or null if the connection doesn't use SSL. */ public TlsVersion getTlsVersion() { return handshake != null ? handshake.tlsVersion() : null; }
@Override public Principal getLocalPrincipal() { if (handshake == null) return null; return handshake.localPrincipal(); }
bufferedSink.writeUtf8(handshake.cipherSuite().javaName()) .writeByte('\n'); writeCertList(bufferedSink, handshake.peerCertificates()); writeCertList(bufferedSink, handshake.localCertificates()); if (handshake.tlsVersion() != null) { bufferedSink.writeUtf8(handshake.tlsVersion().javaName()) .writeByte('\n');
Handshake unverifiedHandshake = Handshake.get(sslSocketSession); List<Certificate> peerCertificates = unverifiedHandshake.peerCertificates(); if (!peerCertificates.isEmpty()) { X509Certificate cert = (X509Certificate) peerCertificates.get(0); unverifiedHandshake.peerCertificates());
sink.writeUtf8(handshake.cipherSuite().javaName()); sink.writeByte('\n'); writeCertList(sink, handshake.peerCertificates()); writeCertList(sink, handshake.localCertificates());
Handshake handshake = Handshake.get( TlsVersion.SSL_3_0, cipherSuite, peerCertificates, localCertificates); okResponseBuilder.handshake(handshake);
public static Handshake get(SSLSession session) throws IOException { String cipherSuiteString = session.getCipherSuite(); if (cipherSuiteString == null) throw new IllegalStateException("cipherSuite == null"); if ("SSL_NULL_WITH_NULL_NULL".equals(cipherSuiteString)) { throw new IOException("cipherSuite == SSL_NULL_WITH_NULL_NULL"); } CipherSuite cipherSuite = CipherSuite.forJavaName(cipherSuiteString); String tlsVersionString = session.getProtocol(); if (tlsVersionString == null) throw new IllegalStateException("tlsVersion == null"); if ("NONE".equals(tlsVersionString)) throw new IOException("tlsVersion == NONE"); TlsVersion tlsVersion = TlsVersion.forJavaName(tlsVersionString); Certificate[] peerCertificates; try { peerCertificates = session.getPeerCertificates(); } catch (SSLPeerUnverifiedException ignored) { peerCertificates = null; } List<Certificate> peerCertificatesList = peerCertificates != null ? Util.immutableList(peerCertificates) : Collections.emptyList(); Certificate[] localCertificates = session.getLocalCertificates(); List<Certificate> localCertificatesList = localCertificates != null ? Util.immutableList(localCertificates) : Collections.emptyList(); return new Handshake(tlsVersion, cipherSuite, peerCertificatesList, localCertificatesList); }
@Override public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { Handshake handshake = handshake(); return handshake != null ? handshake.peerPrincipal() : null; }
public void run() throws Exception { String localhost = InetAddress.getByName("localhost").getCanonicalHostName(); HeldCertificate localhostCertificate = new HeldCertificate.Builder() .addSubjectAlternativeName(localhost) .build(); HandshakeCertificates serverCertificates = new HandshakeCertificates.Builder() .heldCertificate(localhostCertificate) .build(); MockWebServer server = new MockWebServer(); server.useHttps(serverCertificates.sslSocketFactory(), false); server.enqueue(new MockResponse()); HandshakeCertificates clientCertificates = new HandshakeCertificates.Builder() .addTrustedCertificate(localhostCertificate.certificate()) .build(); OkHttpClient client = new OkHttpClient.Builder() .sslSocketFactory(clientCertificates.sslSocketFactory(), clientCertificates.trustManager()) .build(); Call call = client.newCall(new Request.Builder() .url(server.url("/")) .build()); Response response = call.execute(); System.out.println(response.handshake().tlsVersion()); }
@Override public Principal getLocalPrincipal() { Handshake handshake = handshake(); return handshake != null ? handshake.localPrincipal() : null; }