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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.apache.harmony.xnet.tests.support;
20 import java.nio.ByteBuffer;
21 import java.security.KeyManagementException;
22 import java.security.SecureRandom;
23 import javax.net.ssl.KeyManager;
24 import javax.net.ssl.SSLContextSpi;
25 import javax.net.ssl.SSLEngine;
26 import javax.net.ssl.SSLEngineResult;
27 import javax.net.ssl.SSLException;
28 import javax.net.ssl.SSLParameters;
29 import javax.net.ssl.SSLServerSocketFactory;
30 import javax.net.ssl.SSLSession;
31 import javax.net.ssl.SSLSessionContext;
32 import javax.net.ssl.SSLSocketFactory;
33 import javax.net.ssl.TrustManager;
36 * Additional class for verification of SSLContextSpi and SSLContext
41 public class MySSLContextSpi extends SSLContextSpi {
42 private boolean init = false;
43 protected void engineInit(KeyManager[] km, TrustManager[] tm,
44 SecureRandom sr) throws KeyManagementException {
46 throw new KeyManagementException(
47 "secureRandom is null");
52 protected SSLSocketFactory engineGetSocketFactory() {
54 throw new RuntimeException("Not initialiazed");
59 protected SSLServerSocketFactory engineGetServerSocketFactory() {
61 throw new RuntimeException("Not initialiazed");
66 protected SSLSessionContext engineGetServerSessionContext() {
68 throw new RuntimeException("Not initialiazed");
73 protected SSLSessionContext engineGetClientSessionContext() {
75 throw new RuntimeException("Not initialiazed");
80 protected SSLParameters engineGetDefaultSSLParameters() {
81 engineGetSocketFactory();
85 protected SSLParameters engineGetSupportedSSLParameters() {
86 engineGetSocketFactory();
91 * FIXME: add these methods
93 protected SSLEngine engineCreateSSLEngine(String host, int port) {
95 throw new RuntimeException("Not initialiazed");
97 return new tmpSSLEngine(host, port);
100 protected SSLEngine engineCreateSSLEngine() {
102 throw new RuntimeException("Not initialiazed");
104 return new tmpSSLEngine();
107 public class tmpSSLEngine extends SSLEngine {
110 public tmpSSLEngine() {
114 public tmpSSLEngine(String host, int port) {
118 public String getPeerHost() {
121 public int getPeerPort() {
124 public void beginHandshake() throws SSLException { }
125 public void closeInbound() throws SSLException { }
126 public void closeOutbound() {}
127 public Runnable getDelegatedTask() { return null; }
128 public String[] getEnabledCipherSuites() { return null; }
129 public String[] getEnabledProtocols() {return null; }
130 public boolean getEnableSessionCreation() { return true; }
131 public SSLEngineResult.HandshakeStatus getHandshakeStatus() { return null; }
132 public boolean getNeedClientAuth() { return true; }
133 public SSLSession getSession() { return null; }
134 public String[] getSupportedCipherSuites() { return null; }
135 public String[] getSupportedProtocols() { return null; }
136 public boolean getUseClientMode() { return true; }
137 public boolean getWantClientAuth() { return true; }
138 public boolean isInboundDone() { return true; }
139 public boolean isOutboundDone() { return true; }
140 public void setEnabledCipherSuites(String[] suites) { }
141 public void setEnabledProtocols(String[] protocols) { }
142 public void setEnableSessionCreation(boolean flag) { }
143 public void setNeedClientAuth(boolean need) { }
144 public void setUseClientMode(boolean mode) { }
145 public void setWantClientAuth(boolean want) { }
146 public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
147 int offset, int length) throws SSLException {
150 public SSLEngineResult wrap(ByteBuffer[] srcs, int offset,
151 int length, ByteBuffer dst) throws SSLException {