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 18package org.apache.harmony.xnet.tests.support; 19 20import java.security.InvalidAlgorithmParameterException; 21import java.security.KeyStore; 22import java.security.KeyStoreException; 23import java.security.NoSuchAlgorithmException; 24import java.security.UnrecoverableKeyException; 25 26import javax.net.ssl.KeyManager; 27import javax.net.ssl.KeyManagerFactorySpi; 28import javax.net.ssl.ManagerFactoryParameters; 29 30/** 31 * Class for verification KeyManagerFactorySpi and KeyManagerFactory 32 * functionality 33 * 34 */ 35 36public class MyKeyManagerFactorySpi extends KeyManagerFactorySpi { 37 38 protected void engineInit(KeyStore ks, char[] password) 39 throws KeyStoreException, NoSuchAlgorithmException, 40 UnrecoverableKeyException { 41 if (password == null) { 42 throw new KeyStoreException("Incorrect password"); 43 } 44 if (ks == null) { 45 throw new UnrecoverableKeyException("Incorrect keystore"); 46 } 47 } 48 49 protected void engineInit(ManagerFactoryParameters spec) 50 throws InvalidAlgorithmParameterException { 51 if (spec == null) { 52 throw new InvalidAlgorithmParameterException("Incorrect parameter"); 53 } 54 if (spec instanceof Parameters) { 55 try { 56 engineInit(((Parameters)spec).getKeyStore(), 57 ((Parameters)spec).getPassword()); 58 } catch (Exception e) { 59 throw new InvalidAlgorithmParameterException(e.toString()); 60 } 61 } else { 62 throw new InvalidAlgorithmParameterException("Invalid parameter"); 63 } 64 } 65 66 protected KeyManager[] engineGetKeyManagers() { 67 return null; 68 } 69 public static class Parameters implements ManagerFactoryParameters { 70 private KeyStore keyStore; 71 private char[] passWD; 72 public Parameters (KeyStore ks, char[] pass) { 73 this.keyStore = ks; 74 this.passWD = pass; 75 } 76 public KeyStore getKeyStore() { 77 return keyStore; 78 } 79 public char[] getPassword() { 80 return passWD; 81 } 82 }} 83