author | ascarpino |
Wed, 08 Feb 2017 12:08:28 -0800 | |
changeset 43701 | fe8c324ba97c |
parent 43009 | 5af9f7aa93e5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
14664
diff
changeset
|
2 |
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.ssl; |
|
27 |
||
28 |
import java.util.*; |
|
29 |
import java.io.*; |
|
30 |
import java.security.*; |
|
31 |
import java.security.cert.*; |
|
32 |
import javax.net.ssl.*; |
|
33 |
||
34 |
import sun.security.validator.Validator; |
|
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
35 |
import sun.security.validator.TrustStoreUtil; |
2 | 36 |
|
37 |
abstract class TrustManagerFactoryImpl extends TrustManagerFactorySpi { |
|
38 |
||
39 |
private static final Debug debug = Debug.getInstance("ssl"); |
|
40 |
private X509TrustManager trustManager = null; |
|
41 |
private boolean isInitialized = false; |
|
42 |
||
43 |
TrustManagerFactoryImpl() { |
|
44 |
// empty |
|
45 |
} |
|
46 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
10125
diff
changeset
|
47 |
@Override |
2 | 48 |
protected void engineInit(KeyStore ks) throws KeyStoreException { |
49 |
if (ks == null) { |
|
50 |
try { |
|
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
51 |
trustManager = getInstance(TrustStoreManager.getTrustedCerts()); |
2 | 52 |
} catch (SecurityException se) { |
53 |
// eat security exceptions but report other throwables |
|
54 |
if (debug != null && Debug.isOn("trustmanager")) { |
|
55 |
System.out.println( |
|
56 |
"SunX509: skip default keystore: " + se); |
|
57 |
} |
|
58 |
} catch (Error err) { |
|
59 |
if (debug != null && Debug.isOn("trustmanager")) { |
|
60 |
System.out.println( |
|
61 |
"SunX509: skip default keystore: " + err); |
|
62 |
} |
|
63 |
throw err; |
|
64 |
} catch (RuntimeException re) { |
|
65 |
if (debug != null && Debug.isOn("trustmanager")) { |
|
66 |
System.out.println( |
|
67 |
"SunX509: skip default keystore: " + re); |
|
68 |
} |
|
69 |
throw re; |
|
70 |
} catch (Exception e) { |
|
71 |
if (debug != null && Debug.isOn("trustmanager")) { |
|
72 |
System.out.println( |
|
73 |
"SunX509: skip default keystore: " + e); |
|
74 |
} |
|
75 |
throw new KeyStoreException( |
|
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
76 |
"problem accessing trust store", e); |
2 | 77 |
} |
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
78 |
} else { |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
79 |
trustManager = getInstance(TrustStoreUtil.getTrustedCerts(ks)); |
2 | 80 |
} |
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
81 |
|
2 | 82 |
isInitialized = true; |
83 |
} |
|
84 |
||
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
85 |
abstract X509TrustManager getInstance( |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
86 |
Collection<X509Certificate> trustedCerts); |
2 | 87 |
|
88 |
abstract X509TrustManager getInstance(ManagerFactoryParameters spec) |
|
89 |
throws InvalidAlgorithmParameterException; |
|
90 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
10125
diff
changeset
|
91 |
@Override |
2 | 92 |
protected void engineInit(ManagerFactoryParameters spec) throws |
93 |
InvalidAlgorithmParameterException { |
|
94 |
trustManager = getInstance(spec); |
|
95 |
isInitialized = true; |
|
96 |
} |
|
97 |
||
98 |
/** |
|
99 |
* Returns one trust manager for each type of trust material. |
|
100 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
10125
diff
changeset
|
101 |
@Override |
2 | 102 |
protected TrustManager[] engineGetTrustManagers() { |
103 |
if (!isInitialized) { |
|
104 |
throw new IllegalStateException( |
|
105 |
"TrustManagerFactoryImpl is not initialized"); |
|
106 |
} |
|
107 |
return new TrustManager[] { trustManager }; |
|
108 |
} |
|
109 |
||
110 |
/* |
|
111 |
* Try to get an InputStream based on the file we pass in. |
|
112 |
*/ |
|
113 |
private static FileInputStream getFileInputStream(final File file) |
|
114 |
throws Exception { |
|
115 |
return AccessController.doPrivileged( |
|
116 |
new PrivilegedExceptionAction<FileInputStream>() { |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
10125
diff
changeset
|
117 |
@Override |
2 | 118 |
public FileInputStream run() throws Exception { |
119 |
try { |
|
120 |
if (file.exists()) { |
|
121 |
return new FileInputStream(file); |
|
122 |
} else { |
|
123 |
return null; |
|
124 |
} |
|
125 |
} catch (FileNotFoundException e) { |
|
126 |
// couldn't find it, oh well. |
|
127 |
return null; |
|
128 |
} |
|
129 |
} |
|
130 |
}); |
|
131 |
} |
|
132 |
||
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
133 |
public static final class SimpleFactory extends TrustManagerFactoryImpl { |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
134 |
@Override |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
135 |
X509TrustManager getInstance( |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
136 |
Collection<X509Certificate> trustedCerts) { |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
137 |
return new X509TrustManagerImpl( |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
138 |
Validator.TYPE_SIMPLE, trustedCerts); |
2 | 139 |
} |
140 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
10125
diff
changeset
|
141 |
@Override |
2 | 142 |
X509TrustManager getInstance(ManagerFactoryParameters spec) |
143 |
throws InvalidAlgorithmParameterException { |
|
144 |
throw new InvalidAlgorithmParameterException |
|
145 |
("SunX509 TrustManagerFactory does not use " |
|
146 |
+ "ManagerFactoryParameters"); |
|
147 |
} |
|
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
148 |
} |
2 | 149 |
|
150 |
public static final class PKIXFactory extends TrustManagerFactoryImpl { |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
10125
diff
changeset
|
151 |
@Override |
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
152 |
X509TrustManager getInstance( |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
153 |
Collection<X509Certificate> trustedCerts) { |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
154 |
return new X509TrustManagerImpl(Validator.TYPE_PKIX, trustedCerts); |
2 | 155 |
} |
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
25859
diff
changeset
|
156 |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
10125
diff
changeset
|
157 |
@Override |
2 | 158 |
X509TrustManager getInstance(ManagerFactoryParameters spec) |
159 |
throws InvalidAlgorithmParameterException { |
|
160 |
if (spec instanceof CertPathTrustManagerParameters == false) { |
|
161 |
throw new InvalidAlgorithmParameterException |
|
162 |
("Parameters must be CertPathTrustManagerParameters"); |
|
163 |
} |
|
164 |
CertPathParameters params = |
|
165 |
((CertPathTrustManagerParameters)spec).getParameters(); |
|
166 |
if (params instanceof PKIXBuilderParameters == false) { |
|
167 |
throw new InvalidAlgorithmParameterException |
|
168 |
("Encapsulated parameters must be PKIXBuilderParameters"); |
|
169 |
} |
|
170 |
PKIXBuilderParameters pkixParams = (PKIXBuilderParameters)params; |
|
171 |
return new X509TrustManagerImpl(Validator.TYPE_PKIX, pkixParams); |
|
172 |
} |
|
173 |
} |
|
174 |
} |