Path: blob/master/test/jdk/sun/security/tools/jarsigner/EC.java
41152 views
/*1* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 687081226* @summary enhance security tools to use ECC algorithm27* @library /test/lib28*/2930import jdk.test.lib.SecurityTools;31import jdk.test.lib.process.OutputAnalyzer;32import jdk.test.lib.util.JarUtils;3334import java.nio.file.Files;35import java.nio.file.Path;36import java.util.List;3738public class EC {39static OutputAnalyzer kt(String cmd) throws Exception {40return SecurityTools.keytool("-storepass changeit "41+ "-keypass changeit -keystore ks " + cmd);42}4344static void gencert(String owner, String cmd) throws Exception {45kt("-certreq -alias " + owner + " -file tmp.req")46.shouldHaveExitValue(0);47kt("-gencert -infile tmp.req -outfile tmp.cert " + cmd)48.shouldHaveExitValue(0);49kt("-import -alias " + owner + " -file tmp.cert")50.shouldHaveExitValue(0);51}5253static OutputAnalyzer js(String cmd) throws Exception {54return SecurityTools.jarsigner("-keystore ks -storepass changeit " + cmd);55}5657public static void main(String[] args) throws Exception {58Files.write(Path.of("A"), List.of("A"));59JarUtils.createJarFile(Path.of("a.jar"), Path.of("."), Path.of("A"));6061kt("-alias ca -dname CN=ca -keyalg ec -genkey -validity 300 -ext bc:c")62.shouldHaveExitValue(0);63kt("-alias a -dname CN=a -keyalg ec -genkey")64.shouldHaveExitValue(0);65gencert("a", "-alias ca -validity 300");6667kt("-alias b -dname CN=b -keyalg ec -genkey")68.shouldHaveExitValue(0);69gencert("b", "-alias ca -validity 300");7071// Ensure key length sufficient for intended hash (SHA512withECDSA)72kt("-alias c -dname CN=c -keyalg ec -genkey -keysize 521")73.shouldHaveExitValue(0);74gencert("c", "-alias ca -validity 300");7576kt("-alias x -dname CN=x -keyalg ec -genkey -validity 300")77.shouldHaveExitValue(0);78gencert("x", "-alias ca -validity 300");7980js("a.jar a -debug -strict").shouldHaveExitValue(0);81js("a.jar b -debug -strict -sigalg SHA256withECDSA").shouldHaveExitValue(0);82js("a.jar c -debug -strict -sigalg SHA512withECDSA").shouldHaveExitValue(0);8384js("-verify a.jar a -debug -strict").shouldHaveExitValue(0);85js("-verify a.jar b -debug -strict").shouldHaveExitValue(0);86js("-verify a.jar c -debug -strict").shouldHaveExitValue(0);8788// Not signed by x, should exit with non-zero89js("-verify a.jar x -debug -strict").shouldNotHaveExitValue(0);90}91}929394