public class DefaultTrustManager extends Object implements X509TrustManager
In sample below secure context is initialized before creating HTTPS connection. It uses default trust manager to accept server certificate.
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(new KeyManager[0], new TrustManager[]
{
new DefaultTrustManager()
}, new SecureRandom());
SSLContext.setDefault(sslContext);
...
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
Warning: use default trust manager only URL is from safe source, perhaps hard coded, and target server is
safe.| Constructor and Description |
|---|
DefaultTrustManager() |
| Modifier and Type | Method and Description |
|---|---|
void |
checkClientTrusted(X509Certificate[] chain,
String authType)
Given the partial or complete certificate chain provided by the peer, build a certificate path to a trusted root
and return if it can be validated and is trusted for client SSL authentication based on the authentication type.
|
void |
checkServerTrusted(X509Certificate[] chain,
String authType)
Given the partial or complete certificate chain provided by the peer, build a certificate path to a trusted root
and return if it can be validated and is trusted for server SSL authentication based on the authentication type.
|
X509Certificate[] |
getAcceptedIssuers()
Return an array of certificate authority certificates which are trusted for authenticating peers.
|
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException
checkClientTrusted in interface X509TrustManagerchain - the peer certificate chainauthType - the authentication type based on the client certificateIllegalArgumentException - if null or zero-length chain is passed in for the chain parameter or if null or
zero-length string is passed in for the authType parameter.CertificateException - if the certificate chain is not trusted by this TrustManager.public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException
checkServerTrusted in interface X509TrustManagerchain - the peer certificate chainauthType - the authentication type based on the client certificateIllegalArgumentException - if null or zero-length chain is passed in for the chain parameter or if null or
zero-length string is passed in for the authType parameter.CertificateException - if the certificate chain is not trusted by this TrustManager.public X509Certificate[] getAcceptedIssuers()
getAcceptedIssuers in interface X509TrustManagerCopyright © 2018. All rights reserved.