/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 org.apache.harmony.xnet.provider.jsse; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import javax.net.ssl.HandshakeCompletedEvent; import javax.net.ssl.HandshakeCompletedListener; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLServerSocket; import javax.net.ssl.SSLSocket; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * SSLSocketImplTest */ public class SSLSocketFunctionalTest extends TestCase { /** * The cipher suites used for functionality testing. */ private String[] cipher_suites = { "RSA_WITH_RC4_128_MD5", "RSA_WITH_DES_CBC_SHA", "DH_anon_EXPORT_WITH_DES40_CBC_SHA" }; // turn on/off the debug logging private boolean doLog = false; /** * Sets up the test case. */ @Override public void setUp() throws Exception { if (doLog) { System.out.println("========================"); System.out.println("====== Running the test: " + getName()); System.out.println("========================"); } } public void testContextInitialized2() throws Throwable { doTestSelfInteraction(JSSETestData.getContext()); } public void doTestInteraction(SSLContext context, SSLContext ctx_other) throws Throwable { SSLContext ctx1, ctx2; ctx1 = context; ctx2 = ctx_other; int k=1; SSLServerSocket ssocket = (SSLServerSocket) ctx1 .getServerSocketFactory().createServerSocket(0); ssocket.setUseClientMode(false); ssocket.setEnabledCipherSuites( ((k & 1) > 0) ? new String[] {"TLS_"+cipher_suites[0]} : new String[] {"SSL_"+cipher_suites[0]}); SSLSocket csocket = (SSLSocket) ctx2 .getSocketFactory().createSocket("localhost", ssocket.getLocalPort()); csocket.setEnabledProtocols(new String[] {"TLSv1"}); csocket.setUseClientMode(true); csocket.setEnabledCipherSuites( (((k & 2) >> 1) > 0) ? new String[] {"TLS_"+cipher_suites[0]} : new String[] {"SSL_"+cipher_suites[0]}); doTest(ssocket, csocket); } public void _doTestInteraction(SSLContext context, SSLContext ctx_other) throws Throwable { for (int i=0; i> 1)); } ctx1 = ((k & 1) > 0) ? context : ctx_other; ctx2 = (((k & 2) >> 1) > 0) ? context : ctx_other; SSLServerSocket ssocket = (SSLServerSocket) ctx1 .getServerSocketFactory().createServerSocket(0); ssocket.setUseClientMode(false); ssocket.setEnabledCipherSuites( ((k & 1) > 0) ? new String[] {"TLS_"+cipher_suites[i]} : new String[] {"SSL_"+cipher_suites[i]}); SSLSocket csocket = (SSLSocket) ctx2 .getSocketFactory().createSocket("localhost", ssocket.getLocalPort()); csocket.setEnabledProtocols(new String[] {"TLSv1"}); csocket.setUseClientMode(true); csocket.setEnabledCipherSuites( (((k & 2) >> 1) > 0) ? new String[] {"TLS_"+cipher_suites[i]} : new String[] {"SSL_"+cipher_suites[i]}); doTest(ssocket, csocket); } } } /** * Tests the interaction with other implementation. */ public void doTestSelfInteraction(SSLContext context) throws Throwable { String[] protocols = {"SSLv3", "TLSv1"}; for (int i=0; i