Exemple #1
0
        public GlobalName(GeneralNameHook hk, string value)

        {
            NameType = hk;
            if (hk == GeneralNameHook.dirName)
            {
                string sec = SectionManager.CreateSection("S");
                SectionName = sec;
                Value       = "dirName:" + sec;
                StringBuilder sb = new StringBuilder();

                sb.AppendLine("[" + sec + "]");
                foreach (string val in value.Split(','))
                {
                    sb.AppendLine(val);
                }

                SectionValue = sb.ToString();
                SectionManager.DefineSectionFixed(sec, SectionValue);
            }
            else
            {
                Value = hk.ToString() + ":" + value;
            }
        }
Exemple #2
0
        public override string ToOpenSSLEntry()
        {
            StringBuilder sb = new StringBuilder();

            foreach (ASNElement el in Elements)
            {
                string code = el.ToOpenSSLConfig();
                if (code.Length > 0)
                {
                    sb.AppendLine(code);
                }
            }
            string crit = "";

            if (Critical)
            {
                crit = "critical, ";
            }
            if (sb.Length > 0)
            {
                string sec = SectionManager.CreateSection("EXT");
                SectionManager.DefineSection(sec, Environment.NewLine + "[" + sec + "]" + Environment.NewLine + sb.ToString());
                return(NativeName + "=" + crit + "ASN1:SEQUENCE:" + sec);
            }
            return("");
        }
Exemple #3
0
        public string ToOpenSSLConfig()
        {
            if (EType == ElementType.SEQUENCE)
            {
                string sectionname = SectionManager.CreateSectionSequence();
                SectionName = sectionname;
                ExtensionCoder.DefineSection(sectionname);
                if (ParentSection != null)
                {
                    ExtensionCoder.AddFieldInSection(ParentSection.SectionName, Name + "=SEQUENCE:" + sectionname);
                }

                // Childrens
                foreach (ASNElement el in Childs)
                {
                    el.ToOpenSSLConfig();
                }

                if (ParentSection == null)
                {
                    return(Name + "=" + EType.ToString() + ":" + sectionname);
                }
            }
            else if (ParentSection != null)
            {
                ExtensionCoder.AddFieldInSection(ParentSection.SectionName, Name + "=" + EType.ToString() + ":" + Value);
            }
            else
            {
                return(Name + "=" + EType.ToString() + ":" + Value);
            }

            return("");
        }
Exemple #4
0
 public static void Export(string config, List <X509Ext> ext)
 {
     using (StreamWriter str = new StreamWriter(config, false))
     {
         str.WriteLine("[ cert ]");
         str.WriteLine("default_ca	= CA_default");
         str.WriteLine("[ CA_default ]");
         str.WriteLine("x509_extensions	= v3_ca");
         str.WriteLine("[ v3_ca ]");
         foreach (X509Ext ex in ext)
         {
             str.WriteLine(ex.ToOpenSSLEntry());
         }
         str.WriteLine(SectionManager.SectionsToCode());
         //  str.WriteLine(Al.Security.CA.Properties.Resources.newoids);
     }
 }
Exemple #5
0
        public PolicyInformationEntry(string oid, string cps, string org, string usernotice)
        {
            Name = SectionManager.CreateSection("POL");

            SectionValue = "[" + Name + "]" + Environment.NewLine;
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("policyIdentifier=" + oid);
            if (!string.IsNullOrEmpty(cps))
            {
                sb.AppendLine("CPS.1=" + cps);
            }

            if (!string.IsNullOrEmpty(org) || !string.IsNullOrEmpty(usernotice))
            {
                string noticesection = SectionManager.CreateSection("NOTICEPOL");
                sb.AppendLine("userNotice.1=@" + noticesection);
                SectionValue += sb.ToString();

                sb.Length = 0;


                string noticecode = "[" + noticesection + "]" + Environment.NewLine;
                if (!string.IsNullOrEmpty(usernotice))
                {
                    sb.AppendLine("explicitText=" + usernotice);
                    sb.AppendLine("noticeNumbers=1");
                }
                if (!string.IsNullOrEmpty(org))
                {
                    sb.AppendLine("organization=" + org);
                }



                noticecode += sb.ToString();
                SectionManager.DefineSectionFixed(noticesection, noticecode);
                SectionName = noticesection;
            }
            else
            {
                SectionValue += sb.ToString();
            }
            SectionManager.DefineSectionFixed(Name, SectionValue);
        }
Exemple #6
0
        public DistributionPointEntry(List <ReasonsHook> reasons, List <GlobalName> access, bool indirecturl, bool onlyca, bool onlyaa, bool onlyuser)
        {
            Issuer = true;
            string sec = SectionManager.CreateSection("IDP");

            Name = sec;
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("[" + sec + "]");
            string fullname = "";

            if (access.Count > 0)
            {
                fullname = "fullname=";
                string fs = "";
                foreach (GlobalName g in access)
                {
                    if (g.NameType != GeneralNameHook.dirName)
                    {
                        fullname += g.Value + ", ";
                    }

                    //if (g.SectionValue != "")
                    //    fs += g.SectionValue + Environment.NewLine;
                }
                if (fullname.Length > 0)
                {
                    fullname = fullname.Remove(fullname.Length - 2, 2);
                }
            }
            string reason = "";

            if (reasons.Count > 0)
            {
                reason = "onlysomereasons=";
                foreach (ReasonsHook rh in reasons)
                {
                    reason += rh.ToString() + ", ";
                }

                if (reason.Length > 0)
                {
                    reason = reason.Remove(reason.Length - 2, 2);
                }
            }
            sb.AppendLine(fullname);
            sb.AppendLine(reason);
            sb.AppendLine("indirectCRL=" + indirecturl.ToString().ToUpper());
            sb.AppendLine("onlyuser="******"onlyCA=" + onlyca.ToString().ToUpper());
            sb.AppendLine("onlyAA=" + onlyaa.ToString().ToUpper());


            //if (fs == cs)
            //    sb.AppendLine(fs);
            //else
            //{

            //    sb.AppendLine(fs);
            //    sb.AppendLine(cs);
            //}

            sb.AppendLine("[issuer_sect]");
            sb.AppendLine(" C=TN");
            SectionCode = sb.ToString();
            SectionName = sec;
            SectionManager.DefineSectionFixed(sec, SectionCode);
        }
Exemple #7
0
        public DistributionPointEntry(List <ReasonsHook> reasons, List <GlobalName> access, List <GlobalName> crlissuer)
        {
            string sec = SectionManager.CreateSectionCrl();

            Name = sec;
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("[" + sec + "]");
            string fullname = "";

            if (access.Count > 0)
            {
                fullname = "fullname=";
                string fs = "";
                foreach (GlobalName g in access)
                {
                    fullname += g.Value + ", ";

                    //if (g.SectionValue != "")
                    //    fs += g.SectionValue + Environment.NewLine;
                }
                if (fullname.Length > 0)
                {
                    fullname = fullname.Remove(fullname.Length - 2, 2);
                }
            }
            string crliss = "";

            crliss = "CRLissuer=";
            string cs = "";

            foreach (GlobalName g in crlissuer)
            {
                crliss += g.Value + ", ";

                //if (g.SectionValue != "")
                //    cs += g.SectionValue + Environment.NewLine;
            }
            if (crliss.Length > 0)
            {
                crliss = crliss.Remove(crliss.Length - 2, 2);
            }
            string reason = "";

            if (reasons.Count > 0)
            {
                reason = "reasons=";
                foreach (ReasonsHook rh in reasons)
                {
                    reason += rh.ToString() + ", ";
                }

                if (reason.Length > 0)
                {
                    reason = reason.Remove(reason.Length - 2, 2);
                }
            }
            sb.AppendLine(fullname);
            sb.AppendLine(crliss);
            sb.AppendLine(reason);
            //if (fs == cs)
            //    sb.AppendLine(fs);
            //else
            //{

            //    sb.AppendLine(fs);
            //    sb.AppendLine(cs);
            //}
            //sb.AppendLine("[issuer_sect]");
            //sb.AppendLine(" C=TN");
            SectionCode = sb.ToString();
            SectionName = sec;
            SectionManager.DefineSectionFixed(sec, SectionCode);
        }
Exemple #8
0
 public static void DefineSection(string name)
 {
     SectionManager.DefineSection(name, "[" + name + "]");
 }