1 /* 2 * Copyright (c) 2019, 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 java.nio.file.Path; 25 import java.nio.file.Paths; 26 import jdk.jpackage.test.*; 27 28 /** 29 * Tests generation of dmg and pkg with --mac-sign and related arguments. Test will 30 * generate pkg and verifies its signature. It verifies that dmg is not signed, but app 31 * image inside dmg is signed. This test requires that machine is configured with test 32 * certificate for "Developer ID Installer: jpackage.openjdk.java.net" in jpackagerTest 33 * keychain with always allowed access to this keychain for user which runs test. 34 */ 35 36 /* 37 * @test 38 * @summary jpackage with --type pkg,dmg --mac-sign 39 * @library ../helpers 40 * @library /test/lib 41 * @library base 42 * @key jpackagePlatformPackage 43 * @build SigningBase 44 * @build SigningCheck 45 * @build jtreg.SkippedException 46 * @build jdk.jpackage.test.* 47 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal 48 * @requires (os.family == "mac") 49 * @run main/othervm -Xmx512m SigningPackageTest 50 */ 51 public class SigningPackageTest { 52 53 private static void verifyPKG(JPackageCommand cmd) { 54 Path outputBundle = cmd.outputBundle(); 55 SigningBase.verifyPkgutil(outputBundle); 56 SigningBase.verifySpctl(outputBundle, "install"); 57 } 58 59 private static void verifyDMG(JPackageCommand cmd) { 60 Path outputBundle = cmd.outputBundle(); 61 SigningBase.verifyCodesign(outputBundle, false); 62 } 63 64 private static void verifyAppImageInDMG(JPackageCommand cmd) { 65 MacHelper.withExplodedDmg(cmd, dmgImage -> { 66 Path launcherPath = dmgImage.resolve(Path.of("Contents", "MacOS", cmd.name())); 67 SigningBase.verifyCodesign(launcherPath, true); 68 SigningBase.verifyCodesign(dmgImage, true); 69 SigningBase.verifySpctl(dmgImage, "exec"); 70 }); 71 } 72 73 public static void main(String[] args) throws Exception { 74 TKit.run(args, () -> { 75 SigningCheck.checkCertificates(); 76 77 new PackageTest() 78 .configureHelloApp() 79 .forTypes(PackageType.MAC) 80 .addInitializer(cmd -> { 81 cmd.addArguments("--mac-sign", 82 "--mac-signing-key-user-name", SigningBase.DEV_NAME, 83 "--mac-signing-keychain", "jpackagerTest.keychain"); 84 }) 85 .forTypes(PackageType.MAC_PKG) 86 .addBundleVerifier(SigningPackageTest::verifyPKG) 87 .forTypes(PackageType.MAC_DMG) 88 .addBundleVerifier(SigningPackageTest::verifyDMG) 89 .addBundleVerifier(SigningPackageTest::verifyAppImageInDMG) 90 .run(); 91 }); 92 } 93 }