|
25 | 25 |
|
26 | 26 | package jdk.jpackage.internal;
|
27 | 27 |
|
| 28 | +import java.io.ByteArrayOutputStream; |
28 | 29 | import java.io.IOException;
|
29 | 30 | import java.io.InputStream;
|
| 31 | +import java.io.PrintStream; |
30 | 32 | import java.io.Writer;
|
31 | 33 | import java.nio.file.Files;
|
32 | 34 | import java.nio.file.Path;
|
|
53 | 55 | import jdk.internal.util.OSVersion;
|
54 | 56 | import static jdk.jpackage.internal.MacAppBundler.BUNDLE_ID_SIGNING_PREFIX;
|
55 | 57 | import static jdk.jpackage.internal.MacAppBundler.DEVELOPER_ID_APP_SIGNING_KEY;
|
| 58 | +import static jdk.jpackage.internal.MacAppBundler.APP_IMAGE_SIGN_IDENTITY; |
56 | 59 | import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEYCHAIN;
|
| 60 | +import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER; |
| 61 | +import static jdk.jpackage.internal.MacBaseInstallerBundler.INSTALLER_SIGN_IDENTITY; |
57 | 62 | import static jdk.jpackage.internal.OverridableResource.createResource;
|
58 | 63 | import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
|
59 | 64 | import static jdk.jpackage.internal.StandardBundlerParam.CONFIG_ROOT;
|
@@ -395,12 +400,25 @@ private void doSigning(Map<String, ? super Object> params)
|
395 | 400 | } catch (InterruptedException e) {
|
396 | 401 | Log.error(e.getMessage());
|
397 | 402 | }
|
398 |
| - String signingIdentity = |
399 |
| - DEVELOPER_ID_APP_SIGNING_KEY.fetchFrom(params); |
| 403 | + String signingIdentity = null; |
| 404 | + // Try --mac-app-image-sign-identity first if set |
| 405 | + if (!APP_IMAGE_SIGN_IDENTITY.getIsDefaultValue(params)) { |
| 406 | + signingIdentity = APP_IMAGE_SIGN_IDENTITY.fetchFrom(params); |
| 407 | + } else { |
| 408 | + // Check if INSTALLER_SIGN_IDENTITY is set and if it is set |
| 409 | + // then do not sign app image, otherwise use --mac-signing-key-user-name |
| 410 | + if (INSTALLER_SIGN_IDENTITY.getIsDefaultValue(params)) { |
| 411 | + // --mac-sign and/or --mac-signing-key-user-name case |
| 412 | + signingIdentity = DEVELOPER_ID_APP_SIGNING_KEY.fetchFrom(params); |
| 413 | + } |
| 414 | + } |
400 | 415 | if (signingIdentity != null) {
|
401 | 416 | signAppBundle(params, root, signingIdentity,
|
402 | 417 | BUNDLE_ID_SIGNING_PREFIX.fetchFrom(params),
|
403 | 418 | ENTITLEMENTS.fetchFrom(params));
|
| 419 | + } else { |
| 420 | + // Case when user requested to sign installer only |
| 421 | + signAppBundle(params, root, "-", null, null); |
404 | 422 | }
|
405 | 423 | restoreKeychainList(params);
|
406 | 424 | } else if (OperatingSystem.isMacOS()) {
|
@@ -715,6 +733,25 @@ private static List<String> getCodesignArgs(
|
715 | 733 | return args;
|
716 | 734 | }
|
717 | 735 |
|
| 736 | + private static void runCodesign(ProcessBuilder pb, boolean quiet) |
| 737 | + throws IOException { |
| 738 | + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 739 | + PrintStream ps = new PrintStream(baos)) { |
| 740 | + try { |
| 741 | + IOUtils.exec(pb, false, ps, false, |
| 742 | + Executor.INFINITE_TIMEOUT, quiet); |
| 743 | + } catch (IOException ioe) { |
| 744 | + // Log output of "codesign" in case of |
| 745 | + // error. It should help user to diagnose |
| 746 | + // issue when using --mac-app-image-sign-identity |
| 747 | + Log.info(MessageFormat.format(I18N.getString( |
| 748 | + "error.tool.failed.with.output"), "codesign")); |
| 749 | + Log.info(baos.toString().strip()); |
| 750 | + throw ioe; |
| 751 | + } |
| 752 | + } |
| 753 | + } |
| 754 | + |
718 | 755 | static void signAppBundle(
|
719 | 756 | Map<String, ? super Object> params, Path appLocation,
|
720 | 757 | String signingIdentity, String identifierPrefix, Path entitlements)
|
@@ -781,8 +818,7 @@ static void signAppBundle(
|
781 | 818 | p.toFile().setWritable(true, true);
|
782 | 819 | ProcessBuilder pb = new ProcessBuilder(args);
|
783 | 820 | // run quietly
|
784 |
| - IOUtils.exec(pb, false, null, false, |
785 |
| - Executor.INFINITE_TIMEOUT, true); |
| 821 | + runCodesign(pb, true); |
786 | 822 | Files.setPosixFilePermissions(p, oldPermissions);
|
787 | 823 | } catch (IOException ioe) {
|
788 | 824 | toThrow.set(ioe);
|
@@ -810,8 +846,7 @@ static void signAppBundle(
|
810 | 846 | List<String> args = getCodesignArgs(true, path, signingIdentity,
|
811 | 847 | identifierPrefix, entitlements, keyChain);
|
812 | 848 | ProcessBuilder pb = new ProcessBuilder(args);
|
813 |
| - |
814 |
| - IOUtils.exec(pb); |
| 849 | + runCodesign(pb, false); |
815 | 850 | } catch (IOException e) {
|
816 | 851 | toThrow.set(e);
|
817 | 852 | }
|
@@ -842,8 +877,7 @@ static void signAppBundle(
|
842 | 877 | List<String> args = getCodesignArgs(true, appLocation, signingIdentity,
|
843 | 878 | identifierPrefix, entitlements, keyChain);
|
844 | 879 | ProcessBuilder pb = new ProcessBuilder(args);
|
845 |
| - |
846 |
| - IOUtils.exec(pb); |
| 880 | + runCodesign(pb, false); |
847 | 881 | }
|
848 | 882 |
|
849 | 883 | private static String extractBundleIdentifier(Map<String, Object> params) {
|
|
0 commit comments