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