Beispiel #1
0
        //chooseServerAlias { keyType = EC_EC }
        //getClientAliases
        //chooseServerAlias { keyType = RSA }
        //getClientAliases
        //chooseServerAlias { keyType = RSA }
        //getClientAliases
        //chooseServerAlias { keyType = RSA }
        //getClientAliases
        //chooseServerAlias { keyType = RSA }
        //getClientAliases


        public static KeyManager[] WindowsMYKeyManagers()
        {
            Console.WriteLine("enter WindowsMYKeyManagers");
            var KeyManagers = new KeyManager[0];


            try
            {
                var xFileInputStream = default(FileInputStream);


                var xKeyStore = default(KeyStore);
                // certmgr.msc
                var xKeyStoreDefaultType = "Windows-MY";

                try
                {
                    Console.WriteLine(new { xKeyStoreDefaultType });
                    xKeyStore = KeyStore.getInstance(xKeyStoreDefaultType);
                }
                catch
                {
                    xKeyStoreDefaultType = java.security.KeyStore.getDefaultType();
                    // http://www.coderanch.com/t/377172/java/java/cacerts-JAVA-HOME-jre-lib
                    // /usr/lib/jvm/default-java/jre/lib/security/cacerts

                    Console.WriteLine(new { xKeyStoreDefaultType });
                    xKeyStore = KeyStore.getInstance(xKeyStoreDefaultType);

                    var fa           = new FileInfo(typeof(Program).Assembly.Location);
                    var keystorepath = fa.Directory.FullName + "/domain.keystore";

                    try
                    {
                        xFileInputStream = new FileInputStream(keystorepath);
                    }
                    catch { throw; }
                }

                Console.WriteLine("WindowsMYKeyManagers " + new { xKeyStore });

                xKeyStore.load(xFileInputStream, null);

                KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");

                Console.WriteLine("WindowsMYKeyManagers " + new { kmf });


                kmf.init(xKeyStore, null);

                KeyManagers = kmf.getKeyManagers();

                Console.WriteLine("WindowsMYKeyManagers " + new { KeyManagers.Length });


                //{ xKeyStoreDefaultType = Windows-MY }
                //WindowsMYKeyManagers { xKeyStore = java.security.KeyStore@ac4d3b }
                //WindowsMYKeyManagers { kmf = javax.net.ssl.KeyManagerFactory@1c7d56b }
                //WindowsMYKeyManagers { KeyManagers = [Ljavax.net.ssl.KeyManager;@f77511 }

                // http://docs.oracle.com/javase/7/docs/api/javax/net/ssl/KeyManager.html
                // http://stackoverflow.com/questions/5292074/how-to-specify-outbound-certificate-alias-for-https-calls
                // http://www.angelfire.com/or/abhilash/site/articles/jsse-km/customKeyManager.html

                foreach (var KeyManager in KeyManagers)
                {
                    var xX509KeyManager = KeyManager as X509KeyManager;
                    if (xX509KeyManager != null)
                    {
                        Console.WriteLine("WindowsMYKeyManagers " + new { xX509KeyManager });
                    }
                }

                //WindowsMYKeyManagers { Length = 1 }
                //WindowsMYKeyManagers { xX509KeyManager = sun.security.ssl.SunX509KeyManagerImpl@ea3932 }


                //KeyStore ks = KeyStore.getInstance("JKS");
                //// initialize KeyStore object using keystore name
                //ks.load(new FileInputStream(keyFile), null);
                //kmf.init(ks, keystorePasswd.toCharArray());
                //ret = kmf.getKeyManagers();

                // chooseServerAlias { keyType = RSA, StackTrace = <__StackTrace> }

                //java.security.KeyStore ks = null;

                //KeyManagerFactory kmf

                // http://stackoverflow.com/questions/15076820/java-sslhandshakeexception-no-cipher-suites-in-common
                // http://stackoverflow.com/questions/7535154/chrome-closing-connection-on-handshake-with-java-ssl-server
            }
            catch
            {
                throw;
            }

            return(KeyManagers);
        }
Beispiel #2
0
        public localKeyManager(
            string keystorepath
            )
        {
            Console.WriteLine("enter localKeyManager");


            try
            {
                var xFileInputStream = default(FileInputStream);


                var xKeyStore = default(KeyStore);
                // certmgr.msc
                var xKeyStoreDefaultType = "Windows-MY";
                var xKeyStorePassword    = default(char[]);

                //try
                //{
                //    Console.WriteLine(new { xKeyStoreDefaultType });
                //    xKeyStore = KeyStore.getInstance(xKeyStoreDefaultType);
                //}
                //catch
                {
                    xKeyStoreDefaultType = java.security.KeyStore.getDefaultType();
                    // http://www.coderanch.com/t/377172/java/java/cacerts-JAVA-HOME-jre-lib
                    // /usr/lib/jvm/default-java/jre/lib/security/cacerts

                    Console.WriteLine(new { xKeyStoreDefaultType });
                    xKeyStore = KeyStore.getInstance(xKeyStoreDefaultType);

                    var fa = new FileInfo(typeof(Program).Assembly.Location);

                    try
                    {
                        xFileInputStream  = new FileInputStream(keystorepath);
                        xKeyStorePassword = "".PadLeft(6, '0').ToCharArray();
                    }
                    catch
                    {
                        throw;
                    }
                }

                Console.WriteLine("localKeyManager " + new { xKeyStore });

                xKeyStore.load(xFileInputStream, xKeyStorePassword);


                java.util.Enumeration en = xKeyStore.aliases();
                //Console.WriteLine("aliases... done");

                while (en.hasMoreElements())
                {
                    alias = (string)en.nextElement();
                }

                KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");

                Console.WriteLine("localKeyManager " + new { kmf, alias });


                kmf.init(xKeyStore, xKeyStorePassword);

                KeyManagers = kmf.getKeyManagers();

                Console.WriteLine("localKeyManager " + new { KeyManagers.Length });


                //{ xKeyStoreDefaultType = Windows-MY }
                //WindowsMYKeyManagers { xKeyStore = java.security.KeyStore@ac4d3b }
                //WindowsMYKeyManagers { kmf = javax.net.ssl.KeyManagerFactory@1c7d56b }
                //WindowsMYKeyManagers { KeyManagers = [Ljavax.net.ssl.KeyManager;@f77511 }

                // http://docs.oracle.com/javase/7/docs/api/javax/net/ssl/KeyManager.html
                // http://stackoverflow.com/questions/5292074/how-to-specify-outbound-certificate-alias-for-https-calls
                // http://www.angelfire.com/or/abhilash/site/articles/jsse-km/customKeyManager.html

                foreach (var KeyManager in KeyManagers)
                {
                    var xX509KeyManager = KeyManager as X509KeyManager;
                    if (xX509KeyManager != null)
                    {
                        Console.WriteLine("localKeyManager " + new { xX509KeyManager });

                        InternalX509KeyManager = xX509KeyManager;
                    }
                }



                // http://stackoverflow.com/questions/15076820/java-sslhandshakeexception-no-cipher-suites-in-common
                // http://stackoverflow.com/questions/7535154/chrome-closing-connection-on-handshake-with-java-ssl-server
            }
            catch
            {
                throw;
            }
        }
Beispiel #3
0
        private SSLSocketFactory getSSLSocketFactory()
        {
            SSLSocketFactory factory = null;

            try
            {
                //reading the keyStore path and password from the environment properties
                string keyStorePath = java.lang.System.getProperty("javax.net.ssl.keyStore");
                java.io.FileInputStream keyStoreStream = null;
                if (keyStorePath != null)
                {
                    java.io.File file = new java.io.File(keyStorePath);
                    if (file.exists())
                    {
                        keyStoreStream = new java.io.FileInputStream(file);
                    }
                    else
                    {
                        keyStoreStream = searchDefaultCacerts();
                    }
                }
                else
                {
                    keyStoreStream = searchDefaultCacerts();
                }

                string keyStorePassWord = java.lang.System.getProperty("javax.net.ssl.keyStorePassword");
                if (keyStorePassWord == null)
                {
                    keyStorePassWord = "******";
                }
                char[] passphrase = keyStorePassWord.ToCharArray();

                //initiating SSLContext
                SSLContext          ctx = SSLContext.getInstance("TLS");
                KeyManagerFactory   kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
                KeyStore            ks  = KeyStore.getInstance("JKS");
                if (keyStoreStream != null)
                {
                    ks.load(keyStoreStream, passphrase);
                }
                else
                {
                    ks.load(null, null);
                }
                kmf.init(ks, passphrase);
                tmf.init(ks);
                ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

                factory = ctx.getSocketFactory();
            }
            catch (Exception e)
            {
                factory = null;
#if DEBUG
                Console.WriteLine("Can't get SSL Socket Factory, the exception is {0}, {1}", e.GetType(), e.Message);
#endif
            }

            return(factory);
        }