325N/A/*
325N/A * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A/*
325N/A * @test
325N/A * @bug 6535697
325N/A * @summary keytool can be more flexible on format of PEM-encoded
325N/A * X.509 certificates
325N/A */
325N/A
325N/Aimport java.io.*;
325N/Aimport java.nio.file.Files;
325N/Aimport java.nio.file.Paths;
325N/Aimport java.util.Arrays;
325N/Aimport java.security.cert.CertificateFactory;
325N/A
325N/Apublic class OpenSSLCert {
325N/A static final String OUTFILE = "6535697.test";
325N/A
325N/A public static void main(String[] args) throws Exception {
325N/A test("open");
325N/A test("pem");
325N/A test("open", "open");
325N/A test("open", "pem");
325N/A test("pem", "pem");
325N/A test("pem", "open");
325N/A test("open", "pem", "open");
325N/A test("pem", "open", "pem");
325N/A }
325N/A
325N/A static void test(String... files) throws Exception {
325N/A try (FileOutputStream fout = new FileOutputStream(OUTFILE)) {
325N/A String here = System.getProperty("test.src", "");
325N/A for (String file: files) {
325N/A Files.copy(Paths.get(here, file), fout);
325N/A }
325N/A }
325N/A try (FileInputStream fin = new FileInputStream(OUTFILE)) {
325N/A System.out.println("Testing " + Arrays.toString(files) + "...");
325N/A if (CertificateFactory.getInstance("X509")
.generateCertificates(fin)
.size() != files.length) {
throw new Exception("Not same number");
}
}
Files.delete(Paths.get(OUTFILE));
}
}