Skip to content

Commit ed82d53

Browse files
committed
Removed KeyStoreType.reuseKeyStorePassword()
1 parent 1d21642 commit ed82d53

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

jsign-cli/src/test/java/net/jsign/JsignCLITest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,17 @@ public void testSigningJCEKS() throws Exception {
327327
}
328328
}
329329

330+
@Test
331+
public void testSigningJKS() throws Exception {
332+
cli.execute("--name=WinEyes", "--url=http://www.steelblue.com/WinEyes", "--alg=SHA-256", "--keystore=target/test-classes/keystores/keystore.jks", "--alias=test", "--storepass=password", "" + targetFile);
333+
334+
assertTrue("The file " + targetFile + " wasn't changed", SOURCE_FILE_CRC32 != FileUtils.checksumCRC32(targetFile));
335+
336+
try (PEFile peFile = new PEFile(targetFile)) {
337+
SignatureAssert.assertSigned(peFile, SHA256);
338+
}
339+
}
340+
330341
@Test
331342
public void testSigningPVKSPC() throws Exception {
332343
cli.execute("--url=http://www.steelblue.com/WinEyes", "--certfile=target/test-classes/keystores/jsign-test-certificate-full-chain.spc", "--keyfile=target/test-classes/keystores/privatekey-encrypted.pvk", "--storepass=password", "" + targetFile);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,8 @@ private AuthenticodeSigner build() throws SignerException {
383383
}
384384
}
385385

386-
String storepass = ksparams.storepass();
387386
String keypass = ksparams.keypass();
388-
char[] password = keypass != null ? keypass.toCharArray() : null;
389-
if (password == null && storepass != null && storetype.reuseKeyStorePassword()) {
390-
// use the storepass as the keypass
391-
password = storepass.toCharArray();
392-
}
387+
char[] password = keypass != null ? keypass.toCharArray() : new char[0];
393388

394389
PrivateKey privateKey;
395390
try {

jsign-crypto/src/main/java/net/jsign/KeyStoreType.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ KeyStore getKeystore(KeyStoreBuilder params, Provider provider) throws KeyStoreE
100100
try {
101101
ks.load(null, null);
102102
String keypass = params.keypass();
103-
if (keypass == null) {
104-
keypass = params.storepass();
105-
}
106103
ks.setKeyEntry("jsign", privateKey, keypass != null ? keypass.toCharArray() : new char[0], chain);
107104
} catch (Exception e) {
108105
throw new KeyStoreException(e);
@@ -122,6 +119,10 @@ void validate(KeyStoreBuilder params) {
122119
if (!params.createFile(params.keystore()).exists()) {
123120
throw new IllegalArgumentException("The keystore " + params.keystore() + " couldn't be found");
124121
}
122+
if (params.keypass() == null && params.storepass() != null) {
123+
// reuse the storepass as the keypass
124+
params.keypass(params.storepass());
125+
}
125126
}
126127
},
127128

@@ -135,6 +136,10 @@ void validate(KeyStoreBuilder params) {
135136
if (!params.createFile(params.keystore()).exists()) {
136137
throw new IllegalArgumentException("The keystore " + params.keystore() + " couldn't be found");
137138
}
139+
if (params.keypass() == null && params.storepass() != null) {
140+
// reuse the storepass as the keypass
141+
params.keypass(params.storepass());
142+
}
138143
}
139144
},
140145

@@ -148,6 +153,10 @@ void validate(KeyStoreBuilder params) {
148153
if (!params.createFile(params.keystore()).exists()) {
149154
throw new IllegalArgumentException("The keystore " + params.keystore() + " couldn't be found");
150155
}
156+
if (params.keypass() == null && params.storepass() != null) {
157+
// reuse the storepass as the keypass
158+
params.keypass(params.storepass());
159+
}
151160
}
152161
},
153162

@@ -385,11 +394,6 @@ Provider getProvider(KeyStoreBuilder params) {
385394
throw new IllegalStateException("Authentication failed with SSL.com", e);
386395
}
387396
}
388-
389-
@Override
390-
boolean reuseKeyStorePassword() {
391-
return false;
392-
}
393397
},
394398

395399
/**
@@ -656,13 +660,6 @@ Set<String> getAliases(KeyStore keystore) throws KeyStoreException {
656660
return new LinkedHashSet<>(Collections.list(keystore.aliases()));
657661
}
658662

659-
/**
660-
* Tells if the keystore password can be reused as the key password.
661-
*/
662-
boolean reuseKeyStorePassword() {
663-
return true;
664-
}
665-
666663
/**
667664
* Guess the type of the keystore from the header or the extension of the file.
668665
*

0 commit comments

Comments
 (0)