public class HostnameToCertificateChecker extends Object
By default the implementation checks the certificate's Subject Alternative Name and Common Name, following the server identity part of RFC 2818. Additionally the 'service/hostname' syntax is supported (the service prefix is simply ignored).
If there is a name mismatch the nameMismatch() method is called. User of this class must extend it and provide the application specific reaction in this method.
Note that this class should be used only on SSL connections which are authenticated with X.509 certificates.
Modifier and Type | Class and Description |
---|---|
protected static class |
HostnameToCertificateChecker.ResultWrapper |
Constructor and Description |
---|
HostnameToCertificateChecker() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkAltNameMatching(HostnameToCertificateChecker.ResultWrapper result,
String hostname,
X509Certificate certificate) |
protected boolean |
checkCNMatching(String hostname,
X509Certificate certificate) |
boolean |
checkMatching(String hostname,
X509Certificate certificate) |
String |
getMostSpecificCN(X500Principal srcP) |
static String |
makeRegexpHostWildcard(String pattern)
Converts hostname wildcard string to Java regexp, ensuring that
literal sequences are correctly escaped.
|
static boolean |
matchesDNS(String hostname,
String pattern) |
protected boolean |
matchesIP(String what,
String pattern) |
public boolean checkMatching(String hostname, X509Certificate certificate) throws CertificateParsingException, UnknownHostException
protected boolean checkAltNameMatching(HostnameToCertificateChecker.ResultWrapper result, String hostname, X509Certificate certificate) throws CertificateParsingException, UnknownHostException
result
- resulthostname
- hostnamecertificate
- certificateCertificateParsingException
- certificate parsing exceptionUnknownHostException
- unknown host exceptionprotected boolean checkCNMatching(String hostname, X509Certificate certificate)
hostname
- hostnamecertificate
- certificatepublic static String makeRegexpHostWildcard(String pattern)
pattern
- hostname wildcardprotected boolean matchesIP(String what, String pattern) throws UnknownHostException
UnknownHostException
public String getMostSpecificCN(X500Principal srcP)
Copyright © 2012-2017 European Middleware Initiative. All Rights Reserved.