Examples of KeyStore


Examples of java.security.KeyStore

    private KeyManager km;

    @Override
    protected void setUp() throws Exception {
        KeyStore ks = KeyStore.getInstance("JKS");

        FileInputStream fis = new FileInputStream(
                "src/test/resources/keymanager-test.jks");
        ks.load(fis, "".toCharArray());

        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, "".toCharArray());

        km = kmf.getKeyManagers()[0];
View Full Code Here

Examples of java.security.KeyStore

    private KeyManager km;

    @Override
    protected void setUp() throws Exception {
        KeyStore ks = KeyStore.getInstance("JKS");

        FileInputStream fis = new FileInputStream(
                "src/test/resources/keymanager-test.jks");
        ks.load(fis, "".toCharArray());

        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, "".toCharArray());

        km = kmf.getKeyManagers()[0];
View Full Code Here

Examples of java.security.KeyStore

        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

Examples of java.security.KeyStore

        }
        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

Examples of java.security.KeyStore

   
    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

Examples of java.security.KeyStore

            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

Examples of java.security.KeyStore

    * @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

Examples of java.security.KeyStore

        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

Examples of java.security.KeyStore

            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

Examples of java.security.KeyStore

    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
TOP
Copyright © 2018 www.massapi.com. 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.