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
22package javax.net.ssl;
23
24import java.nio.ByteBuffer;
25import java.security.KeyManagementException;
26import java.security.SecureRandom;
27
28/**
29 * Additional class for verification of SSLContextSpi and SSLContext
30 * functionality
31 *
32 */
33
34public class MySSLContextSpi extends SSLContextSpi {
35    private boolean init = false;
36    @Override
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
47    protected SSLSocketFactory engineGetSocketFactory() {
48        if (!init) {
49            throw new RuntimeException("Not initialiazed");
50        }
51        return null;
52    }
53
54    @Override
55    protected SSLServerSocketFactory engineGetServerSocketFactory() {
56        if (!init) {
57            throw new RuntimeException("Not initialiazed");
58        }
59        return null;
60    }
61
62    @Override
63    protected SSLSessionContext engineGetServerSessionContext() {
64        if (!init) {
65            throw new RuntimeException("Not initialiazed");
66        }
67        return null;
68    }
69
70    @Override
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
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
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        public tmpSSLEngine() {
101            tmpHost = null;
102            tmpPort = 0;
103        }
104        public tmpSSLEngine(String host, int port) {
105            tmpHost = host;
106            tmpPort = port;
107        }
108        @Override
109        public String getPeerHost() {
110            return tmpHost;
111        }
112        @Override
113        public int getPeerPort() {
114            return tmpPort;
115        }
116        @Override
117        public void beginHandshake() throws SSLException { }
118        @Override
119        public void closeInbound() throws SSLException { }
120        @Override
121        public void closeOutbound() {}
122        @Override
123        public Runnable getDelegatedTask() { return null; }
124        @Override
125        public String[] getEnabledCipherSuites() { return null; }
126        @Override
127        public String[] getEnabledProtocols() {return null; }
128        @Override
129        public boolean getEnableSessionCreation() { return true; }
130        @Override
131        public SSLEngineResult.HandshakeStatus getHandshakeStatus() { return null; }
132        @Override
133        public boolean getNeedClientAuth() { return true; }
134        @Override
135        public SSLSession getSession() { return null; }
136        @Override
137        public String[] getSupportedCipherSuites()  { return null; }
138        @Override
139        public String[] getSupportedProtocols()  { return null; }
140        @Override
141        public boolean getUseClientMode()  { return true; }
142        @Override
143        public boolean getWantClientAuth()  { return true; }
144        @Override
145        public boolean isInboundDone()  { return true; }
146        @Override
147        public boolean isOutboundDone()  { return true; }
148        @Override
149        public void setEnabledCipherSuites(String[] suites) { }
150        @Override
151        public void setEnabledProtocols(String[] protocols) { }
152        @Override
153        public void setEnableSessionCreation(boolean flag) { }
154        @Override
155        public void setNeedClientAuth(boolean need) { }
156        @Override
157        public void setUseClientMode(boolean mode) { }
158        @Override
159        public void setWantClientAuth(boolean want) { }
160        @Override
161        public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
162                int offset, int length) throws SSLException {
163            return null;
164        }
165        @Override
166        public SSLEngineResult wrap(ByteBuffer[] srcs, int offset,
167                int length, ByteBuffer dst) throws SSLException {
168            return null;
169        }
170
171        @Override
172        public SSLParameters getSSLParameters() {
173            // TODO Auto-generated method stub
174            return null;
175        }
176
177        @Override
178        public void setSSLParameters(SSLParameters sslP) {
179            // TODO Auto-generated method stub
180
181        }
182    }
183}