01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * @version $Revision$
21: */package javax.net.ssl;
22:
23: import java.security.InvalidAlgorithmParameterException;
24: import java.security.KeyStore;
25: import java.security.KeyStoreException;
26: import java.security.NoSuchAlgorithmException;
27: import java.security.UnrecoverableKeyException;
28:
29: /**
30: * Class for verification KeyManagerFactorySpi and KeyManagerFactory
31: * functionality
32: *
33: */
34:
35: public class MyKeyManagerFactorySpi extends KeyManagerFactorySpi {
36:
37: protected void engineInit(KeyStore ks, char[] password)
38: throws KeyStoreException, NoSuchAlgorithmException,
39: UnrecoverableKeyException {
40: if (password == null) {
41: throw new KeyStoreException("Incorrect password");
42: }
43: if (ks == null) {
44: throw new UnrecoverableKeyException("Incorrect keystore");
45: }
46: }
47:
48: protected void engineInit(ManagerFactoryParameters spec)
49: throws InvalidAlgorithmParameterException {
50: if (spec == null) {
51: throw new InvalidAlgorithmParameterException(
52: "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
60: .toString());
61: }
62: } else {
63: throw new InvalidAlgorithmParameterException(
64: "Invalid parameter");
65: }
66: }
67:
68: protected KeyManager[] engineGetKeyManagers() {
69: return null;
70: }
71:
72: public static class Parameters implements ManagerFactoryParameters {
73: private KeyStore keyStore;
74: private char[] passWD;
75:
76: public Parameters(KeyStore ks, char[] pass) {
77: this .keyStore = ks;
78: this .passWD = pass;
79: }
80:
81: public KeyStore getKeyStore() {
82: return keyStore;
83: }
84:
85: public char[] getPassword() {
86: return passWD;
87: }
88: }
89: }
|