java.lang.Object
java.lang.Record
de.cuioss.http.client.handler.SecureSSLContextProvider
- Record Components:
minimumTlsVersion- The minimum TLS version that is considered secure for this instance.
Provider for secure SSL contexts used in HTTPS communications.
This class enforces secure TLS versions when establishing connections to JWKS endpoints and other services. It ensures that only modern, secure TLS protocols are used:
- TLS 1.2 - Minimum recommended version
- TLS 1.3 - Preferred when available
The class prevents the use of insecure, deprecated protocols:
- TLS 1.0 - Deprecated due to security vulnerabilities
- TLS 1.1 - Deprecated due to security vulnerabilities
- SSL 3.0 - Deprecated due to security vulnerabilities (POODLE attack)
For more details on the security aspects, see the Security Specification
- Since:
- 1.0
- Author:
- Oliver Wolff
-
Field Summary
FieldsModifier and TypeFieldDescriptionSet of allowed (secure) TLS versionsstatic final StringDefault secure TLS version to use when creating a new contextSet of forbidden (insecure) TLS versionsstatic final StringSSL version 3 - Insecure, deprecatedstatic final StringGeneric TLS - Secure if implemented correctly by the JVMstatic final StringTLS version 1.0 - Insecure, deprecatedstatic final StringTLS version 1.1 - Insecure, deprecatedstatic final StringTLS version 1.2 - Securestatic final StringTLS version 1.3 - Secure -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new SecureSSLContextProvider instance with the default minimum TLS version (TLS 1.2).SecureSSLContextProvider(String minimumTlsVersion) Creates a new SecureSSLContextProvider instance with the specified minimum TLS version. -
Method Summary
Modifier and TypeMethodDescriptionCreates a secure SSLContext configured with the minimum TLS version set for this instance.final booleanIndicates whether some other object is "equal to" this one.getOrCreateSecureSSLContext(@Nullable SSLContext sslContext) Validates the provided SSLContext and returns a secure SSLContext.final inthashCode()Returns a hash code value for this object.booleanisSecureTlsVersion(@Nullable String protocol) Checks if the given protocol is a secure TLS version according to the minimum version set for this instance.Returns the value of theminimumTlsVersionrecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
TLS_V1_2
TLS version 1.2 - Secure- See Also:
-
TLS_V1_3
TLS version 1.3 - Secure- See Also:
-
TLS
Generic TLS - Secure if implemented correctly by the JVM- See Also:
-
DEFAULT_TLS_VERSION
Default secure TLS version to use when creating a new context- See Also:
-
TLS_V1_0
TLS version 1.0 - Insecure, deprecated- See Also:
-
TLS_V1_1
TLS version 1.1 - Insecure, deprecated- See Also:
-
SSL_V3
SSL version 3 - Insecure, deprecated- See Also:
-
ALLOWED_TLS_VERSIONS
Set of allowed (secure) TLS versions -
FORBIDDEN_TLS_VERSIONS
Set of forbidden (insecure) TLS versions
-
-
Constructor Details
-
SecureSSLContextProvider
public SecureSSLContextProvider()Creates a new SecureSSLContextProvider instance with the default minimum TLS version (TLS 1.2). -
SecureSSLContextProvider
Creates a new SecureSSLContextProvider instance with the specified minimum TLS version.- Parameters:
minimumTlsVersion- the minimum TLS version to consider secure- Throws:
IllegalArgumentException- if the specified version is not in the allowed set
-
-
Method Details
-
isSecureTlsVersion
Checks if the given protocol is a secure TLS version according to the minimum version set for this instance.For TLS_V1_2 and TLS_V1_3, the comparison is based on the version number. For TLS (generic), it's considered secure if it's in the allowed versions set.
- Parameters:
protocol- the protocol to check- Returns:
- true if the protocol is a secure TLS version, false otherwise
-
createSecureSSLContext
public SSLContext createSecureSSLContext() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementExceptionCreates a secure SSLContext configured with the minimum TLS version set for this instance.This method:
- Creates an SSLContext instance with the secure protocol version
- Initializes a TrustManagerFactory with the default algorithm
- Configures the TrustManagerFactory to use the default trust store
- Initializes the SSLContext with the trust managers and a secure random source
The resulting SSLContext is configured to trust the certificates in the JVM's default trust store and does not perform client authentication (no KeyManager is provided).
- Returns:
- a configured SSLContext that uses a secure TLS protocol version
- Throws:
NoSuchAlgorithmException- if the specified protocol or trust manager algorithm is not availableKeyStoreException- if there's an issue accessing the default trust storeKeyManagementException- if there's an issue initializing the SSLContext
-
getOrCreateSecureSSLContext
Validates the provided SSLContext and returns a secure SSLContext.This method:
- If the provided SSLContext is null, creates a new secure SSLContext
- If the provided SSLContext is not null, checks if its protocol is secure
- If the protocol is secure, returns the provided SSLContext
- If the protocol is not secure, creates a new secure SSLContext
- If an exception occurs during validation or creation, falls back to the provided SSLContext or the default SSLContext
- Parameters:
sslContext- the SSLContext to validate, may be null- Returns:
- a secure SSLContext, either the validated input or a newly created one (never null)
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
minimumTlsVersion
Returns the value of theminimumTlsVersionrecord component.- Returns:
- the value of the
minimumTlsVersionrecord component
-