Package de.brendamour.jpasskit.util
Class CertUtils
- java.lang.Object
-
- de.brendamour.jpasskit.util.CertUtils
-
public class CertUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description CertUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Set<java.lang.String>extractApnsTopics(java.security.cert.X509Certificate certificate)Extract topics for sending push notifications fromX509Certificatecertificate.static org.apache.commons.lang3.tuple.ImmutablePair<java.security.PrivateKey,java.security.cert.X509Certificate>extractCertificateWithKey(java.security.KeyStore keyStore, char[] keyStorePassword)Extract a pair of key and certificate from an already loadedKeyStore.static java.lang.StringgetProviderName()static java.io.InputStreamtoInputStream(java.lang.String path)Load a keystore from an already openedInputStream.static java.security.KeyStoretoKeyStore(java.io.InputStream keyStoreInputStream, char[] keyStorePassword)Load a keystore from an already openedInputStream.static java.security.cert.X509CertificatetoX509Certificate(java.io.InputStream certificateInputStream)Load a DER Certificate from an already openedInputStream.
-
-
-
Method Detail
-
toInputStream
public static java.io.InputStream toInputStream(java.lang.String path) throws java.io.FileNotFoundExceptionLoad a keystore from an already openedInputStream. The caller is responsible for closing the resulting stream when it's no longer needed.- Parameters:
path- path of a key store or certificate.- Returns:
InputStreamloaded frompath- Throws:
java.io.FileNotFoundException- If no file exists at the givenpath.
-
toKeyStore
public static java.security.KeyStore toKeyStore(java.io.InputStream keyStoreInputStream, char[] keyStorePassword) throws java.security.cert.CertificateExceptionLoad a keystore from an already openedInputStream. The caller is responsible for closing the stream after this method completes successfully or fails.- Parameters:
keyStoreInputStream-InputStreamcontaining the signing key store.keyStorePassword- password to access the key store.- Returns:
KeyStoreloaded fromkeyPath- Throws:
java.lang.IllegalArgumentException- If eitherkeyPathis orkeyPathorkeyPasswordis empty.java.lang.IllegalStateException- IfKeyStoreloading failed.java.security.cert.CertificateException- If any of the certificates in the keystore could not be loaded.
-
toX509Certificate
public static java.security.cert.X509Certificate toX509Certificate(java.io.InputStream certificateInputStream) throws java.security.cert.CertificateExceptionLoad a DER Certificate from an already openedInputStream. The caller is responsible for closing the stream after this method completes successfully or fails.- Parameters:
certificateInputStream-InputStreamcontaining the certificate.- Returns:
X509Certificateloaded fromcertificateInputStream- Throws:
java.lang.IllegalStateException- IfX509Certificateloading failed.java.security.cert.CertificateException- IfX509Certificateis invalid or cannot be loaded.
-
extractCertificateWithKey
public static org.apache.commons.lang3.tuple.ImmutablePair<java.security.PrivateKey,java.security.cert.X509Certificate> extractCertificateWithKey(java.security.KeyStore keyStore, char[] keyStorePassword)Extract a pair of key and certificate from an already loadedKeyStore.- Parameters:
keyStore-KeyStoreinstance.keyStorePassword- password to access the key store.- Returns:
- pair of valid
PrivateKeyandX509Certificateloaded fromkeyStore - Throws:
java.lang.IllegalStateException- IfX509Certificateloading failed.
-
extractApnsTopics
public static java.util.Set<java.lang.String> extractApnsTopics(java.security.cert.X509Certificate certificate) throws java.io.IOExceptionExtract topics for sending push notifications fromX509Certificatecertificate.- Parameters:
certificate-X509Certificateinstance.- Returns:
- unique
Setof topics from a certificate - Throws:
java.io.IOException- IfX509Certificateparsing failed.
-
getProviderName
public static java.lang.String getProviderName()
-
-