in gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/DefaultTokenAuthorityService.java [292:351]
public void start() throws ServiceLifecycleException {
// Ensure that the default signing keystore is available
KeyStore keystore;
try {
keystore = keystoreService.getSigningKeystore();
if (keystore == null) {
throw new ServiceLifecycleException(RESOURCES.signingKeystoreNotAvailable(config.getSigningKeystorePath()));
}
} catch (KeystoreServiceException e) {
throw new ServiceLifecycleException(RESOURCES.signingKeystoreNotAvailable(config.getSigningKeystorePath()), e);
}
// Ensure that the password for the signing key is available
try {
cachedSigningKeyPassphrase = aliasService.getSigningKeyPassphrase();
if (cachedSigningKeyPassphrase == null) {
throw new ServiceLifecycleException(RESOURCES.signingKeyPassphraseNotAvailable(config.getSigningKeyPassphraseAlias()));
}
} catch (AliasServiceException e) {
throw new ServiceLifecycleException(RESOURCES.signingKeyPassphraseNotAvailable(config.getSigningKeyPassphraseAlias()), e);
}
String signingKeyAlias = getSigningKeyAlias();
// Ensure that the public signing keys is available
try {
Certificate certificate = keystore.getCertificate(signingKeyAlias);
if(certificate == null) {
throw new ServiceLifecycleException(RESOURCES.publicSigningKeyNotFound(signingKeyAlias));
}
PublicKey publicKey = certificate.getPublicKey();
if (publicKey == null) {
throw new ServiceLifecycleException(RESOURCES.publicSigningKeyNotFound(signingKeyAlias));
}
else if (! (publicKey instanceof RSAPublicKey)) {
throw new ServiceLifecycleException(RESOURCES.publicSigningKeyWrongType(signingKeyAlias));
}
cachedSigningKeyID = Optional.of(TokenUtils.getThumbprint((RSAPublicKey) publicKey, "SHA-256"));
} catch (KeyStoreException e) {
throw new ServiceLifecycleException(RESOURCES.publicSigningKeyNotFound(signingKeyAlias), e);
} catch (final JOSEException e) {
/* in case there is an error getting KID log and move one */
LOG.errorGettingKid(e.toString());
cachedSigningKeyID = Optional.empty();
}
// Ensure that the private signing keys is available
try {
Key key = keystore.getKey(signingKeyAlias, cachedSigningKeyPassphrase);
if (key == null) {
throw new ServiceLifecycleException(RESOURCES.privateSigningKeyNotFound(signingKeyAlias));
}
else if (! (key instanceof RSAPrivateKey)) {
throw new ServiceLifecycleException(RESOURCES.privateSigningKeyWrongType(signingKeyAlias));
}
signingKey = (RSAPrivateKey) key;
} catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException e) {
throw new ServiceLifecycleException(RESOURCES.privateSigningKeyNotFound(signingKeyAlias), e);
}
}