Skip to content

Commit 51bb816

Browse files
committed
Properly handle the certfile parameter with the Google Cloud store type (Fixes #91)
1 parent 8fa88ac commit 51bb816

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

jsign-core/src/main/java/net/jsign/SignerHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ private AuthenticodeSigner build() throws SignerException {
361361
if (chain == null) {
362362
throw new SignerException("No certificate found under the alias '" + alias + "' in the keystore " + (provider != null ? provider.getName() : keystore) + " (available aliases: " + String.join(", ", aliases) + ")");
363363
}
364-
if (certfile != null) {
364+
if (certfile != null && !"GOOGLECLOUD".equals(storetype)) {
365365
if (chain.length != 1) {
366366
throw new SignerException("certfile " + parameterName + " can only be specified if the certificate from the keystore contains only one entry");
367367
}

jsign-core/src/test/java/net/jsign/SignerHelperTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import net.jsign.jca.Azure;
3030
import net.jsign.jca.DigiCertONE;
31+
import net.jsign.jca.GoogleCloud;
3132
import net.jsign.pe.PEFile;
3233

3334
import static org.junit.Assert.*;
@@ -100,6 +101,36 @@ public void testAzureKeyVault() throws Exception {
100101
assertEquals("Digest algorithm", NISTObjectIdentifiers.id_sha256, si.getDigestAlgorithmID().getAlgorithm());
101102
}
102103

104+
@Test
105+
public void testGoogleCloud() throws Exception {
106+
File sourceFile = new File("target/test-classes/wineyes.exe");
107+
File targetFile = new File("target/test-classes/wineyes-signed-with-signing-service.exe");
108+
109+
FileUtils.copyFile(sourceFile, targetFile);
110+
111+
SignerHelper helper = new SignerHelper(new StdOutConsole(1), "option")
112+
.storetype("GOOGLECLOUD")
113+
.keystore("projects/fifth-glider-316809/locations/global/keyRings/jsignkeyring")
114+
.storepass(GoogleCloud.getAccessToken())
115+
.alias("test")
116+
.certfile("src/test/resources/keystores/jsign-test-certificate-full-chain-reversed.pem")
117+
.alg("SHA-256");
118+
119+
helper.sign(targetFile);
120+
121+
PEFile peFile = new PEFile(targetFile);
122+
List<CMSSignedData> signatures = peFile.getSignatures();
123+
assertNotNull(signatures);
124+
assertEquals(1, signatures.size());
125+
126+
CMSSignedData signedData = signatures.get(0);
127+
assertNotNull(signedData);
128+
129+
// Check the signature algorithm
130+
SignerInformation si = signedData.getSignerInfos().getSigners().iterator().next();
131+
assertEquals("Digest algorithm", NISTObjectIdentifiers.id_sha256, si.getDigestAlgorithmID().getAlgorithm());
132+
}
133+
103134
@Test
104135
public void testDigiCertONE() throws Exception {
105136
String apikey = DigiCertONE.getApiKey();

0 commit comments

Comments
 (0)