@Test(expected = KeyStoreException.class) public void testLoadPrivateKeyFromTrustStore() throws IOException, GeneralSecurityException { PemReader.loadPrivateKey( x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM), Optional.empty()); }
@Test(expected = KeyStoreException.class) public void testLoadPrivateKeyFromTrustStoreWithPassword() throws IOException, GeneralSecurityException { PemReader.loadPrivateKey( x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM), Optional.of("foobar")); }
@Test public void testLoadJKSTrustStoreAutodetectStoreFileType() throws Exception { // Make sure we can instantiate a trust manager from the JKS file on disk X509TrustManager tm = X509Util.createTrustManager( x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), x509TestContext.getTrustStorePassword(), null, // null StoreFileType means 'autodetect from file extension' true, true, true, true); }
@Test public void testLoadPEMTrustStoreAutodetectStoreFileType() throws Exception { // Make sure we can instantiate a trust manager from the PEM file on disk X509TrustManager tm = X509Util.createTrustManager( x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), x509TestContext.getTrustStorePassword(), null, // null StoreFileType means 'autodetect from file extension' false, false, true, true); }
@Test(expected = X509Exception.TrustManagerException.class) public void testLoadJKSTrustStoreWithWrongPassword() throws Exception { // Attempting to load with the wrong key password should fail X509TrustManager tm = X509Util.createTrustManager( x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), "wrong password", KeyStoreFileType.JKS.getPropertyValue(), true, true, true, true); }
@Test public void testLoadCertificateFromTrustStore() throws IOException, GeneralSecurityException { List<X509Certificate> certs = PemReader.readCertificateChain( x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM)); Assert.assertEquals(1, certs.size()); Assert.assertEquals(x509TestContext.getTrustStoreCertificate(), certs.get(0)); } }
@Test public void testLoadPEMTrustStoreNullPassword() throws Exception { if (!x509TestContext.getTrustStorePassword().isEmpty()) { return; } // Make sure that empty password and null password are treated the same X509TrustManager tm = X509Util.createTrustManager( x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), null, KeyStoreFileType.PEM.getPropertyValue(), false, false, true, true); }
@Test public void testLoadJKSTrustStoreNullPassword() throws Exception { if (!x509TestContext.getTrustStorePassword().isEmpty()) { return; } // Make sure that empty password and null password are treated the same X509TrustManager tm = X509Util.createTrustManager( x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), null, KeyStoreFileType.JKS.getPropertyValue(), false, false, true, true); }
@Test public void testLoadPEMTrustStore() throws Exception { // Make sure we can instantiate a trust manager from the PEM file on disk X509TrustManager tm = X509Util.createTrustManager( x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), x509TestContext.getTrustStorePassword(), KeyStoreFileType.PEM.getPropertyValue(), false, false, true, true); }
@Test public void testLoadJKSTrustStore() throws Exception { // Make sure we can instantiate a trust manager from the JKS file on disk X509TrustManager tm = X509Util.createTrustManager( x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), x509TestContext.getTrustStorePassword(), KeyStoreFileType.JKS.getPropertyValue(), true, true, true, true); }
@Test(expected = Exception.class) public void testLoadTrustStoreWithWrongPassword() throws Exception { String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); new JKSFileLoader.Builder() .setTrustStorePath(path) .setTrustStorePassword("wrong password") .build() .loadTrustStore(); }
@Test(expected = IOException.class) public void testLoadTrustStoreWithWrongFilePath() throws Exception { String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); new PEMFileLoader.Builder() .setTrustStorePath(path + ".does_not_exist") .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); }
@Test(expected = IOException.class) public void testLoadTrustStoreWithWrongFileType() throws Exception { // Trying to load a PEM file with JKS loader should fail String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); new JKSFileLoader.Builder() .setTrustStorePath(path) .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); } }
System.setProperty( x509Util.getSslTruststoreLocationProperty(), this.getTrustStoreFile(trustStoreFileType).getAbsolutePath()); System.setProperty(x509Util.getSslTruststorePasswdProperty(), this.getTrustStorePassword()); System.setProperty(x509Util.getSslTruststoreTypeProperty(), trustStoreFileType.getPropertyValue());
@Test(expected = IOException.class) public void testLoadTrustStoreWithWrongFilePath() throws Exception { String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); new JKSFileLoader.Builder() .setTrustStorePath(path + ".does_not_exist") .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); }
@Test public void testLoadTrustStore() throws Exception { String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); KeyStore ts = new PEMFileLoader.Builder() .setTrustStorePath(path) .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); Assert.assertEquals(1, ts.size()); }
@Test public void testLoadTrustStore() throws Exception { String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); KeyStore ts = new JKSFileLoader.Builder() .setTrustStorePath(path) .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); Assert.assertEquals(1, ts.size()); }
@Test public void testLoadTrustStoreWithWrongFileType() throws Exception { // Trying to load a JKS file with PEM loader should fail String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); KeyStore ts = new PEMFileLoader.Builder() .setTrustStorePath(path) .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); Assert.assertEquals(0, ts.size()); } }