Skip to content

Commit 2acd877

Browse files
author
Alexey Semenyuk
committed
8371440: jpackage should exit with an error if it finds multiple matching signing certificates
Reviewed-by: almatvee
1 parent c8e64e7 commit 2acd877

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/SigningIdentityBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ private static X509Certificate selectSigningIdentity(List<X509Certificate> certs
156156
return certs.getFirst();
157157
}
158158
default -> {
159-
Log.error(I18N.format("error.multiple.certs.found", certificateSelector.signingIdentities().getFirst(),
160-
keychain.map(Keychain::name).orElse("")));
161-
return certs.getFirst();
159+
throw I18N.buildConfigException("error.multiple.certs.found",
160+
certificateSelector.signingIdentities().getFirst(),
161+
keychain.map(Keychain::name).orElse("")
162+
).create();
162163
}
163164
}
164165
}

src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ error.must-sign-app-store=Mac App Store apps must be signed, and signing has bee
3636
error.must-sign-app-store.advice=Use --mac-sign option with appropriate user-name and keychain
3737
error.certificate.expired=Error: Certificate expired {0}
3838
error.cert.not.found=No certificate found matching [{0}] using keychain [{1}]
39-
error.multiple.certs.found=WARNING: Multiple certificates found matching [{0}] using keychain [{1}], using first one
39+
error.multiple.certs.found=Multiple certificates matching name [{0}] found in keychain [{1}]
4040
error.app-image.mac-sign.required=Error: --mac-sign option is required with predefined application image and with type [app-image]
4141
error.tool.failed.with.output=Error: "{0}" failed with following output:
4242
error.invalid-runtime-image-missing-file=Runtime image "{0}" is missing "{1}" file

test/jdk/tools/jpackage/macosx/MacSignTest.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import jdk.jpackage.test.MacHelper;
4040
import jdk.jpackage.test.MacSign;
4141
import jdk.jpackage.test.MacSign.CertificateRequest;
42+
import jdk.jpackage.test.MacSign.CertificateType;
4243
import jdk.jpackage.test.MacSignVerify;
4344
import jdk.jpackage.test.PackageType;
4445
import jdk.jpackage.test.TKit;
@@ -155,30 +156,33 @@ public static void testExpiredCertificate(PackageType type, SignOption... option
155156
}
156157

157158
@Test
158-
// Case "--mac-signing-key-user-name": jpackage selects first certificate
159-
// found with warning message. Certificate hash is pass to "codesign" in this
160-
// case.
161-
@Parameter({"IMAGE", "0", "GOOD_SIGNING_KEY_USER_NAME"})
162-
@Parameter({"MAC_DMG", "0", "GOOD_SIGNING_KEY_USER_NAME"})
163-
@Parameter({"MAC_PKG", "0", "GOOD_SIGNING_KEY_USER_NAME_PKG", "GOOD_SIGNING_KEY_USER_NAME"})
164-
165-
// Case "--mac-app-image-sign-identity": sign identity will be pass to
166-
// "codesign" and "codesign" should fail due to multiple certificates with
167-
// same common name found.
168-
@Parameter({"IMAGE", "1", "GOOD_CODESIGN_SIGN_IDENTITY"})
169-
@Parameter({"MAC_PKG", "1", "GOOD_CODESIGN_SIGN_IDENTITY", "GOOD_PKG_SIGN_IDENTITY"})
170-
@Parameter({"MAC_PKG", "1", "GOOD_PKG_SIGN_IDENTITY"})
171-
public static void testMultipleCertificates(PackageType type, int jpackageExitCode, SignOption... options) {
159+
@Parameter({"IMAGE", "GOOD_SIGNING_KEY_USER_NAME"})
160+
@Parameter({"MAC_DMG", "GOOD_SIGNING_KEY_USER_NAME"})
161+
@Parameter({"MAC_PKG", "GOOD_SIGNING_KEY_USER_NAME_PKG", "GOOD_SIGNING_KEY_USER_NAME"})
162+
@Parameter({"IMAGE", "GOOD_CODESIGN_SIGN_IDENTITY"})
163+
@Parameter({"MAC_PKG", "GOOD_CODESIGN_SIGN_IDENTITY", "GOOD_PKG_SIGN_IDENTITY"})
164+
@Parameter({"MAC_PKG", "GOOD_PKG_SIGN_IDENTITY"})
165+
public static void testMultipleCertificates(PackageType type, SignOption... options) {
172166

173167
MacSign.withKeychain(keychain -> {
174168
final var cmd = MacHelper.useKeychain(JPackageCommand.helloAppImage(), keychain)
175169
.ignoreDefaultVerbose(true)
176170
.addArguments(Stream.of(options).map(SignOption::args).flatMap(List::stream).toList())
177171
.setPackageType(type);
178172

179-
SignOption.configureOutputValidation(cmd, List.of(options), opt -> {
173+
Predicate<SignOption> filter = opt -> {
174+
if (type == PackageType.MAC_PKG && options.length > 1) {
175+
// Only the first error will be reported and it should always be
176+
// for the app image signing, not for the PKG signing.
177+
return opt.identityType() == CertificateType.CODE_SIGN;
178+
} else {
179+
return true;
180+
}
181+
};
182+
183+
SignOption.configureOutputValidation(cmd, Stream.of(options).filter(filter).toList(), opt -> {
180184
return JPackageStringBundle.MAIN.cannedFormattedString("error.multiple.certs.found", opt.identityName(), keychain.name());
181-
}).execute(jpackageExitCode);
185+
}).execute(1);
182186
}, MacSign.Keychain.UsageBuilder::addToSearchList, SigningBase.StandardKeychain.DUPLICATE.keychain());
183187
}
184188

@@ -244,6 +248,10 @@ String identityName() {
244248
return cert.name();
245249
}
246250

251+
CertificateType identityType() {
252+
return cert.type();
253+
}
254+
247255
List<String> args() {
248256
return List.of(option, shortName ? cert.shortName() : cert.name());
249257
}

0 commit comments

Comments
 (0)