From jboss-remoting-commits at lists.jboss.org Fri Aug 14 17:02:57 2009 Content-Type: multipart/mixed; boundary="===============1774525969167711712==" MIME-Version: 1.0 From: jboss-remoting-commits at lists.jboss.org To: jboss-remoting-commits at lists.jboss.org Subject: [jboss-remoting-commits] JBoss Remoting SVN: r5335 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl. Date: Fri, 14 Aug 2009 17:02:57 -0400 Message-ID: <200908142102.n7EL2vDL023024@svn01.web.mwc.hst.phx2.redhat.com> --===============1774525969167711712== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2009-08-14 17:02:57 -0400 (Fri, 14 Aug 2009) New Revision: 5335 Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisoc= ket/ssl/SSLBisocketControlConnectionReplacementTestCase.java Log: JBREM-1147: New unit test. Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/b= isocket/ssl/SSLBisocketControlConnectionReplacementTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/ssl/SSLBisocketControlConnectionReplacementTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/ssl/SSLBisocketControlConnectionReplacementTestCase.java 2009-08-14 21= :02:57 UTC (rev 5335) @@ -0,0 +1,425 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2009, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.test.remoting.transport.bisocket.ssl; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketAddress; +import java.net.UnknownHostException; + +import javax.net.ServerSocketFactory; +import javax.net.ssl.HandshakeCompletedListener; +import javax.net.ssl.SSLServerSocket; +import javax.net.ssl.SSLServerSocketFactory; +import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSocket; + +import org.jboss.logging.Logger; +import org.jboss.remoting.security.SSLSocketBuilder; +import org.jboss.test.remoting.transport.bisocket.BisocketControlConnectio= nReplacementTestCase; + +/** + * Unit test for JBREM-1147. + * = + * @author Ron Sigal + * @version = + *
+ * Copyright Aug 14, 2009 + *
+ */ +public class SSLBisocketControlConnectionReplacementTestCase extends Bisoc= ketControlConnectionReplacementTestCase +{ + private static Logger log =3D Logger.getLogger(SSLBisocketControlConnec= tionReplacementTestCase.class); + = + public void setUp() throws Exception + { + if (firstTime) + { + String keyStoreFilePath =3D getClass().getResource(".keystore").g= etFile(); + System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath); + System.setProperty("javax.net.ssl.keyStorePassword", "unit-tests-= server"); + String trustStoreFilePath =3D getClass().getResource(".truststore= ").getFile(); + System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath= ); + System.setProperty("javax.net.ssl.trustStorePassword", "unit-test= s-client"); + } + super.setUp(); + } + = + protected String getTransport() + { + return "sslbisocket"; + } + = + protected String getServerSocketName() + { + return SSLTestServerSocketFactory.class.getName(); + } + = + static public class SSLTestServerSocketFactory extends ServerSocketFact= ory + { + int timeout; + ServerSocketFactory factory; + int initialWrites; + = + public SSLTestServerSocketFactory() throws IOException + { + this.timeout =3D 5000; + this.initialWrites =3D 3; + setupFactory(); + } = + public SSLTestServerSocketFactory(int timeout, int initialWrites) th= rows IOException + { + this.timeout =3D timeout; + this.initialWrites =3D initialWrites; + setupFactory(); + } + public ServerSocket createServerSocket() throws IOException + { + ServerSocket ss =3D SSLServerSocketFactory.getDefault().createSer= verSocket(); + log.info("returning: " + ss); + return ss; + } + public ServerSocket createServerSocket(int port) throws IOException + { + ServerSocket ss =3D null; + if (port !=3D secondaryServerSocketPort) + { + ss =3D SSLServerSocketFactory.getDefault().createServerSocket(= port); + } + else + { + ss =3D new SSLTestServerSocket(port, timeout, initialWrites, (= (SSLServerSocket) factory.createServerSocket())); + } + log.info("returning: " + ss); + return ss; + } + + public ServerSocket createServerSocket(int port, int backlog) throws= IOException + { + ServerSocket ss =3D null; + if (port !=3D secondaryServerSocketPort) + { + ss =3D SSLServerSocketFactory.getDefault().createServerSocket(= port, backlog); + } + else + { + ss =3D new SSLTestServerSocket(port, backlog, timeout, initial= Writes, ((SSLServerSocket) factory.createServerSocket())); + } + log.info("returning: " + ss); + return ss; + } + + public ServerSocket createServerSocket(int port, int backlog, InetAd= dress ifAddress) throws IOException + { + ServerSocket ss =3D null; + if (port !=3D secondaryServerSocketPort) + { + ss =3D SSLServerSocketFactory.getDefault().createServerSocket(= port, backlog, ifAddress); + } + else + { + ss =3D new SSLTestServerSocket(port, backlog, ifAddress, timeo= ut, initialWrites, ((SSLServerSocket) factory.createServerSocket())); + } + log.info("returning: " + ss); + return ss; + } + = + protected void setupFactory() throws IOException + { + SSLSocketBuilder sslSocketBuilder =3D new SSLSocketBuilder(); + sslSocketBuilder.setUseSSLServerSocketFactory(false); + factory =3D sslSocketBuilder.createSSLServerSocketFactory(); + } + } + = + = + static class SSLTestServerSocket extends SSLServerSocket + { + int timeout; + int initialWrites; + SSLServerSocket serverSocket; + + public SSLTestServerSocket(int timeout, int initialWrites, SSLServer= Socket serverSocket) throws IOException + { + super(); + this.timeout =3D timeout; + this.initialWrites =3D initialWrites; + this.serverSocket =3D serverSocket; + } + public SSLTestServerSocket(int port, int timeout, int initialWrites,= SSLServerSocket serverSocket) throws IOException + { + super(port); + this.timeout =3D timeout; + this.initialWrites =3D initialWrites; + this.serverSocket =3D serverSocket; + bind(new InetSocketAddress(port), 50); + } + public SSLTestServerSocket(int port, int backlog, int timeout, int i= nitialWrites, SSLServerSocket serverSocket) throws IOException + { + super(port, backlog); + this.timeout =3D timeout; + this.initialWrites =3D initialWrites; + this.serverSocket =3D serverSocket; + bind(new InetSocketAddress(port), backlog); + } + public SSLTestServerSocket(int port, int backlog, InetAddress bindAd= dr, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IO= Exception + { + super(port, backlog, bindAddr); + this.timeout =3D timeout; + this.initialWrites =3D initialWrites; + this.serverSocket =3D serverSocket; + bind(new InetSocketAddress(bindAddr, port), 50); + } + public Socket accept() throws IOException + { + SSLSocket s1 =3D (SSLSocket) serverSocket.accept(); + Socket s2 =3D new SSLTestSocket(timeout, initialWrites, s1); + return s2; + } + public void bind(SocketAddress endpoint, int backlog) throws IOExcep= tion + { + log.info("serverSocket: " + serverSocket); + if (serverSocket !=3D null) log.info("bound: " + serverSocket.isB= ound()); + if (serverSocket !=3D null && !serverSocket.isBound()) + { + log.info("binding " + serverSocket); + serverSocket.bind(endpoint, backlog); + } + } + public String toString() + { + return "SSLTestServerSocket[" + serverSocket.toString() + "]"; + } + public boolean getEnableSessionCreation() + { + return serverSocket.getEnableSessionCreation(); + } + public String[] getEnabledCipherSuites() + { + return serverSocket.getEnabledCipherSuites(); + } + public String[] getEnabledProtocols() + { + return serverSocket.getEnabledProtocols(); + } + public boolean getNeedClientAuth() + { + return serverSocket.getNeedClientAuth(); + } + public String[] getSupportedCipherSuites() + { + return serverSocket.getSupportedCipherSuites(); + } + public String[] getSupportedProtocols() + { + return serverSocket.getSupportedProtocols(); + } + public boolean getUseClientMode() + { + return serverSocket.getUseClientMode(); + } + public boolean getWantClientAuth() + { + return serverSocket.getWantClientAuth(); + } + public void setEnableSessionCreation(boolean arg0) + { + serverSocket.setEnableSessionCreation(arg0); + } + public void setEnabledCipherSuites(String[] arg0) + { + serverSocket.setEnabledCipherSuites(arg0); + } + public void setEnabledProtocols(String[] arg0) + { + serverSocket.setEnabledProtocols(arg0); + } + public void setNeedClientAuth(boolean arg0) + { + serverSocket.setNeedClientAuth(arg0); + } + public void setUseClientMode(boolean arg0) + { + serverSocket.setUseClientMode(arg0); + } + public void setWantClientAuth(boolean arg0) + { + serverSocket.setWantClientAuth(arg0); + } + } + + static class SSLTestSocket extends SSLSocket + { + int timeout; + int initialWrites; + SSLSocket socket; + SocketAddress endpoint; + = + public SSLTestSocket(int timeout, int initialWrites, SSLSocket socke= t) + { + this.timeout =3D timeout; + this.initialWrites =3D initialWrites; + this.socket =3D socket; + } + public SSLTestSocket(String host, int port, int timeout, int initial= Writes, SSLSocket socket) throws UnknownHostException, IOException + { + super(host, port); + this.timeout =3D timeout; + this.initialWrites =3D initialWrites; + this.socket =3D socket; + connect(new InetSocketAddress(host, port), timeout); + } + public SSLTestSocket(InetAddress address, int port, int timeout, int= initialWrites, SSLSocket socket) throws IOException + { + super(address, port); + this.timeout =3D timeout; + this.initialWrites =3D initialWrites; + this.socket =3D socket; + connect(new InetSocketAddress(address, port), timeout); + } + public SSLTestSocket(String host, int port, InetAddress localAddr, i= nt localPort, int timeout, int initialWrites, SSLSocket socket) throws IOEx= ception + { + super(host, port, localAddr, localPort); + this.timeout =3D timeout; + this.initialWrites =3D initialWrites; + this.socket =3D socket; + bind(new InetSocketAddress(localAddr, localPort)); + connect(new InetSocketAddress(host, port), timeout); + } + public SSLTestSocket(InetAddress address, int port, InetAddress loca= lAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) thr= ows IOException + { + super(address, port, localAddr, localPort); + this.timeout =3D timeout; + this.initialWrites =3D initialWrites; + this.socket =3D socket; + bind(new InetSocketAddress(localAddr, localPort)); + connect(new InetSocketAddress(address, port), timeout); + } + public String toString() + { + return "SSLTestSocket[" + socket.toString() + "]"; + } + public InputStream getInputStream() throws IOException + { + return socket.getInputStream(); + } + public OutputStream getOutputStream() throws IOException + { + return new TestOutputStream(socket.getOutputStream(), timeout, in= itialWrites); + } + public void addHandshakeCompletedListener(HandshakeCompletedListener= listener) + { + socket.addHandshakeCompletedListener(listener); + } + public void bind(SocketAddress bindpoint) throws IOException + { + if (socket !=3D null) + socket.bind(bindpoint); + } + public void connect(SocketAddress endpoint) throws IOException + { + if (socket !=3D null) + socket.connect(endpoint); + } + public void connect(SocketAddress endpoint, int timeout) throws IOEx= ception + { + socket.connect(endpoint, timeout); + } + public boolean getEnableSessionCreation() + { + return socket.getEnableSessionCreation(); + } + public String[] getEnabledCipherSuites() + { + return socket.getEnabledCipherSuites(); + } + public String[] getEnabledProtocols() + { + return socket.getEnabledProtocols(); + } + public InetAddress getInetAddress() + { + return socket.getInetAddress(); + } + public boolean getNeedClientAuth() + { + return socket.getNeedClientAuth(); + } + public SSLSession getSession() + { + return socket.getSession(); + } + public String[] getSupportedCipherSuites() + { + return socket.getSupportedCipherSuites(); + } + public String[] getSupportedProtocols() + { + return socket.getSupportedProtocols(); + } + public boolean getUseClientMode() + { + return socket.getUseClientMode(); + } + public boolean getWantClientAuth() + { + return socket.getWantClientAuth(); + } + public void removeHandshakeCompletedListener(HandshakeCompletedListe= ner listener) + { + socket.removeHandshakeCompletedListener(listener); + } + public void setEnableSessionCreation(boolean flag) + { + socket.setEnableSessionCreation(flag); + } + public void setEnabledCipherSuites(String[] suites) + { + socket.setEnabledCipherSuites(suites); + } + public void setEnabledProtocols(String[] protocols) + { + socket.setEnabledProtocols(protocols); + } + public void setNeedClientAuth(boolean need) + { + socket.setNeedClientAuth(need); + } + public void setUseClientMode(boolean mode) + { + socket.setUseClientMode(mode); + } + public void setWantClientAuth(boolean want) + { + socket.setWantClientAuth(want); + } + public void startHandshake() throws IOException + { + socket.startHandshake(); + } + } +} --===============1774525969167711712==--