Skip to content

Commit 018d857

Browse files
committed
Handle password protected key stores properly
1 parent 5b8cda7 commit 018d857

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ GNU General Public License for more details.
1212

1313
![Install4j](http://certmgr.carne.de/install4j_small.png) The provided installer/launcher packages have been created using the multi-platform installer builder [Install4J](https://www.ej-technologies.com/products/install4j/overview.html).
1414

15-
### v1.1.3 (2020-03-xx)
15+
### v1.1.3 (2020-03-07)
16+
* Handle password protected key stores properly
1617
* BouncyCastle version bump 1.64
1718

1819
### v1.1.2 (2019-02-23)

RELEASE-v1.1.3-SNAPSHOT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This is a maintenance release of the CertMgr application.
33

44
Main changes are:
5+
* Handle password protected key stores properly
56
* BouncyCastle version bump 1.64
67

78
This program is distributed in the hope that it will be useful,

src/main/java/de/carne/certmgr/certs/io/JKSCertReaderWriter.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class JKSCertReaderWriter implements CertReader, CertWriter {
5353

5454
private static final Log LOG = new Log(CertIOI18N.class.getName());
5555

56-
private static final String KEYSTORE_TYPE = "JKS";
56+
private static final String KEYSTORE_TYPE_JKS = "JKS";
5757

5858
/**
5959
* Provider name.
@@ -85,7 +85,7 @@ public String fileExtension(Class<?> cls) {
8585
public CertObjectStore readBinary(IOResource<InputStream> in, PasswordCallback password) throws IOException {
8686
LOG.debug("Trying to read KeyStore objects from file: ''{0}''...", in);
8787

88-
return readKeyStore(KEYSTORE_TYPE, in.io(), in.resource(), password);
88+
return readKeyStore(KEYSTORE_TYPE_JKS, in.io(), in.resource(), password);
8989
}
9090

9191
@Override
@@ -119,7 +119,7 @@ public void writeEncryptedBinary(IOResource<OutputStream> out, CertObjectStore c
119119
throw new PasswordRequiredException(out.resource());
120120
}
121121
try {
122-
KeyStore keyStore = KeyStore.getInstance(KEYSTORE_TYPE);
122+
KeyStore keyStore = KeyStore.getInstance(KEYSTORE_TYPE_JKS);
123123

124124
keyStore.load(null, null);
125125

@@ -249,7 +249,7 @@ private static CertObjectStore readKeyStore(String keyStoreType, @Nullable Input
249249
private static KeyStore loadKeyStore(String keyStoreType, @Nullable InputStream inputStream, String resource,
250250
PasswordCallback password) throws GeneralSecurityException, IOException {
251251
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
252-
char[] passwordChars = null;
252+
char[] passwordChars = password.queryPassword(resource);
253253
Throwable passwordException = null;
254254

255255
do {
@@ -265,11 +265,8 @@ private static KeyStore loadKeyStore(String keyStoreType, @Nullable InputStream
265265
}
266266
if (passwordException != null) {
267267
passwordChars = password.requeryPassword(resource, passwordException);
268-
if (passwordChars == null) {
269-
throw new PasswordRequiredException(resource, passwordException);
270-
}
271268
}
272-
} while (passwordException != null);
269+
} while (passwordChars != null && passwordException != null);
273270
return keyStore;
274271
}
275272

0 commit comments

Comments
 (0)