Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Mar 6, 2018
1 parent 46da01c commit e003ee6
Showing 1 changed file with 12 additions and 5 deletions.
Expand Up @@ -104,9 +104,10 @@ public class ProtectorImpl extends BaseProtector {
private String digestAlgorithm;

private List<TrustManager> trustManagers;

private static final KeyStore keyStore;

private static final Map<String, SecretKey> aliasToSecretKeyHashMap = new HashMap<>();
private static final Map<SecretKey, String> secretKeyToDigestHashMap = new HashMap<>();
private static final Map<String, SecretKey> digestToSecretKeyHashMap = new HashMap<>();

static {
Expand Down Expand Up @@ -182,9 +183,8 @@ public void init() {

final String digest = Base64.encode(sha1.digest(key.getEncoded()));
LOGGER.trace("Calculated digest {} for key alias {}", digest, key);
secretKeyToDigestHashMap.put(secretKey, digest);
digestToSecretKeyHashMap.put(digest, secretKey);

} catch (UnrecoverableKeyException ex) {
LOGGER.trace("Couldn't recover key {} from keystore, reason: {}", new Object[]{alias, ex.getMessage()});
}
Expand Down Expand Up @@ -403,10 +403,17 @@ private Cipher getCipher(int cipherMode, String algorithmUri) throws NoSuchAlgor
return cipher;
}

/**
* TODO remove, used only in midpoint ninja cmd tool, not part of API
*/
@Deprecated
public String getSecretKeyDigest(SecretKey key) throws EncryptionException {
if (secretKeyToDigestHashMap.containsKey(key)) {
return secretKeyToDigestHashMap.get(key);
for (Map.Entry<String, SecretKey> entry : digestToSecretKeyHashMap.entrySet()) {
if (entry.getValue().equals(key)) {
return entry.getKey();
}
}

throw new EncryptionException("Could not find hash for secret key algorithm " + key.getAlgorithm()
+ ". Hash values for keys must be recomputed during initialization");
}
Expand Down

0 comments on commit e003ee6

Please sign in to comment.