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