// "x:\util\android-sdk-windows\platform-tools\adb.exe"  tcpip 5555
        // restarting in TCP mode port: 5555

        // "x:\util\android-sdk-windows\platform-tools\adb.exe" connect 192.168.1.126:5555
        // connected to 192.168.1.126:5555

        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201505/20150513

        // lets verify this thing . deploy over wifi.

        //C:\Windows\system32> "x:\util\android-sdk-windows\platform-tools\adb.exe" shell netcfg
        //wlan0    UP                               192.168.1.126/24  0x00001043 e8:50:8b:7d:27:7c

        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            //var b = new Button(this).AttachTo(ll);

            //b.WithText("before AtClick");
            //b.AtClick(
            //    v =>
            //    {
            //        b.setText("AtClick");
            //    }
            //);


            this.setContentView(sv);





            // http://www.java2s.com/Tutorial/Java/0490__Security/KeyStoreExample.htm

            //I/System.Console( 5182): 143e:0001 ... { xKeyStoreDefaultType = BKS }
            //I/System.Console( 5182): 143e:0001 { xKeyStore = java.security.KeyStore@274cc17e }
            //I/System.Console( 5182): 143e:0001 load... { keyStoreType = BKS }
            //I/System.Console( 5182): 143e:0001 aliases...


            var xKeyStoreDefaultType = java.security.KeyStore.getDefaultType();

            Console.WriteLine("... " + new { xKeyStoreDefaultType });

            // are we running in GUI or TTY?
            // can we enumerate keystores?

            // ... { xKeyStoreDefaultType = jks }


            Action<string> f = keyStoreType =>
            {
                // jsc should do implicit try catch for closures? while asking for explicit catch for non closures?

                //{ ks = java.security.KeyStore@d3ade7 }
                //{ aliasKey = peer integrity authority for cpu BFEBFBFF000306A9, SerialNumber = 03729f49acf3e79d4cc40da08149433d, SimpleName = peer integrity authority for cpu BFEBFBFF000306A9 }
                //{ aliasKey = peer integrity authority for cpu BFEBFBFF000306C3, SerialNumber = c4761e1ea779bc9546151afce47c7c26, SimpleName = peer integrity authority for cpu BFEBFBFF000306C3 }

                try
                {
                    // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/sun/security/mscapi/SunMSCAPI.java

                    // https://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html

                    // https://social.msdn.microsoft.com/Forums/expression/en-US/52dca221-1e05-44c1-8c45-9e0d4a807853/java-keystoreload-for-windowsmy-pops-up-insert-smart-card-window?forum=windowssecurity
                    // I removed some personal certificaties at key manager (certmgr.msc) and wala!

                    //Client Authentication (1.3.6.1.5.5.7.3.2)
                    //Secure Email (1.3.6.1.5.5.7.3.4)


                    // https://www.chilkatsoft.com/p/p_280.asp
                    // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Base Smart Card Crypto Provider

                    // http://stackoverflow.com/questions/27692904/how-to-avoid-smart-card-selection-popup-when-accessing-windows-my-using-java

                    // http://stackoverflow.com/questions/4552100/how-to-prevent-popups-when-loading-a-keystore
                    // http://stackoverflow.com/questions/15220976/how-to-obtain-a-users-identity-from-a-smartcard-on-windows-mscapi-with-java

                    KeyStore xKeyStore = KeyStore.getInstance(keyStoreType);
                    Console.WriteLine(new { xKeyStore });
                    Console.WriteLine("load... " + new { keyStoreType });
                    xKeyStore.load(null, null);
                    //Console.WriteLine("load... done");
                    Console.WriteLine("aliases...");
                    java.util.Enumeration en = xKeyStore.aliases();
                    //Console.WriteLine("aliases... done");

                    while (en.hasMoreElements())
                    {
                        var aliasKey = (string)en.nextElement();

                        Console.WriteLine(new { aliasKey });

                        // PCSC?
                        var c509 = xKeyStore.getCertificate(aliasKey) as java.security.cert.X509Certificate;
                        if (c509 != null)
                        {
                            X509Certificate2 crt = new __X509Certificate2 { InternalElement = c509 };

                            //Console.WriteLine(new { crt.Subject, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false) });
                            Console.WriteLine(new { aliasKey, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false), crt.Issuer });

                        }
                        //if (aliasKey.equals("myKey") ) {
                        //      PrivateKey key = (PrivateKey)ks.getKey(aliasKey, "monPassword".toCharArray());
                        //      Certificate[] chain = ks.getCertificateChain(aliasKey);
                        //}
                    }

                }
                catch (Exception err)
                {
                    Console.WriteLine(new { err.Message, err.StackTrace });

                }
            };

            //hello ubuntu! { AssemblyQualifiedName = java.lang.Object, rt }
            //... { xKeyStoreDefaultType = jks }
            //{ xKeyStore = java.security.KeyStore@9980d5 }
            //load... { keyStoreType = jks }
            //aliases...
            //done


            new Button(this).AttachTo(ll).WithText(xKeyStoreDefaultType).AtClick(
                delegate
                {

                    // on RED there are no entries?
                    // what about ubuntu?
                    f(xKeyStoreDefaultType);
                }
            );
            //I/System.Console( 7167): 1bff:0001 load... { keyStoreType = AndroidKeyStore }
            //I/System.Console( 7167): 1bff:0001 aliases...


            new Button(this).AttachTo(ll).WithText("AndroidKeyStore").AtClick(
               delegate
               {

                   // on RED there are no entries?
                   // what about ubuntu?
                   f("AndroidKeyStore");
               }
           );



        }
        public static void Main(string[] args)
        {
            // http://stackoverflow.com/questions/11203483/run-a-java-application-as-a-service-on-linux

            // http://askubuntu.com/questions/99232/how-to-make-a-jar-file-run-on-startup-and-when-you-log-out

            // "X:\torrent\ubuntu-14.04.3-server-amd64.iso"
            // http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html

            try
            {
                System.Console.WriteLine("hello ubuntu! " + new
                {
                    typeof(object).AssemblyQualifiedName
                }
                );

                // http://www.java2s.com/Tutorial/Java/0490__Security/KeyStoreExample.htm


                var xKeyStoreDefaultType = java.security.KeyStore.getDefaultType();
                //xKeyStoreDefaultType = "/usr/lib/jvm/default-java/jre/lib/security/cacerts";
                //xKeyStoreDefaultType = "cacerts.jks";

                Console.WriteLine("... " + new { xKeyStoreDefaultType });


                #region useless
                // You can't do it with the system properties. You would have to write and load your own X509KeyManager and create your own SSLContext with it.
                // https://docs.oracle.com/cd/E19830-01/819-4712/ablqw/index.html

                var keyStore = java.lang.System.getProperty("javax.net.ssl.keyStore");
                Console.WriteLine(new { keyStore });
                var trustStore = java.lang.System.getProperty("javax.net.ssl.trustStore");
                Console.WriteLine(new { trustStore });
                #endregion

                // are we running in GUI or TTY?
                // can we enumerate keystores?

                // ... { xKeyStoreDefaultType = jks }


                Action<string> f = keyStoreType =>
                {
                    // jsc should do implicit try catch for closures? while asking for explicit catch for non closures?

                    //{ ks = java.security.KeyStore@d3ade7 }
                    //{ aliasKey = peer integrity authority for cpu BFEBFBFF000306A9, SerialNumber = 03729f49acf3e79d4cc40da08149433d, SimpleName = peer integrity authority for cpu BFEBFBFF000306A9 }
                    //{ aliasKey = peer integrity authority for cpu BFEBFBFF000306C3, SerialNumber = c4761e1ea779bc9546151afce47c7c26, SimpleName = peer integrity authority for cpu BFEBFBFF000306C3 }

                    try
                    {
                        // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/sun/security/mscapi/SunMSCAPI.java

                        // https://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html

                        // https://social.msdn.microsoft.com/Forums/expression/en-US/52dca221-1e05-44c1-8c45-9e0d4a807853/java-keystoreload-for-windowsmy-pops-up-insert-smart-card-window?forum=windowssecurity
                        // I removed some personal certificaties at key manager (certmgr.msc) and wala!

                        //Client Authentication (1.3.6.1.5.5.7.3.2)
                        //Secure Email (1.3.6.1.5.5.7.3.4)


                        // https://www.chilkatsoft.com/p/p_280.asp
                        // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Base Smart Card Crypto Provider

                        // http://stackoverflow.com/questions/27692904/how-to-avoid-smart-card-selection-popup-when-accessing-windows-my-using-java

                        // http://stackoverflow.com/questions/4552100/how-to-prevent-popups-when-loading-a-keystore
                        // http://stackoverflow.com/questions/15220976/how-to-obtain-a-users-identity-from-a-smartcard-on-windows-mscapi-with-java

                        KeyStore xKeyStore = KeyStore.getInstance(keyStoreType);
                        Console.WriteLine(new { xKeyStore });
                        Console.WriteLine("load... " + new { keyStoreType });
                        xKeyStore.load(null, null);
                        //Console.WriteLine("load... done");
                        Console.WriteLine("aliases...");
                        java.util.Enumeration en = xKeyStore.aliases();
                        //Console.WriteLine("aliases... done");

                        while (en.hasMoreElements())
                        {
                            var aliasKey = (string)en.nextElement();

                            Console.WriteLine(new { aliasKey });

                            // PCSC?hhhhhhhhhhhh
                            var c509 = xKeyStore.getCertificate(aliasKey) as java.security.cert.X509Certificate;
                            if (c509 != null)
                            {
                                X509Certificate2 crt = new __X509Certificate2 { InternalElement = c509 };

                                //Console.WriteLine(new { crt.Subject, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false) });
                                Console.WriteLine(new { aliasKey, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false), crt.Issuer });

                            }
                            //if (aliasKey.equals("myKey") ) {
                            //      PrivateKey key = (PrivateKey)ks.getKey(aliasKey, "monPassword".toCharArray());
                            //      Certificate[] chain = ks.getCertificateChain(aliasKey);
                            //}
                        }

                    }
                    catch //(Exception closure)
                    {
                        throw;
                    }
                };

                //hello ubuntu! { AssemblyQualifiedName = java.lang.Object, rt }
                //... { xKeyStoreDefaultType = jks }
                //{ xKeyStore = java.security.KeyStore@9980d5 }
                //load... { keyStoreType = jks }
                //aliases...
                //done


                // on RED there are no entries?
                // what about ubuntu?
                f(xKeyStoreDefaultType);

                //C:\Windows\system32>net use u: \\192.168.1.189\staging
                //The command completed successfully.

                // ubuntu is also empty it seems.
                // what about android?

            }
            catch (Exception err)
            {
                Console.WriteLine(new { err.Message, err.StackTrace });
            }

            Console.WriteLine("done");
            //Thread.Sleep(10000);
            Console.ReadLine();



            // CLR not available? unless there was mono?
            //CLRProgram.CLRMain();
        }
        public static void Main(string[] args)
        {
            // http://stackoverflow.com/questions/1666052/java-https-client-certificate-authentication
            // http://www.berthou.com/us/2007/12/05/ms-capi-and-java-jce-sunmscapi/


            try
            {
                java.lang.System.setProperty("javax.net.debug", "all");



                #region Certificates
                Func<string, IEnumerable<X509Certificate2>> Certificates = keyStoreType =>
                {
                    var a = new List<X509Certificate2> { };

                    try
                    {
                        // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/sun/security/mscapi/SunMSCAPI.java

                        // https://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html

                        // https://social.msdn.microsoft.com/Forums/expression/en-US/52dca221-1e05-44c1-8c45-9e0d4a807853/java-keystoreload-for-windowsmy-pops-up-insert-smart-card-window?forum=windowssecurity
                        // I removed some personal certificaties at key manager (certmgr.msc) and wala!

                        //Client Authentication (1.3.6.1.5.5.7.3.2)
                        //Secure Email (1.3.6.1.5.5.7.3.4)


                        // https://www.chilkatsoft.com/p/p_280.asp
                        // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Base Smart Card Crypto Provider

                        // http://stackoverflow.com/questions/27692904/how-to-avoid-smart-card-selection-popup-when-accessing-windows-my-using-java

                        // http://stackoverflow.com/questions/4552100/how-to-prevent-popups-when-loading-a-keystore
                        // http://stackoverflow.com/questions/15220976/how-to-obtain-a-users-identity-from-a-smartcard-on-windows-mscapi-with-java

                        KeyStore xKeyStore = KeyStore.getInstance(keyStoreType);
                        //Console.WriteLine(new { xKeyStore });
                        //Console.WriteLine("load... " + new { keyStoreType });
                        xKeyStore.load(null, null);
                        //Console.WriteLine("load... done");
                        //Console.WriteLine("aliases...");
                        java.util.Enumeration en = xKeyStore.aliases();
                        //Console.WriteLine("aliases... done");

                        while (en.hasMoreElements())
                        {
                            var aliasKey = (string)en.nextElement();

                            //Console.WriteLine(new { aliasKey });

                            // PCSC?
                            var c509 = xKeyStore.getCertificate(aliasKey) as java.security.cert.X509Certificate;
                            if (c509 != null)
                            {
                                X509Certificate2 crt = new __X509Certificate2 { InternalElement = c509 };

                                //Console.WriteLine(new { crt.Subject, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false) });
                                //Console.WriteLine(new { aliasKey, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false), crt.Issuer });

                                a.Add(crt);

                            }
                            //if (aliasKey.equals("myKey") ) {
                            //      PrivateKey key = (PrivateKey)ks.getKey(aliasKey, "monPassword".toCharArray());
                            //      Certificate[] chain = ks.getCertificateChain(aliasKey);
                            //}
                        }

                    }
                    catch //(Exception closure)
                    {
                        throw;
                    }

                    return a;
                };
                #endregion




                Action<string> f = keyStoreType =>
                {
                    // jsc should do implicit try catch for closures? while asking for explicit catch for non closures?

                    //{ ks = java.security.KeyStore@d3ade7 }
                    //{ aliasKey = peer integrity authority for cpu BFEBFBFF000306A9, SerialNumber = 03729f49acf3e79d4cc40da08149433d, SimpleName = peer integrity authority for cpu BFEBFBFF000306A9 }
                    //{ aliasKey = peer integrity authority for cpu BFEBFBFF000306C3, SerialNumber = c4761e1ea779bc9546151afce47c7c26, SimpleName = peer integrity authority for cpu BFEBFBFF000306C3 }

                    try
                    {
                        // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/sun/security/mscapi/SunMSCAPI.java

                        // https://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html

                        // https://social.msdn.microsoft.com/Forums/expression/en-US/52dca221-1e05-44c1-8c45-9e0d4a807853/java-keystoreload-for-windowsmy-pops-up-insert-smart-card-window?forum=windowssecurity
                        // I removed some personal certificaties at key manager (certmgr.msc) and wala!

                        //Client Authentication (1.3.6.1.5.5.7.3.2)
                        //Secure Email (1.3.6.1.5.5.7.3.4)


                        // https://www.chilkatsoft.com/p/p_280.asp
                        // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Base Smart Card Crypto Provider

                        // http://stackoverflow.com/questions/27692904/how-to-avoid-smart-card-selection-popup-when-accessing-windows-my-using-java

                        // http://stackoverflow.com/questions/4552100/how-to-prevent-popups-when-loading-a-keystore
                        // http://stackoverflow.com/questions/15220976/how-to-obtain-a-users-identity-from-a-smartcard-on-windows-mscapi-with-java

                        KeyStore xKeyStore = KeyStore.getInstance(keyStoreType);
                        Console.WriteLine(new { xKeyStore });
                        Console.WriteLine("load... " + new { keyStoreType });
                        xKeyStore.load(null, null);
                        //Console.WriteLine("load... done");
                        Console.WriteLine("aliases...");
                        java.util.Enumeration en = xKeyStore.aliases();
                        //Console.WriteLine("aliases... done");

                        while (en.hasMoreElements())
                        {
                            var aliasKey = (string)en.nextElement();

                            //Console.WriteLine(new { aliasKey });

                            // PCSC?
                            var c509 = xKeyStore.getCertificate(aliasKey) as java.security.cert.X509Certificate;
                            if (c509 != null)
                            {
                                X509Certificate2 crt = new __X509Certificate2 { InternalElement = c509 };

                                //Console.WriteLine(new { crt.Subject, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false) });
                                Console.WriteLine(new { aliasKey, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false), crt.Issuer });

                            }
                            //if (aliasKey.equals("myKey") ) {
                            //      PrivateKey key = (PrivateKey)ks.getKey(aliasKey, "monPassword".toCharArray());
                            //      Certificate[] chain = ks.getCertificateChain(aliasKey);
                            //}
                        }

                    }
                    catch //(Exception closure)
                    {
                        throw;
                    }
                };

                Certificates("Windows-ROOT").WithEach(
                    crt =>
                    {
                        // aliasKey = peer integrity authority for cpu BFEBFBFF000306A9

                        // SimpleName = peer integrity authority for cpu BFEBFBFF000306A9
                        var SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false);


                        //{ SerialNumber = 01 }
                        //{ SerialNumber = 4a19d2388c82591ca55d735f155ddca3 }
                        //{ SerialNumber = 35def4cf }
                        //{ SerialNumber = 00 }
                        //{ SerialNumber = 7dd9fe07cfa81eb7107967fba78934c6 }
                        //{ SerialNumber = 70bae41d10d92934b638ca7b03ccbabf }
                        //{ SerialNumber = 7dd9fe07cfa81eb7107967fba78934c6 }
                        //{ SerialNumber = 35def4cf }
                        //{ SerialNumber = 00 }
                        //{ SerialNumber = 7dd9fe07cfa81eb7107967fba78934c6 }

                        //                        if (SimpleName == null)
                        //                            Console.WriteLine(new { crt.SerialNumber });
                        //                        else
                        if (SimpleName.StartsWith("peer integrity authority for cpu"))
                            Console.WriteLine(new { SimpleName, crt.SerialNumber, crt.Issuer });
                    }
                );

                //f("Windows-MY");
                Console.WriteLine("-");

                //Caused by: java.lang.NullPointerException
                //        at TestKeyStoreWindowsROOT.Program._Main_b__4(Program.java:214)

                // https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.friendlyname(v=vs.110).aspx


                f("Windows-MY");

                //Certificates("Windows-MY").WithEach(
                //    crt =>
                //    {
                //        // aliasKey = peer integrity authority for cpu BFEBFBFF000306A9

                //        // SimpleName = peer integrity authority for cpu BFEBFBFF000306A9
                //        var SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false);

                //        //if (SimpleName.StartsWith("peer integrity authority for cpu"))
                //        Console.WriteLine(new { SimpleName, crt.SerialNumber, crt.Issuer });
                //    }
                //);

            }
            catch (Exception err)
            {
                Console.WriteLine(new { err.Message, err.StackTrace });
            }


            CLRProgram.CLRMain();
        }
        public static void Main(string[] args)
        {
            // https://javacruft.wordpress.com/2014/06/18/168k-instances/
            // http://www.ubuntu.com/cloud

            //File.WriteAllText(f, w.ToString());

            try
            {
                // https://lists.ubuntu.com/archives/upstart-devel/2014-August/003360.html

                Console.WriteLine("ready!");

                // http://stackoverflow.com/questions/11203483/run-a-java-application-as-a-service-on-linux

                // http://askubuntu.com/questions/99232/how-to-make-a-jar-file-run-on-startup-and-when-you-log-out

                // "X:\torrent\ubuntu-14.04.3-server-amd64.iso"
                // http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
                // http://www.markhneedham.com/blog/2012/09/29/upstart-job-getting-stuck-in-the-startkilled-state/

                System.Console.WriteLine("hello ubuntu!! " + new
                {
                    //typeof(object).AssemblyQualifiedName,

                    // rt location.
                    //typeof(object).Assembly.Location,
                    typeof(Program).Assembly.Location,

                    // /home/xuser
                    //Environment.CurrentDirectory
                }
                );


                //Implementation not found for type import :
                //type: System.Environment
                //method: Void set_CurrentDirectory(System.String)

                //Environment.CurrentDirectory =;

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

                //var fadir = new DirectoryInfo(Path.GetDirectoryName(fa.FullName));



                Console.WriteLine(new { fa.Directory });


                #region truststore/keystore
                {
                    var xKeyStoreDefaultType = java.security.KeyStore.getDefaultType();
                    //xKeyStoreDefaultType = "/usr/lib/jvm/default-java/jre/lib/security/cacerts";
                    //xKeyStoreDefaultType = "cacerts.jks";

                    Console.WriteLine("... " + new { xKeyStoreDefaultType });


                    // You can't do it with the system properties. You would have to write and load your own X509KeyManager and create your own SSLContext with it.
                    // https://docs.oracle.com/cd/E19830-01/819-4712/ablqw/index.html

                    var keyStore = java.lang.System.getProperty("javax.net.ssl.keyStore");
                    Console.WriteLine(new { keyStore });
                    var trustStore = java.lang.System.getProperty("javax.net.ssl.trustStore");
                    Console.WriteLine(new { trustStore });

                    // are we running in GUI or TTY?
                    // can we enumerate keystores?

                    // ... { xKeyStoreDefaultType = jks }


                    Action<string, Func<InputStream>> f = (keyStoreType, loadstream) =>
                    {
                        // jsc should do implicit try catch for closures? while asking for explicit catch for non closures?

                        //{ ks = java.security.KeyStore@d3ade7 }
                        //{ aliasKey = peer integrity authority for cpu BFEBFBFF000306A9, SerialNumber = 03729f49acf3e79d4cc40da08149433d, SimpleName = peer integrity authority for cpu BFEBFBFF000306A9 }
                        //{ aliasKey = peer integrity authority for cpu BFEBFBFF000306C3, SerialNumber = c4761e1ea779bc9546151afce47c7c26, SimpleName = peer integrity authority for cpu BFEBFBFF000306C3 }

                        try
                        {
                            // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/sun/security/mscapi/SunMSCAPI.java

                            // https://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html

                            // https://social.msdn.microsoft.com/Forums/expression/en-US/52dca221-1e05-44c1-8c45-9e0d4a807853/java-keystoreload-for-windowsmy-pops-up-insert-smart-card-window?forum=windowssecurity
                            // I removed some personal certificaties at key manager (certmgr.msc) and wala!

                            //Client Authentication (1.3.6.1.5.5.7.3.2)
                            //Secure Email (1.3.6.1.5.5.7.3.4)


                            // https://www.chilkatsoft.com/p/p_280.asp
                            // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Base Smart Card Crypto Provider

                            // http://stackoverflow.com/questions/27692904/how-to-avoid-smart-card-selection-popup-when-accessing-windows-my-using-java

                            // http://stackoverflow.com/questions/4552100/how-to-prevent-popups-when-loading-a-keystore
                            // http://stackoverflow.com/questions/15220976/how-to-obtain-a-users-identity-from-a-smartcard-on-windows-mscapi-with-java

                            KeyStore xKeyStore = KeyStore.getInstance(keyStoreType);
                            Console.WriteLine(new { xKeyStore });
                            Console.WriteLine("load... " + new { keyStoreType });
                            xKeyStore.load(loadstream(), null);
                            //Console.WriteLine("load... done");
                            Console.WriteLine("aliases...");
                            java.util.Enumeration en = xKeyStore.aliases();
                            //Console.WriteLine("aliases... done");

                            while (en.hasMoreElements())
                            {
                                var aliasKey = (string)en.nextElement();

                                Console.WriteLine(new { aliasKey });

                                // PCSC?hhhhhhhhhhhh
                                var c509 = xKeyStore.getCertificate(aliasKey) as java.security.cert.X509Certificate;
                                if (c509 != null)
                                {
                                    X509Certificate2 crt = new __X509Certificate2 { InternalElement = c509 };

                                    //Console.WriteLine(new { crt.Subject, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false) });
                                    Console.WriteLine(new { aliasKey, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false), crt.Issuer });

                                }
                                //if (aliasKey.equals("myKey") ) {
                                //      PrivateKey key = (PrivateKey)ks.getKey(aliasKey, "monPassword".toCharArray());
                                //      Certificate[] chain = ks.getCertificateChain(aliasKey);
                                //}
                            }

                        }
                        catch //(Exception closure)
                        {
                            throw;
                        }
                    };

                    //hello ubuntu! { AssemblyQualifiedName = java.lang.Object, rt }
                    //... { xKeyStoreDefaultType = jks }
                    //{ xKeyStore = java.security.KeyStore@9980d5 }
                    //load... { keyStoreType = jks }
                    //aliases...
                    //done


                    // on RED there are no entries?
                    // what about ubuntu?
                    f(xKeyStoreDefaultType, () =>
                        {
                            var xx = default(FileInputStream);

                            try
                            {
                                xx = new FileInputStream(keystorepath);
                            }
                            catch { throw; }
                            return xx;
                        }
                        );
                }
                #endregion

                var w = new StringBuilder { };

                w.AppendLine(new { DateTime.Now }.ToString());


                // https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1387241
                // https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
                // http://unix.stackexchange.com/questions/196166/how-to-find-out-if-a-system-uses-sysv-upstart-or-systemd-initsystem
                // https://lists.ubuntu.com/archives/upstart-devel/2011-January/001370.html
                // http://askubuntu.com/questions/62790/upstart-service-never-starts-or-stops-completely
                // http://askubuntu.com/questions/19320/how-to-enable-or-disable-services
                // http://serverfault.com/questions/251982/ubuntu-upstart-script-hangs-on-start-and-stop



                //var servicesdir = new DirectoryInfo("/lib/systemd/system/");

                // https://www.centos.org/forums/viewtopic.php?t=4300
                // http://upstart.ubuntu.com/getting-started.html

                // initctl reload-configuration 
                // https://www.centos.org/forums/viewtopic.php?t=4300
                // initctl show-config
                // http://unix.stackexchange.com/questions/84252/how-to-start-a-service-automatically-when-ubuntu-starts
                // https://serversforhackers.com/video/process-monitoring-with-upstart
                // http://upstart.ubuntu.com/cookbook/

                // http://www.yyosifov.com/2014/04/upstart-syntax-error-bad-fd-number.html
                // /var/log/upstart/ubuntubootexperiment.log

                // http://serverfault.com/questions/453136/understanding-upstart-script-stanza
                // https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=582745
                // http://askubuntu.com/questions/162768/starting-java-processes-with-upstart

                // https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=582745
                // ps aux
                // http://askubuntu.com/questions/397502/reboot-a-server-from-command-line

                var servicesdir = new DirectoryInfo("/etc/init/");
                w.AppendLine(new { servicesdir }.ToString());


                foreach (var service in servicesdir.GetFiles())
                {
                    w.AppendLine(
                        new { service.FullName }.ToString()
                    );

                }


                var ff = fa.Directory.FullName + "/hello.txt";

                Console.WriteLine(new { ff });
                //File.WriteAllText(fadir + "/hello.txt", "hi");

                System.IO.File.WriteAllText(ff, w.ToString());


                // are we running in GUI or TTY?
                // can we enumerate keystores?

                //var sw = Stopwatch.StartNew();

                //while (sw.ElapsedMilliseconds < 20000)
                //{
                //    Console.WriteLine(new { sw.ElapsedMilliseconds });
                //    Thread.Sleep(500);
                //}

                Console.WriteLine("boot into tcp server...");

                // haha. jsc cannot use a release build version of the ref
                // nor can it call the Main again.

                // why cant main call main?
                // cuz the type name is the same?
                JVMCLRTCPServerAsync.Program2.Main2(args);


                //Thread.Sleep(30000);

                // tail -f .log
            }
            catch (Exception err)
            {

                Console.WriteLine(new { err.Message, err.StackTrace });

                Console.ReadLine();
            }


            // CLR not available? unless there was mono?
            //CLRProgram.CLRMain();
        }