Package com.sun.net.ssl

Examples of com.sun.net.ssl.TrustManagerFactory


    /**
     * Constructor for EasyX509TrustManager.
     */
    public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
        super();
        TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509");
        factory.init(keystore);
        TrustManager[] trustmanagers = factory.getTrustManagers();
        if (trustmanagers.length == 0) {
            throw new NoSuchAlgorithmException("SunX509 trust manager not supported");
        }
        this.standardTrustManager = (X509TrustManager)trustmanagers[0];
    }
View Full Code Here


        try {
            ClassLoader cl = SimpleSocketFactory.class.getClassLoader();
            URL url = cl.getResource("org/apache/commons/httpclient/ssl/simpleserver.keystore");
            KeyStore keystore  = KeyStore.getInstance("jks");
            keystore.load(url.openStream(), "nopassword".toCharArray());
            TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
                    TrustManagerFactory.getDefaultAlgorithm());
            tmfactory.init(keystore);
            TrustManager[] trustmanagers = tmfactory.getTrustManagers();
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, trustmanagers, null);
            return sslcontext;
        } catch (Exception ex) {
            // this is not the way a sane exception handling should be done
View Full Code Here

    {
        if (keystore == null) {
            throw new IllegalArgumentException("Keystore may not be null");
        }
        LOG.debug("Initializing trust manager");
        TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
            TrustManagerFactory.getDefaultAlgorithm());
        tmfactory.init(keystore);
        TrustManager[] trustmanagers = tmfactory.getTrustManagers();
        for (int i = 0; i < trustmanagers.length; i++) {
            if (trustmanagers[i] instanceof X509TrustManager) {
                trustmanagers[i] = new AuthSSLX509TrustManager(
                    (X509TrustManager)trustmanagers[i]);
            }
View Full Code Here

    {
        if (keystore == null) {
            throw new IllegalArgumentException("Keystore may not be null");
        }
        LOG.debug("Initializing trust manager");
        TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
            TrustManagerFactory.getDefaultAlgorithm());
        tmfactory.init(keystore);
        TrustManager[] trustmanagers = tmfactory.getTrustManagers();
        for (int i = 0; i < trustmanagers.length; i++) {
            if (trustmanagers[i] instanceof X509TrustManager) {
                trustmanagers[i] = new AuthSSLX509TrustManager(
                    (X509TrustManager)trustmanagers[i]);
            }
View Full Code Here

        try {
            ClassLoader cl = SimpleSocketFactory.class.getClassLoader();
            URL url = cl.getResource("org/apache/commons/httpclient/ssl/simpleserver.keystore");
            KeyStore keystore  = KeyStore.getInstance("jks");
            keystore.load(url.openStream(), "nopassword".toCharArray());
            TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
                    TrustManagerFactory.getDefaultAlgorithm());
            tmfactory.init(keystore);
            TrustManager[] trustmanagers = tmfactory.getTrustManagers();
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, trustmanagers, null);
            return sslcontext;
        } catch (Exception ex) {
            // this is not the way a sane exception handling should be done
View Full Code Here

    {
        if (keystore == null) {
            throw new IllegalArgumentException("Keystore may not be null");
        }
        LOG.debug("Initializing trust manager");
        TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
            TrustManagerFactory.getDefaultAlgorithm());
        tmfactory.init(keystore);
        TrustManager[] trustmanagers = tmfactory.getTrustManagers();
        for (int i = 0; i < trustmanagers.length; i++) {
            if (trustmanagers[i] instanceof X509TrustManager) {
                trustmanagers[i] = new AuthSSLX509TrustManager(
                    (X509TrustManager)trustmanagers[i]);
            }
View Full Code Here

    /**
     * Constructor for EasyX509TrustManager.
     */
    public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
        super();
        TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509");
        factory.init(keystore);
        TrustManager[] trustmanagers = factory.getTrustManagers();
        if (trustmanagers.length == 0) {
            throw new NoSuchAlgorithmException("SunX509 trust manager not supported");
        }
        this.standardTrustManager = (X509TrustManager)trustmanagers[0];
    }
View Full Code Here

         KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(m_keyManagerAlgorithm);
         // Use the keystore password as default if not given
         keyFactory.init(keystore, m_keyManagerPassword == null ? m_keyStorePassword.toCharArray() : m_keyManagerPassword.toCharArray());

         TrustManagerFactory trustFactory = null;
         if (m_trustStoreName != null)
         {
            // User specified a trust store, retrieve it

            if (m_trustStorePassword == null)
            {
               throw new IOException("TrustStore password cannot be null");
            }

            KeyStore trustStore = KeyStore.getInstance(m_trustStoreType);
            InputStream trustStoreStream = getClass().getClassLoader().getResourceAsStream(m_trustStoreName);
            // Check for nullity
            if (trustStoreStream == null)
            {
               throw new IOException("Cannot find TrustStore " + m_trustStoreName);
            }
            trustStore.load(trustStoreStream, m_trustStorePassword.toCharArray());

            trustFactory = TrustManagerFactory.getInstance(m_trustManagerAlgorithm);
            trustFactory.init(trustStore);
         }

         SSLContext context = SSLContext.getInstance(m_sslProtocol);
         // Below call does not handle TrustManagers, needed when server must authenticate clients.
         context.init(keyFactory.getKeyManagers(), trustFactory == null ? null : trustFactory.getTrustManagers(), null);

         SSLServerSocketFactory ssf = context.getServerSocketFactory();
         SSLServerSocket serverSocket = (SSLServerSocket)ssf.createServerSocket(port, backlog, InetAddress.getByName(host));

         return serverSocket;
View Full Code Here

                is = url.openStream();
                keystore.load(is, "nopassword".toCharArray());
            } finally {
                if (is != null) is.close();
            }
            TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
                    TrustManagerFactory.getDefaultAlgorithm());
            tmfactory.init(keystore);
            TrustManager[] trustmanagers = tmfactory.getTrustManagers();
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, trustmanagers, null);
            return sslcontext;
        } catch (Exception ex) {
            // this is not the way a sane exception handling should be done
View Full Code Here

                is = url.openStream();
                keystore.load(is, "nopassword".toCharArray());
            } finally {
                if (is != null) is.close();
            }
            TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
                    TrustManagerFactory.getDefaultAlgorithm());
            tmfactory.init(keystore);
            TrustManager[] trustmanagers = tmfactory.getTrustManagers();
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, trustmanagers, null);
            return sslcontext;
        } catch (Exception ex) {
            // this is not the way a sane exception handling should be done
View Full Code Here

TOP

Related Classes of com.sun.net.ssl.TrustManagerFactory

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.