Class TLSTMUtil
java.lang.Object
org.snmp4j.transport.tls.TLSTMUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default connect and read timeout in milliseconds for retrieving a certificate revocation list. -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidaddCRLCertStore(String crlFilePath, PKIXBuilderParameters pkixBuilderParameters) Return the initialization parameters for a TrustManager for doing cert path validation with CRL revocation based on a CRL file.static voidClears the key store and trust store content cache used bycreateSSLContext(String, String, String, String, String, TransportStateReference, TLSTMTrustManagerFactory, boolean, TlsTmSecurityCallback, String, PKIXRevocationChecker, String).static PKIXRevocationCheckerCreates a default revocation checker with CRL check only (no OCSP) and check is limited to end entity only.static SSLContextcreateSSLContext(String protocol, String keyStore, String keyStorePassword, String trustStore, String trustStorePassword, TransportStateReference transportStateReference, TLSTMTrustManagerFactory trustManagerFactory, boolean useClientMode, TlsTmSecurityCallback<X509Certificate> securityCallback, String localCertificateAlias, PKIXRevocationChecker pkixRevocationChecker, String crlURI) static OctetStringdigest(X509Certificate cert, String algorithm) Computes the hash (message digest) of the DER encoding of the provided certificate.static OctetStringformatIpAddressForTmSecurityName(String ipAddress) Converts the textual representation of an IP address of a certificate'ssubjectAltNameiPAddressfield into thetmSecurityNamerepresentation defined by RFC 6353 for thesnmpTlstmCertSANIpAddressmapping type: an IPv4 address is represented as decimal-dotted quad address and an IPv6 address as 32 character all lowercase hexadecimal string without any colon separators.static intGets the connect and read timeout in milliseconds used to retrieve a certificate revocation list from a remote URI.static OctetStringstatic OctetStringgetFingerprint(X509Certificate cert, int hashAlgorithmID) Computes theSnmpTLSFingerprintvalue (see RFC 6353) of the provided certificate for the given hash algorithm.static StringgetHashAlgorithmName(int hashAlgorithmID) Returns theMessageDigestalgorithm name for a hash algorithm identifier of the IANA TLS HashAlgorithm registry (see RFC 5246).static OctetStringgetIpAddressFromSubjAltName(Collection<List<?>> altNames) static ObjectgetSubjAltName(Collection<List<?>> subjAltNames, int type) static booleanisMatchingFingerprint(X509Certificate[] x509Certificates, OctetString fingerprint, boolean useClientMode, CounterSupport tlstmCounters, LogAdapter logger, Object eventSource) Checks if any of the certificates in the provided array matches the given fingerprint.static booleanisMatchingFingerprint(X509Certificate cert, OctetString fingerprint) Checks whether the provided certificate matches the givenSnmpTLSFingerprintvalue (see RFC 6353).static voidsetCrlFetchTimeoutMillis(int crlFetchTimeoutMillis) Sets the connect and read timeout in milliseconds used to retrieve a certificate revocation list from a remote URI.
-
Field Details
-
DEFAULT_CRL_FETCH_TIMEOUT_MILLIS
public static final int DEFAULT_CRL_FETCH_TIMEOUT_MILLISThe default connect and read timeout in milliseconds for retrieving a certificate revocation list.- Since:
- 3.13.0
- See Also:
-
-
Method Details
-
getFingerprint
-
digest
Computes the hash (message digest) of the DER encoding of the provided certificate.- Parameters:
cert- a X.509 certificate.algorithm- theMessageDigestalgorithm name to be used, for exampleSHA-256.- Returns:
- the hash value or
nullif the digest could not be computed. - Since:
- 3.13.0
-
getHashAlgorithmName
Returns theMessageDigestalgorithm name for a hash algorithm identifier of the IANA TLS HashAlgorithm registry (see RFC 5246). Such an identifier forms the first octet of aSnmpTLSFingerprintvalue as defined by RFC 6353.- Parameters:
hashAlgorithmID- a hash algorithm identifier of the IANA TLS HashAlgorithm registry.- Returns:
- the corresponding
MessageDigestalgorithm name ornullif the identifier does not denote a hash algorithm that can be used to compute a certificate fingerprint (i.e.none(0),intrinsic(7), and unassigned or private use values). - Since:
- 3.13.0
-
getFingerprint
Computes theSnmpTLSFingerprintvalue (see RFC 6353) of the provided certificate for the given hash algorithm. The returned value is composed of the one octet hash algorithm identifier followed by the hash value of the DER encoded certificate.- Parameters:
cert- a X.509 certificate.hashAlgorithmID- a hash algorithm identifier of the IANA TLS HashAlgorithm registry (see RFC 5246), for example4for SHA-256.- Returns:
- the
SnmpTLSFingerprintvalue ofcertornullif the fingerprint could not be computed, because the hash algorithm is not supported. - Since:
- 3.13.0
-
isMatchingFingerprint
Checks whether the provided certificate matches the givenSnmpTLSFingerprintvalue (see RFC 6353). The hash algorithm to be used is taken from the first octet of the fingerprint value as defined by theSnmpTLSFingerprinttextual convention.For backwards compatibility, a fingerprint that does not contain the hash algorithm identifier octet required by RFC 6353 is matched against the hash of the certificate that is computed with the algorithm of the certificate's signature algorithm (this was the only fingerprint format supported by SNMP4J before version 3.13.0).
- Parameters:
cert- a X.509 certificate.fingerprint- aSnmpTLSFingerprintvalue.- Returns:
trueiffingerprintidentifiescert,falseotherwise. In particular,falseis returned ifcertorfingerprintisnullor iffingerprintis a zero length value, because then a matching cannot be performed.- Since:
- 3.13.0
-
isMatchingFingerprint
public static boolean isMatchingFingerprint(X509Certificate[] x509Certificates, OctetString fingerprint, boolean useClientMode, CounterSupport tlstmCounters, LogAdapter logger, Object eventSource) throws CertificateException Checks if any of the certificates in the provided array matches the given fingerprint. If the fingerprint to match isnullor zero length,falsewill be returned, because a matching cannot be performed.- Parameters:
x509Certificates- the certificates to match.fingerprint- the searched fingerprintuseClientMode- defines if server or client mode is active to emit the right counter events.tlstmCounters- the counters to increase on matchinglogger- where to logeventSource- the source object for events emitted by the matching.- Returns:
trueif there is a match,falseif matching could not be performed due tonullor zero length fingerprint- Throws:
CertificateException- if there is no matching, but fingerprint is non-null and has a length greater than zero.
-
getSubjAltName
-
getIpAddressFromSubjAltName
-
formatIpAddressForTmSecurityName
Converts the textual representation of an IP address of a certificate'ssubjectAltNameiPAddressfield into thetmSecurityNamerepresentation defined by RFC 6353 for thesnmpTlstmCertSANIpAddressmapping type: an IPv4 address is represented as decimal-dotted quad address and an IPv6 address as 32 character all lowercase hexadecimal string without any colon separators.- Parameters:
ipAddress- the textual representation of an IPv4 or IPv6 address.- Returns:
- the
tmSecurityNamerepresentation ofipAddressornullifipAddressis not a valid IP address. - Since:
- 3.13.0
-
createSSLContext
public static SSLContext createSSLContext(String protocol, String keyStore, String keyStorePassword, String trustStore, String trustStorePassword, TransportStateReference transportStateReference, TLSTMTrustManagerFactory trustManagerFactory, boolean useClientMode, TlsTmSecurityCallback<X509Certificate> securityCallback, String localCertificateAlias, PKIXRevocationChecker pkixRevocationChecker, String crlURI) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
clearKeyStoreCache
public static void clearKeyStoreCache()Clears the key store and trust store content cache used bycreateSSLContext(String, String, String, String, String, TransportStateReference, TLSTMTrustManagerFactory, boolean, TlsTmSecurityCallback, String, PKIXRevocationChecker, String). The cache detects modified files by their modification time and size; use this method to force a reload if that is not sufficient.- Since:
- 3.13.0
-
createDefaultPKIXRevocationChecker
Creates a default revocation checker with CRL check only (no OCSP) and check is limited to end entity only.- Returns:
- a simple revocation checker to be used with
TLSTM.setPKIXRevocationChecker(PKIXRevocationChecker). - Since:
- 3.6.0
-
addCRLCertStore
protected static void addCRLCertStore(String crlFilePath, PKIXBuilderParameters pkixBuilderParameters) throws GeneralSecurityException Return the initialization parameters for a TrustManager for doing cert path validation with CRL revocation based on a CRL file. Currently, only the defaultPKIXis supported.- Parameters:
crlFilePath- the path to the CRL file that provides the CRL collection for checking revocation.pkixBuilderParameters- thePKIXBuilderParametersto modify.- Throws:
GeneralSecurityException- Since:
- 3.6.0
-
getCrlFetchTimeoutMillis
public static int getCrlFetchTimeoutMillis()Gets the connect and read timeout in milliseconds used to retrieve a certificate revocation list from a remote URI.- Returns:
- the timeout in milliseconds.
- Since:
- 3.13.0
-
setCrlFetchTimeoutMillis
public static void setCrlFetchTimeoutMillis(int crlFetchTimeoutMillis) Sets the connect and read timeout in milliseconds used to retrieve a certificate revocation list from a remote URI. Without a timeout, an unresponsive CRL distribution point stalls the thread that creates the SSL context, which for DTLS is the single listen thread of the transport mapping.- Parameters:
crlFetchTimeoutMillis- the timeout in milliseconds, must be greater than zero.- Since:
- 3.13.0
-