1 /* SSLServerSocketImpl.java --
2    Copyright (C) 2006  Free Software Foundation, Inc.
3 
4 This file is a part of GNU Classpath.
5 
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at
9 your option) any later version.
10 
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 USA
20 
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25 
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37 
38 
39 package gnu.javax.net.ssl.provider;
40 
41 import java.io.IOException;
42 
43 import javax.net.ssl.SSLServerSocket;
44 
45 /**
46  * @author Casey Marshall (csm@gnu.org)
47  */
48 public class SSLServerSocketImpl extends SSLServerSocket
49 {
50   private final SSLContextImpl contextImpl;
51 
52   private boolean enableSessionCreation;
53   private String[] enabledCipherSuites;
54   private String[] enabledProtocols;
55   private boolean needClientAuth;
56   private boolean wantClientAuth;
57   private boolean clientMode;
58 
SSLServerSocketImpl(SSLContextImpl contextImpl)59   public SSLServerSocketImpl(SSLContextImpl contextImpl) throws IOException
60   {
61     super();
62     this.contextImpl = contextImpl;
63     enableSessionCreation = true;
64     enabledCipherSuites = SSLEngineImpl.defaultSuites();
65     enabledProtocols = new String[] { ProtocolVersion.SSL_3.toString(),
66                                       ProtocolVersion.TLS_1.toString(),
67                                       ProtocolVersion.TLS_1_1.toString() };
68     needClientAuth = false;
69     wantClientAuth = false;
70     clientMode = false;
71   }
72 
73   /* (non-Javadoc)
74    * @see javax.net.ssl.SSLServerSocket#getEnableSessionCreation()
75    */
getEnableSessionCreation()76   @Override public boolean getEnableSessionCreation()
77   {
78     return enableSessionCreation;
79   }
80 
81   /* (non-Javadoc)
82    * @see javax.net.ssl.SSLServerSocket#getEnabledCipherSuites()
83    */
getEnabledCipherSuites()84   @Override public String[] getEnabledCipherSuites()
85   {
86     return (String[]) enabledCipherSuites.clone();
87   }
88 
89   /* (non-Javadoc)
90    * @see javax.net.ssl.SSLServerSocket#getEnabledProtocols()
91    */
getEnabledProtocols()92   @Override public String[] getEnabledProtocols()
93   {
94     return (String[]) enabledProtocols.clone();
95   }
96 
97   /* (non-Javadoc)
98    * @see javax.net.ssl.SSLServerSocket#getNeedClientAuth()
99    */
getNeedClientAuth()100   @Override public boolean getNeedClientAuth()
101   {
102     return needClientAuth;
103   }
104 
105   /* (non-Javadoc)
106    * @see javax.net.ssl.SSLServerSocket#getSupportedCipherSuites()
107    */
getSupportedCipherSuites()108   @Override public String[] getSupportedCipherSuites()
109   {
110     return CipherSuite.availableSuiteNames().toArray(new String[0]);
111   }
112 
113   /* (non-Javadoc)
114    * @see javax.net.ssl.SSLServerSocket#getSupportedProtocols()
115    */
getSupportedProtocols()116   @Override public String[] getSupportedProtocols()
117   {
118     return new String[] { ProtocolVersion.SSL_3.toString(),
119                           ProtocolVersion.TLS_1.toString(),
120                           ProtocolVersion.TLS_1_1.toString() };
121   }
122 
123   /* (non-Javadoc)
124    * @see javax.net.ssl.SSLServerSocket#getUseClientMode()
125    */
getUseClientMode()126   @Override public boolean getUseClientMode()
127   {
128     return clientMode;
129   }
130 
131   /* (non-Javadoc)
132    * @see javax.net.ssl.SSLServerSocket#getWantClientAuth()
133    */
getWantClientAuth()134   @Override public boolean getWantClientAuth()
135   {
136     return wantClientAuth;
137   }
138 
139   /* (non-Javadoc)
140    * @see javax.net.ssl.SSLServerSocket#setEnableSessionCreation(boolean)
141    */
setEnableSessionCreation(final boolean enabled)142   @Override public void setEnableSessionCreation(final boolean enabled)
143   {
144     enableSessionCreation = enabled;
145   }
146 
147   /* (non-Javadoc)
148    * @see javax.net.ssl.SSLServerSocket#setEnabledCipherSuites(java.lang.String[])
149    */
setEnabledCipherSuites(final String[] suites)150   @Override public void setEnabledCipherSuites(final String[] suites)
151   {
152     enabledCipherSuites = (String[]) suites.clone();
153   }
154 
155   /* (non-Javadoc)
156    * @see javax.net.ssl.SSLServerSocket#setEnabledProtocols(java.lang.String[])
157    */
setEnabledProtocols(final String[] protocols)158   @Override public void setEnabledProtocols(final String[] protocols)
159   {
160     enabledProtocols = (String[]) protocols.clone();
161   }
162 
163   /* (non-Javadoc)
164    * @see javax.net.ssl.SSLServerSocket#setNeedClientAuth(boolean)
165    */
setNeedClientAuth(final boolean needAuth)166   @Override public void setNeedClientAuth(final boolean needAuth)
167   {
168     needClientAuth = needAuth;
169   }
170 
171   /* (non-Javadoc)
172    * @see javax.net.ssl.SSLServerSocket#setUseClientMode(boolean)
173    */
setUseClientMode(final boolean clientMode)174   @Override public void setUseClientMode(final boolean clientMode)
175   {
176     this.clientMode = clientMode;
177   }
178 
179   /* (non-Javadoc)
180    * @see javax.net.ssl.SSLServerSocket#setWantClientAuth(boolean)
181    */
setWantClientAuth(final boolean wantAuth)182   @Override public void setWantClientAuth(final boolean wantAuth)
183   {
184     wantClientAuth = wantAuth;
185   }
186 
accept()187   @Override public SSLSocketImpl accept() throws IOException
188   {
189     SSLSocketImpl socketImpl = new SSLSocketImpl(contextImpl, null, -1);
190     implAccept(socketImpl);
191     socketImpl.setEnableSessionCreation(enableSessionCreation);
192     socketImpl.setEnabledCipherSuites(enabledCipherSuites);
193     socketImpl.setEnabledProtocols(enabledProtocols);
194     socketImpl.setNeedClientAuth(needClientAuth);
195     socketImpl.setUseClientMode(clientMode);
196     socketImpl.setWantClientAuth(wantClientAuth);
197     return socketImpl;
198   }
199 }
200