Skip to content

Commit 7cac328

Browse files
committed
Add log statements, use Keystore file path for key in Keystore-Password map.
1 parent 73571a8 commit 7cac328

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

core/src/main/java/net/sourceforge/jnlp/security/KeystorePasswordAttempter.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,23 @@ public KeystoreOperation(KeyManagerFactory kmf, KeyStore ks, String alias, Key k
127127
abstract String getId();
128128

129129
}
130-
//static final KeystorePasswordAttempter INSTANCE = new KeystorePasswordAttempter(new SavedPassword(getTrustedCertsPassword()), new AlmightyPassword());
130+
131131
static final KeystorePasswordAttempter INSTANCE = new KeystorePasswordAttempter(new SavedPassword(getTrustedCertsPassword()));
132132
private final List<SavedPassword> passes;
133-
private final Map<KeyStore, SavedPassword> successfulPerKeystore = new HashMap<>();
133+
private final Map<String, SavedPassword> successfulPerKeystore = new HashMap<>();
134134

135135
private KeystorePasswordAttempter(SavedPassword... initialPasswords) {
136136
passes = new ArrayList<>(initialPasswords.length);
137137
passes.addAll(Arrays.asList(initialPasswords));
138138
}
139139

140140
Key unlockKeystore(KeystoreOperation operation) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, IOException, CertificateException {
141-
SavedPassword successfulKey = successfulPerKeystore.get(operation.ks);
141+
final String keyStoreFileName = operation.f != null ? operation.f.getAbsolutePath() : "Unknown";
142+
SavedPassword successfulKey = successfulPerKeystore.get(keyStoreFileName);
143+
LOG.debug("unlockKeyStore: For file {}, found successful pass = {} ", keyStoreFileName, successfulKey != null);
144+
142145
Exception firstEx = null;
143146
String messages = "";
144-
final String keyStoreFileName = operation.f != null ? operation.f.toString() : "Unknown";
145147
List<SavedPassword> localPasses = new ArrayList<>();
146148
if (successfulKey != null){
147149
//successful must be first. If it is not, then writing to keystore by illegal password, will kill keystore's integrity
@@ -151,14 +153,17 @@ Key unlockKeystore(KeystoreOperation operation) throws KeyStoreException, NoSuch
151153
for (int i = 0; i < localPasses.size(); i++) {
152154
SavedPassword pass = localPasses.get(i);
153155
try {
154-
LOG.debug("Operating Keystore {}", keyStoreFileName);
156+
LOG.debug("unlockKeyStore: Operating Keystore {}", keyStoreFileName);
155157
//we expect, that any keystore is loaded before read.
156158
//so we are writing by correct password
157159
//if no successful password was provided during reading, then finish(firstEx); will save us from overwrite
158160
Key result = operation.operateKeystore(pass.pass);
159161
//ok we were successful
160162
//save the loading password for storing purposes (and another reading too)
161-
successfulPerKeystore.put(operation.ks, pass);
163+
if (!keyStoreFileName.equals("Unknown")) {
164+
LOG.debug("Store successful pass for key {}", keyStoreFileName);
165+
successfulPerKeystore.put(keyStoreFileName, pass);
166+
}
162167
return result;
163168
} catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException | IOException | CertificateException ex) {
164169
if (firstEx == null) {
@@ -216,5 +221,4 @@ private void finish(Exception ex) throws KeyStoreException, NoSuchAlgorithmExcep
216221
throw new RuntimeException("Unexpected exception", ex);
217222
}
218223
}
219-
220224
}

0 commit comments

Comments
 (0)