use of org.keycloak.crypto.KeyWrapper in project keycloak by keycloak.
the class AbstractEcdsaKeyProvider method createKeyWrapper.
protected KeyWrapper createKeyWrapper(KeyPair keyPair, String ecInNistRep) {
KeyWrapper key = new KeyWrapper();
key.setProviderId(model.getId());
key.setProviderPriority(model.get("priority", 0l));
key.setKid(KeyUtils.createKeyId(keyPair.getPublic()));
key.setUse(KeyUse.SIG);
key.setType(KeyType.EC);
key.setAlgorithm(AbstractEcdsaKeyProviderFactory.convertECDomainParmNistRepToAlgorithm(ecInNistRep));
key.setStatus(status);
key.setPrivateKey(keyPair.getPrivate());
key.setPublicKey(keyPair.getPublic());
return key;
}
use of org.keycloak.crypto.KeyWrapper in project keycloak by keycloak.
the class OAuthClient method findKey.
private KeyWrapper findKey(JSONWebKeySet jsonWebKeySet, String algoritm, String kid) {
for (JWK k : jsonWebKeySet.getKeys()) {
if (k.getKeyId().equals(kid) && k.getAlgorithm().equals(algoritm)) {
PublicKey publicKey = JWKParser.create(k).toPublicKey();
KeyWrapper key = new KeyWrapper();
key.setKid(k.getKeyId());
key.setAlgorithm(k.getAlgorithm());
key.setPublicKey(publicKey);
key.setUse(KeyUse.SIG);
return key;
}
}
return null;
}
use of org.keycloak.crypto.KeyWrapper in project keycloak by keycloak.
the class OAuthClient method createSigner.
public SignatureSignerContext createSigner(PrivateKey privateKey, String kid, String algorithm) {
KeyWrapper keyWrapper = new KeyWrapper();
keyWrapper.setAlgorithm(algorithm);
keyWrapper.setKid(kid);
keyWrapper.setPrivateKey(privateKey);
SignatureSignerContext signer;
switch(algorithm) {
case Algorithm.ES256:
case Algorithm.ES384:
case Algorithm.ES512:
signer = new ServerECDSASignatureSignerContext(keyWrapper);
break;
default:
signer = new AsymmetricSignatureSignerContext(keyWrapper);
}
return signer;
}
use of org.keycloak.crypto.KeyWrapper in project keycloak by keycloak.
the class OAuthClient method getRealmPublicKey.
private KeyWrapper getRealmPublicKey(String realm, String algoritm, String kid) {
boolean loadedKeysFromServer = false;
JSONWebKeySet jsonWebKeySet = publicKeys.get(realm);
if (jsonWebKeySet == null) {
jsonWebKeySet = getRealmKeys(realm);
publicKeys.put(realm, jsonWebKeySet);
loadedKeysFromServer = true;
}
KeyWrapper key = findKey(jsonWebKeySet, algoritm, kid);
if (key == null && !loadedKeysFromServer) {
jsonWebKeySet = getRealmKeys(realm);
publicKeys.put(realm, jsonWebKeySet);
key = findKey(jsonWebKeySet, algoritm, kid);
}
if (key == null) {
throw new RuntimeException("Public key for realm:" + realm + ", algorithm: " + algoritm + " not found");
}
return key;
}
Aggregations