Search in sources :

Example 6 with KeystoreServiceException

use of org.apache.knox.gateway.services.security.KeystoreServiceException in project knox by apache.

the class DefaultTokenAuthorityService method signTokenWithRSA.

private void signTokenWithRSA(final JWT token, String signingKeystoreName, String signingKeystoreAlias, char[] signingKeystorePassphrase) throws TokenServiceException {
    try {
        final RSAPrivateKey key = getSigningKey(signingKeystoreName, signingKeystoreAlias, signingKeystorePassphrase);
        // allowWeakKey to not break existing 1024 bit certificates
        final JWSSigner signer = new RSASSASigner(key, true);
        token.sign(signer);
    } catch (KeystoreServiceException e) {
        throw new TokenServiceException(e);
    }
}
Also used : RSASSASigner(com.nimbusds.jose.crypto.RSASSASigner) KeystoreServiceException(org.apache.knox.gateway.services.security.KeystoreServiceException) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) JWSSigner(com.nimbusds.jose.JWSSigner) TokenServiceException(org.apache.knox.gateway.services.security.token.TokenServiceException)

Example 7 with KeystoreServiceException

use of org.apache.knox.gateway.services.security.KeystoreServiceException in project knox by apache.

the class DefaultKeystoreService method getCredentialForCluster.

@Override
public char[] getCredentialForCluster(String clusterName, String alias, KeyStore ks) throws KeystoreServiceException {
    try {
        char[] credential = null;
        Key credentialKey = ks.getKey(alias, masterService.getMasterSecret());
        if (credentialKey == null) {
            credentialKey = ks.getKey(alias.toLowerCase(Locale.ROOT), masterService.getMasterSecret());
        }
        if (credentialKey != null) {
            final String credentialString = new String(credentialKey.getEncoded(), StandardCharsets.UTF_8);
            credential = credentialString.toCharArray();
            addToCache(clusterName, alias, credentialString);
        }
        return credential;
    } catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException e) {
        throw new KeystoreServiceException(e);
    }
}
Also used : UnrecoverableKeyException(java.security.UnrecoverableKeyException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeystoreServiceException(org.apache.knox.gateway.services.security.KeystoreServiceException) Key(java.security.Key)

Example 8 with KeystoreServiceException

use of org.apache.knox.gateway.services.security.KeystoreServiceException in project knox by apache.

the class DefaultAliasService method getPasswordFromAliasForCluster.

@Override
public char[] getPasswordFromAliasForCluster(String clusterName, String alias, boolean generate) throws AliasServiceException {
    char[] credential;
    try {
        credential = keystoreService.getCredentialForCluster(clusterName, alias);
        if (credential == null && generate) {
            generateAliasForCluster(clusterName, alias);
            credential = keystoreService.getCredentialForCluster(clusterName, alias);
        }
    } catch (KeystoreServiceException e) {
        LOG.failedToGetCredentialForCluster(clusterName, e);
        throw new AliasServiceException(e);
    }
    return credential;
}
Also used : AliasServiceException(org.apache.knox.gateway.services.security.AliasServiceException) KeystoreServiceException(org.apache.knox.gateway.services.security.KeystoreServiceException)

Example 9 with KeystoreServiceException

use of org.apache.knox.gateway.services.security.KeystoreServiceException in project knox by apache.

the class DefaultAliasService method generateAliasForCluster.

@Override
public void generateAliasForCluster(String clusterName, String alias) throws AliasServiceException {
    try {
        keystoreService.getCredentialStoreForCluster(clusterName);
    } catch (KeystoreServiceException e) {
        LOG.failedToGenerateAliasForCluster(clusterName, e);
        throw new AliasServiceException(e);
    }
    String passwordString = PasswordUtils.generatePassword(16);
    addAliasForCluster(clusterName, alias, passwordString);
}
Also used : AliasServiceException(org.apache.knox.gateway.services.security.AliasServiceException) KeystoreServiceException(org.apache.knox.gateway.services.security.KeystoreServiceException)

Example 10 with KeystoreServiceException

use of org.apache.knox.gateway.services.security.KeystoreServiceException in project knox by apache.

the class DefaultAliasService method getPasswordsForGateway.

// Overriding the default behavior as we want to avoid loading the keystore N-times from the file system
@Override
public Map<String, char[]> getPasswordsForGateway() throws AliasServiceException {
    final Map<String, char[]> passwordAliasMap = new HashMap<>();
    try {
        final KeyStore gatewayCredentialStore = keystoreService.getCredentialStoreForCluster(NO_CLUSTER_NAME);
        final Enumeration<String> aliases = gatewayCredentialStore.aliases();
        String alias;
        while (aliases.hasMoreElements()) {
            alias = aliases.nextElement();
            passwordAliasMap.put(alias, keystoreService.getCredentialForCluster(NO_CLUSTER_NAME, alias, gatewayCredentialStore));
        }
    } catch (KeystoreServiceException | KeyStoreException e) {
        e.printStackTrace();
    }
    return passwordAliasMap;
}
Also used : HashMap(java.util.HashMap) KeyStoreException(java.security.KeyStoreException) KeystoreServiceException(org.apache.knox.gateway.services.security.KeystoreServiceException) KeyStore(java.security.KeyStore)

Aggregations

KeystoreServiceException (org.apache.knox.gateway.services.security.KeystoreServiceException)25 KeyStoreException (java.security.KeyStoreException)14 KeyStore (java.security.KeyStore)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 AliasServiceException (org.apache.knox.gateway.services.security.AliasServiceException)7 IOException (java.io.IOException)6 TokenServiceException (org.apache.knox.gateway.services.security.token.TokenServiceException)5 File (java.io.File)4 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)4 RSAPublicKey (java.security.interfaces.RSAPublicKey)4 PublicKey (java.security.PublicKey)3 X509Certificate (java.security.cert.X509Certificate)3 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)3 JOSEException (com.nimbusds.jose.JOSEException)2 JWSSigner (com.nimbusds.jose.JWSSigner)2 JWSVerifier (com.nimbusds.jose.JWSVerifier)2 RSASSASigner (com.nimbusds.jose.crypto.RSASSASigner)2 RSASSAVerifier (com.nimbusds.jose.crypto.RSASSAVerifier)2 GeneralSecurityException (java.security.GeneralSecurityException)2 InvalidKeyException (java.security.InvalidKeyException)2