Package org.omegazero.net.util
Class SSLUtil
java.lang.Object
org.omegazero.net.util.SSLUtil
Contains utility methods for managing SSL/TLS objects and keys/certificates.
-
Method Summary
Modifier and TypeMethodDescriptionstatic SSLServerSocketFactorygetSecureServerSocketFactory(String keyFile, String certFile) Deprecated.static ServerSocketFactoryDeprecated.static SSLContextgetSSLContextFromKeyStore(String filename, String password, String keypassword) Creates aSSLContextwith the "TLS" protocol from a Java key store stored in a file identified by filename.static SSLContextgetSSLContextFromKeyStore(String protocol, String filename, String password, String keypassword) Creates aSSLContextfrom a Java key store stored in a file identified by filename.static SSLContextgetSSLContextFromPEM(String keyFile, String certFile) Creates aSSLContextwith the "TLS" protocol from PEM-encoded key and certificate files.static SSLContextgetSSLContextFromPEM(String protocol, String keyFile, String certFile) Creates aSSLContextfrom PEM-encoded key and certificate files.static SSLEnginegetSSLEngineWithPEM(String keyFile, String certFile) Deprecated.static X509CertificateloadCertificateFromPEM(String certFile) Reads a singleX509Certificatefrom the given certFile.static X509Certificate[]loadCertificatesFromPEM(String certFile) Reads one or moreX509Certificatefrom the given certFile.static PrivateKeyloadPrivateKeyFromPEM(String keyFile) Reads aPrivateKeyfrom the given keyFile.static List<byte[]> readCertificatePEM(String data) Reads one or more encoded certificates from the given string data and returns the decoded bytes.
-
Method Details
-
getServerSocketFactory
Deprecated.Returns the default server socket factory.- Returns:
- The default server socket factory
-
getSSLContextFromKeyStore
public static SSLContext getSSLContextFromKeyStore(String filename, String password, String keypassword) throws GeneralSecurityException, IOException Creates aSSLContextwith the "TLS" protocol from a Java key store stored in a file identified by filename.- Parameters:
filename- The key store filepassword- The file passwordkeypassword- The key password- Returns:
- The
SSLContext - Throws:
GeneralSecurityException- If an SSL error occursIOException- If an IO error occurs while reading the file- See Also:
-
getSSLContextFromKeyStore
public static SSLContext getSSLContextFromKeyStore(String protocol, String filename, String password, String keypassword) throws GeneralSecurityException, IOException Creates aSSLContextfrom a Java key store stored in a file identified by filename.- Parameters:
protocol- The name of the protocol theSSLContextwill be used forfilename- The key store filepassword- The file passwordkeypassword- The key password- Returns:
- The
SSLContext - Throws:
GeneralSecurityException- If an SSL error occursIOException- If an IO error occurs while reading the file- See Also:
-
getSSLContextFromPEM
public static SSLContext getSSLContextFromPEM(String keyFile, String certFile) throws GeneralSecurityException, IOException Creates aSSLContextwith the "TLS" protocol from PEM-encoded key and certificate files.- Parameters:
keyFile- The key filecertFile- The certificate file- Returns:
- The
SSLContext - Throws:
GeneralSecurityException- If an SSL error occursIOException- If an IO error occurs while reading the file- See Also:
-
getSSLContextFromPEM
public static SSLContext getSSLContextFromPEM(String protocol, String keyFile, String certFile) throws GeneralSecurityException, IOException Creates aSSLContextfrom PEM-encoded key and certificate files.- Parameters:
protocol- The name of the protocol theSSLContextwill be used forkeyFile- The key filecertFile- The certificate file- Returns:
- The
SSLContext - Throws:
GeneralSecurityException- If an SSL error occursIOException- If an IO error occurs while reading the file- See Also:
-
getSecureServerSocketFactory
@Deprecated public static SSLServerSocketFactory getSecureServerSocketFactory(String keyFile, String certFile) throws GeneralSecurityException, IOException Deprecated.Creates aSSLServerSocketFactoryfrom PEM-encoded key and certificate files.- Parameters:
keyFile- The key filecertFile- The certificate file- Returns:
- The
SSLServerSocketFactory - Throws:
GeneralSecurityException- If an SSL error occursIOException- If an IO error occurs while reading the file
-
getSSLEngineWithPEM
@Deprecated public static SSLEngine getSSLEngineWithPEM(String keyFile, String certFile) throws GeneralSecurityException, IOException Deprecated.Creates aSSLEnginefrom PEM-encoded key and certificate files.- Parameters:
keyFile- The key filecertFile- The certificate file- Returns:
- The
SSLEngine - Throws:
GeneralSecurityException- If an SSL error occursIOException- If an IO error occurs while reading the file
-
readCertificatePEM
Reads one or more encoded certificates from the given string data and returns the decoded bytes.The given data is expected to contain one or more blocks of the following format:
-----BEGIN CERTIFICATE----- <base64-encoded certificate data> -----END CERTIFICATE------ Parameters:
data- The string data- Returns:
- The list of decoded certificate blocks
- Throws:
IOException- If the format is invalid
-
loadPrivateKeyFromPEM
public static PrivateKey loadPrivateKeyFromPEM(String keyFile) throws GeneralSecurityException, IOException Reads aPrivateKeyfrom the given keyFile.- Parameters:
keyFile- The key file- Returns:
- The
PrivateKey - Throws:
GeneralSecurityException- If an SSL error occursIOException- If an IO error occurs while reading the file- See Also:
-
loadCertificateFromPEM
public static X509Certificate loadCertificateFromPEM(String certFile) throws GeneralSecurityException, IOException Reads a singleX509Certificatefrom the given certFile.- Parameters:
certFile- The certificate file- Returns:
- The
X509Certificate - Throws:
GeneralSecurityException- If an SSL error occursIOException- If an IO error occurs while reading the file
-
loadCertificatesFromPEM
public static X509Certificate[] loadCertificatesFromPEM(String certFile) throws GeneralSecurityException, IOException Reads one or moreX509Certificatefrom the given certFile.- Parameters:
certFile- The certificate file- Returns:
- The
X509Certificates - Throws:
GeneralSecurityException- If an SSL error occursIOException- If an IO error occurs while reading the file
-
getSSLContextFromPEM(String, String)andSSLContext.getServerSocketFactory()