Search in sources :

Example 26 with NoSuchProviderException

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

the class MongoClientConfigurationFactory method getMongoClientConfiguration.

public static MongoClientConfiguration getMongoClientConfiguration(AbstractReplication replication) {
    HostAndPort syncSource = HostAndPort.fromString(replication.getSyncSource()).withDefaultPort(27017);
    MongoClientConfiguration.Builder mongoClientConfigurationBuilder = new MongoClientConfiguration.Builder(syncSource);
    Ssl ssl = replication.getSsl();
    mongoClientConfigurationBuilder.setSslEnabled(ssl.getEnabled());
    if (ssl.getEnabled()) {
        try {
            mongoClientConfigurationBuilder.setSslAllowInvalidHostnames(ssl.getAllowInvalidHostnames());
            TrustManager[] tms = getTrustManagers(ssl);
            KeyManager[] kms = getKeyManagers(ssl);
            SSLContext sslContext;
            if (ssl.getFipsMode()) {
                sslContext = SSLContext.getInstance("TLS", "SunPKCS11-NSS");
            } else {
                sslContext = SSLContext.getInstance("TLS");
            }
            sslContext.init(kms, tms, null);
            mongoClientConfigurationBuilder.setSocketFactory(sslContext.getSocketFactory());
        } catch (CertificateException | KeyManagementException | KeyStoreException | UnrecoverableKeyException | NoSuchProviderException | NoSuchAlgorithmException | IOException exception) {
            throw new SystemException(exception);
        }
    }
    Auth auth = replication.getAuth();
    if (auth.getMode().isEnabled()) {
        MongoAuthenticationConfiguration mongoAuthenticationConfiguration = getMongoAuthenticationConfiguration(auth, ssl);
        mongoClientConfigurationBuilder.addAuthenticationConfiguration(mongoAuthenticationConfiguration);
    }
    return mongoClientConfigurationBuilder.build();
}
Also used : MongoAuthenticationConfiguration(com.eightkdata.mongowp.client.wrapper.MongoAuthenticationConfiguration) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) MongoClientConfiguration(com.eightkdata.mongowp.client.wrapper.MongoClientConfiguration) Ssl(com.torodb.packaging.config.model.protocol.mongo.Ssl) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) HostAndPort(com.google.common.net.HostAndPort) UnrecoverableKeyException(java.security.UnrecoverableKeyException) SystemException(com.torodb.core.exceptions.SystemException) Auth(com.torodb.packaging.config.model.protocol.mongo.Auth) NoSuchProviderException(java.security.NoSuchProviderException) KeyManager(javax.net.ssl.KeyManager)

Example 27 with NoSuchProviderException

use of java.security.NoSuchProviderException in project j2objc by google.

the class AlgorithmParametersTest method test_getInstanceLjava_lang_StringLjava_lang_String.

/**
     * java.security.AlgorithmParameters#getInstance(String, String)
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String() {
    String[] alg = { "", "qwertyu", "!@#$%^&*()" };
    String[] prv = { "", null };
    String[] prv1 = { "1234567890", "qwertyu", "!@#$%^&*()" };
    try {
        AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", "MyProvider");
        checkUnititialized(ap);
        ap.init(new byte[6]);
        checkAP(ap, p);
    } catch (Exception e) {
        fail("Unexpected exception");
    }
    for (int i = 0; i < alg.length; i++) {
        try {
            AlgorithmParameters ap = AlgorithmParameters.getInstance(alg[i], "MyProvider");
            fail("NoSuchAlgorithmException was not thrown for parameter " + alg[i]);
        } catch (NoSuchAlgorithmException nsae) {
        //expected
        } catch (Exception e) {
            fail("Incorrect exception " + e + " was thrown for " + alg[i]);
        }
    }
    for (int i = 0; i < prv.length; i++) {
        try {
            AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", prv[i]);
            fail("IllegalArgumentException was not thrown for parameter " + prv[i]);
        } catch (IllegalArgumentException iae) {
        //expected
        } catch (Exception e) {
            fail("Incorrect exception " + e + " was thrown for " + prv[i]);
        }
    }
    for (int i = 0; i < prv1.length; i++) {
        try {
            AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", prv1[i]);
            fail("NoSuchProviderException was not thrown for parameter " + prv1[i]);
        } catch (NoSuchProviderException nspe) {
        //expected
        } catch (Exception e) {
            fail("Incorrect exception " + e + " was thrown for " + prv1[i]);
        }
    }
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) NoSuchProviderException(java.security.NoSuchProviderException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 28 with NoSuchProviderException

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

the class SSLContextManager method initMSCAPI.

public int initMSCAPI() throws KeyStoreException, NoSuchProviderException, IOException, NoSuchAlgorithmException, CertificateException {
    try {
        if (!isProviderAvailable("msks")) {
            return -1;
        }
        Provider mscapi = (Provider) Class.forName("se.assembla.jce.provider.ms.MSProvider").newInstance();
        Security.addProvider(mscapi);
        // init the key store
        KeyStore ks = KeyStore.getInstance("msks", "assembla");
        ks.load(null, null);
        return addKeyStore(ks, "Microsoft CAPI Store", null);
    } catch (Exception e) {
        log.error("Error instantiating the MSCAPI provider: " + e.getMessage(), e);
        return -1;
    }
}
Also used : KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateEncodingException(java.security.cert.CertificateEncodingException) Provider(java.security.Provider)

Example 29 with NoSuchProviderException

use of java.security.NoSuchProviderException in project XobotOS by xamarin.

the class JDKKeyStore method decodeCertificate.

private Certificate decodeCertificate(DataInputStream dIn) throws IOException {
    String type = dIn.readUTF();
    byte[] cEnc = new byte[dIn.readInt()];
    dIn.readFully(cEnc);
    try {
        CertificateFactory cFact = CertificateFactory.getInstance(type, BouncyCastleProvider.PROVIDER_NAME);
        ByteArrayInputStream bIn = new ByteArrayInputStream(cEnc);
        return cFact.generateCertificate(bIn);
    } catch (NoSuchProviderException ex) {
        throw new IOException(ex.toString());
    } catch (CertificateException ex) {
        throw new IOException(ex.toString());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateFactory(java.security.cert.CertificateFactory)

Example 30 with NoSuchProviderException

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

the class RelaxedX509TrustManager method getTunnelSSLSocketFactory.

// ZAP: added new ServerSocketFaktory with support of dynamic SSL certificates
public SSLSocketFactory getTunnelSSLSocketFactory(String hostname) {
    //	KeyStore ks;
    try {
        SSLContext ctx = SSLContext.getInstance(SSL);
        // Normally "SunX509", "IbmX509"...
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        SslCertificateService scs = CachedSslCertifificateServiceImpl.getService();
        KeyStore ks = scs.createCertForHost(hostname);
        kmf.init(ks, SslCertificateService.PASSPHRASE);
        java.security.SecureRandom x = new java.security.SecureRandom();
        x.setSeed(System.currentTimeMillis());
        ctx.init(kmf.getKeyManagers(), null, x);
        SSLSocketFactory tunnelSSLFactory = createDecoratedServerSslSocketFactory(ctx.getSocketFactory());
        return tunnelSSLFactory;
    } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | UnrecoverableKeyException | KeyManagementException | InvalidKeyException | NoSuchProviderException | SignatureException | IOException e) {
        // friendly way?
        throw new RuntimeException(e);
    }
}
Also used : SslCertificateService(org.parosproxy.paros.security.SslCertificateService) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) KeyStore(java.security.KeyStore) KeyManagementException(java.security.KeyManagementException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) UnrecoverableKeyException(java.security.UnrecoverableKeyException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) NoSuchProviderException(java.security.NoSuchProviderException)

Aggregations

NoSuchProviderException (java.security.NoSuchProviderException)93 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)67 InvalidKeyException (java.security.InvalidKeyException)30 IOException (java.io.IOException)28 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)18 CertificateException (java.security.cert.CertificateException)18 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)14 Cipher (javax.crypto.Cipher)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 BadPaddingException (javax.crypto.BadPaddingException)12 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)12 KeyStoreException (java.security.KeyStoreException)11 SignatureException (java.security.SignatureException)10 X509Certificate (java.security.cert.X509Certificate)10 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