Ejemplo n.º 1
0
        // http://tel.search.ch/api/?was=john+meier&key=IhrSchluessel
        // cor:
        // http://tel.search.ch/api/help
        // http://admin.tel.search.ch/api/getkey#terms

        // http://blog.unto.net/add-opensearch-to-your-site-in-five-minutes.html
        static void Test()
        {
            string loc = System.Reflection.Assembly.GetExecutingAssembly().Location;

            loc = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(loc), @"..\..\".Replace('\\', System.IO.Path.DirectorySeparatorChar));
            loc = System.IO.Path.GetFullPath(loc);


            string fn = System.IO.Path.Combine(loc, "JohnMeier.xml");
            //fn = System.IO.Path.Combine(loc, "MeierError.xml");

            //Person pers = new Person();
            //Tools.XML.Serialization.SerializeToXml<Person>(pers, System.Console.Out);

            //cFeed telsearch = Tools.XML.Serialization.DeserializeXmlFromFile<cFeed>(fn);
            //string strText = System.IO.File.ReadAllText(fn, System.Text.Encoding.UTF8);

            string ApiKey = SecretManager.GetSecret <string>("tel.search.ch API Key");


            string name = "John Meier";

            string strURL = "http://tel.search.ch/api/?was=john+meier&key=API_KEX_HERE";

            strURL = string.Format("http://tel.search.ch/api/?was={0}&key={1}", System.Web.HttpUtility.UrlEncode(name), ApiKey);
            string strText = TelSearch.HttpRequest.HTTP_Get(@"D:\log_telsearch.log.txt", strURL);


            cFeed telsearch = Tools.XML.Serialization.DeserializeXmlFromString <cFeed>(strText);

            Tools.XML.Serialization.SerializeToXml <cFeed>(telsearch, System.Console.Out);
            Tools.XML.Serialization.SerializeToXml <cFeed>(telsearch, @"d:\lol.xml");


            System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
            System.Console.WriteLine(js.Serialize(telsearch));

            //System.Web.Script.Serialization.JavaScriptConverter jcon = new System.Web.Script.Serialization.JavaScriptConverter();

            // http://stackoverflow.com/questions/814001/json-net-convert-json-string-to-xml-or-xml-to-json-string
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.LoadXml(strText);


            string jsonText = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);

            // To convert JSON text contained in string json into an XML node
            System.Xml.XmlDocument doc2 = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(jsonText);
        } // End Sub Main
Ejemplo n.º 2
0
        public void InvalidSecret()
        {
            var dict = new Dictionary <string, string>
            {
                { "key1", "value1" },
                { "key2", "value2" }
            };

            var configuration = new ConfigurationBuilder()
                                .AddInMemoryCollection(dict)
                                .Build();

            SecretManager secretManager = new SecretManager(configuration);

            Assert.Null(secretManager.GetSecret("wrong_key"));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var secretManager         = new SecretManager();
            var emailSenderRequisites = new EmailSenderRequisites
            {
                ServerLogin    = "******",
                ServerEmail    = "*****@*****.**",
                ServerPassword = secretManager.GetSecret("password"),
                SmtpHost       = "smtp.gmail.com",
                SmtpPort       = 587,
            };
            var responsibleRepository = new ResponsibleRepository();
            var emailRepository       = new EmailRepository();
            var emailSender           = new EmailSender(emailSenderRequisites);

            Console.Out.WriteLine("Email sender started!");
            while (true)
            {
                var unsentEmails = emailRepository.ReadUnsentEmails().Shuffle();
                Console.Out.WriteLine($"Found {unsentEmails.Length} unsent emails");
                foreach (var emailId in unsentEmails)
                {
                    try
                    {
                        var email    = emailRepository.ReadEmail(emailId);
                        var doublers = responsibleRepository.GetDoublers(email.ResponsibleId);
                        var myEmail  = "*****@*****.**";
                        // todo(sivukhin, 19.05.2019): Use email.RecipientEmail instead of myEmail
                        foreach (var targetEmail in new[] { myEmail }.Concat(doublers.Select(x => x.Email)))
                        {
                            Console.Out.WriteLine($"Send message to recipient: {targetEmail}");
                            email.RecipientEmail = targetEmail;
                            emailSender.SendEmail(email);
                            emailRepository.SetEmailProcessed(emailId);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine(e);
                    }
                }

                Thread.Sleep(TimeSpan.FromSeconds(1));
            }
        }
Ejemplo n.º 4
0
        public void NewSecret()
        {
            var dict = new Dictionary <string, string>
            {
                { "key1", "value1" },
                { "key2", "value2" }
            };

            var configuration = new ConfigurationBuilder()
                                .AddInMemoryCollection(dict)
                                .Build();

            SecretManager secretManager = new SecretManager(configuration);

            secretManager.SetSecret("key3", "value3");

            Assert.Equal("value3", secretManager.GetSecret("key3"));
        }
Ejemplo n.º 5
0
        private static Redmine.Net.Api.RedmineManager CreateManager()
        {
            /*
             * Redmine.Net.Api.RedmineManager rm2 = new Redmine.Net.Api.RedmineManager(
             *   "host"
             *  ,"apikey"
             *  ,Redmine.Net.Api.MimeFormat.Xml
             *  ,false // Verify SSL-certificate
             *  ,null // Proxy
             *  ,System.Net.SecurityProtocolType.Tls
             * );
             *
             *
             * Redmine.Net.Api.RedmineManager rm = new Redmine.Net.Api.RedmineManager(
             *   "host"
             *  ,Redmine.Net.Api.MimeFormat.Xml
             *  ,false // Verify SSL-certificate
             *  ,null // Proxy
             *  ,System.Net.SecurityProtocolType.Tls
             * );
             */


            string dbUserId = SecretManager.GetSecret <string>("DefaultDbUser");
            string dbPw     = SecretManager.GetSecret <string>("DefaultDbPassword");


            Redmine.Net.Api.RedmineManager redmineManager = new Redmine.Net.Api.RedmineManager(
                // "http://redmine.cor.local"
                //"http://redmine.cor-management.ch"

                //"https://servicedesk.cor-management.ch/Servicedesk/"
                "http://localhost:3000/"
                , SecretManager.GetSecret <string>("RedmineSuperUser")
                , SecretManager.GetSecret <string>("RedmineSuperUserPassword")
                , Redmine.Net.Api.MimeFormat.Xml
                , false // Verify SSL-certificate
                , null  // Proxy
                       // ,new System.Net.WebProxy("http://127.0.0.1:80") // http(s)://<IP>:<Port> e.g. http://127.0.0.1:80
                , System.Net.SecurityProtocolType.Tls
                );

            return(redmineManager);
        } // End Sub CreateManager
        // https://twitter.com/HackerNewsOnion/status/740228588520247296?lang=en
        // Announcing Let’s Decrypt, A SSL Certificate Authority Backed By The NSA

        // Talk about throwing a skunk in the jury pool! I feel like now we need proof this is fiction!
        // ok this activated my paranoia.
        // Announcing Let’s Decrypt, A SSL Certificate Authority Backed By The NSA < It’s totes secure. Promise.
        public static async System.Threading.Tasks.Task Main(string[] args)
        {
            // CreateSslCertificate();
            // SetRegistry();
            // SelfSignedCertificateGenerator.Test.MonitoringTest.TestMonitorChanges();

            string pemKey  = SecretManager.GetSecret <string>("skynet_key");
            string pemCert = SecretManager.GetSecret <string>("skynet_cert");


            Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair rootKey = ReadAsymmetricKeyParameter(pemKey);
            System.Console.WriteLine(rootKey.Private);

            Org.BouncyCastle.X509.X509Certificate rootCert = PemStringToX509(pemCert);
            System.Console.WriteLine(rootCert);

            Org.BouncyCastle.Security.SecureRandom          random      = new Org.BouncyCastle.Security.SecureRandom(NonBackdooredPrng.Create());
            Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair certKeyPair = KeyGenerator.GenerateRsaKeyPair(2048, random);

            Org.BouncyCastle.X509.X509Certificate sslCertificate = SelfSignSslCertificate(
                random
                , rootCert
                , certKeyPair.Public
                , rootKey.Private
                );

            bool val = CerGenerator.ValidateSelfSignedCert(sslCertificate, rootCert.GetPublicKey());

            if (val == false)
            {
                throw new System.InvalidOperationException("SSL certificate does NOT validate successfully.");
            }


            CreatePfxBytes(sslCertificate, certKeyPair.Private, "");

            System.Console.WriteLine(" --- Press any key to continue --- ");
            System.Console.ReadKey();

            await System.Threading.Tasks.Task.CompletedTask;
        }
Ejemplo n.º 7
0
        public static string GetConnectionString()
        {
            System.Data.SqlClient.SqlConnectionStringBuilder csb = new System.Data.SqlClient.SqlConnectionStringBuilder();

            csb.DataSource = System.Environment.MachineName;
            if (System.StringComparer.OrdinalIgnoreCase.Equals("COR", System.Environment.UserDomainName))
            {
                csb.DataSource += @"\SqlExpress";
            }

            csb.InitialCatalog = "COR_Basic_Demo_V4";
            csb.InitialCatalog = "SwissRe_Test_V4";

            csb.IntegratedSecurity = System.StringComparer.OrdinalIgnoreCase.Equals(System.Environment.UserDomainName, "COR");
            if (!csb.IntegratedSecurity)
            {
                csb.UserID   = SecretManager.GetSecret <string>("DefaultDbUser");
                csb.Password = SecretManager.GetSecret <string>("DefaultDbPassword");
            }

            return(csb.ToString());
        }
        } // End Sub ConfigureEndpointDefaults

        public static void HttpsDefaults(
            Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionAdapterOptions listenOptions
            , System.IO.FileSystemWatcher watcher
            )
        {
            bool isNotWindows = !System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);

            System.Collections.Concurrent.ConcurrentDictionary <string, CertHackStore> certs =
                new System.Collections.Concurrent.ConcurrentDictionary <string, CertHackStore>(
                    System.StringComparer.OrdinalIgnoreCase
                    );

            string cert = SecretManager.GetSecret <string>("ssl_cert");
            string key  = SecretManager.GetSecret <string>("ssl_key");

            certs["localhost"] = CertHackStore.FromPem(cert, key);


            // watcher.Filters.Add("localhost.yml");
            // watcher.Filters.Add("example.com.yaml");
            // watcher.Filters.Add("sub.example.com.yaml");

            System.IO.FileSystemEventHandler onChange = delegate(object sender, System.IO.FileSystemEventArgs e)
            {
                CertificateFileChanged(certs, sender, e);
            };


            watcher.Changed += new System.IO.FileSystemEventHandler(onChange);
            watcher.Created += new System.IO.FileSystemEventHandler(onChange);
            watcher.Deleted += new System.IO.FileSystemEventHandler(onChange);
            // watcher.Renamed += new System.IO.RenamedEventHandler(OnRenamed);

            if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
            {
                watcher.EnableRaisingEvents = true;
            }



            listenOptions.ServerCertificateSelector =
                delegate(Microsoft.AspNetCore.Connections.ConnectionContext connectionContext, string name)
            {
                return(ServerCertificateSelector(certs, connectionContext, name));
            };



#if NO_NGINX_FUCKUP
            listenOptions.OnAuthenticate =
                delegate(Microsoft.AspNetCore.Connections.ConnectionContext connectionContext, System.Net.Security.SslServerAuthenticationOptions sslOptions)
            {
                // not supported on Windoze
                if (isNotWindows)
                {
                    sslOptions.CipherSuitesPolicy = new System.Net.Security.CipherSuitesPolicy(
                        new System.Net.Security.TlsCipherSuite[]
                    {
                        System.Net.Security.TlsCipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
                        System.Net.Security.TlsCipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
                        System.Net.Security.TlsCipherSuite.TLS_CHACHA20_POLY1305_SHA256,
                        // ...
                    });
                } // End if (!isWindows)
            }     // End Delegate
            ;     // End OnAuthenticate
#endif
        } // End Sub HttpsDefaults