Java Code Examples for javax.net.ssl.HttpsURLConnection#getLocalCertificates()

The following examples show how to use javax.net.ssl.HttpsURLConnection#getLocalCertificates() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpResponseCache.java    From cordova-android-chromeview with Apache License 2.0 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  if (isHttps()) {
    HttpsURLConnection httpsConnection = (HttpsURLConnection) httpConnection;
    cipherSuite = httpsConnection.getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = httpsConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = httpsConnection.getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 2
Source File: HttpResponseCache.java    From cordova-android-chromeview with Apache License 2.0 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  if (isHttps()) {
    HttpsURLConnection httpsConnection = (HttpsURLConnection) httpConnection;
    cipherSuite = httpsConnection.getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = httpsConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = httpsConnection.getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 3
Source File: HttpResponseCache.java    From phonegap-plugin-loading-spinner with Apache License 2.0 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  if (isHttps()) {
    HttpsURLConnection httpsConnection = (HttpsURLConnection) httpConnection;
    cipherSuite = httpsConnection.getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = httpsConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = httpsConnection.getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 4
Source File: HttpResponseCache.java    From phonegap-plugin-loading-spinner with Apache License 2.0 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  if (isHttps()) {
    HttpsURLConnection httpsConnection = (HttpsURLConnection) httpConnection;
    cipherSuite = httpsConnection.getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = httpsConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = httpsConnection.getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 5
Source File: JCurl.java    From JCurl with Apache License 2.0 5 votes vote down vote up
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.
    }
  }
}
 
Example 6
Source File: HttpsURLConnectionInfo.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * This constructor is used to create the info object
 * representing the this HttpsURLConnection. Connection parameter is
 * of supertype HttpURLConnection, which allows internal cast to
 * potentially divergent subtype (Https) implementations.
 */
public HttpsURLConnectionInfo(HttpURLConnection connection)
    throws IOException {
    super(connection.getURL(), connection.getRequestMethod());
    if (connection instanceof HttpsURLConnection) {
        HttpsURLConnection conn = (HttpsURLConnection) connection;
        enabledCipherSuite = conn.getCipherSuite();
        localCertificates = conn.getLocalCertificates();
        localPrincipal = conn.getLocalPrincipal();
        serverCertificates = conn.getServerCertificates();
        peerPrincipal = conn.getPeerPrincipal();
    } else {
        Exception ex = null;
        try {
            Method method = null;
            method = connection.getClass().getMethod("getCipherSuite", (Class[]) null);
            enabledCipherSuite = (String) method.invoke(connection, (Object[]) null);
            method = connection.getClass().getMethod("getLocalCertificates", (Class[]) null);
            localCertificates = (Certificate[]) method.invoke(connection, (Object[]) null);
            method = connection.getClass().getMethod("getServerCertificates", (Class[]) null);
            serverCertificates = (Certificate[]) method.invoke(connection, (Object[]) null);

            //TODO Obtain localPrincipal and peerPrincipal using the com.sun.net.ssl api
        } catch (Exception e) {
            ex = e;
        } finally {
            if (ex != null) {
                if (ex instanceof IOException) {
                    throw (IOException) ex;
                }
                IOException ioe = new IOException("Error constructing HttpsURLConnectionInfo "
                                                  + "for connection class "
                                                  + connection.getClass().getName());
                ioe.initCause(ex);
                throw ioe;

            }
        }
    }
}