當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpsURLConnection.getCipherSuite方法代碼示例

本文整理匯總了Java中javax.net.ssl.HttpsURLConnection.getCipherSuite方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpsURLConnection.getCipherSuite方法的具體用法?Java HttpsURLConnection.getCipherSuite怎麽用?Java HttpsURLConnection.getCipherSuite使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.net.ssl.HttpsURLConnection的用法示例。


在下文中一共展示了HttpsURLConnection.getCipherSuite方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: secureResponseCaching

import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
@Test public void secureResponseCaching() throws IOException {
  assumeFalse(getPlatform().equals("jdk9"));

  server.useHttps(sslClient.socketFactory, false);
  server.enqueue(new MockResponse()
      .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS))
      .addHeader("Expires: " + formatDate(1, TimeUnit.HOURS))
      .setBody("ABC"));

  HttpsURLConnection c1 = (HttpsURLConnection) openConnection(server.url("/").url());
  c1.setSSLSocketFactory(sslClient.socketFactory);
  c1.setHostnameVerifier(hostnameVerifier);
  assertEquals("ABC", readAscii(c1));

  // OpenJDK 6 fails on this line, complaining that the connection isn't open yet
  String suite = c1.getCipherSuite();
  List<Certificate> localCerts = toListOrNull(c1.getLocalCertificates());
  List<Certificate> serverCerts = toListOrNull(c1.getServerCertificates());
  Principal peerPrincipal = c1.getPeerPrincipal();
  Principal localPrincipal = c1.getLocalPrincipal();

  HttpsURLConnection c2 = (HttpsURLConnection) openConnection(server.url("/").url()); // cached!
  c2.setSSLSocketFactory(sslClient.socketFactory);
  c2.setHostnameVerifier(hostnameVerifier);
  assertEquals("ABC", readAscii(c2));

  assertEquals(suite, c2.getCipherSuite());
  assertEquals(localCerts, toListOrNull(c2.getLocalCertificates()));
  assertEquals(serverCerts, toListOrNull(c2.getServerCertificates()));
  assertEquals(peerPrincipal, c2.getPeerPrincipal());
  assertEquals(localPrincipal, c2.getLocalPrincipal());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:33,代碼來源:ResponseCacheTest.java

示例2: inspectHandshakeThroughoutRequestLifecycle

import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
@Test public void inspectHandshakeThroughoutRequestLifecycle() throws Exception {
  server.useHttps(sslClient.socketFactory, false);
  server.enqueue(new MockResponse());

  urlFactory.setClient(urlFactory.client().newBuilder()
      .sslSocketFactory(sslClient.socketFactory, sslClient.trustManager)
      .hostnameVerifier(new RecordingHostnameVerifier())
      .build());

  HttpsURLConnection httpsConnection
      = (HttpsURLConnection) urlFactory.open(server.url("/foo").url());

  // Prior to calling connect(), getting the cipher suite is forbidden.
  try {
    httpsConnection.getCipherSuite();
    fail();
  } catch (IllegalStateException expected) {
  }

  // Calling connect establishes a handshake...
  httpsConnection.connect();
  assertNotNull(httpsConnection.getCipherSuite());

  // ...which remains after we read the response body...
  assertContent("", httpsConnection);
  assertNotNull(httpsConnection.getCipherSuite());

  // ...and after we disconnect.
  httpsConnection.disconnect();
  assertNotNull(httpsConnection.getCipherSuite());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:URLConnectionTest.java

示例3: secureResponseCaching

import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
@Test public void secureResponseCaching() throws IOException {
  assumeFalse(getPlatform().equals("jdk9"));

  server.useHttps(sslClient.socketFactory, false);
  server.enqueue(new MockResponse().addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS))
      .addHeader("Expires: " + formatDate(1, TimeUnit.HOURS))
      .setBody("ABC"));

  HttpsURLConnection c1 = (HttpsURLConnection) urlFactory.open(server.url("/").url());
  c1.setSSLSocketFactory(sslClient.socketFactory);
  c1.setHostnameVerifier(NULL_HOSTNAME_VERIFIER);
  assertEquals("ABC", readAscii(c1));

  // OpenJDK 6 fails on this line, complaining that the connection isn't open yet
  String suite = c1.getCipherSuite();
  List<Certificate> localCerts = toListOrNull(c1.getLocalCertificates());
  List<Certificate> serverCerts = toListOrNull(c1.getServerCertificates());
  Principal peerPrincipal = c1.getPeerPrincipal();
  Principal localPrincipal = c1.getLocalPrincipal();

  HttpsURLConnection c2 = (HttpsURLConnection) urlFactory.open(server.url("/").url()); // cached!
  c2.setSSLSocketFactory(sslClient.socketFactory);
  c2.setHostnameVerifier(NULL_HOSTNAME_VERIFIER);
  assertEquals("ABC", readAscii(c2));

  assertEquals(2, cache.requestCount());
  assertEquals(1, cache.networkCount());
  assertEquals(1, cache.hitCount());

  assertEquals(suite, c2.getCipherSuite());
  assertEquals(localCerts, toListOrNull(c2.getLocalCertificates()));
  assertEquals(serverCerts, toListOrNull(c2.getServerCertificates()));
  assertEquals(peerPrincipal, c2.getPeerPrincipal());
  assertEquals(localPrincipal, c2.getLocalPrincipal());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:36,代碼來源:UrlConnectionCacheTest.java

示例4: processResponseCertificates

import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
private void processResponseCertificates(HttpURLConnection con, Response response) throws SSLPeerUnverifiedException {
  if (con instanceof HttpsURLConnection) {
    try {
      HttpsURLConnection secureConn = (HttpsURLConnection) con;
      response.cipherSuite = secureConn.getCipherSuite();
      response.serverCertificates = secureConn.getServerCertificates();
      response.clientCertificates = secureConn.getLocalCertificates();
    } catch (IllegalStateException e) {
      // If the response is not a 200, getting response certificates will fail with the (misleading) message
      // "connection not yet open". Ignore this.
    }
  }
}
 
開發者ID:symphonyoss,項目名稱:JCurl,代碼行數:14,代碼來源:JCurl.java

示例5: createOkResponseForCachePut

import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
/**
 * Creates an OkHttp {@link Response} using the supplied {@link URI} and {@link URLConnection} to
 * supply the data. The URLConnection is assumed to already be connected. If this method returns
 * {@code null} the response is uncacheable.
 */
public static Response createOkResponseForCachePut(URI uri, URLConnection urlConnection)
    throws IOException {

  HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection;

  Response.Builder okResponseBuilder = new Response.Builder();

  // Request: Create one from the URL connection.
  Headers responseHeaders = createHeaders(urlConnection.getHeaderFields());
  // Some request headers are needed for Vary caching.
  Headers varyHeaders = varyHeaders(urlConnection, responseHeaders);
  if (varyHeaders == null) {
    return null;
  }

  // OkHttp's Call API requires a placeholder body; the real body will be streamed separately.
  String requestMethod = httpUrlConnection.getRequestMethod();
  RequestBody placeholderBody = HttpMethod.requiresRequestBody(requestMethod)
      ? Util.EMPTY_REQUEST
      : null;

  Request okRequest = new Request.Builder()
      .url(uri.toString())
      .method(requestMethod, placeholderBody)
      .headers(varyHeaders)
      .build();
  okResponseBuilder.request(okRequest);

  // Status line
  StatusLine statusLine = StatusLine.parse(extractStatusLine(httpUrlConnection));
  okResponseBuilder.protocol(statusLine.protocol);
  okResponseBuilder.code(statusLine.code);
  okResponseBuilder.message(statusLine.message);

  // A network response is required for the Cache to find any Vary headers it needs.
  Response networkResponse = okResponseBuilder.build();
  okResponseBuilder.networkResponse(networkResponse);

  // Response headers
  Headers okHeaders = extractOkResponseHeaders(httpUrlConnection, okResponseBuilder);
  okResponseBuilder.headers(okHeaders);

  // Response body
  ResponseBody okBody = createOkBody(urlConnection);
  okResponseBuilder.body(okBody);

  // Handle SSL handshake information as needed.
  if (httpUrlConnection instanceof HttpsURLConnection) {
    HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) httpUrlConnection;

    Certificate[] peerCertificates;
    try {
      peerCertificates = httpsUrlConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException e) {
      peerCertificates = null;
    }

    Certificate[] localCertificates = httpsUrlConnection.getLocalCertificates();

    String cipherSuiteString = httpsUrlConnection.getCipherSuite();
    CipherSuite cipherSuite = CipherSuite.forJavaName(cipherSuiteString);
    Handshake handshake = Handshake.get(null, cipherSuite,
        nullSafeImmutableList(peerCertificates), nullSafeImmutableList(localCertificates));
    okResponseBuilder.handshake(handshake);
  }

  return okResponseBuilder.build();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:74,代碼來源:JavaApiConverter.java

示例6: createOkResponseForCachePut

import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
/**
 * Creates an OkHttp {@link Response} using the supplied {@link URI} and {@link URLConnection} to
 * supply the data. The URLConnection is assumed to already be connected. If this method returns
 * {@code null} the response is uncacheable.
 */
public static Response createOkResponseForCachePut(URI uri, URLConnection urlConnection)
    throws IOException {

  HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection;

  Response.Builder okResponseBuilder = new Response.Builder();

  // Request: Create one from the URL connection.
  Headers responseHeaders = createHeaders(urlConnection.getHeaderFields());
  // Some request headers are needed for Vary caching.
  Headers varyHeaders = varyHeaders(urlConnection, responseHeaders);
  if (varyHeaders == null) {
    return null;
  }

  // OkHttp's Call API requires a placeholder body; the real body will be streamed separately.
  String requestMethod = httpUrlConnection.getRequestMethod();
  RequestBody placeholderBody = HttpMethod.requiresRequestBody(requestMethod)
      ? Util.EMPTY_REQUEST
      : null;

  Request okRequest = new Request.Builder()
      .url(uri.toString())
      .method(requestMethod, placeholderBody)
      .headers(varyHeaders)
      .build();
  okResponseBuilder.request(okRequest);

  // Status line
  StatusLine statusLine = StatusLine.parse(extractStatusLine(httpUrlConnection));
  okResponseBuilder.protocol(statusLine.protocol);
  okResponseBuilder.code(statusLine.code);
  okResponseBuilder.message(statusLine.message);

  // A network response is required for the Cache to find any Vary headers it needs.
  Response networkResponse = okResponseBuilder.build();
  okResponseBuilder.networkResponse(networkResponse);

  // Response headers
  Headers okHeaders = extractOkResponseHeaders(httpUrlConnection, okResponseBuilder);
  okResponseBuilder.headers(okHeaders);

  // Response body
  ResponseBody okBody = createOkBody(urlConnection);
  okResponseBuilder.body(okBody);

  // Handle SSL handshake information as needed.
  if (httpUrlConnection instanceof HttpsURLConnection) {
    HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) httpUrlConnection;

    Certificate[] peerCertificates;
    try {
      peerCertificates = httpsUrlConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException e) {
      peerCertificates = null;
    }

    Certificate[] localCertificates = httpsUrlConnection.getLocalCertificates();

    String cipherSuiteString = httpsUrlConnection.getCipherSuite();
    CipherSuite cipherSuite = CipherSuite.forJavaName(cipherSuiteString);
    Handshake handshake = Handshake.get(TlsVersion.SSL_3_0, cipherSuite,
        nullSafeImmutableList(peerCertificates), nullSafeImmutableList(localCertificates));
    okResponseBuilder.handshake(handshake);
  }

  return okResponseBuilder.build();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:74,代碼來源:JavaApiConverter.java


注:本文中的javax.net.ssl.HttpsURLConnection.getCipherSuite方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。