Search in sources :

Example 21 with NoSuchProviderException

use of java.security.NoSuchProviderException in project gerrit by GerritCodeReview.

the class SshKeyCreatorImpl method create.

@Override
public AccountSshKey create(AccountSshKey.Id id, String encoded) throws InvalidSshKeyException {
    try {
        AccountSshKey key = new AccountSshKey(id, SshUtil.toOpenSshPublicKey(encoded));
        SshUtil.parse(key);
        return key;
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        throw new InvalidSshKeyException();
    } catch (NoSuchProviderException e) {
        log.error("Cannot parse SSH key", e);
        throw new InvalidSshKeyException();
    }
}
Also used : InvalidSshKeyException(com.google.gerrit.common.errors.InvalidSshKeyException) AccountSshKey(com.google.gerrit.reviewdb.client.AccountSshKey) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 22 with NoSuchProviderException

use of java.security.NoSuchProviderException in project sling by apache.

the class DelegatingLoginModule method initialize.

public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
    Configuration config = null;
    try {
        config = Configuration.getInstance(JAAS_CONFIG_ALGO_NAME, null, providerName);
    } catch (NoSuchProviderException e) {
        logger.debug("No provider " + providerName + "found so far", e);
    } catch (NoSuchAlgorithmException e) {
        logger.debug("No provider " + providerName + "found so far for fetching JAAS " + "config with algorithm name " + JAAS_CONFIG_ALGO_NAME, e);
    }
    if (config != null) {
        final Thread current = Thread.currentThread();
        final ClassLoader orig = current.getContextClassLoader();
        try {
            current.setContextClassLoader(DelegatingLoginModule.class.getClassLoader());
            loginContext = new LoginContext(appName, subject, callbackHandler, config);
        } catch (LoginException e) {
            loginException = e;
        } finally {
            current.setContextClassLoader(orig);
        }
    } else {
        //No support so far from OSGi so would use default logic used by Jackrabbit
        //to construct the LoginModule
        Properties p = new Properties();
        p.putAll(options);
        BeanConfig bc = new BeanConfig(delegateLoginModuleClass, p);
        LoginModuleConfig lmc = new LoginModuleConfig(bc);
        try {
            delegate = lmc.getLoginModule();
            delegate.initialize(subject, callbackHandler, sharedState, options);
            logger.info("No JAAS Configuration provider found would be directly invoking LoginModule {}", delegateLoginModuleClass);
        } catch (ConfigurationException e) {
            //Behaviour is same as org.apache.jackrabbit.core.security.authentication.LocalAuthContext.login()
            loginException = new LoginException(e.getMessage());
        }
    }
}
Also used : BeanConfig(org.apache.jackrabbit.core.config.BeanConfig) LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) ConfigurationException(org.apache.jackrabbit.core.config.ConfigurationException) LoginModuleConfig(org.apache.jackrabbit.core.config.LoginModuleConfig) LoginException(javax.security.auth.login.LoginException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) Properties(java.util.Properties)

Example 23 with NoSuchProviderException

use of java.security.NoSuchProviderException in project cloudstack by apache.

the class SAML2AuthManagerImpl method initSP.

protected boolean initSP() {
    KeystoreVO keyStoreVO = _ksDao.findByName(SAMLPluginConstants.SAMLSP_KEYPAIR);
    if (keyStoreVO == null) {
        try {
            KeyPair keyPair = SAMLUtils.generateRandomKeyPair();
            _ksDao.save(SAMLPluginConstants.SAMLSP_KEYPAIR, SAMLUtils.savePrivateKey(keyPair.getPrivate()), SAMLUtils.savePublicKey(keyPair.getPublic()), "samlsp-keypair");
            keyStoreVO = _ksDao.findByName(SAMLPluginConstants.SAMLSP_KEYPAIR);
            s_logger.info("No SAML keystore found, created and saved a new Service Provider keypair");
        } catch (NoSuchProviderException | NoSuchAlgorithmException e) {
            s_logger.error("Unable to create and save SAML keypair: " + e.toString());
        }
    }
    String spId = SAMLServiceProviderID.value();
    String spSsoUrl = SAMLServiceProviderSingleSignOnURL.value();
    String spSloUrl = SAMLServiceProviderSingleLogOutURL.value();
    String spOrgName = SAMLServiceProviderOrgName.value();
    String spOrgUrl = SAMLServiceProviderOrgUrl.value();
    String spContactPersonName = SAMLServiceProviderContactPersonName.value();
    String spContactPersonEmail = SAMLServiceProviderContactEmail.value();
    KeyPair spKeyPair = null;
    X509Certificate spX509Key = null;
    if (keyStoreVO != null) {
        PrivateKey privateKey = SAMLUtils.loadPrivateKey(keyStoreVO.getCertificate());
        PublicKey publicKey = SAMLUtils.loadPublicKey(keyStoreVO.getKey());
        if (privateKey != null && publicKey != null) {
            spKeyPair = new KeyPair(publicKey, privateKey);
            KeystoreVO x509VO = _ksDao.findByName(SAMLPluginConstants.SAMLSP_X509CERT);
            if (x509VO == null) {
                try {
                    spX509Key = SAMLUtils.generateRandomX509Certificate(spKeyPair);
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    ObjectOutput out = new ObjectOutputStream(bos);
                    out.writeObject(spX509Key);
                    out.flush();
                    _ksDao.save(SAMLPluginConstants.SAMLSP_X509CERT, Base64.encodeBase64String(bos.toByteArray()), "", "samlsp-x509cert");
                    bos.close();
                } catch (NoSuchAlgorithmException | NoSuchProviderException | CertificateEncodingException | SignatureException | InvalidKeyException | IOException e) {
                    s_logger.error("SAML Plugin won't be able to use X509 signed authentication");
                }
            } else {
                try {
                    ByteArrayInputStream bi = new ByteArrayInputStream(Base64.decodeBase64(x509VO.getCertificate()));
                    ObjectInputStream si = new ObjectInputStream(bi);
                    spX509Key = (X509Certificate) si.readObject();
                    bi.close();
                } catch (IOException | ClassNotFoundException ignored) {
                    s_logger.error("SAML Plugin won't be able to use X509 signed authentication. Failed to load X509 Certificate from Database.");
                }
            }
        }
    }
    if (spKeyPair != null && spX509Key != null && spId != null && spSsoUrl != null && spSloUrl != null && spOrgName != null && spOrgUrl != null && spContactPersonName != null && spContactPersonEmail != null) {
        _spMetadata.setEntityId(spId);
        _spMetadata.setOrganizationName(spOrgName);
        _spMetadata.setOrganizationUrl(spOrgUrl);
        _spMetadata.setContactPersonName(spContactPersonName);
        _spMetadata.setContactPersonEmail(spContactPersonEmail);
        _spMetadata.setSsoUrl(spSsoUrl);
        _spMetadata.setSloUrl(spSloUrl);
        _spMetadata.setKeyPair(spKeyPair);
        _spMetadata.setSigningCertificate(spX509Key);
        _spMetadata.setEncryptionCertificate(spX509Key);
        return true;
    }
    return false;
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) ObjectOutput(java.io.ObjectOutput) PublicKey(java.security.PublicKey) CertificateEncodingException(java.security.cert.CertificateEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SignatureException(java.security.SignatureException) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) InvalidKeyException(java.security.InvalidKeyException) X509Certificate(java.security.cert.X509Certificate) ByteArrayInputStream(java.io.ByteArrayInputStream) KeystoreVO(org.apache.cloudstack.framework.security.keystore.KeystoreVO) NoSuchProviderException(java.security.NoSuchProviderException) ObjectInputStream(java.io.ObjectInputStream)

Example 24 with NoSuchProviderException

use of java.security.NoSuchProviderException in project cloudstack by apache.

the class SAMLUtils method getKeyFactory.

public static KeyFactory getKeyFactory() {
    KeyFactory keyFactory = null;
    try {
        Security.addProvider(new BouncyCastleProvider());
        keyFactory = KeyFactory.getInstance("RSA", "BC");
    } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
        s_logger.error("Unable to create KeyFactory:" + e.getMessage());
    }
    return keyFactory;
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) KeyFactory(java.security.KeyFactory) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 25 with NoSuchProviderException

use of java.security.NoSuchProviderException in project robovm by robovm.

the class KeyStore4Test method testGetInstanceStringString.

public void testGetInstanceStringString() {
    try {
        KeyStore ks = KeyStore.getInstance("TestKeyStore", provider.getName());
        assertNotNull("keystore is null", ks);
        assertEquals("KeyStore is not of expected type", "TestKeyStore", ks.getType());
    } catch (KeyStoreException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchProviderException e) {
        fail("unexpected exception: " + e);
    }
    try {
        KeyStore.getInstance("UnknownKeyStore", provider.getName());
        fail("expected KeyStoreException");
    } catch (KeyStoreException e) {
    // ok
    } catch (NoSuchProviderException e) {
        fail("unexpected exception: " + e);
    }
    try {
        KeyStore.getInstance("TestKeyStore", (String) null);
        fail("expected IllegalArgumentException");
    } catch (KeyStoreException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchProviderException e) {
        fail("unexpected exception: " + e);
    } catch (IllegalArgumentException e) {
    // ok
    }
    try {
        KeyStore.getInstance("TestKeyStore", "");
        fail("expected IllegalArgumentException");
    } catch (KeyStoreException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchProviderException e) {
        fail("unexpected exception: " + e);
    } catch (IllegalArgumentException e) {
    // ok
    }
    try {
        KeyStore.getInstance(null, provider.getName());
        fail("expected KeyStoreException");
    } catch (KeyStoreException e) {
    // ok
    } catch (NoSuchProviderException e) {
        fail("unexpected exception: " + e);
    } catch (NullPointerException e) {
    // also ok
    }
    try {
        KeyStore.getInstance("TestKeyStore", "UnknownProvider");
        fail("expected NoSuchProviderException");
    } catch (NoSuchProviderException e) {
    // ok
    } catch (KeyStoreException e) {
        fail("unexpected exception: " + e);
    }
}
Also used : KeyStoreException(java.security.KeyStoreException) NoSuchProviderException(java.security.NoSuchProviderException) KeyStore(java.security.KeyStore)

Aggregations

NoSuchProviderException (java.security.NoSuchProviderException)97 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)70 InvalidKeyException (java.security.InvalidKeyException)31 IOException (java.io.IOException)29 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)20 CertificateException (java.security.cert.CertificateException)19 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)14 Cipher (javax.crypto.Cipher)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 KeyStoreException (java.security.KeyStoreException)12 X509Certificate (java.security.cert.X509Certificate)12 BadPaddingException (javax.crypto.BadPaddingException)12 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)12 SignatureException (java.security.SignatureException)11 SecretKey (javax.crypto.SecretKey)10 CertificateFactory (java.security.cert.CertificateFactory)9 CertificateEncodingException (java.security.cert.CertificateEncodingException)8 IvParameterSpec (javax.crypto.spec.IvParameterSpec)8 KeyStore (java.security.KeyStore)7 Provider (java.security.Provider)7