Exemplo n.º 1
0
        public void BuildCertificates()
        {
            //Cria os certificados digitais

            //firstEnterprise
            Int64 enterpriseCount = db.ExecuteScalar <Int64>("select count(*) from [enterprise]", CommandType.Text, null, null);

            if (enterpriseCount > 0)
            {
                firstEnterprise = false;
            }

            EnterpriseKey ent = new EnterpriseKey(new Uri("//" + this.fqdn), this.name, firstEnterprise);

            ent.BuildCerts(); //Cria os certificados

            this.ServerPKCS12Cert = ent.ServerPKCS12Cert;
            this.ServerCert       = ent.ServerCert;
            this.ClientPKCS12Cert = ent.ClientPKCS12Cert;
        }
Exemplo n.º 2
0
        private void BuildCert(SqlConnection conn, SqlTransaction trans)
        {
            base.Connection = conn;

            DataTable dt = ExecuteDataTable("select fqdn, name from enterprise with(nolock) where id = " + this.enterpriseId, trans);

            if ((dt == null) || (dt.Rows.Count == 0)) //Não encontrou a empresa
            {
                throw new Exception("Enterprise '" + enterpriseId + "' not found");
            }


            System.Security.Cryptography.SHA1Managed sha = new System.Security.Cryptography.SHA1Managed();
            Byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(dt.Rows[0]["fqdn"].ToString()));
            String key  = BitConverter.ToString(hash).Replace("-", "");


            EnterpriseKey keys = new EnterpriseKey(new Uri("//" + dt.Rows[0]["fqdn"].ToString()), dt.Rows[0]["name"].ToString());

            keys.BuildCerts();

            try
            {
                this.ServerPKCS12String = keys.ServerPKCS12Cert;

                Byte[] certData = Convert.FromBase64String(this.ServerPKCS12String);
                this.ServerCert       = CATools.GetX509CertFromPKCS12(certData, key);
                this.ServerCertString = CATools.X509ToBase64(this.ServerCert);
                this.ServerPKCS12Cert = CATools.LoadCert(certData, key);

                this.ClientPKCS12String = keys.ClientPKCS12Cert;
                this.ClientPKCS12Cert   = CATools.LoadCert(Convert.FromBase64String(this.ClientPKCS12String), key);
            }
            finally
            {
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            String data = "Integrity check error: Multiplus entities (10583, 13065) found at this filtered data";

            List <String> duplicatedEntities = new List <String>();

            //Captura somente os IDs das entidades
            Regex rex = new Regex(@"\((.*?)\)");
            Match m   = rex.Match(data);

            if (m.Success)
            {
                String[] entities = m.Groups[1].Value.Replace(" ", "").Split(",".ToCharArray());
                duplicatedEntities.AddRange(entities);
            }


            FilterRule r = new FilterRule("teste001");

            r.AddCondition("g1", FilterSelector.AND, 1, "Nome", DataType.Text, "Helvio", FilterConditionType.Equal, FilterSelector.OR);
            r.AddCondition("g1", FilterSelector.OR, 1, "Nome", DataType.Text, "Thais", FilterConditionType.Equal, FilterSelector.OR);
            r.AddCondition("g2", FilterSelector.AND, 2, "Setor", DataType.Text, "Financeiro", FilterConditionType.Equal, FilterSelector.OR);
            r.AddCondition("g3", FilterSelector.OR, 3, "Cidade", DataType.Text, "Curitiba", FilterConditionType.Equal, FilterSelector.OR);

            FilterRuleCollection frCol = new FilterRuleCollection();

            frCol.AddFilterRule(r);

            foreach (FilterRule r1 in frCol)
            {
                Console.WriteLine(r1.ToString());
                Console.WriteLine(r1.ToSqlString());
            }

            FilterChecker chk = new FilterChecker(frCol);

            for (Int32 i = 10; i <= 100; i++)
            {
                chk.AddFieldData(i, DataType.Text, "Test 0" + i);
            }

            for (Int32 i = 10; i <= 100; i++)
            {
                chk.AddFieldData(1, DataType.Text, "Teste 1 " + i);
            }

            for (Int32 i = 10; i <= 100; i++)
            {
                chk.AddFieldData(2, DataType.Text, "Teste 2 " + i);
            }

            for (Int32 i = 10; i <= 100; i++)
            {
                chk.AddFieldData(3, DataType.Text, "Teste 3 " + i);
            }

            chk.AddFieldData(1, DataType.Text, "Helvio");
            chk.AddFieldData(1, DataType.Text, "SafeTrend.com.br");
            chk.AddFieldData(1, DataType.Text, "Helvio Carvalho");
            chk.AddFieldData(1, DataType.Text, "Thais Freitas Lima");
            chk.AddFieldData(2, DataType.Text, "Financeiro");
            chk.AddFieldData(3, DataType.Text, "Curitiba");

            FilterMatchCollection col = chk.Matches();

            return;

            String tstj = "{ \"type\":\"SpecificTime\", \"start_time\":\"07:30:00\", \"end_time\":\"19:00:00\", \"week_day\":[\"monday\",\"tuesday\",\"wednesday\",\"thursday\",\"friday\"] }";

            IAM.TimeACL.TimeAccess acl = new IAM.TimeACL.TimeAccess();
            acl.FromJsonString(tstj);
            Console.WriteLine(acl.BetweenTimes(DateTime.Now));


            return;

            String   tst  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff");
            DateTime tst2 = DateTime.Parse(tst);

            EnterpriseKey ent = new EnterpriseKey(new Uri("//demo.safeid.com.br"), "SafeID - Demo");

            ent.BuildCerts(); //Cria os certificados

            StringBuilder text = new StringBuilder();

            text.AppendLine("Server cert");
            text.AppendLine(ent.ServerCert);
            text.AppendLine("");

            text.AppendLine("Server PKCS#12 cert");
            text.AppendLine(ent.ServerPKCS12Cert);
            text.AppendLine("");

            text.AppendLine("Client PKCS#12 cert");
            text.AppendLine(ent.ClientPKCS12Cert);

            File.WriteAllText("certdata.txt", text.ToString());


            /*
             * Dictionary<String, String> properties = new Dictionary<string, string>();
             * properties.Add("locked", "false");
             *
             * UserData user = new UserData(properties);
             *
             * //string parsestr = "(u.ContainsProperty('locked'))";
             * string parsestr = "(u.PropertyIsEqual('locked', 'false'))";
             * var p = new CompiledExpression(parsestr);
             * p.RegisterType("u", user);
             * p.Parse();
             * p.Compile();
             * Console.WriteLine("Result: {0} {1}", p.Eval(), p.Eval().GetType().Name);*/

            //"(vars.myExternalVar + 3) / 2 * 4.5 " // returns 20.25
            //"vars.getRandomNumber()"  // returns a random number
        }