Example #1
0
        /// <summary>
        /// Edit an extension within a profile
        /// </summary>
        /// <param name="profile">Profile object</param>
        /// <param name="Extension">Extension name</param>
        internal static void EditExtension(Profile profile, string Extension)
        {
            switch (Extension)
            {
            case "Basic Constraints":
                BasicConstraints bc = new BasicConstraints((basicConstraints)FindExtension(profile, typeof(basicConstraints)));
                bc.ShowDialog();
                break;

            case "Key Usage":
                KeyUsage ku = new KeyUsage((keyUsage)FindExtension(profile, typeof(keyUsage)));
                ku.ShowDialog();
                break;

            case "Extended Key Usage":
                ExtendedKeyUsage eku = new ExtendedKeyUsage((extendedKeyUsage)FindExtension(profile, typeof(extendedKeyUsage)));
                eku.ShowDialog();
                break;

            case "CRL Distribution Points":
                CrlDistributionPoint cdp = new CrlDistributionPoint((crlDistPoint)FindExtension(profile, typeof(crlDistPoint)));
                cdp.ShowDialog();
                break;

            case "Subject Alternative Name":
                SubjectAltNames san = new SubjectAltNames((subjectAltName)FindExtension(profile, typeof(subjectAltName)));
                san.ShowDialog();
                break;

            case "Issuer Alternative Name":
                IssuerAltNames ian = new IssuerAltNames((issuerAltName)FindExtension(profile, typeof(issuerAltName)));
                ian.ShowDialog();
                break;

            case "Authority Information Access":
                AuthorityInfoAccess aia = new AuthorityInfoAccess((authorityInfoAccess)FindExtension(profile, typeof(authorityInfoAccess)));
                aia.ShowDialog();
                break;

            case "Subject Information Access":
                SubjectInfoAccess sia = new SubjectInfoAccess((subjectInfoAccess)FindExtension(profile, typeof(subjectInfoAccess)));
                sia.ShowDialog();
                break;

            case "Name Constraints":
                NameConstraints nc = new NameConstraints((nameConstraints)FindExtension(profile, typeof(nameConstraints)));
                nc.ShowDialog();
                break;

            case "Certificate Policies":
                CertificatePolicies cp = new CertificatePolicies((certificatePolicies)FindExtension(profile, typeof(certificatePolicies)));
                cp.ShowDialog();
                break;

            case "Policy Mappings":
                PolicyMappings map = new PolicyMappings((policyMappings)FindExtension(profile, typeof(policyMappings)),
                                                        (certificatePolicies)FindExtension(profile, typeof(certificatePolicies)));
                map.ShowDialog();
                break;

            case "OCSP Nocheck":
                OcspNocheck on = new OcspNocheck((ocspNocheck)FindExtension(profile, typeof(ocspNocheck)));
                on.ShowDialog();
                break;

            case "Inhibit AnyPolicy":
                InhibitAnyPolicy iap = new InhibitAnyPolicy((inhibitAnyPolicy)FindExtension(profile, typeof(inhibitAnyPolicy)));
                iap.ShowDialog();
                break;

            case "Policy Constraints":
                PolicyConstraints pc = new PolicyConstraints((policyConstraints)FindExtension(profile, typeof(policyConstraints)));
                pc.ShowDialog();
                break;

            default:
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Create an extension and add to the profile
        /// </summary>
        /// <param name="profile">Profile object</param>
        /// <param name="Extension">Extension name</param>
        internal static bool CreateExtension(Profile profile, string Extension)
        {
            bool ok = true;

            switch (Extension)
            {
            case "Basic Constraints":
                BasicConstraints bc = new BasicConstraints(null);
                if (bc.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(bc.basCon);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;     // User clicked cancel
                }
                break;

            case "Key Usage":
                KeyUsage ku = new KeyUsage(null);
                if (ku.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(ku.keyUsage);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "Extended Key Usage":
                ExtendedKeyUsage eku = new ExtendedKeyUsage(null);
                if (eku.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(eku.extKeyUsage);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "CRL Distribution Points":
                CrlDistributionPoint cdp = new CrlDistributionPoint(null);
                if (cdp.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(cdp.crlDP);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "Subject Alternative Name":
                SubjectAltNames san = new SubjectAltNames(null);
                if (san.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(san.san);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "Issuer Alternative Name":
                IssuerAltNames ian = new IssuerAltNames(null);
                if (ian.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(ian.ian);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "Authority Information Access":
                AuthorityInfoAccess aia = new AuthorityInfoAccess(null);
                if (aia.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(aia.aia);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "Subject Information Access":
                SubjectInfoAccess sia = new SubjectInfoAccess(null);
                if (sia.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(sia.sia);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "Name Constraints":
                NameConstraints nc = new NameConstraints(null);
                if (nc.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(nc.nc);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "Certificate Policies":
                CertificatePolicies cp = new CertificatePolicies(null);
                if (cp.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(cp.cp);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "Policy Mappings":
                // Can't process this until CertPolicies is defined
                certificatePolicies policy = (certificatePolicies)FindExtension(profile, typeof(certificatePolicies));
                if (policy == null)
                {
                    MessageBox.Show("You must define Certificate Policies before adding this extension", "Policy Mappings", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    ok = false;
                }
                else
                {
                    PolicyMappings map = new PolicyMappings(null, policy);
                    if (map.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            profile.AddExtension(map.mapping);
                        }
                        catch (ArgumentException)
                        {
                            ok = false;
                            MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        ok = false;
                    }
                }
                break;

            case "OCSP Nocheck":
                OcspNocheck on = new OcspNocheck(null);
                if (on.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(on.ocsp);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "Inhibit AnyPolicy":
                InhibitAnyPolicy iap = new InhibitAnyPolicy(null);
                if (iap.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(iap.iAnypol);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            case "Policy Constraints":
                PolicyConstraints pc = new PolicyConstraints(null);
                if (pc.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        profile.AddExtension(pc.polCon);
                    }
                    catch (ArgumentException)
                    {
                        ok = false;
                        MessageBox.Show("Duplicate extensions not permitted", "Profile Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    ok = false;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(Extension);
            }
            return(ok);
        }