NullPointerException when key is not available in the database (#25395)

* NullPointerException when key is not available in the database
Closes #24485
Signed-off-by: Douglas Palmer <dpalmer@redhat.com>


Co-authored-by: Alexander Schwartz <alexander.schwartz@gmx.net>
Co-authored-by: Thomas Darimont <thomas.darimont@googlemail.com>
This commit is contained in:
Douglas Palmer 2023-12-14 00:57:53 -08:00 committed by GitHub
parent 67d8a7ff9c
commit 4b11afa87b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View file

@ -88,6 +88,9 @@ public class KeystoreUtil {
throw new RuntimeException("Couldn't load key with alias '" + keyAlias + "' from keystore");
}
PublicKey publicKey = keyStore.getCertificate(keyAlias).getPublicKey();
if (publicKey == null) {
throw new RuntimeException("Couldn't load public key with alias '" + keyAlias + "' from keystore");
}
return new KeyPair(publicKey, privateKey);
} catch (Exception e) {
throw new RuntimeException("Failed to load private key: " + e.getMessage(), e);

View file

@ -44,6 +44,9 @@ public class ImportedRsaKeyProvider extends AbstractRsaKeyProvider {
String certificatePem = model.getConfig().getFirst(Attributes.CERTIFICATE_KEY);
PrivateKey privateKey = PemUtils.decodePrivateKey(privateRsaKeyPem);
if (privateKey == null) {
throw new RuntimeException("Key not found on the server. Check key for " + ImportedRsaKeyProviderFactory.ID + " in realm " + realm.getName());
}
PublicKey publicKey = KeyUtils.extractPublicKey(privateKey);
KeyPair keyPair = new KeyPair(publicKey, privateKey);