Class SslContextBuilder


  • public class SslContextBuilder
    extends Object
    Helps to create an SSL context.
    • Method Detail

      • addServerCertificate

        public void addServerCertificate​(InputStream certificate)
                                  throws GeneralSecurityException
        Adds the given server certificate to the trust store.
        Parameters:
        certificate - the certificate to add.
        Throws:
        GeneralSecurityException - if the certificate could not be loaded or added.
      • addClientKey

        public void addClientKey​(byte[] privateKey,
                                 InputStream certificate,
                                 InputStream... certificationChain)
                          throws GeneralSecurityException
        Adds the given client key and the associated certificate and certification chain to the key store.
        Parameters:
        privateKey - the private key to add.
        certificate - the associated certificate.
        certificationChain - the certification chain, ordered, the root certificate at the end.
        Throws:
        GeneralSecurityException - if the certificates could not be loaded or the private key could not be added.
      • addClientKey

        public void addClientKey​(byte[] privateKey,
                                 InputStream certificate)
                          throws GeneralSecurityException
        Adds the given client key and the associated self-signed certificate.
        Parameters:
        privateKey - the private key to add.
        certificate - the associated certificate.
        Throws:
        GeneralSecurityException - if the certificates could not be loaded or the private key could not be added.
      • addClientKey

        public void addClientKey​(InputStream privateKey,
                                 InputStream certificate,
                                 InputStream... certificationChain)
                          throws IOException,
                                 GeneralSecurityException
        Adds the given client key and the associated certificate and certification chain to the key store.
        Parameters:
        privateKey - the private key to add.
        certificate - the associated certificate.
        certificationChain - the certification chain, ordered, the root certificate at the end.
        Throws:
        GeneralSecurityException - if the certificate could not be loaded or the private key could not be added.
        IOException - if the given privateKey could not be read.
      • addClientKey

        public void addClientKey​(InputStream privateKey,
                                 InputStream certificate)
                          throws IOException,
                                 GeneralSecurityException
        Adds the given client key and the associated self-signed certificate.
        Parameters:
        privateKey - the private key to add.
        certificate - the associated certificate.
        Throws:
        GeneralSecurityException - if the certificate could not be loaded or the private key could not be added.
        IOException - if the given privateKey could not be read.
      • addClientKey

        public void addClientKey​(String privateKeyPath,
                                 String certificatePath,
                                 String... certificationChainPaths)
                          throws IOException,
                                 GeneralSecurityException
        Adds the given client key and the associated certificate and certification chain to the key store. Tries to find the resource in the application's classpath (using Class.getResourceAsStream(String)).
        Parameters:
        privateKeyPath - the path to the private key to add.
        certificatePath - the path to the associated certificate.
        certificationChainPaths - the paths to the certification chain, ordered, the root certificate at the end.
        Throws:
        GeneralSecurityException - if the certificate could not be loaded or the private key could not be added.
        IOException - if the given privateKey could not be read.
      • build

        public SSLContext build​(String keyStorePassword)
                         throws GeneralSecurityException
        Creates an SSL context using the populated trust store and an the populated key store, using the given key store password.
        Parameters:
        keyStorePassword - the password of the key store.
        Returns:
        the created SSL context.
        Throws:
        GeneralSecurityException - if an exception occurred while creating the SSL context.