Class 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 from X509Certificate certificate.
      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 loaded KeyStore.
      static java.lang.String getProviderName()  
      static java.io.InputStream toInputStream​(java.lang.String path)
      Load a keystore from an already opened InputStream.
      static java.security.KeyStore toKeyStore​(java.io.InputStream keyStoreInputStream, char[] keyStorePassword)
      Load a keystore from an already opened InputStream.
      static java.security.cert.X509Certificate toX509Certificate​(java.io.InputStream certificateInputStream)
      Load a DER Certificate from an already opened InputStream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CertUtils

        public CertUtils()
    • Method Detail

      • toInputStream

        public static java.io.InputStream toInputStream​(java.lang.String path)
                                                 throws java.io.FileNotFoundException
        Load a keystore from an already opened InputStream. 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:
        InputStream loaded from path
        Throws:
        java.io.FileNotFoundException - If no file exists at the given path.
      • toKeyStore

        public static java.security.KeyStore toKeyStore​(java.io.InputStream keyStoreInputStream,
                                                        char[] keyStorePassword)
                                                 throws java.security.cert.CertificateException
        Load a keystore from an already opened InputStream. The caller is responsible for closing the stream after this method completes successfully or fails.
        Parameters:
        keyStoreInputStream - InputStream containing the signing key store.
        keyStorePassword - password to access the key store.
        Returns:
        KeyStore loaded from keyPath
        Throws:
        java.lang.IllegalArgumentException - If either keyPath is or keyPath or keyPassword is empty.
        java.lang.IllegalStateException - If KeyStore loading 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.CertificateException
        Load a DER Certificate from an already opened InputStream. The caller is responsible for closing the stream after this method completes successfully or fails.
        Parameters:
        certificateInputStream - InputStream containing the certificate.
        Returns:
        X509Certificate loaded from certificateInputStream
        Throws:
        java.lang.IllegalStateException - If X509Certificate loading failed.
        java.security.cert.CertificateException - If X509Certificate is 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 loaded KeyStore.
        Parameters:
        keyStore - KeyStore instance.
        keyStorePassword - password to access the key store.
        Returns:
        pair of valid PrivateKey and X509Certificate loaded from keyStore
        Throws:
        java.lang.IllegalStateException - If X509Certificate loading failed.
      • extractApnsTopics

        public static java.util.Set<java.lang.String> extractApnsTopics​(java.security.cert.X509Certificate certificate)
                                                                 throws java.io.IOException
        Extract topics for sending push notifications from X509Certificate certificate.
        Parameters:
        certificate - X509Certificate instance.
        Returns:
        unique Set of topics from a certificate
        Throws:
        java.io.IOException - If X509Certificate parsing failed.
      • getProviderName

        public static java.lang.String getProviderName()