Package org.apache.hc.core5.ssl
Interface TrustStrategy
public interface TrustStrategy
A strategy to establish trustworthiness of certificates without consulting the trust manager
configured in the actual SSL context. This interface can be used to override the standard
JSSE certificate verification process.
Security Warning
If a trust strategy considers a certificate chain to be trusted, then the default trust manager will not be consulted. Trust strategy implementations should therefore consider properly checking the complete certificate chain. Checking for example only the subject of a certificate does not protect against man-in-the-middle attacks. For self-signed certificates prefer specifying a keystore containing the certificate chain when calling theSSLContextBuilder
loadTrustMaterial
methods instead of implementing a custom trust strategy.
A trust strategy alone cannot be used for certificate pinning. When isTrusted
returns
false
the certificate check falls back to the trust manager which might consider
the certificate trusted. See the isTrusted(X509Certificate[], String)
documentation.
- Since:
- 4.4
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionboolean
isTrusted
(X509Certificate[] chain, String authType) Determines whether the certificate chain can be trusted without consulting the trust manager configured in the actual SSL context.
-
Method Details
-
isTrusted
Determines whether the certificate chain can be trusted without consulting the trust manager configured in the actual SSL context. This method can be used to override the standard JSSE certificate verification process.Please note that, if this method returns
false
, the trust manager configured in the actual SSL context can still clear the certificate as trusted.- Parameters:
chain
- the peer certificate chainauthType
- the authentication type based on the client certificate- Returns:
true
if the certificate can be trusted without verification by the trust manager,false
otherwise.- Throws:
CertificateException
- thrown if the certificate is not trusted or invalid.
-