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: package org.apache.harmony.xnet.tests.support;
019:
020: import java.nio.ByteBuffer;
021: import java.security.KeyManagementException;
022: import java.security.SecureRandom;
023:
024: import javax.net.ssl.KeyManager;
025: import javax.net.ssl.SSLContextSpi;
026: import javax.net.ssl.SSLEngine;
027: import javax.net.ssl.SSLEngineResult;
028: import javax.net.ssl.SSLException;
029: import javax.net.ssl.SSLSession;
030: import javax.net.ssl.SSLSessionContext;
031: import javax.net.ssl.SSLServerSocketFactory;
032: import javax.net.ssl.SSLSocketFactory;
033: import javax.net.ssl.TrustManager;
034:
035: /**
036: * Additional class for verification of SSLContextSpi and SSLContext
037: * functionality
038: *
039: */
040:
041: public class MySSLContextSpi extends SSLContextSpi {
042: private boolean init = false;
043:
044: protected void engineInit(KeyManager[] km, TrustManager[] tm,
045: SecureRandom sr) throws KeyManagementException {
046: if (sr == null) {
047: throw new KeyManagementException("secureRandom is null");
048: }
049: init = true;
050: }
051:
052: protected SSLSocketFactory engineGetSocketFactory() {
053: if (!init) {
054: throw new RuntimeException("Not initialiazed");
055: }
056: ;
057: return null;
058: }
059:
060: protected SSLServerSocketFactory engineGetServerSocketFactory() {
061: if (!init) {
062: throw new RuntimeException("Not initialiazed");
063: }
064: return null;
065: }
066:
067: protected SSLSessionContext engineGetServerSessionContext() {
068: if (!init) {
069: throw new RuntimeException("Not initialiazed");
070: }
071: return null;
072: }
073:
074: protected SSLSessionContext engineGetClientSessionContext() {
075: if (!init) {
076: throw new RuntimeException("Not initialiazed");
077: }
078: return null;
079: }
080:
081: /*
082: * FIXME: add these methods
083: */
084: protected SSLEngine engineCreateSSLEngine(String host, int port) {
085: if (!init) {
086: throw new RuntimeException("Not initialiazed");
087: }
088: return new tmpSSLEngine(host, port);
089: }
090:
091: protected SSLEngine engineCreateSSLEngine() {
092: if (!init) {
093: throw new RuntimeException("Not initialiazed");
094: }
095: return new tmpSSLEngine();
096: }
097:
098: public class tmpSSLEngine extends SSLEngine {
099: String tmpHost;
100: int tmpPort;
101:
102: public tmpSSLEngine() {
103: tmpHost = null;
104: tmpPort = 0;
105: }
106:
107: public tmpSSLEngine(String host, int port) {
108: tmpHost = host;
109: tmpPort = port;
110: }
111:
112: public String getPeerHost() {
113: return tmpHost;
114: }
115:
116: public int getPeerPort() {
117: return tmpPort;
118: }
119:
120: public void beginHandshake() throws SSLException {
121: }
122:
123: public void closeInbound() throws SSLException {
124: }
125:
126: public void closeOutbound() {
127: }
128:
129: public Runnable getDelegatedTask() {
130: return null;
131: }
132:
133: public String[] getEnabledCipherSuites() {
134: return null;
135: }
136:
137: public String[] getEnabledProtocols() {
138: return null;
139: }
140:
141: public boolean getEnableSessionCreation() {
142: return true;
143: }
144:
145: public SSLEngineResult.HandshakeStatus getHandshakeStatus() {
146: return null;
147: };
148:
149: public boolean getNeedClientAuth() {
150: return true;
151: }
152:
153: public SSLSession getSession() {
154: return null;
155: }
156:
157: public String[] getSupportedCipherSuites() {
158: return null;
159: }
160:
161: public String[] getSupportedProtocols() {
162: return null;
163: }
164:
165: public boolean getUseClientMode() {
166: return true;
167: }
168:
169: public boolean getWantClientAuth() {
170: return true;
171: }
172:
173: public boolean isInboundDone() {
174: return true;
175: }
176:
177: public boolean isOutboundDone() {
178: return true;
179: }
180:
181: public void setEnabledCipherSuites(String[] suites) {
182: }
183:
184: public void setEnabledProtocols(String[] protocols) {
185: }
186:
187: public void setEnableSessionCreation(boolean flag) {
188: }
189:
190: public void setNeedClientAuth(boolean need) {
191: }
192:
193: public void setUseClientMode(boolean mode) {
194: }
195:
196: public void setWantClientAuth(boolean want) {
197: }
198:
199: public SSLEngineResult unwrap(ByteBuffer src,
200: ByteBuffer[] dsts, int offset, int length)
201: throws SSLException {
202: return null;
203: }
204:
205: public SSLEngineResult wrap(ByteBuffer[] srcs, int offset,
206: int length, ByteBuffer dst) throws SSLException {
207: return null;
208: }
209: }
210: }
|