|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.net.www.protocol.https; |
|
|
|
import java.net.URL; |
|
import java.net.Proxy; |
|
import java.net.SecureCacheResponse; |
|
import java.security.Principal; |
|
import java.io.IOException; |
|
import java.util.List; |
|
import java.util.Optional; |
|
import javax.net.ssl.SSLSession; |
|
import javax.net.ssl.SSLPeerUnverifiedException; |
|
import sun.net.www.http.*; |
|
import sun.net.www.protocol.http.HttpURLConnection; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public abstract class AbstractDelegateHttpsURLConnection extends |
|
HttpURLConnection { |
|
|
|
protected AbstractDelegateHttpsURLConnection(URL url, |
|
sun.net.www.protocol.http.Handler handler) throws IOException { |
|
this(url, null, handler); |
|
} |
|
|
|
protected AbstractDelegateHttpsURLConnection(URL url, Proxy p, |
|
sun.net.www.protocol.http.Handler handler) throws IOException { |
|
super(url, p, handler); |
|
} |
|
|
|
protected abstract javax.net.ssl.SSLSocketFactory getSSLSocketFactory(); |
|
|
|
protected abstract javax.net.ssl.HostnameVerifier getHostnameVerifier(); |
|
|
|
/** |
|
* No user application is able to call these routines, as no one |
|
* should ever get access to an instance of |
|
* DelegateHttpsURLConnection (sun.* or com.*) |
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setNewClient (URL url) |
|
throws IOException { |
|
setNewClient (url, false); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setNewClient (URL url, boolean useCache) |
|
throws IOException { |
|
int readTimeout = getReadTimeout(); |
|
http = HttpsClient.New (getSSLSocketFactory(), |
|
url, |
|
getHostnameVerifier(), |
|
null, |
|
-1, |
|
useCache, |
|
getConnectTimeout(), |
|
this); |
|
http.setReadTimeout(readTimeout); |
|
((HttpsClient)http).afterConnect(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setProxiedClient (URL url, String proxyHost, int proxyPort) |
|
throws IOException { |
|
setProxiedClient(url, proxyHost, proxyPort, false); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setProxiedClient (URL url, String proxyHost, int proxyPort, |
|
boolean useCache) throws IOException { |
|
proxiedConnect(url, proxyHost, proxyPort, useCache); |
|
if (!http.isCachedConnection()) { |
|
doTunneling(); |
|
} |
|
((HttpsClient)http).afterConnect(); |
|
} |
|
|
|
protected void proxiedConnect(URL url, String proxyHost, int proxyPort, |
|
boolean useCache) throws IOException { |
|
if (connected) |
|
return; |
|
int readTimeout = getReadTimeout(); |
|
http = HttpsClient.New (getSSLSocketFactory(), |
|
url, |
|
getHostnameVerifier(), |
|
proxyHost, |
|
proxyPort, |
|
useCache, |
|
getConnectTimeout(), |
|
this); |
|
http.setReadTimeout(readTimeout); |
|
connected = true; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public boolean isConnected() { |
|
return connected; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void setConnected(boolean conn) { |
|
connected = conn; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void connect() throws IOException { |
|
if (connected) |
|
return; |
|
plainConnect(); |
|
if (cachedResponse != null) { |
|
|
|
return; |
|
} |
|
if (!http.isCachedConnection() && http.needsTunneling()) { |
|
doTunneling(); |
|
} |
|
((HttpsClient)http).afterConnect(); |
|
} |
|
|
|
|
|
protected HttpClient getNewHttpClient(URL url, Proxy p, int connectTimeout) |
|
throws IOException { |
|
return HttpsClient.New(getSSLSocketFactory(), url, |
|
getHostnameVerifier(), p, true, connectTimeout, |
|
this); |
|
} |
|
|
|
|
|
protected HttpClient getNewHttpClient(URL url, Proxy p, int connectTimeout, |
|
boolean useCache) |
|
throws IOException { |
|
return HttpsClient.New(getSSLSocketFactory(), url, |
|
getHostnameVerifier(), p, |
|
useCache, connectTimeout, this); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public String getCipherSuite () { |
|
if (cachedResponse != null) { |
|
return ((SecureCacheResponse)cachedResponse).getCipherSuite(); |
|
} |
|
if (http == null) { |
|
throw new IllegalStateException("connection not yet open"); |
|
} else { |
|
return ((HttpsClient)http).getCipherSuite (); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public java.security.cert.Certificate[] getLocalCertificates() { |
|
if (cachedResponse != null) { |
|
List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain(); |
|
if (l == null) { |
|
return null; |
|
} else { |
|
return l.toArray(new java.security.cert.Certificate[0]); |
|
} |
|
} |
|
if (http == null) { |
|
throw new IllegalStateException("connection not yet open"); |
|
} else { |
|
return (((HttpsClient)http).getLocalCertificates ()); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public java.security.cert.Certificate[] getServerCertificates() |
|
throws SSLPeerUnverifiedException { |
|
if (cachedResponse != null) { |
|
List<java.security.cert.Certificate> l = |
|
((SecureCacheResponse)cachedResponse) |
|
.getServerCertificateChain(); |
|
if (l == null) { |
|
return null; |
|
} else { |
|
return l.toArray(new java.security.cert.Certificate[0]); |
|
} |
|
} |
|
|
|
if (http == null) { |
|
throw new IllegalStateException("connection not yet open"); |
|
} else { |
|
return (((HttpsClient)http).getServerCertificates ()); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
Principal getPeerPrincipal() |
|
throws SSLPeerUnverifiedException |
|
{ |
|
if (cachedResponse != null) { |
|
return ((SecureCacheResponse)cachedResponse).getPeerPrincipal(); |
|
} |
|
|
|
if (http == null) { |
|
throw new IllegalStateException("connection not yet open"); |
|
} else { |
|
return (((HttpsClient)http).getPeerPrincipal()); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
Principal getLocalPrincipal() |
|
{ |
|
if (cachedResponse != null) { |
|
return ((SecureCacheResponse)cachedResponse).getLocalPrincipal(); |
|
} |
|
|
|
if (http == null) { |
|
throw new IllegalStateException("connection not yet open"); |
|
} else { |
|
return (((HttpsClient)http).getLocalPrincipal()); |
|
} |
|
} |
|
|
|
SSLSession getSSLSession() { |
|
if (cachedResponse != null) { |
|
Optional<SSLSession> option = |
|
((SecureCacheResponse)cachedResponse).getSSLSession(); |
|
if (option.isPresent()) { |
|
return option.orElseThrow(); |
|
} |
|
} |
|
|
|
if (http == null) { |
|
throw new IllegalStateException("connection not yet open"); |
|
} |
|
|
|
return ((HttpsClient)http).getSSLSession(); |
|
} |
|
} |