Skip to content

Commit

Permalink
fix: select first sig key if none requested (#2494)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurem committed Sep 28, 2022
1 parent 9f646ff commit 31fb464
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,15 @@ private static Token request(final String tokenUrl, final String clientKeyStoreF

try {
String tmpKeyId = keyId;
if (StringHelper.isEmpty(tmpKeyId)) {
if (StringHelper.isEmpty(keyId)) {
// Get first key
List<String> aliases = cryptoProvider.getKeys();
if (!aliases.isEmpty()) {
tmpKeyId = aliases.get(0);
}
}
tmpKeyId = cryptoProvider.getKeys().stream().filter(k -> k.contains("_sig_")).findFirst().orElse(null);

if (StringHelper.isEmpty(tmpKeyId)) {
throw new UmaException("UMA keyId is empty");
if (StringHelper.isEmpty(tmpKeyId)) {
throw new UmaException("Unable to find a key in the keystore with use = sig");
}
} else if (keyId.contains("_enc_")) {
throw new UmaException("Encryption keys not allowed. Supply a key having use = sig");
}

SignatureAlgorithm algorithm = cryptoProvider.getSignatureAlgorithm(tmpKeyId);
Expand Down

0 comments on commit 31fb464

Please sign in to comment.