Class CertificateUtils
java.lang.Object
net.solarnetwork.central.security.CertificateUtils
Certificate utilities.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringGet the canonical subject DN value of a certificate.static StringExtract the first available RFC 822 (email) value from the Subject Alternative Name estatic X509Certificate[]parsePemCertificates(Reader pemData) Parse PEM certificate data.static KeyStoreserverKeyStore(Path certificatePath, Path certificateKey, String alias) Create a new key store from TLS server settings.static PKIXCertPathValidatorResultvalidateCertificateChain(KeyStore trustStore, X509Certificate[] chain) Validate a certificate chain.static CertificateFactoryGet a certificate factory for X.509 certificates.
-
Field Details
-
RFC_822_SAN_ID
The RFC 822 Subject Alternative Name ID. -
EMAIL_ADDRESS_OID
TheemailAddressOID.- See Also:
-
X509_CERTIFICATE_TYPE
The X.509 certificate type.- See Also:
-
-
Constructor Details
-
CertificateUtils
public CertificateUtils()
-
-
Method Details
-
x509CertificateFactory
Get a certificate factory for X.509 certificates.- Returns:
- the factory
- Throws:
net.solarnetwork.service.CertificateException- if unable to instantiate the factory
-
emailSubjectAlternativeName
public static String emailSubjectAlternativeName(X509Certificate cert) throws CertificateParsingException Extract the first available RFC 822 (email) value from the Subject Alternative Name e- Parameters:
cert- the certificate to extract the email from- Returns:
- the extracted email, or null if none available
- Throws:
IllegalArgumentException- if any argument is nullCertificateParsingException- if an error parsing the subject alternative names occurs
-
canonicalSubjectDn
Get the canonical subject DN value of a certificate.- Parameters:
cert- the certificate to extract the canonical subject DN value from- Returns:
- the canonical subject DN
- Throws:
IllegalArgumentException- if any argument is null
-
parsePemCertificates
public static X509Certificate[] parsePemCertificates(Reader pemData) throws net.solarnetwork.service.CertificateException Parse PEM certificate data.- Parameters:
pemData- the PEM data to parse- Returns:
- the parsed certificates
- Throws:
net.solarnetwork.service.CertificateException- if any error occurs
-
serverKeyStore
public static KeyStore serverKeyStore(Path certificatePath, Path certificateKey, String alias) throws net.solarnetwork.service.CertificateException Create a new key store from TLS server settings.- Parameters:
certificatePath- the path to the PEM encoded certificate filecertificateKey- the path to the PEM encoded, unencrypted private keyalias- the key store alias to use for the certificate- Returns:
- the key store, or null if no settings are available
- Throws:
net.solarnetwork.service.CertificateException- if an error occurs initializing the key store
-
validateCertificateChain
public static PKIXCertPathValidatorResult validateCertificateChain(KeyStore trustStore, X509Certificate[] chain) throws net.solarnetwork.service.CertificateException Validate a certificate chain.- Parameters:
trustStore- the trust store containing all available trusted CA certificateschain- the certificate chain to validate- Returns:
- the validation result, if successful
- Throws:
net.solarnetwork.service.CertificateException- if validation fails for any reason
-