/** * Creates a new KeyStore containing the specified root certificate and private key. * * @param keyStoreType type of the generated KeyStore, such as PKCS12 or JKS * @param certificate root certificate to add to the KeyStore * @param privateKeyAlias alias for the private key in the KeyStore * @param privateKey private key to add to the KeyStore * @param privateKeyPassword password for the private key * @param provider JCA provider to use, or null to use the system default * @return new KeyStore containing the root certificate and private key */ public static KeyStore createRootCertificateKeyStore(String keyStoreType, X509Certificate certificate, String privateKeyAlias, PrivateKey privateKey, String privateKeyPassword, String provider) { if (privateKeyPassword == null) { throw new IllegalArgumentException("Must specify a KeyStore password"); } KeyStore newKeyStore = KeyStoreUtil.createEmptyKeyStore(keyStoreType, provider); try { newKeyStore.setKeyEntry(privateKeyAlias, privateKey, privateKeyPassword.toCharArray(), new Certificate[]{certificate}); } catch (KeyStoreException e) { throw new KeyStoreAccessException("Unable to store certificate and private key in KeyStore", e); } return newKeyStore; }
@Override public KeyStore createServerKeyStore(String keyStoreType, CertificateAndKey serverCertificateAndKey, X509Certificate rootCertificate, String privateKeyAlias, String password) { if (password == null) { throw new IllegalArgumentException("KeyStore password cannot be null"); } if (privateKeyAlias == null) { throw new IllegalArgumentException("Private key alias cannot be null"); } // create a KeyStore containing the impersonated certificate's private key and a certificate chain with the // impersonated cert and our root certificate KeyStore impersonatedCertificateKeyStore = KeyStoreUtil.createEmptyKeyStore(keyStoreType, null); // create the certificate chain back for the impersonated certificate back to the root certificate Certificate[] chain = {serverCertificateAndKey.getCertificate(), rootCertificate}; try { // place the impersonated certificate and its private key in the KeyStore impersonatedCertificateKeyStore.setKeyEntry(privateKeyAlias, serverCertificateAndKey.getPrivateKey(), password.toCharArray(), chain); } catch (KeyStoreException e) { throw new KeyStoreAccessException("Error storing impersonated certificate and private key in KeyStore", e); } return impersonatedCertificateKeyStore; }
/** * Creates a new KeyStore containing the specified root certificate and private key. * * @param keyStoreType type of the generated KeyStore, such as PKCS12 or JKS * @param certificate root certificate to add to the KeyStore * @param privateKeyAlias alias for the private key in the KeyStore * @param privateKey private key to add to the KeyStore * @param privateKeyPassword password for the private key * @param provider JCA provider to use, or null to use the system default * @return new KeyStore containing the root certificate and private key */ public static KeyStore createRootCertificateKeyStore(String keyStoreType, X509Certificate certificate, String privateKeyAlias, PrivateKey privateKey, String privateKeyPassword, String provider) { if (privateKeyPassword == null) { throw new IllegalArgumentException("Must specify a KeyStore password"); } KeyStore newKeyStore = KeyStoreUtil.createEmptyKeyStore(keyStoreType, provider); try { newKeyStore.setKeyEntry(privateKeyAlias, privateKey, privateKeyPassword.toCharArray(), new Certificate[]{certificate}); } catch (KeyStoreException e) { throw new KeyStoreAccessException("Unable to store certificate and private key in KeyStore", e); } return newKeyStore; }
/** * Creates a new KeyStore containing the specified root certificate and private key. * * @param keyStoreType type of the generated KeyStore, such as PKCS12 or JKS * @param certificate root certificate to add to the KeyStore * @param privateKeyAlias alias for the private key in the KeyStore * @param privateKey private key to add to the KeyStore * @param privateKeyPassword password for the private key * @param provider JCA provider to use, or null to use the system default * @return new KeyStore containing the root certificate and private key */ public static KeyStore createRootCertificateKeyStore(String keyStoreType, X509Certificate certificate, String privateKeyAlias, PrivateKey privateKey, String privateKeyPassword, String provider) { if (privateKeyPassword == null) { throw new IllegalArgumentException("Must specify a KeyStore password"); } KeyStore newKeyStore = KeyStoreUtil.createEmptyKeyStore(keyStoreType, provider); try { newKeyStore.setKeyEntry(privateKeyAlias, privateKey, privateKeyPassword.toCharArray(), new Certificate[]{certificate}); } catch (KeyStoreException e) { throw new KeyStoreAccessException("Unable to store certificate and private key in KeyStore", e); } return newKeyStore; }
@Override public KeyStore createServerKeyStore(String keyStoreType, CertificateAndKey serverCertificateAndKey, X509Certificate rootCertificate, String privateKeyAlias, String password) { if (password == null) { throw new IllegalArgumentException("KeyStore password cannot be null"); } if (privateKeyAlias == null) { throw new IllegalArgumentException("Private key alias cannot be null"); } // create a KeyStore containing the impersonated certificate's private key and a certificate chain with the // impersonated cert and our root certificate KeyStore impersonatedCertificateKeyStore = KeyStoreUtil.createEmptyKeyStore(keyStoreType, null); // create the certificate chain back for the impersonated certificate back to the root certificate Certificate[] chain = {serverCertificateAndKey.getCertificate(), rootCertificate}; try { // place the impersonated certificate and its private key in the KeyStore impersonatedCertificateKeyStore.setKeyEntry(privateKeyAlias, serverCertificateAndKey.getPrivateKey(), password.toCharArray(), chain); } catch (KeyStoreException e) { throw new KeyStoreAccessException("Error storing impersonated certificate and private key in KeyStore", e); } return impersonatedCertificateKeyStore; }
@Override public KeyStore createServerKeyStore(String keyStoreType, CertificateAndKey serverCertificateAndKey, X509Certificate rootCertificate, String privateKeyAlias, String password) { if (password == null) { throw new IllegalArgumentException("KeyStore password cannot be null"); } if (privateKeyAlias == null) { throw new IllegalArgumentException("Private key alias cannot be null"); } // create a KeyStore containing the impersonated certificate's private key and a certificate chain with the // impersonated cert and our root certificate KeyStore impersonatedCertificateKeyStore = KeyStoreUtil.createEmptyKeyStore(keyStoreType, null); // create the certificate chain back for the impersonated certificate back to the root certificate Certificate[] chain = {serverCertificateAndKey.getCertificate(), rootCertificate}; try { // place the impersonated certificate and its private key in the KeyStore impersonatedCertificateKeyStore.setKeyEntry(privateKeyAlias, serverCertificateAndKey.getPrivateKey(), password.toCharArray(), chain); } catch (KeyStoreException e) { throw new KeyStoreAccessException("Error storing impersonated certificate and private key in KeyStore", e); } return impersonatedCertificateKeyStore; }