diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/ssl/SslContextFactory.java b/jetty-http/src/main/java/org/eclipse/jetty/http/ssl/SslContextFactory.java index 4645a199c69..bb715c00943 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/ssl/SslContextFactory.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/ssl/SslContextFactory.java @@ -1377,7 +1377,7 @@ public class SslContextFactory extends AbstractLifeCycle /** Set the trust store resource. * @param resource the trust store resource to set */ - public void setTrustStore(Resource resource) + public void setTrustStoreResource(Resource resource) { checkNotStarted(); diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/SslContextFactoryTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/SslContextFactoryTest.java index f7fce832c0e..2812cec1995 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/SslContextFactoryTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/SslContextFactoryTest.java @@ -6,6 +6,7 @@ import java.io.FileInputStream; import java.security.KeyStore; import org.eclipse.jetty.http.ssl.SslContextFactory; +import org.eclipse.jetty.util.resource.Resource; import org.junit.Test; @@ -72,4 +73,70 @@ public class SslContextFactoryTest cf.start(); assertTrue(cf.getSslContext()!=null); } + + @Test + public void testNoTsResourceKs() throws Exception + { + Resource keystoreResource = Resource.newSystemResource("keystore"); + + SslContextFactory cf = new SslContextFactory(); + cf.setKeyStoreResource(keystoreResource); + cf.setKeyStorePassword("storepwd"); + cf.setKeyManagerPassword("keypwd"); + + cf.start(); + + assertTrue(cf.getSslContext()!=null); + + } + + @Test + public void testResourceTsResourceKs() throws Exception + { + Resource keystoreResource = Resource.newSystemResource("keystore"); + Resource truststoreResource = Resource.newSystemResource("keystore"); + + SslContextFactory cf = new SslContextFactory(); + cf.setKeyStoreResource(keystoreResource); + cf.setTrustStoreResource(truststoreResource); + cf.setKeyStorePassword("storepwd"); + cf.setKeyManagerPassword("keypwd"); + cf.setTrustStorePassword("storepwd"); + + cf.start(); + + assertTrue(cf.getSslContext()!=null); + } + + @Test(expected = java.security.UnrecoverableKeyException.class) + public void testResourceTsResourceKsWrongPW() throws Exception + { + Resource keystoreResource = Resource.newSystemResource("keystore"); + Resource truststoreResource = Resource.newSystemResource("keystore"); + + SslContextFactory cf = new SslContextFactory(); + cf.setKeyStoreResource(keystoreResource); + cf.setTrustStoreResource(truststoreResource); + cf.setKeyStorePassword("storepwd"); + cf.setKeyManagerPassword("wrong_keypwd"); + cf.setTrustStorePassword("storepwd"); + + cf.start(); + } + + @Test(expected = java.io.IOException.class) + public void testResourceTsWrongPWResourceKs() throws Exception + { + Resource keystoreResource = Resource.newSystemResource("keystore"); + Resource truststoreResource = Resource.newSystemResource("keystore"); + + SslContextFactory cf = new SslContextFactory(); + cf.setKeyStoreResource(keystoreResource); + cf.setTrustStoreResource(truststoreResource); + cf.setKeyStorePassword("storepwd"); + cf.setKeyManagerPassword("keypwd"); + cf.setTrustStorePassword("wrong_storepwd"); + + cf.start(); + } }