--- a/jdk/test/sun/security/validator/CertReplace.java Thu Jun 10 15:55:26 2010 -0700
+++ b/jdk/test/sun/security/validator/CertReplace.java Fri Jun 11 11:38:36 2010 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -16,9 +16,9 @@
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
*/
/*
@@ -37,25 +37,28 @@
public class CertReplace {
- private final static String cacerts = "certreplace.jks";
- private final static String certs = "certreplace.certs";
-
+ /**
+ * @param args {cacerts keystore, cert chain}
+ */
public static void main(String[] args) throws Exception {
KeyStore ks = KeyStore.getInstance("JKS");
- ks.load(new FileInputStream(cacerts), "changeit".toCharArray());
+ ks.load(new FileInputStream(args[0]), "changeit".toCharArray());
Validator v = Validator.getInstance
(Validator.TYPE_PKIX, Validator.VAR_GENERIC, ks);
- X509Certificate[] chain = createPath();
- System.out.println(Arrays.toString(v.validate(chain)));
-
+ X509Certificate[] chain = createPath(args[1]);
+ System.out.println("Chain: ");
+ for (X509Certificate c: v.validate(chain)) {
+ System.out.println(" " + c.getSubjectX500Principal() +
+ " issued by " + c.getIssuerX500Principal());
+ }
}
- public static X509Certificate[] createPath() throws Exception {
+ public static X509Certificate[] createPath(String chain) throws Exception {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
List list = new ArrayList();
for (Certificate c: cf.generateCertificates(
- new FileInputStream(certs))) {
+ new FileInputStream(chain))) {
list.add((X509Certificate)c);
}
return (X509Certificate[]) list.toArray(new X509Certificate[0]);