use of io.jans.as.model.exception.CryptoProviderException in project jans by JanssenProject.
the class AuthCryptoProvider method getPrivateKey.
@Override
public PrivateKey getPrivateKey(String alias) throws CryptoProviderException {
if (Util.isNullOrEmpty(alias)) {
return null;
}
try {
Key key = keyStore.getKey(alias, keyStoreSecret.toCharArray());
if (key == null) {
return null;
}
PrivateKey privateKey = (PrivateKey) key;
checkKeyExpiration(alias);
return privateKey;
} catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException e) {
throw new CryptoProviderException(e);
}
}
use of io.jans.as.model.exception.CryptoProviderException in project jans by JanssenProject.
the class ElevenCryptoProvider method sign.
@Override
public String sign(String signingInput, String keyId, String shardSecret, SignatureAlgorithm signatureAlgorithm) throws CryptoProviderException {
SignRequest request = new SignRequest();
request.getSignRequestParam().setSigningInput(signingInput);
request.getSignRequestParam().setAlias(keyId);
request.getSignRequestParam().setSharedSecret(shardSecret);
request.getSignRequestParam().setSignatureAlgorithm(signatureAlgorithm.getName());
request.setAccessToken(accessToken);
SignClient client = new SignClient(signEndpoint);
client.setRequest(request);
SignResponse response = null;
try {
response = client.exec();
} catch (Exception e) {
throw new CryptoProviderException(e);
}
if (response.getStatus() == HttpStatus.SC_OK && response.getSignature() != null) {
return response.getSignature();
} else {
throw new CryptoProviderException(response.getEntity());
}
}
use of io.jans.as.model.exception.CryptoProviderException in project jans by JanssenProject.
the class ElevenCryptoProvider method deleteKey.
@Override
public boolean deleteKey(String keyId) throws CryptoProviderException {
DeleteKeyRequest request = new DeleteKeyRequest();
request.setAlias(keyId);
request.setAccessToken(accessToken);
DeleteKeyClient client = new DeleteKeyClient(deleteKeyEndpoint);
client.setRequest(request);
DeleteKeyResponse response = null;
try {
response = client.exec();
} catch (Exception e) {
throw new CryptoProviderException(e);
}
if (response.getStatus() == HttpStatus.SC_OK) {
return response.isDeleted();
} else {
throw new CryptoProviderException(response.getEntity());
}
}
use of io.jans.as.model.exception.CryptoProviderException in project jans by JanssenProject.
the class ServerCryptoProvider method getKeyId.
@Override
public String getKeyId(JSONWebKeySet jsonWebKeySet, Algorithm algorithm, Use use) throws CryptoProviderException {
try {
if (algorithm == null || AlgorithmFamily.HMAC.equals(algorithm.getFamily())) {
return null;
}
final AppConfiguration appConfiguration = configurationFactory.getAppConfiguration();
if (appConfiguration.getKeySignWithSameKeyButDiffAlg()) {
// open banking: same key with different algorithms
LOG.trace("Getting key by use: " + use);
for (JSONWebKey key : jsonWebKeySet.getKeys()) {
if (use != null && use == key.getUse()) {
LOG.trace("Found " + key.getKid() + ", use: " + use);
return key.getKid();
}
}
}
final String staticKid = appConfiguration.getStaticKid();
if (StringUtils.isNotBlank(staticKid)) {
LOG.trace("Use staticKid: " + staticKid);
return staticKid;
}
final String kid = cryptoProvider.getKeyId(jsonWebKeySet, algorithm, use);
if (!cryptoProvider.getKeys().contains(kid) && configurationFactory.reloadConfFromLdap()) {
return cryptoProvider.getKeyId(jsonWebKeySet, algorithm, use);
}
return kid;
} catch (CryptoProviderException e) {
LOG.trace("Try to re-load configuration due to keystore exception (it can be rotated).");
if (configurationFactory.reloadConfFromLdap()) {
return cryptoProvider.getKeyId(jsonWebKeySet, algorithm, use);
}
}
return null;
}
use of io.jans.as.model.exception.CryptoProviderException in project jans by JanssenProject.
the class AuthCryptoProvider method getPublicKey.
@Override
public PublicKey getPublicKey(String alias) throws CryptoProviderException {
if (Util.isNullOrEmpty(alias) || keyStore == null) {
return null;
}
try {
java.security.cert.Certificate certificate = keyStore.getCertificate(alias);
if (certificate == null) {
return null;
}
checkKeyExpiration(alias);
return certificate.getPublicKey();
} catch (KeyStoreException e) {
throw new CryptoProviderException(e);
}
}
Aggregations