author | lana |
Thu, 10 Jun 2010 18:58:31 -0700 | |
changeset 5753 | e0ee3917e318 |
parent 5613 | 1146efa21514 |
child 5782 | 50575882b36f |
permissions | -rw-r--r-- |
5613
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
1 |
/* |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
2 |
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
4 |
* |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
8 |
* |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
14 |
* |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
18 |
* |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
21 |
* have any questions. |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
22 |
*/ |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
23 |
|
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
24 |
/* |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
25 |
* This test is called by certreplace.sh |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
26 |
*/ |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
27 |
|
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
28 |
import java.io.FileInputStream; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
29 |
import java.security.KeyStore; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
30 |
import java.security.cert.Certificate; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
31 |
import java.security.cert.CertificateFactory; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
32 |
import java.security.cert.X509Certificate; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
33 |
import java.util.Arrays; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
34 |
import java.util.ArrayList; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
35 |
import java.util.List; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
36 |
import sun.security.validator.Validator; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
37 |
|
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
38 |
public class CertReplace { |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
39 |
|
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
40 |
private final static String cacerts = "certreplace.jks"; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
41 |
private final static String certs = "certreplace.certs"; |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
42 |
|
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
43 |
public static void main(String[] args) throws Exception { |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
44 |
|
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
45 |
KeyStore ks = KeyStore.getInstance("JKS"); |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
46 |
ks.load(new FileInputStream(cacerts), "changeit".toCharArray()); |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
47 |
Validator v = Validator.getInstance |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
48 |
(Validator.TYPE_PKIX, Validator.VAR_GENERIC, ks); |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
49 |
X509Certificate[] chain = createPath(); |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
50 |
System.out.println(Arrays.toString(v.validate(chain))); |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
51 |
|
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
52 |
} |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
53 |
|
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
54 |
public static X509Certificate[] createPath() throws Exception { |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
55 |
CertificateFactory cf = CertificateFactory.getInstance("X.509"); |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
56 |
List list = new ArrayList(); |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
57 |
for (Certificate c: cf.generateCertificates( |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
58 |
new FileInputStream(certs))) { |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
59 |
list.add((X509Certificate)c); |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
60 |
} |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
61 |
return (X509Certificate[]) list.toArray(new X509Certificate[0]); |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
62 |
} |
1146efa21514
6948803: CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
weijun
parents:
diff
changeset
|
63 |
} |