Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: select first sig key if none requested #2494

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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