|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.net.URLConnection
java.net.HttpURLConnection
javax.net.ssl.HttpsURLConnection
nl.nikhef.slcshttps.trust.HttxURLConnection
public class HttxURLConnection
This class extends a HttpsURLConnection that can use a TrustManager that not only can check the certificate chain but also the
hostname against the server certificate.
More details can be found in the package
description.
In addition it can also warn the user when his/her client certificate is
about to expire or has already expired. Communication about this is handled
by an implementation of HttxURLConnection.HttxClientCommunicator. An implementation
using just stdio is given by HttxURLConnection.StdioComm. It can be
configured using the following system properties:
true or false, whether
to warn for (almost) expired client certificates. Can also be set using
setExpire(String).
setExpireWarnTime(String).
"stdio"
or "popup", when unset, "stdio" is used. Can also
be set using setCommunicator(String).
HttxURLConnection is implemented as a delegate class
for HttpsURLConnection since that class is abstract while its
actual implementation is kept internal in the JDK API. Note that undocumented
overriding methods just call the corresponding overridden method of the
implementation, see the overridden methods for documentation.
| Nested Class Summary | |
|---|---|
static interface |
HttxURLConnection.HttxClientCommunicator
Interface for HttxURLConnection communication about client
certificate expiration. |
(package private) static class |
HttxURLConnection.StdioComm
This Implementation uses only stdio/stderr for I/O. |
| Field Summary | |
|---|---|
private static boolean |
clientExpireAcknowl
Whether a warning has been given about expiry. |
private static Date |
clientExpireDate
Expiry time of client side certificate ( null for unset),
can be set using setClientExpireDate(Date). |
private static boolean |
clientExpireWarn
Whether we want warnings, set at class initialization using the property "nl.nikhef.slcshttps.httxclientwarn" or using setExpire(String). |
private static boolean |
clientExpireWarnAcknowl
Whether a warning has been given about imminent expiry. |
private static long |
clientExpireWarnTime
Time in milliseconds before expiry to warn the user, use 0 for warning only after actual expiry, set at class initialization using the property "nl.nikhef.slcshttps.httxclientwarntime" or using setExpireWarnTime(String). |
private static HttxURLConnection.HttxClientCommunicator |
comm
The HttxURLConnection.HttxClientCommunicator used for communication about client
certificate expiry, can be set using setCommunicator(String). |
private static String |
COMMPROP
Name of property that sets the type of communicator: "nl.nikhef.slcshttps.comm", can be overridden using setCommunicator(String). |
private static String |
commString
describes the type of communicator in use, initialized using the value of property "nl.nikhef.slcshttps.comm" by setCommunicator(String). |
private static SSLSocketFactory |
defaultSSLSocketFactory
Default SSLSocketFactory, is initialized with an empty set of
KeyManager and a TrustManagerImpl. |
private static String |
EXPIREPROP
Name of property that determines whether to warn: "nl.nikhef.slcshttps.httxclientwarn", default is true, see also EXPIRETIMEPROP, can be overridden using setExpire(String). |
private static String |
EXPIRETIMEPROP
Name of property that determines when to give an 'about-to-expire' warning: "nl.nikhef.slcshttps.httxclientwarntime", value is number of seconds; when it is unspecified or invalid, 0 is assumed and only a warning upon actual expiry is given, see also EXPIREPROP, can be overridden using
setExpireWarnTime(String). |
private String |
hostName
hostname part of the URL. |
private static HostnameVerifier |
hostVerifier
Default HostnameVerifier, is initialized to a trivial one, since
all functionality is in the TrustManagerImpl. |
private HttpURLConnection |
httpImpl
Masked HttpURLConnection or HttpsURLConnection. |
private int |
portNumber
portnumber of the URL. |
private boolean |
ssl
whether this is a HTTPS or HTTP connection. |
private URL |
url
URL of the connection. |
| Fields inherited from class javax.net.ssl.HttpsURLConnection |
|---|
hostnameVerifier |
| Fields inherited from class java.net.URLConnection |
|---|
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, useCaches |
| Constructor Summary | |
|---|---|
HttxURLConnection(HttpURLConnection httpConnection)
Constructs a HttxURLConnection from given HttpURLConnection or HttpsURLConnection (a subclass of the
former). |
|
HttxURLConnection(URL url)
Constructs a HttxURLConnection to url. |
|
| Methods inherited from class java.net.URLConnection |
|---|
getDefaultRequestProperty, setDefaultRequestProperty |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private HttpURLConnection httpImpl
HttpURLConnection or HttpsURLConnection.
private static SSLSocketFactory defaultSSLSocketFactory
SSLSocketFactory, is initialized with an empty set of
KeyManager and a TrustManagerImpl.
private static boolean clientExpireWarn
setExpire(String).
private static long clientExpireWarnTime
setExpireWarnTime(String).
private static final String EXPIREPROP
EXPIRETIMEPROP, can be overridden using setExpire(String).
private static final String EXPIRETIMEPROP
EXPIREPROP, can be overridden using
setExpireWarnTime(String).
private static final String COMMPROP
setCommunicator(String).
private static Date clientExpireDate
null for unset),
can be set using setClientExpireDate(Date).
private static boolean clientExpireWarnAcknowl
private static boolean clientExpireAcknowl
private static String commString
setCommunicator(String).
private static HttxURLConnection.HttxClientCommunicator comm
HttxURLConnection.HttxClientCommunicator used for communication about client
certificate expiry, can be set using setCommunicator(String).
private static HostnameVerifier hostVerifier
HostnameVerifier, is initialized to a trivial one, since
all functionality is in the TrustManagerImpl.
private URL url
URL of the connection.
private String hostName
URL.
private int portNumber
URL.
private boolean ssl
| Constructor Detail |
|---|
public HttxURLConnection(HttpURLConnection httpConnection)
throws IOException
HttxURLConnection from given HttpURLConnection or HttpsURLConnection (a subclass of the
former). If this is a SSL connection (i.e. Https) it sets the hostname
and portnumber of the URL into the static TrustManagerImpl
fields. The preferred way is to call the static method openConnection(URL). We like to have the constructor public instead of
protected: we do not have the option to cast the object
returned by URL.openConnection() since that will be a JDK
internal implementation of e.g. HttpsURLConnection; however,
we can use the constructor to construct a new
HttxURLConnection from such an object.
httpConnection - HttpURLConnection to construct a
HttxURLConnection from.
- Throws:
IOException - in case of error, including expired client
certificate.- See Also:
openConnection(URL)
public HttxURLConnection(URL url)
throws IOException
HttxURLConnection to url.
The preferred way is to call the static method
openConnection(URL).
url - URL to open a connection to.
IOExceptionHttxURLConnection(HttpURLConnection),
openConnection(URL)| Method Detail |
|---|
public static HttxURLConnection openConnection(URL url)
throws IOException
HttxURLConnection for given
url. This is the preferred method to open the connection.
url - URL to open a connection to.
url
IOException - upon error
public void connect()
throws IOException
HttxURLConnection. Note that it is not
necessary to explicitly call URLConnection.connect(), it
will automatically connect when starting I/O to it. This method will set
(again) the hostname and portnumber of the TrustManagerImpl,
which will not happen when it is connected automatically.
connect in class URLConnectionIOException - upon errorpublic void disconnect()
HttxURLConnection, which also resets
the hostname and portnumber for the TrustManagerImpl.
disconnect in class HttpURLConnectionpublic static void setDefaultSSLSocketFactory(SSLSocketFactory sslSocketFactory)
SSLSocketFactory for
HttxURLConnection. Note that this does not set the
default SSLSocketFactory for HttpsURLConnection.
sslSocketFactory - will be set as default.getDefaultSSLSocketFactory()public static SSLSocketFactory getDefaultSSLSocketFactory()
SSLSocketFactory for
HttxURLConnection. Note that this is different from the
default SSLSocketFactory for HttpsURLConnection.
SSLSocketFactorysetDefaultSSLSocketFactory(SSLSocketFactory)public void setHostnameVerifier(HostnameVerifier hostnameVerifier)
setHostnameVerifier in class HttpsURLConnectionhostnameVerifier - ignored.getHostnameVerifier().public static void setDefaultHostnameVerifier(HostnameVerifier hostnameVerifier)
hostnameVerifier - ignored.getDefaultHostnameVerifier().public HostnameVerifier getHostnameVerifier()
HostnameVerifier for
HttxURLConnection. This is actually the same as returned by
getDefaultHostnameVerifier() since we do not implement setter
methods.
getHostnameVerifier in class HttpsURLConnectionHttxURLConnection.getDefaultHostnameVerifier().,
setHostnameVerifier(HostnameVerifier).public static HostnameVerifier getDefaultHostnameVerifier()
HostnameVerifier for
HttxURLConnection. This is actually the same as returned by
getHostnameVerifier() since we do not implement setter methods.
HttxURLConnection.getDefaultHostnameVerifier().,
setDefaultHostnameVerifier(HostnameVerifier).public static boolean checkClientExpire()
public static void setClientExpireDate(Date date)
Date of the client side certificate,
null for no certificate. This also resets the acknowledgment
flags.
date - expiry date of client certificate.getClientExpireDate()public static Date getClientExpireDate()
Date of the client side certificate,
null for no certificate.
setClientExpireDate(Date)public static void setExpire(String setString)
setString - String representation of a boolean, whether
to check and warn about expiry of client certificate. If
null or invalid, use the default true.getExpire(),
EXPIREPROPpublic static boolean getExpire()
setExpire(String),
EXPIREPROPpublic static void setExpireWarnTime(String timeString)
timeString is null or is not a
valid number (which includes negative numbers), it will be set to 0,
meaning no special 'about-to-expire' warning will be given, only a
'already-expired'.
timeString - String representation of the time in
seconds before expiry time when a warning should be given.getExpireWarnTime(),
EXPIRETIMEPROPpublic static long getExpireWarnTime()
setExpireWarnTime(String),
EXPIRETIMEPROPpublic static String setCommunicator(String commInput)
HttxURLConnection.HttxClientCommunicator based on
commInput. Valid values are:"stdio" - use stdin/stdout/stderr
"popup" - use (swing) popups
null - use default "stdio"
commInput - String describing the wished type of
communicator to be used.
String describing the actual type being used.getCommunicator()public static String getCommunicator()
HttxURLConnection.HttxClientCommunicator used for user
interaction.
setCommunicator(String)public void setSSLSocketFactory(SSLSocketFactory arg0)
setSSLSocketFactory in class HttpsURLConnection
public Certificate[] getServerCertificates()
throws SSLPeerUnverifiedException
getServerCertificates in class HttpsURLConnectionSSLPeerUnverifiedExceptionpublic SSLSocketFactory getSSLSocketFactory()
getSSLSocketFactory in class HttpsURLConnection
public Principal getPeerPrincipal()
throws SSLPeerUnverifiedException
getPeerPrincipal in class HttpsURLConnectionSSLPeerUnverifiedExceptionpublic Principal getLocalPrincipal()
getLocalPrincipal in class HttpsURLConnectionpublic Certificate[] getLocalCertificates()
getLocalCertificates in class HttpsURLConnectionpublic String getCipherSuite()
getCipherSuite in class HttpsURLConnectionpublic static void setFileNameMap(FileNameMap arg0)
URLConnection.setFileNameMap(FileNameMap).
arg0 - FileNameMapgetFileNameMap(),
URLConnection.setFileNameMap(FileNameMap)public static FileNameMap getFileNameMap()
URLConnection.getFileNameMap().
setFileNameMap(FileNameMap),
URLConnection.getFileNameMap()public static void setDefaultAllowUserInteraction(boolean arg0)
URLConnection.setDefaultAllowUserInteraction(boolean).
arg0 - booleangetDefaultAllowUserInteraction(),
URLConnection.setDefaultAllowUserInteraction(boolean)public static boolean getDefaultAllowUserInteraction()
URLConnection.getDefaultAllowUserInteraction().
setDefaultAllowUserInteraction(boolean),
URLConnection.getDefaultAllowUserInteraction()public static void setFollowRedirects(boolean arg0)
HttpURLConnection.setFollowRedirects(boolean).
arg0 - booleangetFollowRedirects(),
HttpURLConnection.setFollowRedirects(boolean)public static boolean getFollowRedirects()
HttpURLConnection.getFollowRedirects().
setFollowRedirects(boolean),
HttpURLConnection.getFollowRedirects()public static void setContentHandlerFactory(ContentHandlerFactory arg0)
URLConnection.setContentHandlerFactory(ContentHandlerFactory).
arg0 - ContentHandlerFactoryURLConnection.setContentHandlerFactory(ContentHandlerFactory)
public static String guessContentTypeFromStream(InputStream arg0)
throws IOException
URLConnection.guessContentTypeFromStream(InputStream).
arg0 - InputStream
IOExceptionURLConnection.guessContentTypeFromStream(InputStream)public static String guessContentTypeFromName(String arg0)
URLConnection.guessContentTypeFromName(String).
arg0 - String with name.
URLConnection.guessContentTypeFromName(String)public int hashCode()
hashCode in class Objectpublic boolean equals(Object arg0)
equals in class Objectpublic String toString()
toString in class URLConnectionpublic void setUseCaches(boolean arg0)
setUseCaches in class URLConnection
public void setRequestProperty(String arg0,
String arg1)
setRequestProperty in class URLConnectionpublic void setReadTimeout(int arg0)
setReadTimeout in class URLConnectionpublic void setIfModifiedSince(long arg0)
setIfModifiedSince in class URLConnectionpublic void setDoOutput(boolean arg0)
setDoOutput in class URLConnectionpublic void setDoInput(boolean arg0)
setDoInput in class URLConnectionpublic void setDefaultUseCaches(boolean arg0)
setDefaultUseCaches in class URLConnectionpublic void setConnectTimeout(int arg0)
setConnectTimeout in class URLConnectionpublic void setAllowUserInteraction(boolean arg0)
setAllowUserInteraction in class URLConnectionpublic boolean getUseCaches()
getUseCaches in class URLConnectionpublic URL getURL()
getURL in class URLConnectionpublic String getRequestProperty(String arg0)
getRequestProperty in class URLConnectionpublic Map<String,List<String>> getRequestProperties()
getRequestProperties in class URLConnectionpublic int getReadTimeout()
getReadTimeout in class URLConnection
public OutputStream getOutputStream()
throws IOException
getOutputStream in class URLConnectionIOExceptionpublic long getLastModified()
getLastModified in class URLConnection
public InputStream getInputStream()
throws IOException
getInputStream in class URLConnectionIOExceptionpublic long getIfModifiedSince()
getIfModifiedSince in class URLConnectionpublic Map<String,List<String>> getHeaderFields()
getHeaderFields in class URLConnection
public int getHeaderFieldInt(String arg0,
int arg1)
getHeaderFieldInt in class URLConnectionpublic String getHeaderField(String arg0)
getHeaderField in class URLConnectionpublic long getExpiration()
getExpiration in class URLConnectionpublic boolean getDoOutput()
getDoOutput in class URLConnectionpublic boolean getDoInput()
getDoInput in class URLConnectionpublic boolean getDefaultUseCaches()
getDefaultUseCaches in class URLConnectionpublic long getDate()
getDate in class URLConnectionpublic String getContentType()
getContentType in class URLConnectionpublic int getContentLength()
getContentLength in class URLConnectionpublic String getContentEncoding()
getContentEncoding in class URLConnection
public Object getContent(Class[] arg0)
throws IOException
getContent in class URLConnectionIOException
public Object getContent()
throws IOException
getContent in class URLConnectionIOExceptionpublic int getConnectTimeout()
getConnectTimeout in class URLConnectionpublic boolean getAllowUserInteraction()
getAllowUserInteraction in class URLConnection
public void addRequestProperty(String arg0,
String arg1)
addRequestProperty in class URLConnectionpublic boolean usingProxy()
usingProxy in class HttpURLConnection
public void setRequestMethod(String arg0)
throws ProtocolException
setRequestMethod in class HttpURLConnectionProtocolExceptionpublic void setInstanceFollowRedirects(boolean arg0)
setInstanceFollowRedirects in class HttpURLConnectionpublic void setFixedLengthStreamingMode(int arg0)
setFixedLengthStreamingMode in class HttpURLConnectionpublic void setChunkedStreamingMode(int arg0)
setChunkedStreamingMode in class HttpURLConnection
public String getResponseMessage()
throws IOException
getResponseMessage in class HttpURLConnectionIOException
public int getResponseCode()
throws IOException
getResponseCode in class HttpURLConnectionIOExceptionpublic String getRequestMethod()
getRequestMethod in class HttpURLConnection
public Permission getPermission()
throws IOException
getPermission in class HttpURLConnectionIOExceptionpublic boolean getInstanceFollowRedirects()
getInstanceFollowRedirects in class HttpURLConnectionpublic String getHeaderFieldKey(int arg0)
getHeaderFieldKey in class HttpURLConnection
public long getHeaderFieldDate(String arg0,
long arg1)
getHeaderFieldDate in class HttpURLConnectionpublic String getHeaderField(int arg0)
getHeaderField in class HttpURLConnectionpublic InputStream getErrorStream()
getErrorStream in class HttpURLConnection
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
| nl.nikhef.slcshttps | Mischa Sallé - msalle(AT)nikhef.nl |