Package org.apache.servicemix.jbi.security.keystore

Examples of org.apache.servicemix.jbi.security.keystore.KeystoreInstance


     */
    public SSLSocketFactory createSSLFactory(String provider, String protocol,
                                             String algorithm, String keyStore,
                                             String keyAlias, String trustStore) throws GeneralSecurityException  {
        // the keyStore is optional.
        KeystoreInstance keyInstance = null;
        if (keyStore != null) {
            keyInstance = getKeystore(keyStore);
            if (keyInstance.isKeystoreLocked()) {
                throw new KeystoreIsLocked("Keystore '" + keyStore
                                + "' is locked; please use the keystore page in the admin console to unlock it");
            }
            if (keyInstance.isKeyLocked(keyAlias)) {
                throw new KeystoreIsLocked("Key '" + keyAlias + "' in keystore '" + keyStore
                                + "' is locked; please use the keystore page in the admin console to unlock it");
            }
        }
        KeystoreInstance trustInstance = trustStore == null ? null : getKeystore(trustStore);
        if (trustInstance != null && trustInstance.isKeystoreLocked()) {
            throw new KeystoreIsLocked("Keystore '" + trustStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }

        // OMG this hurts, but it causes ClassCastExceptions elsewhere unless
        // done this way!
        try {
            /*
            Class cls = loader.loadClass("javax.net.ssl.SSLContext");
            Object ctx = cls.getMethod("getInstance", new Class[] { String.class }).invoke(null,
                            new Object[] { protocol });
            Class kmc = loader.loadClass("[Ljavax.net.ssl.KeyManager;");
            Class tmc = loader.loadClass("[Ljavax.net.ssl.TrustManager;");
            Class src = loader.loadClass("java.security.SecureRandom");
            cls.getMethod("init", new Class[] { kmc, tmc, src }).invoke(
                            ctx,
                            new Object[] { keyInstance == null ? null : keyInstance.getKeyManager(algorithm, keyAlias),
                                            trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                            new java.security.SecureRandom() });
            Object result = cls.getMethod("getSocketFactory", new Class[0]).invoke(ctx, new Object[0]);
            return (SSLSocketFactory) result;
            */
            SSLContext context;
            if (provider == null) {
                context = SSLContext.getInstance(protocol);
            } else {
                context = SSLContext.getInstance(protocol, provider);
            }
            context.init(keyInstance == null ? null : keyInstance.getKeyManager(algorithm, keyAlias),
                         trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                         new SecureRandom());
            return context.getSocketFactory();
        } catch (Exception e) {
            LOGGER.error("Unable to dynamically load", e);
            return null;
View Full Code Here


     *             it has not been unlocked.
     */
    public SSLServerSocketFactory createSSLServerFactory(String provider, String protocol,
                                                         String algorithm, String keyStore,
                                                         String keyAlias, String trustStore) throws GeneralSecurityException {
        KeystoreInstance keyInstance = getKeystore(keyStore);
        if (keyInstance.isKeystoreLocked()) {
            throw new KeystoreIsLocked("Keystore '" + keyStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }
        if (keyInstance.isKeyLocked(keyAlias)) {
            throw new KeystoreIsLocked("Key '" + keyAlias + "' in keystore '" + keyStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }
        KeystoreInstance trustInstance = trustStore == null ? null : getKeystore(trustStore);
        if (trustInstance != null && trustInstance.isKeystoreLocked()) {
            throw new KeystoreIsLocked("Keystore '" + trustStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }

        // OMG this hurts, but it causes ClassCastExceptions elsewhere unless
        // done this way!
        try {
            /*
            Class cls = loader.loadClass("javax.net.ssl.SSLContext");
            Object ctx = cls.getMethod("getInstance", new Class[] { String.class }).invoke(null,
                            new Object[] { protocol });
            Class kmc = loader.loadClass("[Ljavax.net.ssl.KeyManager;");
            Class tmc = loader.loadClass("[Ljavax.net.ssl.TrustManager;");
            Class src = loader.loadClass("java.security.SecureRandom");
            cls.getMethod("init", new Class[] { kmc, tmc, src }).invoke(
                            ctx,
                            new Object[] { keyInstance.getKeyManager(algorithm, keyAlias),
                                            trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                            new java.security.SecureRandom() });
            Object result = cls.getMethod("getServerSocketFactory", new Class[0]).invoke(ctx, new Object[0]);
            return (SSLServerSocketFactory) result;
            */
            SSLContext context;
            if (provider == null) {
                context = SSLContext.getInstance(protocol);
            } else {
                context = SSLContext.getInstance(protocol, provider);
            }
            context.init(keyInstance == null ? null : keyInstance.getKeyManager(algorithm, keyAlias),
                         trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                         new SecureRandom());
            return context.getServerSocketFactory();
        } catch (Exception e) {
            LOGGER.error("Unable to dynamically load", e);
            return null;
View Full Code Here

     */
    public SSLSocketFactory createSSLFactory(String provider, String protocol,
                                             String algorithm, String keyStore,
                                             String keyAlias, String trustStore) throws GeneralSecurityException  {
        // the keyStore is optional.
        KeystoreInstance keyInstance = null;
        if (keyStore != null) {
            keyInstance = getKeystore(keyStore);
            if (keyInstance.isKeystoreLocked()) {
                throw new KeystoreIsLocked("Keystore '" + keyStore
                                + "' is locked; please use the keystore page in the admin console to unlock it");
            }
            if (keyInstance.isKeyLocked(keyAlias)) {
                throw new KeystoreIsLocked("Key '" + keyAlias + "' in keystore '" + keyStore
                                + "' is locked; please use the keystore page in the admin console to unlock it");
            }
        }
        KeystoreInstance trustInstance = trustStore == null ? null : getKeystore(trustStore);
        if (trustInstance != null && trustInstance.isKeystoreLocked()) {
            throw new KeystoreIsLocked("Keystore '" + trustStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }

        // OMG this hurts, but it causes ClassCastExceptions elsewhere unless
        // done this way!
        try {
            /*
            Class cls = loader.loadClass("javax.net.ssl.SSLContext");
            Object ctx = cls.getMethod("getInstance", new Class[] { String.class }).invoke(null,
                            new Object[] { protocol });
            Class kmc = loader.loadClass("[Ljavax.net.ssl.KeyManager;");
            Class tmc = loader.loadClass("[Ljavax.net.ssl.TrustManager;");
            Class src = loader.loadClass("java.security.SecureRandom");
            cls.getMethod("init", new Class[] { kmc, tmc, src }).invoke(
                            ctx,
                            new Object[] { keyInstance == null ? null : keyInstance.getKeyManager(algorithm, keyAlias),
                                            trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                            new java.security.SecureRandom() });
            Object result = cls.getMethod("getSocketFactory", new Class[0]).invoke(ctx, new Object[0]);
            return (SSLSocketFactory) result;
            */
            SSLContext context;
            if (provider == null) {
                context = SSLContext.getInstance(protocol);
            } else {
                context = SSLContext.getInstance(protocol, provider);
            }
            context.init(keyInstance == null ? null : keyInstance.getKeyManager(algorithm, keyAlias),
                         trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                         new SecureRandom());
            return context.getSocketFactory();
        } catch (Exception e) {
            log.error("Unable to dynamically load", e);
            return null;
View Full Code Here

     *             cannot be used because it has not been unlocked.
     */
    public SSLServerSocketFactory createSSLServerFactory(String provider, String protocol,
                                                         String algorithm, String keyStore,
                                                         String keyAlias, String trustStore) throws GeneralSecurityException {
        KeystoreInstance keyInstance = getKeystore(keyStore);
        if (keyInstance.isKeystoreLocked()) {
            throw new KeystoreIsLocked("Keystore '" + keyStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }
        if (keyInstance.isKeyLocked(keyAlias)) {
            throw new KeystoreIsLocked("Key '" + keyAlias + "' in keystore '" + keyStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }
        KeystoreInstance trustInstance = trustStore == null ? null : getKeystore(trustStore);
        if (trustInstance != null && trustInstance.isKeystoreLocked()) {
            throw new KeystoreIsLocked("Keystore '" + trustStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }

        // OMG this hurts, but it causes ClassCastExceptions elsewhere unless
        // done this way!
        try {
            /*
            Class cls = loader.loadClass("javax.net.ssl.SSLContext");
            Object ctx = cls.getMethod("getInstance", new Class[] { String.class }).invoke(null,
                            new Object[] { protocol });
            Class kmc = loader.loadClass("[Ljavax.net.ssl.KeyManager;");
            Class tmc = loader.loadClass("[Ljavax.net.ssl.TrustManager;");
            Class src = loader.loadClass("java.security.SecureRandom");
            cls.getMethod("init", new Class[] { kmc, tmc, src }).invoke(
                            ctx,
                            new Object[] { keyInstance.getKeyManager(algorithm, keyAlias),
                                            trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                            new java.security.SecureRandom() });
            Object result = cls.getMethod("getServerSocketFactory", new Class[0]).invoke(ctx, new Object[0]);
            return (SSLServerSocketFactory) result;
            */
            SSLContext context;
            if (provider == null) {
                context = SSLContext.getInstance(protocol);
            } else {
                context = SSLContext.getInstance(protocol, provider);
            }
            context.init(keyInstance == null ? null : keyInstance.getKeyManager(algorithm, keyAlias),
                         trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                         new SecureRandom());
            return context.getServerSocketFactory();
        } catch (Exception e) {
            log.error("Unable to dynamically load", e);
            return null;
View Full Code Here

    public void testGetUnknownKeystoreInstance() throws Exception {
        assertNull(keystoreManager.getKeystore("ks2"));
    }
   
    public void testPrivateKey() throws Exception {
        KeystoreInstance ks = keystoreManager.getKeystore("ks");
        String[] pk = ks.listPrivateKeys();
        assertNotNull(pk);
        assertEquals(1, pk.length);
        assertEquals("myalias", pk[0]);
        assertNotNull(ks.getCertificate("myalias"));
        assertNotNull(ks.getPrivateKey("myalias"));
    }
View Full Code Here

                                String keyAlias,
                                String trustStore) throws KeystoreIsLocked, KeyIsLocked,
                    NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException,
                    NoSuchProviderException {
        // the keyStore is optional.
        KeystoreInstance keyInstance = null;
        if (keyStore != null) {
            keyInstance = getKeystore(keyStore);
            if (keyInstance.isKeystoreLocked()) {
                throw new KeystoreIsLocked("Keystore '" + keyStore
                                + "' is locked; please use the keystore page in the admin console to unlock it");
            }
            if (keyInstance.isKeyLocked(keyAlias)) {
                throw new KeystoreIsLocked("Key '" + keyAlias + "' in keystore '" + keyStore
                                + "' is locked; please use the keystore page in the admin console to unlock it");
            }
        }
        KeystoreInstance trustInstance = trustStore == null ? null : getKeystore(trustStore);
        if (trustInstance != null && trustInstance.isKeystoreLocked()) {
            throw new KeystoreIsLocked("Keystore '" + trustStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }

        // OMG this hurts, but it causes ClassCastExceptions elsewhere unless
        // done this way!
        try {
            /*
            Class cls = loader.loadClass("javax.net.ssl.SSLContext");
            Object ctx = cls.getMethod("getInstance", new Class[] { String.class }).invoke(null,
                            new Object[] { protocol });
            Class kmc = loader.loadClass("[Ljavax.net.ssl.KeyManager;");
            Class tmc = loader.loadClass("[Ljavax.net.ssl.TrustManager;");
            Class src = loader.loadClass("java.security.SecureRandom");
            cls.getMethod("init", new Class[] { kmc, tmc, src }).invoke(
                            ctx,
                            new Object[] { keyInstance == null ? null : keyInstance.getKeyManager(algorithm, keyAlias),
                                            trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                            new java.security.SecureRandom() });
            Object result = cls.getMethod("getSocketFactory", new Class[0]).invoke(ctx, new Object[0]);
            return (SSLSocketFactory) result;
            */
            SSLContext context;
            if (provider == null) {
                context = SSLContext.getInstance(protocol);
            } else {
                context= SSLContext.getInstance(protocol, provider);
            }
            context.init(keyInstance == null ? null : keyInstance.getKeyManager(algorithm, keyAlias),
                         trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                         new SecureRandom());
            return context.getSocketFactory();
        } catch (Exception e) {
            log.error("Unable to dynamically load", e);
            return null;
View Full Code Here

                                String keyStore,
                                String keyAlias,
                                String trustStore) throws KeystoreIsLocked,
                    KeyIsLocked, NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException,
                    KeyManagementException, NoSuchProviderException {
        KeystoreInstance keyInstance = getKeystore(keyStore);
        if (keyInstance.isKeystoreLocked()) {
            throw new KeystoreIsLocked("Keystore '" + keyStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }
        if (keyInstance.isKeyLocked(keyAlias)) {
            throw new KeystoreIsLocked("Key '" + keyAlias + "' in keystore '" + keyStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }
        KeystoreInstance trustInstance = trustStore == null ? null : getKeystore(trustStore);
        if (trustInstance != null && trustInstance.isKeystoreLocked()) {
            throw new KeystoreIsLocked("Keystore '" + trustStore
                            + "' is locked; please use the keystore page in the admin console to unlock it");
        }

        // OMG this hurts, but it causes ClassCastExceptions elsewhere unless
        // done this way!
        try {
            /*
            Class cls = loader.loadClass("javax.net.ssl.SSLContext");
            Object ctx = cls.getMethod("getInstance", new Class[] { String.class }).invoke(null,
                            new Object[] { protocol });
            Class kmc = loader.loadClass("[Ljavax.net.ssl.KeyManager;");
            Class tmc = loader.loadClass("[Ljavax.net.ssl.TrustManager;");
            Class src = loader.loadClass("java.security.SecureRandom");
            cls.getMethod("init", new Class[] { kmc, tmc, src }).invoke(
                            ctx,
                            new Object[] { keyInstance.getKeyManager(algorithm, keyAlias),
                                            trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                            new java.security.SecureRandom() });
            Object result = cls.getMethod("getServerSocketFactory", new Class[0]).invoke(ctx, new Object[0]);
            return (SSLServerSocketFactory) result;
            */
            SSLContext context;
            if (provider == null) {
                context = SSLContext.getInstance(protocol);
            } else {
                context= SSLContext.getInstance(protocol, provider);
            }
            context.init(keyInstance == null ? null : keyInstance.getKeyManager(algorithm, keyAlias),
                         trustInstance == null ? null : trustInstance.getTrustManager(algorithm),
                                         new SecureRandom());
            return context.getServerSocketFactory();
        } catch (Exception e) {
            log.error("Unable to dynamically load", e);
            return null;
View Full Code Here

    public void testGetUnknownKeystoreInstance() throws Exception {
        assertNull(keystoreManager.getKeystore("ks2"));
    }
   
    public void testPrivateKey() throws Exception {
        KeystoreInstance ks = keystoreManager.getKeystore("ks");
        String[] pk = ks.listPrivateKeys();
        assertNotNull(pk);
        assertEquals(1, pk.length);
        assertEquals("myalias", pk[0]);
        assertNotNull(ks.getCertificate("myalias"));
        assertNotNull(ks.getPrivateKey("myalias"));
    }
View Full Code Here

TOP

Related Classes of org.apache.servicemix.jbi.security.keystore.KeystoreInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.