Home | History | Annotate | Download | only in support
      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.security.tests.support;
     19 
     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;
     34 
     35 /**
     36  * Additional class for verification of SSLContextSpi and SSLContext
     37  * functionality
     38  *
     39  */
     40 
     41 public class MySSLContextSpi extends SSLContextSpi {
     42 
     43     private boolean init = false;
     44 
     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     protected SSLSocketFactory engineGetSocketFactory() {
     55         if (!init) {
     56             throw new RuntimeException("Not initialiazed");
     57         }
     58         return null;
     59     }
     60 
     61     protected SSLServerSocketFactory engineGetServerSocketFactory() {
     62         if (!init) {
     63             throw new RuntimeException("Not initialiazed");
     64         }
     65         return null;
     66     }
     67 
     68     protected SSLSessionContext engineGetServerSessionContext() {
     69         if (!init) {
     70             throw new RuntimeException("Not initialiazed");
     71         }
     72         return null;
     73     }
     74 
     75     protected SSLSessionContext engineGetClientSessionContext() {
     76         if (!init) {
     77             throw new RuntimeException("Not initialiazed");
     78         }
     79         return null;
     80     }
     81 
     82     protected SSLParameters engineGetDefaultSSLParameters() {
     83         engineGetSocketFactory();
     84         return null;
     85     }
     86 
     87     protected SSLParameters engineGetSupportedSSLParameters() {
     88         engineGetSocketFactory();
     89         return null;
     90     }
     91 
     92     /*
     93      * FIXME: add these methods
     94      */
     95     protected SSLEngine engineCreateSSLEngine(String host, int port) {
     96         if (!init) {
     97             throw new RuntimeException("Not initialiazed");
     98         }
     99         return new tmpSSLEngine(host, port);
    100     }
    101 
    102     protected SSLEngine engineCreateSSLEngine() {
    103         if (!init) {
    104             throw new RuntimeException("Not initialiazed");
    105         }
    106         return new tmpSSLEngine();
    107     }
    108 
    109     public class tmpSSLEngine extends SSLEngine {
    110         String tmpHost;
    111         int tmpPort;
    112         public tmpSSLEngine() {
    113             tmpHost = null;
    114             tmpPort = 0;
    115         }
    116         public tmpSSLEngine(String host, int port) {
    117             tmpHost = host;
    118             tmpPort = port;
    119         }
    120         public String getPeerHost() {
    121             return tmpHost;
    122         }
    123         public int getPeerPort() {
    124             return tmpPort;
    125         }
    126         public void beginHandshake() throws SSLException { }
    127         public void closeInbound() throws SSLException { }
    128         public void closeOutbound() {}
    129         public Runnable getDelegatedTask() { return null; }
    130         public String[] getEnabledCipherSuites() { return null; }
    131         public String[] getEnabledProtocols() {return null; }
    132         public boolean getEnableSessionCreation() { return true; }
    133         public SSLEngineResult.HandshakeStatus getHandshakeStatus() { return null; }
    134         public boolean getNeedClientAuth() { return true; }
    135         public SSLSession getSession() { return null; }
    136         public String[] getSupportedCipherSuites()  { return null; }
    137         public String[] getSupportedProtocols()  { return null; }
    138         public boolean getUseClientMode()  { return true; }
    139         public boolean getWantClientAuth()  { return true; }
    140         public boolean isInboundDone()  { return true; }
    141         public boolean isOutboundDone()  { return true; }
    142         public void setEnabledCipherSuites(String[] suites) { }
    143         public void setEnabledProtocols(String[] protocols) { }
    144         public void setEnableSessionCreation(boolean flag) { }
    145         public void setNeedClientAuth(boolean need) { }
    146         public void setUseClientMode(boolean mode) { }
    147         public void setWantClientAuth(boolean want) { }
    148         public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
    149                 int offset, int length) throws SSLException {
    150             return null;
    151         }
    152         public SSLEngineResult wrap(ByteBuffer[] srcs, int offset,
    153                 int length, ByteBuffer dst) throws SSLException {
    154             return null;
    155         }
    156     }
    157 }
    158