Package java.security

Examples of java.security.KeyStore$SimpleLoadStoreParameter


        try {
            SSLContext sslctx = SSLContext.getInstance(secureSocketProtocol);

            KeyManagerFactory kmf =
                KeyManagerFactory.getInstance(keystoreKeyManagerFactoryAlgorithm)
            KeyStore ks = KeyStore.getInstance(keyStoreType);
            FileInputStream fis = new FileInputStream(keyStoreLocation);
            DataInputStream dis = new DataInputStream(fis);
            byte[] bytes = new byte[dis.available()];
            dis.readFully(bytes);
            ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
           
            KeyManager[] keystoreManagers = null;
            if (keyStorePassword != null) {
                try {
                    ks.load(bin, keyStorePassword.toCharArray());
                    kmf.init(ks, keyStorePassword.toCharArray());
                    keystoreManagers = kmf.getKeyManagers();
                    LogUtils.log(LOG, Level.INFO, "LOADED_KEYSTORE", new Object[]{keyStoreLocation});
                } catch (Exception e) {
                    LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE",
                                 new Object[]{keyStoreLocation, e.getMessage()});
               
            }
            if ((keyStorePassword == null) && (keyStoreLocation != null)) {
                LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE_NULL_PASSWORD",
                             new Object[]{keyStoreLocation});
            }
           
            // ************************* Load Trusted CA file *************************
           
            TrustManager[] trustStoreManagers = null;
            KeyStore trustedCertStore = KeyStore.getInstance(trustStoreType);
           
            trustedCertStore.load(new FileInputStream(trustStoreLocation), null);
            TrustManagerFactory tmf  =
                TrustManagerFactory.getInstance(trustStoreKeyManagerFactoryAlgorithm);
            try {
                tmf.init(trustedCertStore);
                trustStoreManagers = tmf.getTrustManagers();
View Full Code Here


        }
        try {
            SSLContext sslctx = SSLContext.getInstance(secureSocketProtocol);
            KeyManagerFactory kmf =
                KeyManagerFactory.getInstance(keystoreKeyManagerFactoryAlgorithm)
            KeyStore ks = KeyStore.getInstance(keyStoreType);
            KeyManager[] keystoreManagers = null;
           
           
            byte[] sslCert = loadClientCredential(keyStoreLocation);
           
            if (sslCert != null && sslCert.length > 0 && keyStorePassword != null) {
                ByteArrayInputStream bin = new ByteArrayInputStream(sslCert);
                try {
                    ks.load(bin, keyStorePassword.toCharArray());
                    kmf.init(ks, keyStorePassword.toCharArray());
                    keystoreManagers = kmf.getKeyManagers();
                    LogUtils.log(LOG, Level.INFO, "LOADED_KEYSTORE", new Object[]{keyStoreLocation});
                } catch (Exception e) {
                    LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE",
                                                     new Object[]{keyStoreLocation, e.getMessage()});
                }
            } 
            if ((keyStorePassword == null) && (keyStoreLocation != null)) {
                LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE_NULL_PASSWORD",
                             new Object[]{keyStoreLocation});
            }
           
            // ************************* Load Trusted CA file *************************
            //TODO could support multiple trust cas
            TrustManager[] trustStoreManagers = new TrustManager[1];
            
            KeyStore trustedCertStore = KeyStore.getInstance(trustStoreType);
            trustedCertStore.load(null, "".toCharArray());
            CertificateFactory cf = CertificateFactory.getInstance(CERTIFICATE_FACTORY_TYPE);
            byte[] caCert = loadCACert(trustStoreLocation);
            try {
                if (caCert != null) {
                    ByteArrayInputStream cabin = new ByteArrayInputStream(caCert);
                    X509Certificate cert = (X509Certificate)cf.generateCertificate(cabin);
                    trustedCertStore.setCertificateEntry(cert.getIssuerDN().toString(), cert);
                    cabin.close();
                }
            } catch (Exception e) {
                LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_TRUST_STORE",
                             new Object[]{trustStoreLocation, e.getMessage()});
View Full Code Here

   
    try {
      String filename = getTestKeyStoreFilename();
     
      char[] passphrase = PASSWORD.toCharArray();
      KeyStore ks = KeyStore.getInstance("JKS");
      ks.load(new FileInputStream(filename), passphrase);
 
      KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
      kmf.init(ks, passphrase);
     
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
View Full Code Here

            if (!ksFile.exists() || !ksFile.isFile())
                throw new WinstoneException(SSL_RESOURCES.getString(
                        "HttpsListener.KeyStoreNotFound", ksFile.getPath()));
            InputStream in = new FileInputStream(ksFile);
            char[] passwordChars = password == null ? null : password.toCharArray();
            KeyStore ks = KeyStore.getInstance("JKS");
            ks.load(in, passwordChars);
            kmf.init(ks, passwordChars);
            Logger.log(Logger.FULL_DEBUG, SSL_RESOURCES,
                    "HttpsListener.KeyCount", ks.size() + "");
            for (Enumeration e = ks.aliases(); e.hasMoreElements();) {
                String alias = (String) e.nextElement();
                Logger.log(Logger.FULL_DEBUG, SSL_RESOURCES,
                        "HttpsListener.KeyFound", new String[] { alias,
                                ks.getCertificate(alias) + "" });
            }

            SSLContext context = SSLContext.getInstance("SSL");
            context.init(kmf.getKeyManagers(), null, null);
            Arrays.fill(passwordChars, 'x');
View Full Code Here

    * @param unused
    * @throws Exception
    */
   public static void main(String unused[]) throws Exception {

      KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

      ks.load(
         new java.io.FileInputStream(
         "data/com/sun/org/apache/xml/internal/security/samples/input/keystore.jks"),
            "xmlsecurity".toCharArray());

      KeyStoreResolver krs = new KeyStoreResolver(ks);
View Full Code Here

        switch (trustMode)
        {
            case TRUST_ALWAYS:
                try
                {
                    KeyStore kStore = getKeyStore();
                    synchronized (kStore)
                    {
                        kStore.setCertificateEntry(
                            String.valueOf(System.currentTimeMillis()), cert);

                        kStore.store(new FileOutputStream(getKeyStoreLocation()),
                            defaultPassword);
                    }
                }
                catch (Exception e)
                {
View Full Code Here

            return DO_NOT_TRUST;
        else if(dialog.alwaysTrustCheckBox.isSelected())
        {
            try
            {
                KeyStore kStore = getKeyStore();

                synchronized(kStore)
                {
                    // TODO this is potentially dangerous and not what the user
                    // wanted (e.g. trusting a complete fraud CA instead of only
                    // trusting one single certificate
                    for (X509Certificate c : chain)
                        kStore.setCertificateEntry(
                            String.valueOf(System.currentTimeMillis()), c);

                    kStore.store(
                        new FileOutputStream(getKeyStoreLocation()),
                        defaultPassword);
                }
            } catch (Throwable e)
            {
View Full Code Here

    public SSLContext getSSLContext(String message)
        throws IOException
    {
        try
        {
            KeyStore ks = KeyStore.getInstance(
                    System.getProperty(
                            "javax.net.ssl.keyStoreType",
                            KeyStore.getDefaultType()
                        )
                );
            KeyManagerFactory kmFactory = KeyManagerFactory.getInstance(
                    KeyManagerFactory.getDefaultAlgorithm()
            );

            String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
            if(System.getProperty("javax.net.ssl.keyStore") != null)
            {
                ks.load(
                        new FileInputStream(System.getProperty("javax.net.ssl.keyStore")),
                        null
                    );
            }
            else
            {
                ks.load(null, null);
            }

            kmFactory.init(
                    ks,
                    keyStorePassword == null ? null : keyStorePassword.toCharArray()
View Full Code Here

        private void checkLocalTrust(X509Certificate[] chain,
                                    String authType,
                                    CertificateException certificateException)
            throws CertificateException
        {
            KeyStore kStore = getKeyStore();

            if(kStore == null)
                throw certificateException;

            try
            {
                for (int i = 0; i < chain.length; i++)
                {
                    X509Certificate c = chain[i];

                    // check for temporaly allowed certs
                    if(temporalyAllowed.contains(c))
                    {
                        return;
                    }

                    // now check for permanent allow of certs
                    String alias = kStore.getCertificateAlias(c);
                    if(alias != null)
                    {
                        return;
                    }
                }
View Full Code Here

    if (conn instanceof HttpsURLConnection) {
      // Setup the test keystore (truststore).
      URL keyStoreURL = Thread.currentThread().getContextClassLoader()
          .getResource("META-INF/tst.keystore");
      InputStream stream = keyStoreURL.openStream();
      KeyStore keyStore = KeyStore.getInstance("JKS");
      keyStore.load(stream, "unit-tests".toCharArray());
      // Setup the test TrustManagerFactory.
      TrustManagerFactory trustMgr = TrustManagerFactory
          .getInstance(TrustManagerFactory.getDefaultAlgorithm());
      trustMgr.init(keyStore);
      // Setup the test SSLSocketFactory.
View Full Code Here

TOP

Related Classes of java.security.KeyStore$SimpleLoadStoreParameter

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.