001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander Y. Kleymenov
020: * @version $Revision$
021: */package org.apache.harmony.xnet.provider.jsse;
022:
023: import org.apache.harmony.xnet.provider.jsse.SSLSocketImpl;
024: import org.apache.harmony.xnet.provider.jsse.SSLParameters;
025:
026: import java.io.IOException;
027: import java.net.InetAddress;
028: import java.net.Socket;
029: import javax.net.ssl.SSLServerSocket;
030:
031: /**
032: * SSLServerSocket implementation
033: * @see javax.net.ssl.SSLServerSocket class documentation for more information.
034: */
035: public class SSLServerSocketImpl extends SSLServerSocket {
036:
037: // the sslParameters object incapsulates all the info
038: // about supported and enabled cipher suites and protocols,
039: // as well as the information about client/server mode of
040: // ssl socket, whether it require/want client authentication or not,
041: // and controls whether new SSL sessions may be established by this
042: // socket or not.
043: private final SSLParameters sslParameters;
044:
045: // logger
046: private Logger.Stream logger = Logger.getStream("ssocket");
047:
048: /**
049: * Ctor
050: * @param sslParameters: SSLParameters
051: * @throws IOException
052: */
053: protected SSLServerSocketImpl(SSLParameters sslParameters)
054: throws IOException {
055: super ();
056: this .sslParameters = sslParameters;
057: }
058:
059: /**
060: * Ctor
061: * @param port: int
062: * @param sslParameters: SSLParameters
063: * @throws IOException
064: */
065: protected SSLServerSocketImpl(int port, SSLParameters sslParameters)
066: throws IOException {
067: super (port);
068: this .sslParameters = sslParameters;
069: }
070:
071: /**
072: * Ctor
073: * @param port: int
074: * @param backlog: int
075: * @param sslParameters: SSLParameters
076: * @throws IOException
077: */
078: protected SSLServerSocketImpl(int port, int backlog,
079: SSLParameters sslParameters) throws IOException {
080: super (port, backlog);
081: this .sslParameters = sslParameters;
082: }
083:
084: /**
085: * Ctor
086: * @param port: int
087: * @param backlog: int
088: * @param iAddress: InetAddress
089: * @param sslParameters: SSLParameters
090: * @throws IOException
091: */
092: protected SSLServerSocketImpl(int port, int backlog,
093: InetAddress iAddress, SSLParameters sslParameters)
094: throws IOException {
095: super (port, backlog, iAddress);
096: this .sslParameters = sslParameters;
097: }
098:
099: // --------------- SSLParameters based methods ---------------------
100:
101: /**
102: * This method works according to the specification of implemented class.
103: * @see javax.net.ssl.SSLServerSocket#getSupportedCipherSuites()
104: * method documentation for more information
105: */
106: public String[] getSupportedCipherSuites() {
107: return CipherSuite.getSupportedCipherSuiteNames();
108: }
109:
110: /**
111: * This method works according to the specification of implemented class.
112: * @see javax.net.ssl.SSLServerSocket#getEnabledCipherSuites()
113: * method documentation for more information
114: */
115: public String[] getEnabledCipherSuites() {
116: return sslParameters.getEnabledCipherSuites();
117: }
118:
119: /**
120: * This method works according to the specification of implemented class.
121: * @see javax.net.ssl.SSLServerSocket#setEnabledCipherSuites(String[])
122: * method documentation for more information
123: */
124: public void setEnabledCipherSuites(String[] suites) {
125: sslParameters.setEnabledCipherSuites(suites);
126: }
127:
128: /**
129: * This method works according to the specification of implemented class.
130: * @see javax.net.ssl.SSLServerSocket#getSupportedProtocols()
131: * method documentation for more information
132: */
133: public String[] getSupportedProtocols() {
134: return (String[]) ProtocolVersion.supportedProtocols.clone();
135: }
136:
137: /**
138: * This method works according to the specification of implemented class.
139: * @see javax.net.ssl.SSLServerSocket#getEnabledProtocols()
140: * method documentation for more information
141: */
142: public String[] getEnabledProtocols() {
143: return sslParameters.getEnabledProtocols();
144: }
145:
146: /**
147: * This method works according to the specification of implemented class.
148: * @see javax.net.ssl.SSLServerSocket#setEnabledProtocols(String[])
149: * method documentation for more information
150: */
151: public void setEnabledProtocols(String[] protocols) {
152: sslParameters.setEnabledProtocols(protocols);
153: }
154:
155: /**
156: * This method works according to the specification of implemented class.
157: * @see javax.net.ssl.SSLServerSocket#setUseClientMode(boolean)
158: * method documentation for more information
159: */
160: public void setUseClientMode(boolean mode) {
161: sslParameters.setUseClientMode(mode);
162: }
163:
164: /**
165: * This method works according to the specification of implemented class.
166: * @see javax.net.ssl.SSLServerSocket#getUseClientMode()
167: * method documentation for more information
168: */
169: public boolean getUseClientMode() {
170: return sslParameters.getUseClientMode();
171: }
172:
173: /**
174: * This method works according to the specification of implemented class.
175: * @see javax.net.ssl.SSLServerSocket#setNeedClientAuth(boolean)
176: * method documentation for more information
177: */
178: public void setNeedClientAuth(boolean need) {
179: sslParameters.setNeedClientAuth(need);
180: }
181:
182: /**
183: * This method works according to the specification of implemented class.
184: * @see javax.net.ssl.SSLServerSocket#getNeedClientAuth()
185: * method documentation for more information
186: */
187: public boolean getNeedClientAuth() {
188: return sslParameters.getNeedClientAuth();
189: }
190:
191: /**
192: * This method works according to the specification of implemented class.
193: * @see javax.net.ssl.SSLServerSocket#setWantClientAuth(boolean)
194: * method documentation for more information
195: */
196: public void setWantClientAuth(boolean want) {
197: sslParameters.setWantClientAuth(want);
198: }
199:
200: /**
201: * This method works according to the specification of implemented class.
202: * @see javax.net.ssl.SSLServerSocket#getWantClientAuth()
203: * method documentation for more information
204: */
205: public boolean getWantClientAuth() {
206: return sslParameters.getWantClientAuth();
207: }
208:
209: /**
210: * This method works according to the specification of implemented class.
211: * @see javax.net.ssl.SSLServerSocket#setEnableSessionCreation(boolean)
212: * method documentation for more information
213: */
214: public void setEnableSessionCreation(boolean flag) {
215: sslParameters.setEnableSessionCreation(flag);
216: }
217:
218: /**
219: * This method works according to the specification of implemented class.
220: * @see javax.net.ssl.SSLServerSocket#getEnableSessionCreation()
221: * method documentation for more information
222: */
223: public boolean getEnableSessionCreation() {
224: return sslParameters.getEnableSessionCreation();
225: }
226:
227: // ------------- ServerSocket's methods overridings ----------------
228:
229: /**
230: * This method works according to the specification of implemented class.
231: * @see java.net.ServerSocket#accept()
232: * method documentation for more information
233: */
234: public Socket accept() throws IOException {
235: if (logger != null) {
236: logger.println("SSLServerSocketImpl.accept ..");
237: }
238: SSLSocketImpl s = new SSLSocketImpl(
239: (SSLParameters) sslParameters.clone());
240: implAccept(s);
241: SecurityManager sm = System.getSecurityManager();
242: if (sm != null) {
243: try {
244: sm.checkAccept(s.getInetAddress().getHostAddress(), s
245: .getPort());
246: } catch (SecurityException e) {
247: s.close();
248: throw e;
249: }
250: }
251: s.init();
252: s.startHandshake();
253: if (logger != null) {
254: logger
255: .println("SSLServerSocketImpl: accepted, initialized");
256: }
257: return s;
258: }
259:
260: /**
261: * Returns the string representation of the object.
262: */
263: public String toString() {
264: return "[SSLServerSocketImpl]";
265: }
266:
267: // -----------------------------------------------------------------
268: }
|