# Class CMKeyStores

java.lang.Object
com.io7m.canonmill.core.CMKeyStores

public final class CMKeyStores extends Object
Convenience methods for keystores.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static KeyStore`
  `createKeyStore()`
  Create a new keystore using the `canonmill` provider.
  `static KeyStore`
  `createKeyStore(CMKeyStoreProvider provider)`
  Create a new keystore using the `canonmill provider`.
  `static SSLContext`
  `createSSLContext(KeyStore keyStore, KeyStore trustStore, String protocol)`
  Create an SSL context using the given keystore and truststore.
  `static SSLContext`
  `createSSLContext(KeyStore keyStore, KeyStore trustStore, String protocol, SecureRandom random)`
  Create an SSL context using the given keystore and truststore.
  `static KeyStore`
  `openKeyStore(Path file)`
  Open a `canonmill` keystore from the given file.
  `static KeyStore`
  `openKeyStore(Path file, CMKeyStoreProvider provider)`
  Open a `canonmill` keystore from the given file.
  `static void`
  `reloadKeystoreFromFile(KeyStore keyStore, Path file)`
  Reload the given keystore from the given file.
  `static void`
  `reloadSSLContext(KeyStore keyStore, KeyStore trustStore, SSLContext context)`
  Reload the given SSL context's key manager and trust manager.
  `static void`
  `reloadSSLContext(KeyStore keyStore, KeyStore trustStore, SSLContext context, SecureRandom random)`
  Reload the given SSL context's key manager and trust manager.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### createKeyStore

    public static KeyStore createKeyStore() throws KeyStoreException, NoSuchProviderException
    Create a new keystore using the `canonmill` provider.
    Returns:
      A new keystore
    Throws:
      `KeyStoreException` - On errors
      `NoSuchProviderException` - If the `canonmill` provider is not loaded.

  - ### createKeyStore

    public static KeyStore createKeyStore(CMKeyStoreProvider provider) throws KeyStoreException
    Create a new keystore using the `canonmill provider`.
    Parameters:
      `provider` - A specific provider instance
    Returns:
      A new keystore
    Throws:
      `KeyStoreException` - On errors

  - ### reloadKeystoreFromFile

    public static void reloadKeystoreFromFile(KeyStore keyStore, Path file) throws CertificateException, IOException, NoSuchAlgorithmException
    Reload the given keystore from the given file.
    Parameters:
      `keyStore` - The keystore
      `file` - The file
    Throws:
      `CertificateException` - On certificate errors
      `IOException` - On I/O errors
      `NoSuchAlgorithmException` - On unsupported algorithms

  - ### createSSLContext

    public static SSLContext createSSLContext(KeyStore keyStore, KeyStore trustStore, String protocol) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException
    Create an SSL context using the given keystore and truststore.
    Parameters:
      `keyStore` - The keystore
      `trustStore` - The truststore
      `protocol` - The protocol (such as "TLSv1.3")
    Returns:
      A new SSL context
    Throws:
      `NoSuchAlgorithmException` - On missing algorithms
      `KeyStoreException` - On keystore exceptions
      `UnrecoverableKeyException` - On unrecoverable keys
      `KeyManagementException` - On key management errors

  - ### createSSLContext

    public static SSLContext createSSLContext(KeyStore keyStore, KeyStore trustStore, String protocol, SecureRandom random) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException
    Create an SSL context using the given keystore and truststore.
    Parameters:
      `keyStore` - The keystore
      `trustStore` - The truststore
      `protocol` - The protocol (such as "TLSv1.3")
      `random` - A secure random instance
    Returns:
      A new SSL context
    Throws:
      `NoSuchAlgorithmException` - On missing algorithms
      `KeyStoreException` - On keystore exceptions
      `UnrecoverableKeyException` - On unrecoverable keys
      `KeyManagementException` - On key management errors

  - ### reloadSSLContext

    public static void reloadSSLContext(KeyStore keyStore, KeyStore trustStore, SSLContext context, SecureRandom random) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException
    Reload the given SSL context's key manager and trust manager. This, effectively, reloads the keys and certificates in the context.
    Parameters:
      `keyStore` - The keystore
      `trustStore` - The truststore
      `context` - The SSL context
      `random` - A secure random instance
    Throws:
      `NoSuchAlgorithmException` - On missing algorithms
      `KeyStoreException` - On keystore exceptions
      `UnrecoverableKeyException` - On unrecoverable keys
      `KeyManagementException` - On key management errors

  - ### reloadSSLContext

    public static void reloadSSLContext(KeyStore keyStore, KeyStore trustStore, SSLContext context) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException
    Reload the given SSL context's key manager and trust manager. This, effectively, reloads the keys and certificates in the context.
    Parameters:
      `keyStore` - The keystore
      `trustStore` - The truststore
      `context` - The SSL context
    Throws:
      `NoSuchAlgorithmException` - On missing algorithms
      `KeyStoreException` - On keystore exceptions
      `UnrecoverableKeyException` - On unrecoverable keys
      `KeyManagementException` - On key management errors

  - ### openKeyStore

    public static KeyStore openKeyStore(Path file, CMKeyStoreProvider provider) throws KeyStoreException, CertificateException, IOException, NoSuchAlgorithmException
    Open a `canonmill` keystore from the given file.
    Parameters:
      `file` - The file
      `provider` - The specific provider
    Returns:
      A keystore
    Throws:
      `NoSuchAlgorithmException` - On missing algorithms
      `KeyStoreException` - On keystore exceptions
      `CertificateException` - On certificate exceptions
      `IOException` - On I/O errors

  - ### openKeyStore

    public static KeyStore openKeyStore(Path file) throws KeyStoreException, CertificateException, IOException, NoSuchAlgorithmException, NoSuchProviderException
    Open a `canonmill` keystore from the given file.
    Parameters:
      `file` - The file
    Returns:
      A keystore
    Throws:
      `NoSuchAlgorithmException` - On missing algorithms
      `KeyStoreException` - On keystore exceptions
      `CertificateException` - On certificate exceptions
      `IOException` - On I/O errors
      `NoSuchProviderException` - If the `canonmill` provider is not loaded