@Test public void testLoadPrivateKeyFromKeyStore() throws IOException, GeneralSecurityException { Optional<String> optPassword = x509TestContext.getKeyStorePassword().length() > 0 ? Optional.of(x509TestContext.getKeyStorePassword()) : Optional.empty(); PrivateKey privateKey = PemReader.loadPrivateKey( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM), optPassword); Assert.assertEquals(x509TestContext.getKeyStoreKeyPair().getPrivate(), privateKey); }
@Test public void testLoadPEMKeyStoreAutodetectStoreFileType() throws Exception { // Make sure we can instantiate a key manager from the PEM file on disk X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), x509TestContext.getKeyStorePassword(), null /* null StoreFileType means 'autodetect from file extension' */); }
@Test public void testLoadJKSKeyStoreAutodetectStoreFileType() throws Exception { // Make sure we can instantiate a key manager from the JKS file on disk X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), x509TestContext.getKeyStorePassword(), null /* null StoreFileType means 'autodetect from file extension' */); }
@Test public void testLoadPEMKeyStoreNullPassword() throws Exception { if (!x509TestContext.getKeyStorePassword().isEmpty()) { return; } // Make sure that empty password and null password are treated the same X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), null, KeyStoreFileType.PEM.getPropertyValue()); }
@Test public void testLoadJKSKeyStoreNullPassword() throws Exception { if (!x509TestContext.getKeyStorePassword().isEmpty()) { return; } // Make sure that empty password and null password are treated the same X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), null, KeyStoreFileType.JKS.getPropertyValue()); }
@Test public void testLoadPEMKeyStore() throws Exception { // Make sure we can instantiate a key manager from the PEM file on disk X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), x509TestContext.getKeyStorePassword(), KeyStoreFileType.PEM.getPropertyValue()); }
@Test public void testLoadJKSKeyStore() throws Exception { // Make sure we can instantiate a key manager from the JKS file on disk X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), x509TestContext.getKeyStorePassword(), KeyStoreFileType.JKS.getPropertyValue()); }
x509Util.getSslKeystoreLocationProperty(), this.getKeyStoreFile(keyStoreFileType).getAbsolutePath()); System.setProperty(x509Util.getSslKeystorePasswdProperty(), this.getKeyStorePassword()); System.setProperty(x509Util.getSslKeystoreTypeProperty(), keyStoreFileType.getPropertyValue()); System.setProperty(
@Test(expected = NullPointerException.class) public void testLoadKeyStoreWithNullFilePath() throws Exception { new JKSFileLoader.Builder() .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test(expected = IOException.class) public void testLoadKeyStoreWithWrongFileType() throws Exception { // Trying to load a PEM file with JKS loader should fail String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); new JKSFileLoader.Builder() .setKeyStorePath(path) .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test(expected = KeyStoreException.class) public void testLoadKeyStoreWithWrongFileType() throws Exception { // Trying to load a JKS file with PEM loader should fail String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); new PEMFileLoader.Builder() .setKeyStorePath(path) .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test(expected = IOException.class) public void testLoadKeyStoreWithWrongFilePath() throws Exception { String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); new JKSFileLoader.Builder() .setKeyStorePath(path + ".does_not_exist") .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test(expected = IOException.class) public void testLoadKeyStoreWithWrongFilePath() throws Exception { String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); new PEMFileLoader.Builder() .setKeyStorePath(path + ".does_not_exist") .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test(expected = NullPointerException.class) public void testLoadKeyStoreWithNullFilePath() throws Exception { new PEMFileLoader.Builder() .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test public void testLoadKeyStore() throws Exception { String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); KeyStore ks = new PEMFileLoader.Builder() .setKeyStorePath(path) .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); Assert.assertEquals(1, ks.size()); }
@Test public void testLoadKeyStore() throws Exception { String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); KeyStore ks = new JKSFileLoader.Builder() .setKeyStorePath(path) .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); Assert.assertEquals(1, ks.size()); }