1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 
18 /**
19  * @author Vera Y. Petrashkova
20  */
21 
22 package javax.net.ssl;
23 
24 import java.nio.ByteBuffer;
25 import java.security.KeyManagementException;
26 import java.security.SecureRandom;
27 
28 /**
29  * Additional class for verification of SSLContextSpi and SSLContext
30  * functionality
31  */
32 
33 public class MySSLContextSpi extends SSLContextSpi {
34     private boolean init = false;
35 
36     @Override
engineInit(KeyManager[] km, TrustManager[] tm, SecureRandom sr)37     protected void engineInit(KeyManager[] km, TrustManager[] tm,
38             SecureRandom sr) throws KeyManagementException {
39         if (sr == null) {
40             throw new KeyManagementException(
41                     "secureRandom is null");
42         }
43         init = true;
44     }
45 
46     @Override
engineGetSocketFactory()47     protected SSLSocketFactory engineGetSocketFactory() {
48         if (!init) {
49             throw new RuntimeException("Not initialiazed");
50         }
51         return null;
52     }
53 
54     @Override
engineGetServerSocketFactory()55     protected SSLServerSocketFactory engineGetServerSocketFactory() {
56         if (!init) {
57             throw new RuntimeException("Not initialiazed");
58         }
59         return null;
60     }
61 
62     @Override
engineGetServerSessionContext()63     protected SSLSessionContext engineGetServerSessionContext() {
64         if (!init) {
65             throw new RuntimeException("Not initialiazed");
66         }
67         return null;
68     }
69 
70     @Override
engineGetClientSessionContext()71     protected SSLSessionContext engineGetClientSessionContext() {
72         if (!init) {
73             throw new RuntimeException("Not initialiazed");
74         }
75         return null;
76     }
77 
78     /*
79      * FIXME: add these methods
80      */
81     @Override
engineCreateSSLEngine(String host, int port)82     protected SSLEngine engineCreateSSLEngine(String host, int port) {
83         if (!init) {
84             throw new RuntimeException("Not initialiazed");
85         }
86         return new tmpSSLEngine(host, port);
87     }
88 
89     @Override
engineCreateSSLEngine()90     protected SSLEngine engineCreateSSLEngine() {
91         if (!init) {
92             throw new RuntimeException("Not initialiazed");
93         }
94         return new tmpSSLEngine();
95     }
96 
97     public class tmpSSLEngine extends SSLEngine {
98         String tmpHost;
99         int tmpPort;
100 
tmpSSLEngine()101         public tmpSSLEngine() {
102             tmpHost = null;
103             tmpPort = 0;
104         }
105 
tmpSSLEngine(String host, int port)106         public tmpSSLEngine(String host, int port) {
107             tmpHost = host;
108             tmpPort = port;
109         }
110 
111         @Override
getPeerHost()112         public String getPeerHost() {
113             return tmpHost;
114         }
115 
116         @Override
getPeerPort()117         public int getPeerPort() {
118             return tmpPort;
119         }
120 
121         @Override
beginHandshake()122         public void beginHandshake() throws SSLException {
123         }
124 
125         @Override
closeInbound()126         public void closeInbound() throws SSLException {
127         }
128 
129         @Override
closeOutbound()130         public void closeOutbound() {
131         }
132 
133         @Override
getDelegatedTask()134         public Runnable getDelegatedTask() {
135             return null;
136         }
137 
138         @Override
getEnabledCipherSuites()139         public String[] getEnabledCipherSuites() {
140             return null;
141         }
142 
143         @Override
getEnabledProtocols()144         public String[] getEnabledProtocols() {
145             return null;
146         }
147 
148         @Override
getEnableSessionCreation()149         public boolean getEnableSessionCreation() {
150             return true;
151         }
152 
153         @Override
getHandshakeStatus()154         public SSLEngineResult.HandshakeStatus getHandshakeStatus() {
155             return null;
156         }
157 
158         @Override
getNeedClientAuth()159         public boolean getNeedClientAuth() {
160             return true;
161         }
162 
163         @Override
getSession()164         public SSLSession getSession() {
165             return null;
166         }
167 
168         @Override
getSupportedCipherSuites()169         public String[] getSupportedCipherSuites() {
170             return null;
171         }
172 
173         @Override
getSupportedProtocols()174         public String[] getSupportedProtocols() {
175             return null;
176         }
177 
178         @Override
getUseClientMode()179         public boolean getUseClientMode() {
180             return true;
181         }
182 
183         @Override
getWantClientAuth()184         public boolean getWantClientAuth() {
185             return true;
186         }
187 
188         @Override
isInboundDone()189         public boolean isInboundDone() {
190             return true;
191         }
192 
193         @Override
isOutboundDone()194         public boolean isOutboundDone() {
195             return true;
196         }
197 
198         @Override
setEnabledCipherSuites(String[] suites)199         public void setEnabledCipherSuites(String[] suites) {
200         }
201 
202         @Override
setEnabledProtocols(String[] protocols)203         public void setEnabledProtocols(String[] protocols) {
204         }
205 
206         @Override
setEnableSessionCreation(boolean flag)207         public void setEnableSessionCreation(boolean flag) {
208         }
209 
210         @Override
setNeedClientAuth(boolean need)211         public void setNeedClientAuth(boolean need) {
212         }
213 
214         @Override
setUseClientMode(boolean mode)215         public void setUseClientMode(boolean mode) {
216         }
217 
218         @Override
setWantClientAuth(boolean want)219         public void setWantClientAuth(boolean want) {
220         }
221 
222         @Override
unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length)223         public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
224                 int offset, int length) throws SSLException {
225             return null;
226         }
227 
228         @Override
wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer dst)229         public SSLEngineResult wrap(ByteBuffer[] srcs, int offset,
230                 int length, ByteBuffer dst) throws SSLException {
231             return null;
232         }
233 
234         @Override
getSSLParameters()235         public SSLParameters getSSLParameters() {
236             // TODO Auto-generated method stub
237             return null;
238         }
239 
240         @Override
setSSLParameters(SSLParameters sslP)241         public void setSSLParameters(SSLParameters sslP) {
242             // TODO Auto-generated method stub
243 
244         }
245     }
246 }