Search in sources :

Example 11 with SecureCacheResponse

use of java.net.SecureCacheResponse in project robovm by robovm.

the class HttpsURLConnectionImpl method getServerCertificates.

@Override
public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException {
    SecureCacheResponse cacheResponse = delegate.getSecureCacheResponse();
    if (cacheResponse != null) {
        List<Certificate> result = cacheResponse.getServerCertificateChain();
        return result != null ? result.toArray(new Certificate[result.size()]) : null;
    }
    SSLSocket sslSocket = getSslSocket();
    if (sslSocket != null) {
        return sslSocket.getSession().getPeerCertificates();
    }
    return null;
}
Also used : SecureCacheResponse(java.net.SecureCacheResponse) SSLSocket(javax.net.ssl.SSLSocket) Certificate(java.security.cert.Certificate)

Example 12 with SecureCacheResponse

use of java.net.SecureCacheResponse in project robovm by robovm.

the class HttpsURLConnectionImpl method getPeerPrincipal.

@Override
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
    SecureCacheResponse cacheResponse = delegate.getSecureCacheResponse();
    if (cacheResponse != null) {
        return cacheResponse.getPeerPrincipal();
    }
    SSLSocket sslSocket = getSslSocket();
    if (sslSocket != null) {
        return sslSocket.getSession().getPeerPrincipal();
    }
    return null;
}
Also used : SecureCacheResponse(java.net.SecureCacheResponse) SSLSocket(javax.net.ssl.SSLSocket)

Example 13 with SecureCacheResponse

use of java.net.SecureCacheResponse in project robovm by robovm.

the class HttpsURLConnectionImpl method getCipherSuite.

@Override
public String getCipherSuite() {
    SecureCacheResponse cacheResponse = delegate.getSecureCacheResponse();
    if (cacheResponse != null) {
        return cacheResponse.getCipherSuite();
    }
    SSLSocket sslSocket = getSslSocket();
    if (sslSocket != null) {
        return sslSocket.getSession().getCipherSuite();
    }
    return null;
}
Also used : SecureCacheResponse(java.net.SecureCacheResponse) SSLSocket(javax.net.ssl.SSLSocket)

Example 14 with SecureCacheResponse

use of java.net.SecureCacheResponse in project phonegap-facebook-plugin by Wizcorp.

the class HttpsURLConnectionImpl method getPeerPrincipal.

@Override
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
    SecureCacheResponse cacheResponse = delegate.getSecureCacheResponse();
    if (cacheResponse != null) {
        return cacheResponse.getPeerPrincipal();
    }
    SSLSocket sslSocket = getSslSocket();
    if (sslSocket != null) {
        return sslSocket.getSession().getPeerPrincipal();
    }
    return null;
}
Also used : SecureCacheResponse(java.net.SecureCacheResponse) SSLSocket(javax.net.ssl.SSLSocket)

Example 15 with SecureCacheResponse

use of java.net.SecureCacheResponse in project jdk8u_jdk by JetBrains.

the class EmptyInputStream method plainConnect0.

protected void plainConnect0() throws IOException {
    // try to see if request can be served from local cache
    if (cacheHandler != null && getUseCaches()) {
        try {
            URI uri = ParseUtil.toURI(url);
            if (uri != null) {
                cachedResponse = cacheHandler.get(uri, getRequestMethod(), getUserSetHeaders().getHeaders());
                if ("https".equalsIgnoreCase(uri.getScheme()) && !(cachedResponse instanceof SecureCacheResponse)) {
                    cachedResponse = null;
                }
                if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
                    logger.finest("Cache Request for " + uri + " / " + getRequestMethod());
                    logger.finest("From cache: " + (cachedResponse != null ? cachedResponse.toString() : "null"));
                }
                if (cachedResponse != null) {
                    cachedHeaders = mapToMessageHeader(cachedResponse.getHeaders());
                    cachedInputStream = cachedResponse.getBody();
                }
            }
        } catch (IOException ioex) {
        // ignore and commence normal connection
        }
        if (cachedHeaders != null && cachedInputStream != null) {
            connected = true;
            return;
        } else {
            cachedResponse = null;
        }
    }
    try {
        if (instProxy == null) {
            // no instance Proxy is set
            /**
                 * Do we have to use a proxy?
                 */
            ProxySelector sel = java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<ProxySelector>() {

                public ProxySelector run() {
                    return ProxySelector.getDefault();
                }
            });
            if (sel != null) {
                URI uri = sun.net.www.ParseUtil.toURI(url);
                if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
                    logger.finest("ProxySelector Request for " + uri);
                }
                Iterator<Proxy> it = sel.select(uri).iterator();
                Proxy p;
                while (it.hasNext()) {
                    p = it.next();
                    try {
                        if (!failedOnce) {
                            http = getNewHttpClient(url, p, connectTimeout);
                            http.setReadTimeout(readTimeout);
                        } else {
                            // make sure to construct new connection if first
                            // attempt failed
                            http = getNewHttpClient(url, p, connectTimeout, false);
                            http.setReadTimeout(readTimeout);
                        }
                        if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
                            if (p != null) {
                                logger.finest("Proxy used: " + p.toString());
                            }
                        }
                        break;
                    } catch (IOException ioex) {
                        if (p != Proxy.NO_PROXY) {
                            sel.connectFailed(uri, p.address(), ioex);
                            if (!it.hasNext()) {
                                // fallback to direct connection
                                http = getNewHttpClient(url, null, connectTimeout, false);
                                http.setReadTimeout(readTimeout);
                                break;
                            }
                        } else {
                            throw ioex;
                        }
                        continue;
                    }
                }
            } else {
                // No proxy selector, create http client with no proxy
                if (!failedOnce) {
                    http = getNewHttpClient(url, null, connectTimeout);
                    http.setReadTimeout(readTimeout);
                } else {
                    // make sure to construct new connection if first
                    // attempt failed
                    http = getNewHttpClient(url, null, connectTimeout, false);
                    http.setReadTimeout(readTimeout);
                }
            }
        } else {
            if (!failedOnce) {
                http = getNewHttpClient(url, instProxy, connectTimeout);
                http.setReadTimeout(readTimeout);
            } else {
                // make sure to construct new connection if first
                // attempt failed
                http = getNewHttpClient(url, instProxy, connectTimeout, false);
                http.setReadTimeout(readTimeout);
            }
        }
        ps = (PrintStream) http.getOutputStream();
    } catch (IOException e) {
        throw e;
    }
    // constructor to HTTP client calls openserver
    connected = true;
}
Also used : ProxySelector(java.net.ProxySelector) Proxy(java.net.Proxy) SecureCacheResponse(java.net.SecureCacheResponse) URI(java.net.URI)

Aggregations

SecureCacheResponse (java.net.SecureCacheResponse)27 SSLSocket (javax.net.ssl.SSLSocket)15 Certificate (java.security.cert.Certificate)11 CacheResponse (java.net.CacheResponse)6 List (java.util.List)5 Request (okhttp3.Request)5 Response (okhttp3.Response)5 Handshake (okhttp3.Handshake)4 ResponseBody (okhttp3.ResponseBody)4 Test (org.junit.Test)4 Headers (okhttp3.Headers)3 URI (java.net.URI)2 JavaNetHeaders (okhttp3.internal.JavaNetHeaders)2 HttpHeaders (okhttp3.internal.http.HttpHeaders)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Proxy (java.net.Proxy)1 ProxySelector (java.net.ProxySelector)1 Principal (java.security.Principal)1 X509Certificate (java.security.cert.X509Certificate)1 LinkedHashMap (java.util.LinkedHashMap)1