|
ehsbe CommonsTM Version 1.1.0rc3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ehsbe.commons.util.LocalHostnameVerifier
public class LocalHostnameVerifier
A hostname verifier, which extracts the CN name from the first certificate in
peers certificate chain and compares it against the hostname used in the SSL
session. If they do not match, all fully quallified host names for the given
SSL session hostname are computed and compared against the CN hostname. If one
matches verification ends and returns true
, otherwise false
.
HttpsURLConnection.setDefaultHostnameVerifier($LocalHostnameVerifier)
NOTE: A pre-requisit to get this verifier invoked, is that the certificate of
the given host has been accepted by the SSLSocketFactory
of the
related connection. For unknown certificates one probably wants to initialize
the default SSLFactory
with its own TrustManager
s. E.g.
TrustManager[] localTM = new TrustManager[] {
new LocalTrustManager(crtPath, new InvalidCertHandler() {
public boolean accept(X509Certificate[] chain,
CertificateException ex)
{
return true;
}
})
};
SSLContext = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new LocalHostnameVerifier());
Of course, your TrustManagers should not accept all certificates blindly!
JxHostnameVerifier
Nested Class Summary | |
---|---|
class |
LocalHostnameVerifier.VerifyResult
Result of the verify(String, SSLSession, VerifyResult)
operation wrt. to the first certificate in the peers certificate chain. |
Constructor Summary | |
---|---|
LocalHostnameVerifier()
|
Method Summary | |
---|---|
boolean |
verify(String hostname,
SSLSession session)
If URLConnection.getAllowUserInteraction() is true ,
a dialog gets displayed, which asks the user, whether to accept the
connection. |
boolean |
verify(String hostname,
SSLSession session,
LocalHostnameVerifier.VerifyResult result)
Same as verify(String, SSLSession) , but stores intermediate
results into LocalHostnameVerifier.VerifyResult for later use. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LocalHostnameVerifier()
Method Detail |
---|
public boolean verify(String hostname, SSLSession session)
URLConnection.getAllowUserInteraction()
is true
,
a dialog gets displayed, which asks the user, whether to accept the
connection.
verify
in interface HostnameVerifier
hostname
- session
-
false
, if the connection should be discarded because of
CN name and hostname mismatch or the certificate is not yet
valid/expired.public boolean verify(String hostname, SSLSession session, LocalHostnameVerifier.VerifyResult result)
verify(String, SSLSession)
, but stores intermediate
results into LocalHostnameVerifier.VerifyResult
for later use.
hostname
- SSL session hostnamesession
- SSL sessionresult
- container for storing intermediate results. Ignored if
null
.
false
, if the connection should be discarded or
URLConnection.getAllowUserInteraction()
returned false
.
|
ehsbe CommonsTM Version 1.1.0rc3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |