okhttp3.Handshake类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中okhttp3.Handshake类的一些代码示例,展示了Handshake类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Handshake类的具体详情如下:
包路径:okhttp3.Handshake
类名称:Handshake

Handshake介绍

[英]A record of a TLS handshake. For HTTPS clients, the client is local and the remote server is its peer.

This value object describes a completed handshake. Use javax.net.ssl.SSLSocketFactory to set policy for new handshakes.
[中]TLS握手的记录。对于HTTPS客户端,客户端是本地的,远程服务器是它的对等服务器。
此值对象描述已完成的握手。使用javax。网ssl。SSLSocketFactory为新握手设置策略。

代码示例

代码示例来源:origin: square/okhttp

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());
 }
}

代码示例来源:origin: square/okhttp

@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;
}

代码示例来源:origin: square/okhttp

@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;
}

代码示例来源:origin: square/okhttp

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());
  }
 }
}

代码示例来源:origin: square/okhttp

sink.writeUtf8(handshake.cipherSuite().javaName())
  .writeByte('\n');
writeCertList(sink, handshake.peerCertificates());
writeCertList(sink, handshake.localCertificates());
sink.writeUtf8(handshake.tlsVersion().javaName()).writeByte('\n');

代码示例来源:origin: square/okhttp

Handshake unverifiedHandshake = Handshake.get(sslSocketSession);
 List<Certificate> peerCertificates = unverifiedHandshake.peerCertificates();
 if (!peerCertificates.isEmpty()) {
  X509Certificate cert = (X509Certificate) peerCertificates.get(0);
  unverifiedHandshake.peerCertificates());

代码示例来源:origin: huxq17/SwipeCardsView

sink.writeUtf8(handshake.cipherSuite().javaName());
sink.writeByte('\n');
writeCertList(sink, handshake.peerCertificates());
writeCertList(sink, handshake.localCertificates());

代码示例来源:origin: square/okhttp

if (socket instanceof SSLSocket) {
 try {
  this.handshake = Handshake.get(((SSLSocket) socket).getSession());
 } catch (IOException e) {
  throw new IllegalArgumentException(e);

代码示例来源:origin: square/okhttp

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));
}

代码示例来源:origin: square/okhttp

@Override
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
 if (handshake == null) return null;
 return handshake.peerPrincipal();
}

代码示例来源:origin: square/okhttp

/** Returns the connection's TLS version or null if the connection doesn't use SSL. */
public TlsVersion getTlsVersion() {
 return handshake != null ? handshake.tlsVersion() : null;
}

代码示例来源:origin: square/okhttp

@Override
public Principal getLocalPrincipal() {
 if (handshake == null) return null;
 return handshake.localPrincipal();
}

代码示例来源:origin: apollographql/apollo-android

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');

代码示例来源:origin: com.squareup.okhttp3/okhttp

Handshake unverifiedHandshake = Handshake.get(sslSocketSession);
 List<Certificate> peerCertificates = unverifiedHandshake.peerCertificates();
 if (!peerCertificates.isEmpty()) {
  X509Certificate cert = (X509Certificate) peerCertificates.get(0);
  unverifiedHandshake.peerCertificates());

代码示例来源:origin: huxq17/tractor

sink.writeUtf8(handshake.cipherSuite().javaName());
sink.writeByte('\n');
writeCertList(sink, handshake.peerCertificates());
writeCertList(sink, handshake.localCertificates());

代码示例来源:origin: square/okhttp

Handshake handshake = Handshake.get(
  TlsVersion.SSL_3_0, cipherSuite, peerCertificates, localCertificates);
okResponseBuilder.handshake(handshake);

代码示例来源:origin: square/okhttp

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);
}

代码示例来源:origin: square/okhttp

@Override public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
 Handshake handshake = handshake();
 return handshake != null ? handshake.peerPrincipal() : null;
}

代码示例来源:origin: square/okhttp

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());
}

代码示例来源:origin: square/okhttp

@Override public Principal getLocalPrincipal() {
 Handshake handshake = handshake();
 return handshake != null ? handshake.localPrincipal() : null;
}

相关文章