Package org.globus.gsi.util
Class CertificateLoadUtil
java.lang.Object
org.globus.gsi.util.CertificateLoadUtil
Contains various security-related utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionprotected static CertificateFactory
Returns appropriateCertificateFactory
.static Collection
<X509Certificate> getTrustedCertificates
(KeyStore keyStore, X509CertSelector selector) static void
init()
A no-op function that can be used to force the class to load and initialize.static X509Certificate
Loads a X509 certificate from the specified input stream.static X509Certificate
loadCertificate
(String file) Loads an X.509 certificate from the specified file.static X509Certificate[]
loadCertificates
(String file) Loads multiple X.509 certificates from the specified file.static X509CRL
loadCrl
(InputStream in) static X509CRL
static X509Certificate
readCertificate
(BufferedReader reader) Loads a X.509 certificate from the specified reader.static void
setProvider
(String providerName) Sets a provider name to use for loading certificates and for generating key pairs.
-
Method Details
-
init
public static void init()A no-op function that can be used to force the class to load and initialize. -
setProvider
Sets a provider name to use for loading certificates and for generating key pairs.- Parameters:
providerName
- provider name to use.
-
getCertificateFactory
Returns appropriateCertificateFactory
. If provider was set a provider-specificCertificateFactory
will be used. Otherwise, a defaultCertificateFactory
will be used.- Returns:
CertificateFactory
- Throws:
GeneralSecurityException
-
loadCertificate
Loads a X509 certificate from the specified input stream. Input stream must contain DER-encoded certificate.- Parameters:
in
- the input stream to read the certificate from.- Returns:
X509Certificate
the loaded certificate.- Throws:
GeneralSecurityException
- if certificate failed to load.
-
loadCertificate
public static X509Certificate loadCertificate(String file) throws IOException, GeneralSecurityException Loads an X.509 certificate from the specified file. The certificate file must be in PEM/Base64 format and start with "BEGIN CERTIFICATE" and end with "END CERTIFICATE" line.- Parameters:
file
- the file to load the certificate from.- Returns:
java.security.cert.X509Certificate
the loaded certificate.- Throws:
IOException
- if I/O error occursGeneralSecurityException
- if security problems occurs.
-
loadCertificates
public static X509Certificate[] loadCertificates(String file) throws IOException, GeneralSecurityException Loads multiple X.509 certificates from the specified file. Each certificate must be in PEM/Base64 format and start with "BEGIN CERTIFICATE" and end with "END CERTIFICATE" line.- Parameters:
file
- the certificate file to load the certificate from.- Returns:
- an array of certificates loaded from the file.
- Throws:
IOException
- if I/O error occursGeneralSecurityException
- if security problems occurs.
-
readCertificate
public static X509Certificate readCertificate(BufferedReader reader) throws IOException, GeneralSecurityException Loads a X.509 certificate from the specified reader. The certificate contents must start with "BEGIN CERTIFICATE" line and end with "END CERTIFICATE" line, and be in PEM/Base64 format.This function does not close the input stream.
- Parameters:
reader
- the stream from which load the certificate.- Returns:
- the loaded certificate or null if there was no certificate in the stream or the stream is closed.
- Throws:
IOException
- if I/O error occursGeneralSecurityException
- if security problems occurs.
-
loadCrl
- Throws:
IOException
GeneralSecurityException
-
loadCrl
- Throws:
GeneralSecurityException
-
getTrustedCertificates
public static Collection<X509Certificate> getTrustedCertificates(KeyStore keyStore, X509CertSelector selector) throws KeyStoreException - Throws:
KeyStoreException
-