1 /* 2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import jdk.testlibrary.OutputAnalyzer; 25 import jdk.test.lib.util.JarUtils; 26 27 /** 28 * @test 29 * @bug 8024302 8026037 30 * @summary Test for notSignedByAlias warning 31 * @library /lib/testlibrary /test/lib ../ 32 * @build jdk.test.lib.util.JarUtils 33 * @run main NotSignedByAliasTest 34 */ 35 public class NotSignedByAliasTest extends Test { 36 37 /** 38 * The test signs and verifies a jar that contains signed entries 39 * which are not signed by the specified alias(es) (notSignedByAlias). 40 * Warning message is expected. 41 */ 42 public static void main(String[] args) throws Throwable { 43 NotSignedByAliasTest test = new NotSignedByAliasTest(); 44 test.start(); 45 } 46 47 protected void start() throws Throwable { 48 // create a jar file that contains one class file 49 Utils.createFiles(FIRST_FILE); 50 JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE); 51 52 createAlias(CA_KEY_ALIAS); 53 54 // create first key pair for signing 55 createAlias(FIRST_KEY_ALIAS); 56 issueCert( 57 FIRST_KEY_ALIAS, 58 "-validity", Integer.toString(VALIDITY)); 59 60 // create first key pair for signing 61 createAlias(SECOND_KEY_ALIAS); 62 issueCert( 63 SECOND_KEY_ALIAS, 64 "-validity", Integer.toString(VALIDITY)); 65 66 // sign jar with first key 67 OutputAnalyzer analyzer = jarsigner( 68 "-keystore", KEYSTORE, 69 "-storepass", PASSWORD, 70 "-keypass", PASSWORD, 71 "-signedjar", SIGNED_JARFILE, 72 UNSIGNED_JARFILE, 73 FIRST_KEY_ALIAS); 74 75 checkSigning(analyzer); 76 77 // verify jar with second key 78 analyzer = jarsigner( 79 "-verify", 80 "-keystore", KEYSTORE, 81 "-storepass", PASSWORD, 82 "-keypass", PASSWORD, 83 SIGNED_JARFILE, 84 SECOND_KEY_ALIAS); 85 86 checkVerifying(analyzer, 0, NOT_SIGNED_BY_ALIAS_VERIFYING_WARNING); 87 88 // verify jar with second key in strict mode 89 analyzer = jarsigner( 90 "-verify", 91 "-strict", 92 "-keystore", KEYSTORE, 93 "-storepass", PASSWORD, 94 "-keypass", PASSWORD, 95 SIGNED_JARFILE, 96 SECOND_KEY_ALIAS); 97 98 checkVerifying(analyzer, NOT_SIGNED_BY_ALIAS_EXIT_CODE, 99 NOT_SIGNED_BY_ALIAS_VERIFYING_WARNING); 100 101 // verify jar with non-existing alias 102 analyzer = jarsigner( 103 "-verify", 104 "-keystore", KEYSTORE, 105 "-storepass", PASSWORD, 106 "-keypass", PASSWORD, 107 SIGNED_JARFILE, 108 "bogus"); 109 110 checkVerifying(analyzer, 0, NOT_SIGNED_BY_ALIAS_VERIFYING_WARNING); 111 112 // verify jar with non-existing alias in strict mode 113 analyzer = jarsigner( 114 "-verify", 115 "-strict", 116 "-keystore", KEYSTORE, 117 "-storepass", PASSWORD, 118 "-keypass", PASSWORD, 119 SIGNED_JARFILE, 120 "bogus"); 121 122 checkVerifying(analyzer, NOT_SIGNED_BY_ALIAS_EXIT_CODE, 123 NOT_SIGNED_BY_ALIAS_VERIFYING_WARNING); 124 125 System.out.println("Test passed"); 126 } 127 128 }