CertReplace.java revision 2404
2404N/A/*
2404N/A * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
2404N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2404N/A *
2404N/A * This code is free software; you can redistribute it and/or modify it
2404N/A * under the terms of the GNU General Public License version 2 only, as
2404N/A * published by the Free Software Foundation.
2404N/A *
2404N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2404N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2404N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2404N/A * version 2 for more details (a copy is included in the LICENSE file that
2404N/A * accompanied this code).
2404N/A *
2404N/A * You should have received a copy of the GNU General Public License version
2404N/A * 2 along with this work; if not, write to the Free Software Foundation,
2404N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2404N/A *
2404N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2404N/A * CA 95054 USA or visit www.sun.com if you need additional information or
2404N/A * have any questions.
2404N/A */
2404N/A
2404N/A/*
2404N/A * This test is called by certreplace.sh
2404N/A */
2404N/A
2404N/Aimport java.io.FileInputStream;
2404N/Aimport java.security.KeyStore;
2404N/Aimport java.security.cert.Certificate;
2404N/Aimport java.security.cert.CertificateFactory;
2404N/Aimport java.security.cert.X509Certificate;
2404N/Aimport java.util.Arrays;
2404N/Aimport java.util.ArrayList;
2404N/Aimport java.util.List;
2404N/Aimport sun.security.validator.Validator;
2404N/A
2404N/Apublic class CertReplace {
2404N/A
2404N/A private final static String cacerts = "certreplace.jks";
2404N/A private final static String certs = "certreplace.certs";
2404N/A
2404N/A public static void main(String[] args) throws Exception {
2404N/A
2404N/A KeyStore ks = KeyStore.getInstance("JKS");
2404N/A ks.load(new FileInputStream(cacerts), "changeit".toCharArray());
2404N/A Validator v = Validator.getInstance
2404N/A (Validator.TYPE_PKIX, Validator.VAR_GENERIC, ks);
2404N/A X509Certificate[] chain = createPath();
2404N/A System.out.println(Arrays.toString(v.validate(chain)));
2404N/A
2404N/A }
2404N/A
2404N/A public static X509Certificate[] createPath() throws Exception {
2404N/A CertificateFactory cf = CertificateFactory.getInstance("X.509");
2404N/A List list = new ArrayList();
2404N/A for (Certificate c: cf.generateCertificates(
2404N/A new FileInputStream(certs))) {
2404N/A list.add((X509Certificate)c);
2404N/A }
2404N/A return (X509Certificate[]) list.toArray(new X509Certificate[0]);
2404N/A }
2404N/A}