Skip to content

Commit

Permalink
Add security warning to TrustStrategy documentation (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcono1234 authored Oct 3, 2023
1 parent 371347a commit 0d4aeb5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ public SSLContextBuilder setSecureRandom(final SecureRandom secureRandom) {
return this;
}

/**
* @param trustStrategy
* custom trust strategy to use; can be {@code null} in which case
* only the default trust managers will be used
*/
public SSLContextBuilder loadTrustMaterial(
final KeyStore trustStore,
final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException {
Expand Down
13 changes: 13 additions & 0 deletions httpcore5/src/main/java/org/apache/hc/core5/ssl/TrustStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
* configured in the actual SSL context. This interface can be used to override the standard
* JSSE certificate verification process.
*
* <h2>Security Warning</h2>
* 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 the {@link SSLContextBuilder} {@code loadTrustMaterial}
* methods instead of implementing a custom trust strategy.
*
* <p>A trust strategy alone cannot be used for certificate pinning. When {@code isTrusted} returns
* {@code false} the certificate check falls back to the trust manager which might consider
* the certificate trusted. See the {@link #isTrusted(X509Certificate[], String)} documentation.
*
* @see SSLContextBuilder
* @since 4.4
*/
public interface TrustStrategy {
Expand Down

0 comments on commit 0d4aeb5

Please sign in to comment.