Package com.unboundid.util.ssl
Class PromptTrustManager
java.lang.Object
com.unboundid.util.ssl.PromptTrustManager
- All Implemented Interfaces:
TrustManager,X509TrustManager
@NotMutable
@ThreadSafety(level=COMPLETELY_THREADSAFE)
public final class PromptTrustManager
extends Object
implements X509TrustManager
This class provides an SSL trust manager that will interactively prompt the
user to determine whether to trust any certificate that is presented to it.
It provides the ability to cache information about certificates that had been
previously trusted so that the user is not prompted about the same
certificate repeatedly, and it can be configured to store trusted
certificates in a file so that the trust information can be persisted.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of this prompt trust manager.PromptTrustManager(String acceptedCertsFile) Creates a new instance of this prompt trust manager.PromptTrustManager(String acceptedCertsFile, boolean examineValidityDates, InputStream in, PrintStream out) Creates a new instance of this prompt trust manager.PromptTrustManager(String acceptedCertsFile, boolean examineValidityDates, String expectedAddress, InputStream in, PrintStream out) Creates a new instance of this prompt trust manager.PromptTrustManager(String acceptedCertsFile, boolean examineValidityDates, Collection<String> expectedAddresses, InputStream in, PrintStream out) Creates a new instance of this prompt trust manager. -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckClientTrusted(X509Certificate[] chain, String authType) Checks to determine whether the provided client certificate chain should be trusted.voidcheckServerTrusted(X509Certificate[] chain, String authType) Checks to determine whether the provided server certificate chain should be trusted.booleanIndicate whether to prompt about certificates contained in the cache if the current time is outside the validity window for the certificate.Retrieves the accepted issuer certificates for this trust manager.Retrieves a list of the addresses that the client is expected to use to communicate with the server, if available.booleanwouldPrompt(X509Certificate[] chain) Indicates whether this trust manager would interactively prompt the user about whether to trust the provided certificate chain.
-
Constructor Details
-
PromptTrustManager
public PromptTrustManager()Creates a new instance of this prompt trust manager. It will cache trust information in memory but not on disk. -
PromptTrustManager
Creates a new instance of this prompt trust manager. It may optionally cache trust information on disk.- Parameters:
acceptedCertsFile- The path to a file in which the certificates that have been previously accepted will be cached. It may benullif the cache should only be maintained in memory.
-
PromptTrustManager
public PromptTrustManager(@Nullable String acceptedCertsFile, boolean examineValidityDates, @Nullable InputStream in, @Nullable PrintStream out) Creates a new instance of this prompt trust manager. It may optionally cache trust information on disk, and may also be configured to examine or ignore validity dates.- Parameters:
acceptedCertsFile- The path to a file in which the certificates that have been previously accepted will be cached. It may benullif the cache should only be maintained in memory.examineValidityDates- Indicates whether to reject certificates if the current time is outside the validity window for the certificate.in- The input stream that will be used to read input from the user. If this isnullthenSystem.inwill be used.out- The print stream that will be used to display the prompt to the user. If this isnullthen System.out will be used.
-
PromptTrustManager
public PromptTrustManager(@Nullable String acceptedCertsFile, boolean examineValidityDates, @Nullable String expectedAddress, @Nullable InputStream in, @Nullable PrintStream out) Creates a new instance of this prompt trust manager. It may optionally cache trust information on disk, and may also be configured to examine or ignore validity dates.- Parameters:
acceptedCertsFile- The path to a file in which the certificates that have been previously accepted will be cached. It may benullif the cache should only be maintained in memory.examineValidityDates- Indicates whether to reject certificates if the current time is outside the validity window for the certificate.expectedAddress- An optional address that the client is expected to use to connect to the target server. This may benullif no expected address is available, if this trust manager is only expected to be used to validate client certificates, or if no server address validation should be performed. If a non-nullvalue is provided, then the trust manager may issue a warning if the certificate does not contain that address.in- The input stream that will be used to read input from the user. If this isnullthenSystem.inwill be used.out- The print stream that will be used to display the prompt to the user. If this isnullthen System.out will be used.
-
PromptTrustManager
public PromptTrustManager(@Nullable String acceptedCertsFile, boolean examineValidityDates, @Nullable Collection<String> expectedAddresses, @Nullable InputStream in, @Nullable PrintStream out) Creates a new instance of this prompt trust manager. It may optionally cache trust information on disk, and may also be configured to examine or ignore validity dates.- Parameters:
acceptedCertsFile- The path to a file in which the certificates that have been previously accepted will be cached. It may benullif the cache should only be maintained in memory.examineValidityDates- Indicates whether to reject certificates if the current time is outside the validity window for the certificate.expectedAddresses- An optional collection of the addresses that the client is expected to use to connect to one of the target servers. This may benullor empty if no expected addresses are available, if this trust manager is only expected to be used to validate client certificates, or if no server address validation should be performed. If a non-empty collection is provided, then the trust manager may issue a warning if the certificate does not contain any of these addresses.in- The input stream that will be used to read input from the user. If this isnullthenSystem.inwill be used.out- The print stream that will be used to display the prompt to the user. If this isnullthen System.out will be used.
-
-
Method Details
-
wouldPrompt
Indicates whether this trust manager would interactively prompt the user about whether to trust the provided certificate chain.- Parameters:
chain- The chain of certificates for which to make the determination.- Returns:
trueif this trust manger would interactively prompt the user about whether to trust the certificate chain, orfalseif not (e.g., because the certificate is already known to be trusted).
-
examineValidityDates
Indicate whether to prompt about certificates contained in the cache if the current time is outside the validity window for the certificate.- Returns:
trueif the certificate validity time should be examined for cached certificates and the user should be prompted if they are expired or not yet valid, orfalseif cached certificates should be accepted even outside of the validity window.
-
getExpectedAddresses
Retrieves a list of the addresses that the client is expected to use to communicate with the server, if available.- Returns:
- A list of the addresses that the client is expected to use to communicate with the server, or an empty list if this is not available or applicable.
-
checkClientTrusted
public void checkClientTrusted(@NotNull X509Certificate[] chain, @NotNull String authType) throws CertificateException Checks to determine whether the provided client certificate chain should be trusted.- Specified by:
checkClientTrustedin interfaceX509TrustManager- Parameters:
chain- The client certificate chain for which to make the determination.authType- The authentication type based on the client certificate.- Throws:
CertificateException- If the provided client certificate chain should not be trusted.
-
checkServerTrusted
public void checkServerTrusted(@NotNull X509Certificate[] chain, @NotNull String authType) throws CertificateException Checks to determine whether the provided server certificate chain should be trusted.- Specified by:
checkServerTrustedin interfaceX509TrustManager- Parameters:
chain- The server certificate chain for which to make the determination.authType- The key exchange algorithm used.- Throws:
CertificateException- If the provided server certificate chain should not be trusted.
-
getAcceptedIssuers
Retrieves the accepted issuer certificates for this trust manager. This will always return an empty array.- Specified by:
getAcceptedIssuersin interfaceX509TrustManager- Returns:
- The accepted issuer certificates for this trust manager.
-