2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
22
package org.jboss.test.remoting.transport.socket.ssl.config;
24
import java.net.Socket;
25
import java.net.SocketException;
26
import java.util.HashSet;
29
import javax.net.ssl.SSLSocket;
30
import javax.net.ssl.SSLSocketFactory;
32
import org.apache.log4j.Logger;
33
import org.jboss.remoting.security.SSLSocketBuilder;
34
import org.jboss.remoting.transport.socket.SocketServerInvoker;
35
import org.jboss.remoting.transport.sslsocket.SSLSocketServerInvoker;
36
import org.jboss.test.remoting.transport.socket.configuration.SocketServerSocketConfigurationTestCase;
40
* Unit test for JBREM-703.
42
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
43
* @version $Revision: 1.1 $
45
* Copyright Feb 28, 2008
48
public class SSLSocketServerSocketConfigurationTestCase
49
extends SocketServerSocketConfigurationTestCase
51
private static Logger log = Logger.getLogger(SSLSocketServerSocketConfigurationTestCase.class);
53
static protected String[] cipherSuites;
54
static protected String[] protocols;
57
public void setUp() throws Exception
63
SSLSocket s = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
65
String[] strings = s.getSupportedCipherSuites();
66
log.info("supported cipher suites: ");
67
for (int i = 0; i < strings.length; i++)
68
log.info(" " + strings[i]);
69
strings = s.getEnabledCipherSuites();
70
log.info("enabled cipher suites: ");
71
for (int i = 0; i < strings.length; i++)
72
log.info(" " + strings[i]);
73
strings = s.getSupportedProtocols();
74
log.info("supported protocols: ");
75
for (int i = 0; i < strings.length; i++)
76
log.info(" " + strings[i]);
77
strings = s.getEnabledProtocols();
78
log.info("enabled protocols: ");
79
for (int i = 0; i < strings.length; i++)
80
log.info(" " + strings[i]);
82
strings = s.getSupportedCipherSuites();
83
int len = strings.length - 1;
84
cipherSuites = new String[len];
85
for (int i = 0; i < len; i++)
86
cipherSuites[i] = strings[i];
88
strings = s.getSupportedProtocols();
89
len = strings.length - 1;
90
protocols = new String[len];
91
for (int i = 0; i < len; i++)
92
protocols[i] = strings[i];
94
log.info("using cipherSuites: ");
95
for (int i = 0; i < cipherSuites.length; i++)
96
log.info(" " + cipherSuites[i]);
97
log.info("using protocols: ");
98
for (int i = 0; i < protocols.length; i++)
99
log.info(" " + protocols[i]);
104
public void tearDown()
109
protected void doSocketTest(Socket s) throws SocketException
111
assertTrue(s.getKeepAlive());
112
suggestEquals(2345, s.getReceiveBufferSize(), "receiveBufferSize");
113
suggestEquals(3456, s.getSendBufferSize(), "sendBufferSize");
114
assertEquals(4567, s.getSoLinger());
115
suggestEquals(0, s.getTrafficClass(), "trafficClass");
117
assertTrue(s instanceof SSLSocket);
118
SSLSocket ss = (SSLSocket) s;
119
assertTrue(ss.getEnableSessionCreation());
121
log.info("actual enabledCipherSuites: ");
122
String[] strings = ss.getEnabledCipherSuites();
123
for (int i = 0; i < strings.length; i++)
124
log.info(" " + strings[i]);
125
assertEquals(cipherSuites, ss.getEnabledCipherSuites());
126
assertEquals(protocols, ss.getEnabledProtocols());
130
protected void assertEquals(String[] strings1, String[] strings2)
132
HashSet set1 = new HashSet();
133
for (int i = 0; i < strings1.length; i++)
134
set1.add(strings1[i]);
135
HashSet set2 = new HashSet();
136
for (int i = 0; i < strings2.length; i++)
137
set2.add(strings2[i]);
138
assertEquals(set1, set2);
142
protected String getTransport()
148
protected void addExtraClientConfig(Map config)
150
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
151
String trustStoreFilePath = this.getClass().getResource("../.truststore").getFile();
152
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
153
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
157
protected void addExtraServerConfig(Map config)
159
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
160
String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile();
161
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
162
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
166
protected void addServerSocketConfig(Map config)
168
super.addServerSocketConfig(config);
169
config.put("enabledCipherSuites", cipherSuites);
170
config.put("enabledProtocols", protocols);
171
config.put("enableSessionCreation", "true");
175
protected void configureServerInvoker(SocketServerInvoker invoker)
177
super.configureServerInvoker(invoker);
178
if (invoker instanceof SSLSocketServerInvoker)
180
SSLSocketServerInvoker sslInvoker = (SSLSocketServerInvoker) invoker;
181
sslInvoker.setEnabledCipherSuites(cipherSuites);
182
sslInvoker.setEnabledProtocols(protocols);
183
sslInvoker.setEnableSessionCreation(true);
188
protected void shutdownServer() throws Exception
190
if (connector != null)
b'\\ No newline at end of file'