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.provider.jsse;
19:
20: import java.io.InputStream;
21: import java.security.KeyStore;
22: import java.security.SecureRandom;
23:
24: import javax.net.ssl.KeyManagerFactory;
25: import javax.net.ssl.SSLContext;
26: import javax.net.ssl.TrustManagerFactory;
27:
28: import tests.support.resource.Support_Resources;
29:
30: /**
31: * JSSETestData
32: */
33: public class JSSETestData {
34:
35: private static Exception initException;
36:
37: // the password to the store
38: public static final char[] KS_PASSWORD = "password".toCharArray();
39:
40: private static SSLContext context;
41: private static KeyStore keyStore;
42: private static SSLParameters sslParameters;
43:
44: static {
45: try {
46: String ksDefaultType = KeyStore.getDefaultType();
47: InputStream is = Support_Resources
48: .getResourceStream("key_store."
49: + ksDefaultType.toLowerCase());
50:
51: keyStore = KeyStore.getInstance(ksDefaultType);
52: keyStore.load(is, KS_PASSWORD);
53:
54: KeyManagerFactory kmf = KeyManagerFactory
55: .getInstance("X509");
56: kmf.init(keyStore, KS_PASSWORD);
57:
58: TrustManagerFactory tmf = TrustManagerFactory
59: .getInstance("X509");
60: tmf.init(keyStore);
61:
62: sslParameters = new SSLParameters(kmf.getKeyManagers(), tmf
63: .getTrustManagers(), new SecureRandom(),
64: new SSLSessionContextImpl(),
65: new SSLSessionContextImpl());
66:
67: context = SSLContext.getInstance("TLSv1");
68: context.init(kmf.getKeyManagers(), tmf.getTrustManagers(),
69: new SecureRandom());
70: } catch (Exception e) {
71: e.printStackTrace();
72: initException = e;
73: }
74: }
75:
76: public static SSLContext getContext() throws Exception {
77: if (initException != null) {
78: throw initException;
79: }
80: return context;
81: }
82:
83: public static SSLParameters getSSLParameters() throws Exception {
84: if (initException != null) {
85: throw initException;
86: }
87: return sslParameters;
88: }
89:
90: public static KeyStore getKeyStore() throws Exception {
91: if (initException != null) {
92: throw initException;
93: }
94: return keyStore;
95: }
96: }
|