aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/test/java/test/at/gv/egovernment/moa/id/util/SSLUtilsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/idserverlib/src/test/java/test/at/gv/egovernment/moa/id/util/SSLUtilsTest.java')
-rw-r--r--id/server/idserverlib/src/test/java/test/at/gv/egovernment/moa/id/util/SSLUtilsTest.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/id/server/idserverlib/src/test/java/test/at/gv/egovernment/moa/id/util/SSLUtilsTest.java b/id/server/idserverlib/src/test/java/test/at/gv/egovernment/moa/id/util/SSLUtilsTest.java
new file mode 100644
index 000000000..fa5b51a91
--- /dev/null
+++ b/id/server/idserverlib/src/test/java/test/at/gv/egovernment/moa/id/util/SSLUtilsTest.java
@@ -0,0 +1,107 @@
+/*
+* Copyright 2003 Federal Chancellery Austria
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package test.at.gv.egovernment.moa.id.util;
+
+import iaik.pki.jsse.IAIKX509TrustManager;
+
+import java.net.URL;
+import java.security.Security;
+
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSocketFactory;
+
+import com.sun.net.ssl.HttpsURLConnection;
+
+import at.gv.egovernment.moa.id.config.ConfigurationProvider;
+import at.gv.egovernment.moa.id.config.ConnectionParameter;
+import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProvider;
+import at.gv.egovernment.moa.id.config.proxy.OAProxyParameter;
+import at.gv.egovernment.moa.id.config.proxy.ProxyConfigurationProvider;
+import at.gv.egovernment.moa.id.iaik.config.LoggerConfigImpl;
+import at.gv.egovernment.moa.id.util.SSLUtils;
+import test.at.gv.egovernment.moa.id.UnitTestCase;
+
+/*
+ * @author Paul Ivancsics
+ * @version $Id$
+ */
+public class SSLUtilsTest extends UnitTestCase {
+
+ public SSLUtilsTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ //System.setProperty("javax.net.debug", "all");
+ Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
+ System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
+ IAIKX509TrustManager.initLog(new LoggerConfigImpl("file:" + TESTDATA_ROOT + "conf/log4j.properties"));
+ System.setProperty("https.cipherSuites", "SSL_DHE_DSS_WITH_DES_CBC_SHA,SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA,SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA,SSL_RSA_WITH_DES_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_RSA_EXPORT_WITH_RC4_40_MD5");
+ }
+
+ public void testVerisignOK() throws Exception {
+ doTestOA("conf/ConfigurationTest.xml", "http://verisign.moa.gv.at/", true, null);
+ }
+ public void testATrustOK() throws Exception {
+ doTestOA("conf/ConfigurationTest.xml", "http://a-trust.moa.gv.at/", true, null);
+ }
+ public void testBaltimoreOK() throws Exception {
+ doTestOA("conf/ConfigurationTest.xml", "http://baltimore.moa.gv.at/", true, null);
+ }
+ public void testCIOOK() throws Exception {
+ doTestOA("conf/ConfigurationTest.xml", "http://cio.moa.gv.at/", true, null);
+ }
+ public void testMOASPOK() throws Exception {
+ System.setProperty(ConfigurationProvider.CONFIG_PROPERTY_NAME,
+ TESTDATA_ROOT + "conf/ConfigurationTest.xml");
+ ConnectionParameter connParam = AuthConfigurationProvider.getInstance().getMoaSpConnectionParameter();
+ doTest(connParam, true, null);
+ }
+ private void doTestOA(String configFile, String publicURLPrefix, boolean shouldOK, String exMessageFragment) throws Exception {
+ System.setProperty(ConfigurationProvider.CONFIG_PROPERTY_NAME,
+ TESTDATA_ROOT + configFile);
+ ProxyConfigurationProvider proxyConf =
+ ProxyConfigurationProvider.getInstance();
+ OAProxyParameter oaParam = proxyConf.getOnlineApplicationParameter(publicURLPrefix);
+ ConnectionParameter connParam = oaParam.getConnectionParameter();
+ doTest(connParam, shouldOK, exMessageFragment);
+ }
+ private void doTest(ConnectionParameter connParam, boolean shouldOK, String exMessageFragment) throws Exception {
+ SSLUtils.initialize();
+ AuthConfigurationProvider authConf = AuthConfigurationProvider.getInstance();
+ SSLSocketFactory ssf = SSLUtils.getSSLSocketFactory(authConf, connParam);
+ URL url = new URL(connParam.getUrl());
+ HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
+ conn.setRequestMethod("GET");
+ conn.setDoInput(true);
+ conn.setDoOutput(true);
+ conn.setUseCaches(false);
+ conn.setAllowUserInteraction(false);
+ conn.setSSLSocketFactory(ssf);
+ try {
+ conn.connect();
+ assertTrue(shouldOK);
+ assertEquals(200, conn.getResponseCode());
+ conn.disconnect();
+ }
+ catch (SSLException ex) {
+ ex.printStackTrace();
+ assertFalse(shouldOK);
+ assertTrue(ex.getMessage().indexOf(exMessageFragment) >= 0);
+ }
+ }
+
+}