|
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.LocalTrustManager
public class LocalTrustManager
A none-default TrustManager
, which validates client and server
certificates against its own list of certificates (TrustAnchor
s).
Also it validates forward with the shortest possible path, i.e. if a certifcate in the chain to check matches a trusted certificate, only the path from the beginning of the chain 'til the certificate found gets validated.
To avoid the manipulation of this TrustManager, one should not allow "foreign"
packages to add/remove certificates. So it is recommended to overwrite
addCerts(Collection)
, removeCerts(Collection)
and
by calling its super method and make them final.
It handles X.509 certificates, only.
CertPathValidator
,
CertPathBuilder
,
InvalidCertHandler
,
JxInvalidCertHandler
Constructor Summary | |
---|---|
LocalTrustManager()
Create a new TrustManager with an empty list of trusted certificates. |
|
LocalTrustManager(InvalidCertHandler handler)
Create a new TrustManager with an empty list of trusted certificates. |
|
LocalTrustManager(String caCertBundlePath)
Create a new TrustManager and add all X.509 certificates from the given CA cert bundle to the internal certificate list. |
|
LocalTrustManager(String caCertBundlePath,
InvalidCertHandler handler)
Create a new TrustManager and add all X.509 certificates from the given CA cert bundle to the internal certificate list. |
Method Summary | |
---|---|
protected void |
addCertBundle(String caCertBundlePath)
Add all X.509 certificates from the given CA cert bundle to the internal certificate list. |
protected void |
addCerts(Collection<Certificate> certs)
Add the given certificate to the internal certificate list. |
protected void |
addOtherCerts(Collection<Certificate> certs)
Add the given certificate to the internal other certificate list. |
void |
checkClientTrusted(X509Certificate[] chain,
String authType)
|
void |
checkServerTrusted(X509Certificate[] chain,
String authType)
|
ArrayList<Certificate> |
checkTrusted(X509Certificate[] chain)
Same as check*Trusted(...) , but returns the chain, which has been
validate and the the certificate of the trusted anchor for this chain
at the end of the list (which might be null if an unexpected
error occured) |
X509Certificate[] |
getAcceptedIssuers()
|
static X509TrustManager |
getInstance()
Get the JVM singleton instance, which handles local certs. |
X509Certificate[] |
getOtherCerts()
Get the internal list of other certificates. |
protected void |
removeCerts(Collection<Certificate> certs)
Remove the given certificates from the internal TrustAnchor
certificate list. |
protected void |
removeOtherCerts(Collection<Certificate> certs)
Remove the given certificates from the internal other certificate list. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LocalTrustManager()
public LocalTrustManager(InvalidCertHandler handler)
handler
- handler to use if validation of a certificate path fails.addCertBundle(String)
public LocalTrustManager(String caCertBundlePath) throws IOException, CertificateException
caCertBundlePath
- the resource path name of the CA certificate
bundle to load. All none-X.509 certificates are ignored.
IOException
- if the resource can not be found or a read error
occures when reading the resource stream.
CertificateException
- if no Provider can be found, which supports
X.509 certificates.addCertBundle(String)
public LocalTrustManager(String caCertBundlePath, InvalidCertHandler handler) throws IOException, CertificateException
caCertBundlePath
- the resource path name of the CA certificate
bundle to load. All none-X.509 certificates are ignored.handler
- handler to use if validation of a certificate path fails.
IOException
- if the resource can not be found or a read error
occures when reading the resource stream.
CertificateException
- if no Provider can be found, which supports
X.509 certificates.addCertBundle(String)
Method Detail |
---|
public static X509TrustManager getInstance()
protected void addCertBundle(String caCertBundlePath) throws IOException, CertificateException
TrustAnchor
s.
The bundle is expected to be a concatenation of Base64 DER encoded (aka
PEM encoded) X.509 certificates, i.e. each certificate is enclosed
between a "-----BEGIN CERTIFICATE-----" and a "-----END CERTIFICATE-----"
line. See also openssl x509 -in file -inform PEM -text
. The file
itself is US-ASCII
formated.
caCertBundlePath
- the resource path name of the CA certificate
bundle to load. All none-X.509 certificates are ignored.
IOException
- if the resource can not be found or a read error
occures when reading the resource stream.
CertificateException
- if no Provider can be found, which supports
X.509 certificates.addCerts(Collection)
,
CertificateFactory.generateCertificate(InputStream)
protected void addCerts(Collection<Certificate> certs)
TrustAnchor
s.
certs
- a list of X.509 certificates to add. Every certificate added
to this instance gets removed from this list. So on return it contains
not accepted certificates, only.removeCerts(Collection)
protected void addOtherCerts(Collection<Certificate> certs)
TrustAnchor
s, but as helper
to establish a cert path.
certs
- a list of X.509 certificates to add. Every certificate added
to this instance gets removed from this list. So on return it contains
not accepted certificates, only.removeOtherCerts(Collection)
protected void removeCerts(Collection<Certificate> certs)
TrustAnchor
certificate list.
certs
- X.509 certificate to remove. Every certificate removed
from this instance gets removed from this list. So on return it contains
unremoved certificates (i.e. which have not been in this internal list),
only.addCerts(Collection)
,
addCertBundle(String)
protected void removeOtherCerts(Collection<Certificate> certs)
certs
- X.509 certificate to remove. Every certificate removed
from this instance gets removed from this list. So on return it contains
unremoved certificates (i.e. which have not been in this internal list),
only.addOtherCerts(Collection)
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException
checkClientTrusted
in interface X509TrustManager
CertificateException
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException
checkServerTrusted
in interface X509TrustManager
CertificateException
public ArrayList<Certificate> checkTrusted(X509Certificate[] chain) throws CertificateException
check*Trusted(...)
, but returns the chain, which has been
validate and the the certificate of the trusted anchor for this chain
at the end of the list (which might be null
if an unexpected
error occured)
chain
- chain of certificates to validate
CertificateException
public X509Certificate[] getAcceptedIssuers()
getAcceptedIssuers
in interface X509TrustManager
public X509Certificate[] getOtherCerts()
|
ehsbe CommonsTM Version 1.1.0rc3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |