~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/transport/socket/ssl/config/SSLSocketServerSocketConfigurationTestCase.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
6
*
 
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.
 
11
*
 
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.
 
16
*
 
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.
 
21
*/
 
22
package org.jboss.test.remoting.transport.socket.ssl.config;
 
23
 
 
24
import java.net.Socket;
 
25
import java.net.SocketException;
 
26
import java.util.HashSet;
 
27
import java.util.Map;
 
28
 
 
29
import javax.net.ssl.SSLSocket;
 
30
import javax.net.ssl.SSLSocketFactory;
 
31
 
 
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;
 
37
 
 
38
 
 
39
/**
 
40
 * Unit test for JBREM-703.
 
41
 * 
 
42
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
43
 * @version $Revision: 1.1 $
 
44
 * <p>
 
45
 * Copyright Feb 28, 2008
 
46
 * </p>
 
47
 */
 
48
public class SSLSocketServerSocketConfigurationTestCase
 
49
extends SocketServerSocketConfigurationTestCase
 
50
{
 
51
   private static Logger log = Logger.getLogger(SSLSocketServerSocketConfigurationTestCase.class);
 
52
   
 
53
   static protected String[] cipherSuites;
 
54
   static protected String[] protocols;
 
55
 
 
56
   
 
57
   public void setUp() throws Exception
 
58
   {  
 
59
      if (firstTime)
 
60
      {
 
61
         super.setUp();
 
62
         
 
63
         SSLSocket s = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
 
64
         
 
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]);
 
81
 
 
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];
 
87
         
 
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];
 
93
         
 
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]);
 
100
      }
 
101
   }
 
102
 
 
103
   
 
104
   public void tearDown()
 
105
   {
 
106
   }
 
107
   
 
108
   
 
109
   protected void doSocketTest(Socket s) throws SocketException
 
110
   {
 
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");
 
116
      
 
117
      assertTrue(s instanceof SSLSocket);
 
118
      SSLSocket ss = (SSLSocket) s;
 
119
      assertTrue(ss.getEnableSessionCreation());
 
120
      
 
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());
 
127
   }
 
128
   
 
129
   
 
130
   protected void assertEquals(String[] strings1, String[] strings2)
 
131
   {
 
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);
 
139
   }
 
140
   
 
141
   
 
142
   protected String getTransport()
 
143
   {
 
144
      return "sslsocket";
 
145
   }
 
146
   
 
147
   
 
148
   protected void addExtraClientConfig(Map config)
 
149
   {
 
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");
 
154
   }
 
155
   
 
156
   
 
157
   protected void addExtraServerConfig(Map config)
 
158
   {
 
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");
 
163
   }
 
164
   
 
165
   
 
166
   protected void addServerSocketConfig(Map config)
 
167
   {
 
168
      super.addServerSocketConfig(config);
 
169
      config.put("enabledCipherSuites", cipherSuites);
 
170
      config.put("enabledProtocols", protocols);
 
171
      config.put("enableSessionCreation", "true");
 
172
   }
 
173
   
 
174
   
 
175
   protected void configureServerInvoker(SocketServerInvoker invoker)
 
176
   {
 
177
      super.configureServerInvoker(invoker);
 
178
      if (invoker instanceof SSLSocketServerInvoker)
 
179
      {
 
180
         SSLSocketServerInvoker sslInvoker = (SSLSocketServerInvoker) invoker;
 
181
         sslInvoker.setEnabledCipherSuites(cipherSuites);
 
182
         sslInvoker.setEnabledProtocols(protocols);
 
183
         sslInvoker.setEnableSessionCreation(true);
 
184
      }
 
185
   }
 
186
   
 
187
   
 
188
   protected void shutdownServer() throws Exception
 
189
   {
 
190
      if (connector != null)
 
191
         connector.stop();
 
192
   }
 
193
}
 
 
b'\\ No newline at end of file'