public class SSLUtil extends Object
Constructor and Description |
---|
SSLUtil() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
getCertificates(byte[] certBuf)
Extracts all the certificates from the argument, decodes them
from base64 to byte[] and concatenates all the certificates
preserving the order.
|
static SSLSocketFactory |
getSocketFactory(File pemFile)
Initialise the default SSL socket factory so that all HTTPS
connections use the provided key store to authenticate (when the
server requires client authentication).
|
static SSLSocketFactory |
getSocketFactory(File certFile,
File keyFile)
Initialise the default SSL socket factory so that all HTTPS
connections use the provided key store to authenticate (when the
server requies client authentication).
|
static SSLSocketFactory |
getSocketFactory(Subject s)
Create an SSLSocketfactory from the credentials in the specified
Subject.
|
static SSLSocketFactory |
getSocketFactory(X509CertificateChain chain) |
static void |
initSSL(File pemFile) |
static void |
initSSL(File certFile,
File keyFile)
Initialise the default SSL socket factory so that all HTTPS
connections use the provided key store to authenticate (when the
server requires client authentication).
|
static RSAPrivateCrtKeySpec |
parseKeySpec(byte[] code)
Parses a byte array and constructs the corresponding RSAPrivateCrtKeySpec.
|
static X509Certificate[] |
readCertificateChain(byte[] certBuf) |
static X509Certificate[] |
readCertificateChain(File certFile) |
static byte[] |
readFile(File f)
Read a (small) file into a byte array.
|
static X509CertificateChain |
readPemCertificateAndKey(byte[] data)
Parses PEM encoded data that contains certificates and a key and
returns the corresponding X509CertificateChain that can be used to
create an SSL socket.
|
static X509CertificateChain |
readPemCertificateAndKey(File pemFile)
Convenience method to parse a PEM encoded file and return the
corresponding X509 Certificate chain.
|
static PrivateKey |
readPrivateKey(byte[] bytesPrivateKey) |
static PrivateKey |
readPrivateKey(File keyFile) |
static void |
validateSubject(Subject subject,
Date date)
Checks whether the subject's certificate credentials are valid
at a given date.
|
public static void initSSL(File certFile, File keyFile)
certFile
- proxy certificatekeyFile
- private key file in DER formatHttpsURLConnection.setDefaultSSLSocketFactory(javax.net.ssl.SSLSocketFactory)
public static void initSSL(File pemFile)
public static SSLSocketFactory getSocketFactory(File certFile, File keyFile)
certFile
- proxy certificatekeyFile
- private key file in DER formatpublic static SSLSocketFactory getSocketFactory(File pemFile)
pemFile
- proxy certificatepublic static SSLSocketFactory getSocketFactory(Subject s)
s
- subjectpublic static SSLSocketFactory getSocketFactory(X509CertificateChain chain)
public static byte[] getCertificates(byte[] certBuf) throws IOException
certBuf
- buffer containing certificatesIOException
public static X509Certificate[] readCertificateChain(File certFile) throws CertificateException, IOException
CertificateException
IOException
public static X509Certificate[] readCertificateChain(byte[] certBuf) throws CertificateException, IOException
CertificateException
IOException
public static PrivateKey readPrivateKey(File keyFile) throws InvalidKeySpecException, NoSuchAlgorithmException, IOException
public static PrivateKey readPrivateKey(byte[] bytesPrivateKey) throws InvalidKeySpecException, NoSuchAlgorithmException, IOException
public static X509CertificateChain readPemCertificateAndKey(File pemFile) throws InvalidKeySpecException, NoSuchAlgorithmException, IOException, CertificateException
pemFile
- file containing PEM dataInvalidKeySpecException
NoSuchAlgorithmException
IOException
CertificateException
public static X509CertificateChain readPemCertificateAndKey(byte[] data) throws InvalidKeySpecException, NoSuchAlgorithmException, IOException, CertificateException
data
- content encoded as PEM.InvalidKeySpecException
NoSuchAlgorithmException
IOException
CertificateException
public static RSAPrivateCrtKeySpec parseKeySpec(byte[] code) throws IOException
code
- byte array containing the keyIOException
public static void validateSubject(Subject subject, Date date) throws CertificateException, CertificateExpiredException, CertificateNotYetValidException
subject
- Subject to checkdate
- Date the certificate is verified against. If null,
the credentials are verified against current time.CertificateException
- Subject has no associated certificate
credentials or there is a problem with the existing certificate.CertificateExpiredException
- Certificate is expired.CertificateNotYetValidException
- Certificate not valid yet.public static byte[] readFile(File f) throws IOException
f
- fileIOException
Copyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.