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 package org.apache.harmony.xnet.tests.support; 19 20 import java.nio.ByteBuffer; 21 import java.security.KeyManagementException; 22 import java.security.SecureRandom; 23 24 import javax.net.ssl.KeyManager; 25 import javax.net.ssl.SSLContextSpi; 26 import javax.net.ssl.SSLEngine; 27 import javax.net.ssl.SSLEngineResult; 28 import javax.net.ssl.SSLException; 29 import javax.net.ssl.SSLParameters; 30 import javax.net.ssl.SSLSession; 31 import javax.net.ssl.SSLSessionContext; 32 import javax.net.ssl.SSLServerSocketFactory; 33 import javax.net.ssl.SSLSocketFactory; 34 import javax.net.ssl.TrustManager; 35 36 /** 37 * Additional class for verification of SSLContextSpi and SSLContext 38 * functionality 39 */ 40 41 public class MySSLContextSpi extends SSLContextSpi { 42 private boolean init = false; 43 44 @Override 45 protected void engineInit(KeyManager[] km, TrustManager[] tm, 46 SecureRandom sr) throws KeyManagementException { 47 if (sr == null) { 48 throw new KeyManagementException( 49 "secureRandom is null"); 50 } 51 init = true; 52 } 53 54 @Override 55 protected SSLSocketFactory engineGetSocketFactory() { 56 if (!init) { 57 throw new RuntimeException("Not initialiazed"); 58 } 59 ; 60 return null; 61 } 62 63 @Override 64 protected SSLServerSocketFactory engineGetServerSocketFactory() { 65 if (!init) { 66 throw new RuntimeException("Not initialiazed"); 67 } 68 return null; 69 } 70 71 @Override 72 protected SSLSessionContext engineGetServerSessionContext() { 73 if (!init) { 74 throw new RuntimeException("Not initialiazed"); 75 } 76 return null; 77 } 78 79 @Override 80 protected SSLSessionContext engineGetClientSessionContext() { 81 if (!init) { 82 throw new RuntimeException("Not initialiazed"); 83 } 84 return null; 85 } 86 87 /* 88 * FIXME: add these methods 89 */ 90 @Override 91 protected SSLEngine engineCreateSSLEngine(String host, int port) { 92 if (!init) { 93 throw new RuntimeException("Not initialiazed"); 94 } 95 return new tmpSSLEngine(host, port); 96 } 97 98 @Override 99 protected SSLEngine engineCreateSSLEngine() { 100 if (!init) { 101 throw new RuntimeException("Not initialiazed"); 102 } 103 return new tmpSSLEngine(); 104 } 105 106 public class tmpSSLEngine extends SSLEngine { 107 String tmpHost; 108 int tmpPort; 109 110 public tmpSSLEngine() { 111 tmpHost = null; 112 tmpPort = 0; 113 } 114 115 public tmpSSLEngine(String host, int port) { 116 tmpHost = host; 117 tmpPort = port; 118 } 119 120 @Override 121 public String getPeerHost() { 122 return tmpHost; 123 } 124 125 @Override 126 public int getPeerPort() { 127 return tmpPort; 128 } 129 130 @Override 131 public void beginHandshake() throws SSLException { 132 } 133 134 @Override 135 public void closeInbound() throws SSLException { 136 } 137 138 @Override 139 public void closeOutbound() { 140 } 141 142 @Override 143 public Runnable getDelegatedTask() { 144 return null; 145 } 146 147 @Override 148 public String[] getEnabledCipherSuites() { 149 return null; 150 } 151 152 @Override 153 public String[] getEnabledProtocols() { 154 return null; 155 } 156 157 @Override 158 public boolean getEnableSessionCreation() { 159 return true; 160 } 161 162 @Override 163 public SSLEngineResult.HandshakeStatus getHandshakeStatus() { 164 return null; 165 } 166 167 ; 168 169 @Override 170 public boolean getNeedClientAuth() { 171 return true; 172 } 173 174 @Override 175 public SSLSession getSession() { 176 return null; 177 } 178 179 @Override 180 public String[] getSupportedCipherSuites() { 181 return null; 182 } 183 184 @Override 185 public String[] getSupportedProtocols() { 186 return null; 187 } 188 189 @Override 190 public boolean getUseClientMode() { 191 return true; 192 } 193 194 @Override 195 public boolean getWantClientAuth() { 196 return true; 197 } 198 199 @Override 200 public boolean isInboundDone() { 201 return true; 202 } 203 204 @Override 205 public boolean isOutboundDone() { 206 return true; 207 } 208 209 @Override 210 public void setEnabledCipherSuites(String[] suites) { 211 } 212 213 @Override 214 public void setEnabledProtocols(String[] protocols) { 215 } 216 217 @Override 218 public void setEnableSessionCreation(boolean flag) { 219 } 220 221 @Override 222 public void setNeedClientAuth(boolean need) { 223 } 224 225 @Override 226 public void setUseClientMode(boolean mode) { 227 } 228 229 @Override 230 public void setWantClientAuth(boolean want) { 231 } 232 233 @Override 234 public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, 235 int offset, int length) throws SSLException { 236 return null; 237 } 238 239 @Override 240 public SSLEngineResult wrap(ByteBuffer[] srcs, int offset, 241 int length, ByteBuffer dst) throws SSLException { 242 return null; 243 } 244 245 @Override 246 public SSLParameters getSSLParameters() { 247 // TODO Auto-generated method stub 248 return null; 249 } 250 251 @Override 252 public void setSSLParameters(SSLParameters sslP) { 253 // TODO Auto-generated method stub 254 255 } 256 } 257 258 @Override 259 protected SSLParameters engineGetDefaultSSLParameters() { 260 return new SSLParameters(new String[] { "Default_SSL_Parameters_For_Test1" }, 261 new String[] { "TLSv1" }); 262 } 263 264 @Override 265 protected SSLParameters engineGetSupportedSSLParameters() { 266 return new SSLParameters(new String[] { "Default_SSL_Parameters_For_Test1", 267 "Default_SSL_Parameters_For_Test2" }, new String[] { "TLSv1", "SSLv3" }); 268 } 269 }