Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2012-01-23 05:58:29 +0000
committerGreg Wilkins2012-01-23 05:58:29 +0000
commit067e3f17cbcf18228b2073bc6c963148086d2bac (patch)
tree0281f3ff322cc2f443d6d16d4d93981bd13c9975
parentae5ddb2930ac2e247047e0c51f83a8b94f94353f (diff)
downloadorg.eclipse.jetty.project-067e3f17cbcf18228b2073bc6c963148086d2bac.tar.gz
org.eclipse.jetty.project-067e3f17cbcf18228b2073bc6c963148086d2bac.tar.xz
org.eclipse.jetty.project-067e3f17cbcf18228b2073bc6c963148086d2bac.zip
avoid NPE with jdk 7u4ea8 changed behaviour of SslContext init
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java14
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java32
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java2
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslRenegotiateTest.java18
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java10
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java33
-rw-r--r--tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpsSocketImpl.java23
7 files changed, 34 insertions, 98 deletions
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java
index 09e1970c3e..607c271abe 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java
@@ -188,20 +188,6 @@ public class HttpServerTestFixture
}
}
- // Create a trust manager that does not validate certificate chains
- public final static TrustManager[] __trustAllCerts = new TrustManager[] {
- new X509TrustManager(){
- public java.security.cert.X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- public void checkClientTrusted(
- java.security.cert.X509Certificate[] certs, String authType) {
- }
- public void checkServerTrusted(
- java.security.cert.X509Certificate[] certs, String authType) {
- }
- }
- };
public final static HostnameVerifier __hostnameverifier = new HostnameVerifier()
{
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java
index c0d39e2bf2..2fcb497d05 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java
@@ -20,7 +20,8 @@ package org.eclipse.jetty.server.ssl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
import java.io.BufferedReader;
import java.io.IOException;
@@ -37,8 +38,6 @@ import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
@@ -81,25 +80,6 @@ public class SSLEngineTest
private static final int BODY_SIZE=300;
- private static final TrustManager[] s_dummyTrustManagers=new TrustManager[]
- {
- new X509TrustManager()
- {
- public java.security.cert.X509Certificate[] getAcceptedIssuers()
- {
- return null;
- }
-
- public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
- {
- }
-
- public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
- {
- }
- }
- };
-
private static Server server;
private static SslSelectChannelConnector connector;
@@ -134,7 +114,7 @@ public class SSLEngineTest
public void testBigResponse() throws Exception
{
SSLContext ctx=SSLContext.getInstance("TLS");
- ctx.init(null,s_dummyTrustManagers,new java.security.SecureRandom());
+ ctx.init(null,SslContextFactory.TRUST_ALL_CERTS,new java.security.SecureRandom());
int port=connector.getLocalPort();
@@ -152,7 +132,7 @@ public class SSLEngineTest
String response = IO.toString(client.getInputStream());
- assertTrue(response.length()>102400);
+ assertThat(response.length(),greaterThan(102400));
}
@Test
@@ -164,7 +144,7 @@ public class SSLEngineTest
Socket[] client=new Socket[numConns];
SSLContext ctx=SSLContext.getInstance("SSLv3");
- ctx.init(null,s_dummyTrustManagers,new java.security.SecureRandom());
+ ctx.init(null,SslContextFactory.TRUST_ALL_CERTS,new java.security.SecureRandom());
int port=connector.getLocalPort();
@@ -231,7 +211,7 @@ public class SSLEngineTest
server.start();
SSLContext context = SSLContext.getInstance("SSL");
- context.init(null,s_dummyTrustManagers,new java.security.SecureRandom());
+ context.init(null,SslContextFactory.TRUST_ALL_CERTS,new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
URL url = new URL("https://localhost:"+connector.getLocalPort()+"/test");
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java
index a7424b9949..2c219cc0f8 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java
@@ -73,7 +73,7 @@ public class SelectChannelServerSslTest extends HttpServerTestBase
{
HttpsURLConnection.setDefaultHostnameVerifier(__hostnameverifier);
SSLContext sc = SSLContext.getInstance("TLS");
- sc.init(null, __trustAllCerts, new java.security.SecureRandom());
+ sc.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
catch(Exception e)
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslRenegotiateTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslRenegotiateTest.java
index 69a96818d4..a38967f164 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslRenegotiateTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslRenegotiateTest.java
@@ -37,22 +37,6 @@ public class SslRenegotiateTest
{
private static final Logger LOG = Log.getLogger(SslRenegotiateTest.class);
- private static final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager()
- {
- public java.security.cert.X509Certificate[] getAcceptedIssuers()
- {
- return null;
- }
-
- public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType )
- {
- }
-
- public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType )
- {
- }
- } };
-
private ByteBuffer _outAppB;
private ByteBuffer _outPacketB;
private ByteBuffer _inAppB;
@@ -110,7 +94,7 @@ public class SslRenegotiateTest
_socket.configureBlocking(true);
SSLContext context=SSLContext.getInstance("SSL");
- context.init( null, trustAllCerts, new java.security.SecureRandom() );
+ context.init( null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom() );
_engine = context.createSSLEngine();
_engine.setUseClientMode(true);
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java
index 4e62833356..10ff80a4e9 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java
@@ -37,7 +37,7 @@ public class StdErrLog extends AbstractLogger
{
private static final String EOL = System.getProperty("line.separator");
private static DateCache _dateCache;
- private static Properties __props = Log.__props;
+ private static final Properties __props = new Properties();
private final static boolean __source = Boolean.parseBoolean(Log.__props.getProperty("org.eclipse.jetty.util.log.SOURCE",
Log.__props.getProperty("org.eclipse.jetty.util.log.stderr.SOURCE","false")));
@@ -45,6 +45,8 @@ public class StdErrLog extends AbstractLogger
static
{
+ __props.putAll(Log.__props);
+
String deprecatedProperties[] =
{ "DEBUG", "org.eclipse.jetty.util.log.DEBUG", "org.eclipse.jetty.util.log.stderr.DEBUG" };
@@ -97,7 +99,8 @@ public class StdErrLog extends AbstractLogger
public StdErrLog(String name, Properties props)
{
- __props = props;
+ if (props!=null)
+ __props.putAll(props);
this._name = name == null?"":name;
this._abbrevname = condensePackageString(this._name);
this._level = getLoggingLevel(props,this._name);
@@ -603,7 +606,8 @@ public class StdErrLog extends AbstractLogger
public static void setProperties(Properties props)
{
- __props = props;
+ __props.clear();
+ __props.putAll(props);
}
public void ignore(Throwable ignored)
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java
index 94c0d93cf6..9ad2cb0dd4 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java
@@ -71,6 +71,22 @@ import org.eclipse.jetty.util.security.Password;
*/
public class SslContextFactory extends AbstractLifeCycle
{
+ public final static TrustManager[] TRUST_ALL_CERTS = new X509TrustManager[]{new X509TrustManager()
+ {
+ public java.security.cert.X509Certificate[] getAcceptedIssuers()
+ {
+ return new java.security.cert.X509Certificate[]{};
+ }
+
+ public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
+ {
+ }
+
+ public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
+ {
+ }
+ }};
+
private static final Logger LOG = Log.getLogger(SslContextFactory.class);
public static final String DEFAULT_KEYMANAGERFACTORY_ALGORITHM =
@@ -229,22 +245,7 @@ public class SslContextFactory extends AbstractLifeCycle
{
LOG.debug("No keystore or trust store configured. ACCEPTING UNTRUSTED CERTIFICATES!!!!!");
// Create a trust manager that does not validate certificate chains
- TrustManager trustAllCerts = new X509TrustManager()
- {
- public java.security.cert.X509Certificate[] getAcceptedIssuers()
- {
- return null;
- }
-
- public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
- {
- }
-
- public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
- {
- }
- };
- trust_managers = new TrustManager[] { trustAllCerts };
+ trust_managers = TRUST_ALL_CERTS;
}
SecureRandom secureRandom = (_secureRandomAlgorithm == null)?null:SecureRandom.getInstance(_secureRandomAlgorithm);
diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpsSocketImpl.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpsSocketImpl.java
index 332aa4fed3..705314dd10 100644
--- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpsSocketImpl.java
+++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpsSocketImpl.java
@@ -32,6 +32,7 @@ import javax.net.ssl.X509TrustManager;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
/**
* An HTTPS Socket Impl
@@ -45,26 +46,6 @@ public class HttpsSocketImpl implements HttpSocket
public HttpsSocketImpl() throws Exception
{
- // Create loose SSL context.
- // Create a trust manager that does not validate certificate
- // chains
- TrustManager[] trustAllCerts = new TrustManager[]
- { new X509TrustManager()
- {
- public java.security.cert.X509Certificate[] getAcceptedIssuers()
- {
- return null;
- }
-
- public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
- {
- }
-
- public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
- {
- }
- } };
-
@SuppressWarnings("unused")
HostnameVerifier hostnameVerifier = new HostnameVerifier()
{
@@ -80,7 +61,7 @@ public class HttpsSocketImpl implements HttpSocket
{
// TODO real trust manager
this.sslContext = SSLContext.getInstance("TLS");
- sslContext.init(null,trustAllCerts,new java.security.SecureRandom());
+ sslContext.init(null,SslContextFactory.TRUST_ALL_CERTS,new java.security.SecureRandom());
}
catch (Exception e)
{

Back to the top