diff -urN testsuite/src/main/org/jboss/test/security/service/HttpsClient.java.orig testsuite/src/main/org/jboss/test/security/service/HttpsClient.java --- testsuite/src/main/org/jboss/test/security/service/HttpsClient.javai.orig 2005-10-29 01:05:46.000000000 -0400 +++ testsuite/src/main/org/jboss/test/security/service/HttpsClient.java 2006-07-31 10:08:08.000000000 -0400 @@ -36,12 +36,13 @@ import java.util.jar.JarFile; import javax.net.ssl.SSLSocketFactory; -import com.sun.net.ssl.internal.ssl.Provider; +import java.util.Properties; import org.jboss.logging.Logger; import org.jboss.system.ServiceMBeanSupport; import org.jboss.invocation.http.interfaces.Util; + /** A test mbean service that reads input from an https url passed in to its readURL method. @@ -53,11 +54,16 @@ { // Constants ----------------------------------------------------- + private static final String PROP_FILE_NAME = "provider.properties"; + private static final String JSSE_PROV_NAME_PREFIX = "jsse.provider.class."; + private static final String WWW_PROTOCOL_NAME_PREFIX = "www.protocol.class."; + + // Attributes ---------------------------------------------------- private boolean addedHttpsHandler; - private boolean addedSunJSSEProvider; - + private boolean addedJSSEProvider; + // Static -------------------------------------------------------- // Constructors -------------------------------------------------- @@ -113,27 +119,37 @@ // Public -------------------------------------------------------- protected void startService() throws Exception { - addedSunJSSEProvider = false; + addedJSSEProvider = false; try { new URL("https://www.https.test"); } catch(MalformedURLException e) { - // Install the default JSSE security provider - log.debug("Adding com.sun.net.ssl.internal.ssl.Provider"); - addedSunJSSEProvider = Security.addProvider(new Provider()) != -1; - if (addedSunJSSEProvider) + String jsseProvider = getJSSEProviderName(); + + // Install the default JSSE security provider + log.debug("Adding " + jsseProvider); + + String jsseProviderName = jsseProvider; + Class providerClass = Class.forName(jsseProviderName); + java.security.Provider provider = (java.security.Provider)providerClass.newInstance(); + + addedJSSEProvider = Security.addProvider(provider) != -1; + + + if (addedJSSEProvider) { - log.debug("Added com.sun.net.ssl.internal.ssl.Provider"); + log.debug("Added "+ jsseProviderName); } addedHttpsHandler = false; // Install the JSSE https handler if it has not already been added String handlers = System.getProperty("java.protocol.handler.pkgs"); - if( handlers == null || handlers.indexOf("com.sun.net.ssl.internal.www.protocol") < 0 ) + String wwwProtocol = getWWWProtocolName (); + if( handlers == null || handlers.indexOf(wwwProtocol) < 0 ) { - handlers += "|com.sun.net.ssl.internal.www.protocol"; + handlers += "|" + wwwProtocol; log.debug("Adding https handler to java.protocol.handler.pkgs"); System.setProperty("java.protocol.handler.pkgs", handlers); addedHttpsHandler = true; @@ -167,10 +183,10 @@ } protected void stopService() throws Exception { - if (addedSunJSSEProvider) + if (addedJSSEProvider) { - String name = (new Provider()).getName(); - log.debug("Removing com.sun.net.ssl.internal.ssl.Provider"); + String name = getJSSEProviderName(); + log.debug("Removing " + name); Security.removeProvider(name); } if( addedHttpsHandler == true ) @@ -182,7 +198,8 @@ while( tokenizer.hasMoreTokens() ) { String handler = tokenizer.nextToken(); - if( handler.equals("com.sun.net.ssl.internal.www.protocol") == false ) + String wwwProtocol = getWWWProtocolName (); + if( handler.equals(wwwProtocol) == false ) { buffer.append('|'); buffer.append(handler); @@ -258,5 +275,87 @@ return factoryDelegate.getSupportedCipherSuites(); } } + + // Private -------------------------------------------------------- + + private String getJSSEProviderName (){ + + String jsseProviderName = null; + + try{ + Properties prop = new Properties(); + prop.load(ClassLoader.getSystemResourceAsStream(PROP_FILE_NAME)); + + boolean searched = false; + int i=1; + while (!searched){ + boolean found = prop.containsKey(JSSE_PROV_NAME_PREFIX + i); + if (found){ + String jsseProvider = prop.getProperty(JSSE_PROV_NAME_PREFIX + i); + try { + Class.forName(jsseProvider); + jsseProviderName = jsseProvider; + //log.debug ("Using JSEE Provider :" + jsseProvider); + } catch (ClassNotFoundException cnfe){ + //log.debug ("Could not find JSEE Provider :" + jsseProvider ); + } + + } else { + searched = true; + } + i++; + } + + if (jsseProviderName == null){ + log.error ("No JSSE Providers found. Please add the appropriate provider class name in provider.properties"); + } + } catch (Exception e){ + log.error ("Error getting JSSEProvider : "); + e.printStackTrace(); + } + + log.debug (jsseProviderName); + return jsseProviderName; + } + + private String getWWWProtocolName (){ + + String wwwProtocolName = null; + + try{ + Properties prop = new Properties(); + prop.load(ClassLoader.getSystemResourceAsStream(PROP_FILE_NAME)); + + boolean searched = false; + int i=1; + while (!searched){ + boolean found = prop.containsKey(WWW_PROTOCOL_NAME_PREFIX + i); + if (found){ + String wwwProtocol = prop.getProperty(WWW_PROTOCOL_NAME_PREFIX + i); + try { + Class.forName(wwwProtocol); + wwwProtocolName = wwwProtocol; + log.debug ("Using WWW Protocol :" + wwwProtocol); + } catch (ClassNotFoundException cnfe){ + log.debug ("Could not find WWW Protocol :" + wwwProtocol ); + } + + } else { + searched = true; + } + i++; + } + + if (wwwProtocolName == null){ + log.error ("No WWW Protocols found. Please add the appropriate protocol class name in provider.properties"); + } + } catch (Exception e){ + log.error ("Error getting WWWProtocol : "); + e.printStackTrace(); + } + + return wwwProtocolName; + } } + diff -urN testsuite/src/main/org/jboss/test/security/test/HttpsUnitTestCase.java.orig testsuite/src/main/org/jboss/test/security/test/HttpsUnitTestCase.java --- testsuite/src/main/org/jboss/test/security/test/HttpsUnitTestCase.java.orig 2005-10-29 01:05:46.000000000 -0400 +++ testsuite/src/main/org/jboss/test/security/test/HttpsUnitTestCase.java 2006-07-31 10:08:52.000000000 -0400 @@ -51,6 +51,8 @@ import org.jboss.test.JBossTestCase; import org.jboss.test.JBossTestSetup; +import java.util.Properties; + /** Test of using https urls inside of the JBoss server. This testcase creates a simple https server and deploys a service that tries to connect to the server using the https url passed to the service. @@ -62,6 +64,9 @@ { static final String JAR = "https-service.sar"; static final String KEYSTORE_PASSWORD = "unit-tests"; + + private static final String PROP_FILE_NAME = "provider.properties"; + private static final String PROP_NAME_PREFIX = "jsse.provider.class."; public HttpsUnitTestCase(String name) { @@ -167,7 +172,10 @@ { super.setUp(); deploy(JAR); - Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); + String jsseProviderName = getJSSEProviderName(); + Class providerClass = Class.forName(jsseProviderName); + java.security.Provider provider = (java.security.Provider)providerClass.newInstance(); + Security.addProvider(provider); } protected void tearDown() throws Exception { @@ -177,6 +185,46 @@ }; return wrapper; } + + private static String getJSSEProviderName (){ + + Category log = Category.getInstance(HttpsUnitTestCase.class.getName()); + + String jsseProviderName = null; + + try{ + Properties prop = new Properties(); + prop.load(ClassLoader.getSystemResourceAsStream(PROP_FILE_NAME)); + + boolean searched = false; + int i=1; + while (!searched){ + boolean found = prop.containsKey(PROP_NAME_PREFIX + i); + if (found){ + String jsseProvider = prop.getProperty(PROP_NAME_PREFIX + i); + try { + Class.forName(jsseProvider); + jsseProviderName = jsseProvider; + log.debug ("Using JSEE Provider :" + jsseProvider); + } catch (ClassNotFoundException cnfe){ + log.debug ("Could not find JSEE Provider :" + jsseProvider ); + } + + } else { + searched = true; + } + i++; + } + + if (jsseProviderName == null){ + log.error ("No JSSE Providers found. Please add the appropriate provider in providers.properties"); + } + } catch (Exception e){ + log.error ("Error getting JSSE Provider : "); + e.printStackTrace(); + } + return jsseProviderName; + } /** A subclass of Thread that processes a single request sent to the serverSocket. diff -urN testsuite/src/resources/provider.properties.orig testsuite/src/resources/provider.properties --- testsuite/src/resources/provider.properties.orig 1969-12-31 19:00:00.000000000 -0500 +++ testsuite/src/resources/provider.properties 2006-07-31 09:50:58.000000000 -0400 @@ -0,0 +1,9 @@ +# Specifies a list of possible jsse provider classes. +# Numbers must start from 1 upwards and denotes priority. +jsse.provider.class.1 com.sun.net.ssl.internal.ssl.Provider +jsse.provider.class.2 com.ibm.jsse.IBMJSSEProvider + +# Specifies a list of possible www protocol classes. +# Numbers must start from 1 upwards and denotes priority. +www.protocol.class.1 com.sun.net.ssl.internal.www.protocol +www.protocol.class.2 com.ibm.net.ssl.internal.www.protocol