Class KeyStoreUtils
java.lang.Object
net.devh.boot.grpc.common.security.KeyStoreUtils
Helper class to create
KeyStore
related components.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic String
detectFormat
(String format, String name) Detects the keystore format from the given keystore file name.static KeyManagerFactory
loadKeyManagerFactory
(String keyStoreFormat, Resource keyStore, String keyStorePassword) static TrustManagerFactory
loadTrustManagerFactory
(String trustStoreFormat, Resource trustStore, String trustStorePassword)
-
Field Details
-
FORMAT_AUTODETECT
Automatically detects the keystore format. -
FORMAT_FALLBACK
The fallback keystore format to use.
-
-
Method Details
-
detectFormat
Detects the keystore format from the given keystore file name.- Parameters:
format
- The format to base the decision on.name
- The filename of the keystore.- Returns:
- The detected keystore format. If unknown defaults to the systems default.
-
loadKeyManagerFactory
public static KeyManagerFactory loadKeyManagerFactory(String keyStoreFormat, Resource keyStore, String keyStorePassword) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException - Parameters:
keyStoreFormat
- The format of the keystore.keyStore
- The resource containing the keystore.keyStorePassword
- The password for the keystore. May be empty or null.- Returns:
- The newly created KeyManagerFactory.
- Throws:
KeyStoreException
- If the keystore format isn't supported.IOException
- If there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, thecause
of theIOException
should be anUnrecoverableKeyException
NoSuchAlgorithmException
- If the algorithm used to check the integrity of the keystore cannot be foundCertificateException
- If any of the certificates in the keystore could not be loadedUnrecoverableKeyException
- If the key cannot be recovered(e.g. the given password is wrong).
-
loadTrustManagerFactory
public static TrustManagerFactory loadTrustManagerFactory(String trustStoreFormat, Resource trustStore, String trustStorePassword) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException - Parameters:
trustStoreFormat
- The format of the truststore.trustStore
- The resource containing the truststore.trustStorePassword
- The password for the truststore. May be empty or null.- Returns:
- The newly created KeyManagerFactory.
- Throws:
KeyStoreException
- If the keystore format isn't supported.IOException
- If there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, thecause
of theIOException
should be anUnrecoverableKeyException
NoSuchAlgorithmException
- If the algorithm used to check the integrity of the keystore cannot be foundCertificateException
- If any of the certificates in the keystore could not be loaded
-