use of io.jans.as.model.jwk.JSONWebKey in project jans by JanssenProject.
the class JwksResource method getKeyById.
@GET
@ProtectedApi(scopes = { ApiAccessConstants.JWKS_READ_ACCESS })
@Path(ApiConstants.KID_PATH)
public Response getKeyById(@PathParam(ApiConstants.KID) @NotNull String kid) {
log.debug("Fetch JWK details by kid = " + kid);
WebKeysConfiguration webkeys = configurationService.findConf().getWebKeys();
log.debug("WebKeysConfiguration before addding new key =" + webkeys);
JSONWebKey jwk = getJSONWebKey(webkeys, kid);
return Response.ok(jwk).build();
}
use of io.jans.as.model.jwk.JSONWebKey in project jans by JanssenProject.
the class KeyGeneratorService method generateKeys.
private JSONWebKeySet generateKeys(List<Algorithm> signatureAlgorithms, List<Algorithm> encryptionAlgorithms, int expiration_hours) {
LOG.trace("Generating jwks keys...");
JSONWebKeySet jwks = new JSONWebKeySet();
Calendar calendar = new GregorianCalendar();
calendar.add(Calendar.HOUR, expiration_hours);
for (Algorithm algorithm : signatureAlgorithms) {
try {
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.fromString(algorithm.name());
JSONObject result = this.cryptoProvider.generateKey(algorithm, calendar.getTimeInMillis());
JSONWebKey key = JSONWebKey.fromJSONObject(result);
jwks.getKeys().add(key);
} catch (Exception ex) {
LOG.error(ex.getMessage(), ex);
}
}
for (Algorithm algorithm : encryptionAlgorithms) {
try {
KeyEncryptionAlgorithm encryptionAlgorithm = KeyEncryptionAlgorithm.fromName(algorithm.getParamName());
JSONObject result = this.cryptoProvider.generateKey(algorithm, calendar.getTimeInMillis());
JSONWebKey key = JSONWebKey.fromJSONObject(result);
jwks.getKeys().add(key);
} catch (Exception ex) {
LOG.error(ex.getMessage(), ex);
}
}
// LOG.trace("jwks: ", jwks);
LOG.trace("jwks generated successfully.");
return jwks;
}
use of io.jans.as.model.jwk.JSONWebKey in project jans by JanssenProject.
the class TokenRestWebServiceImpl method runDPoP.
private String runDPoP(HttpServletRequest httpRequest) throws InvalidJwtException, JWKException, NoSuchAlgorithmException, NoSuchProviderException {
String dpopStr = httpRequest.getHeader(TokenRequestParam.DPOP);
if (StringUtils.isBlank(dpopStr))
return null;
Jwt dpop = Jwt.parseOrThrow(dpopStr);
JSONWebKey jwk = JSONWebKey.fromJSONObject(dpop.getHeader().getJwk());
String dpopJwkThumbprint = jwk.getJwkThumbprint();
if (dpopJwkThumbprint == null)
throw new InvalidJwtException("Invalid DPoP Proof Header. The jwk header is not valid.");
return dpopJwkThumbprint;
}
use of io.jans.as.model.jwk.JSONWebKey in project jans by JanssenProject.
the class JwkResponse method getKeys.
public List<JSONWebKey> getKeys(Algorithm algorithm) {
List<JSONWebKey> jsonWebKeys = new ArrayList<JSONWebKey>();
if (AlgorithmFamily.RSA.equals(algorithm.getFamily())) {
for (JSONWebKey jsonWebKey : jwks.getKeys()) {
if (jsonWebKey.getAlg().equals(algorithm)) {
jsonWebKeys.add(jsonWebKey);
}
}
} else if (AlgorithmFamily.EC.equals(algorithm.getFamily())) {
for (JSONWebKey jsonWebKey : jwks.getKeys()) {
if (jsonWebKey.getAlg().equals(algorithm)) {
jsonWebKeys.add(jsonWebKey);
}
}
}
Collections.sort(jsonWebKeys, KeySelectionStrategy.compareExp());
return jsonWebKeys;
}
use of io.jans.as.model.jwk.JSONWebKey in project jans by JanssenProject.
the class JwkResponse method getPublicKey.
@Deprecated
public PublicKey getPublicKey(String keyId) {
PublicKey publicKey = null;
JSONWebKey JSONWebKey = getKeyValue(keyId);
if (JSONWebKey != null) {
switch(JSONWebKey.getKty()) {
case RSA:
publicKey = new RSAPublicKey(JSONWebKey.getN(), JSONWebKey.getE());
break;
case EC:
publicKey = new ECDSAPublicKey(SignatureAlgorithm.fromString(JSONWebKey.getAlg().getParamName()), JSONWebKey.getX(), JSONWebKey.getY());
break;
default:
break;
}
}
return publicKey;
}
Aggregations