internal CertificateTemplateSettings(IX509CertificateTemplate template)
 {
     initializeFromCOM(template);
     Cryptography          = new CryptographyTemplateSettings(template);
     RegistrationAuthority = new IssuanceRequirements(template);
     KeyArchivalSettings   = new KeyArchivalOptions(template);
 }
Beispiel #2
0
 void InitializeCom(IX509CertificateTemplate template)
 {
     if (CryptographyUtils.TestOleCompat())
     {
         if (((Int32)template.Property[EnrollmentTemplateProperty.TemplatePropPrivateKeyFlags] & (Int32)PrivateKeyFlags.RequireKeyArchival) > 0)
         {
             KeyArchival = true;
             try {
                 IObjectId soid = (IObjectId)template.Property[EnrollmentTemplateProperty.TemplatePropSymmetricAlgorithm];
                 EncryptionAlgorithm = new Oid(soid.Value);
             } catch { }
             try {
                 KeyLength = (Int32)template.Property[EnrollmentTemplateProperty.TemplatePropSymmetricKeyLength];
             } catch { }
         }
     }
     else
     {
         if (((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropPrivateKeyFlags] & (Int32)PrivateKeyFlags.RequireKeyArchival) > 0)
         {
             KeyArchival = true;
             try {
                 IObjectId soid = (IObjectId)template.Property[EnrollmentTemplateProperty.TemplatePropSymmetricAlgorithm];
                 EncryptionAlgorithm = new Oid(soid.Value);
             } catch { }
             try {
                 KeyLength = Convert.ToInt32(template.Property[EnrollmentTemplateProperty.TemplatePropSymmetricKeyLength]);
             } catch { }
         }
     }
 }
        void initializeFromCOM(IX509CertificateTemplate template)
        {
            if (CryptographyUtils.TestOleCompat())
            {
                GeneralFlags      = (CertificateTemplateFlags)template.Property[EnrollmentTemplateProperty.TemplatePropGeneralFlags];
                EnrollmentOptions = (CertificateTemplateEnrollmentFlags)template.Property[EnrollmentTemplateProperty.TemplatePropEnrollmentFlags];
                subjectFlags      = (Int32)template.Property[EnrollmentTemplateProperty.TemplatePropSubjectNameFlags];
                ValidityPeriod    = readValidity(null, (Int64)template.Property[EnrollmentTemplateProperty.TemplatePropValidityPeriod]);
                RenewalPeriod     = readValidity(null, (Int64)template.Property[EnrollmentTemplateProperty.TemplatePropRenewalPeriod]);
            }
            else
            {
                GeneralFlags      = (CertificateTemplateFlags)Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropGeneralFlags]);
                EnrollmentOptions = (CertificateTemplateEnrollmentFlags)Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropEnrollmentFlags]);
                subjectFlags      = unchecked ((Int32)(UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropSubjectNameFlags]);
                ValidityPeriod    = readValidity(null, Convert.ToInt64((UInt64)template.Property[EnrollmentTemplateProperty.TemplatePropValidityPeriod]));
                RenewalPeriod     = readValidity(null, Convert.ToInt64((UInt64)template.Property[EnrollmentTemplateProperty.TemplatePropRenewalPeriod]));
            }
            try {
                SupersededTemplates = (String[])template.Property[EnrollmentTemplateProperty.TemplatePropSupersede];
            } catch {
                SupersededTemplates = Array.Empty <String>();
            }
            List <X509Extension> exts2 = (from IX509Extension ext in (IX509Extensions)template.Property[EnrollmentTemplateProperty.TemplatePropExtensions] select new X509Extension(ext.ObjectId.Value, Convert.FromBase64String(ext.RawData[Interop.CERTENROLLLib.EncodingType.XCN_CRYPT_STRING_BASE64]), ext.Critical)).Select(CryptographyUtils.ConvertExtension).ToList();

            foreach (X509Extension ext in exts2)
            {
                _extensions.Add(ext);
            }
        }
Beispiel #4
0
 internal CertificateTemplateSettings(IX509CertificateTemplate template)
 {
     InitializeCom(template);
     Cryptography          = new CryptographyTemplateSettings(template);
     RegistrationAuthority = new IssuanceRequirements(template);
     CriticalExtensions    = new OidCollection();
     KeyArchivalSettings   = new KeyArchivalOptions(template);
 }
 void initializeCom(IX509CertificateTemplate template)
 {
     Name        = (String)template.Property[EnrollmentTemplateProperty.TemplatePropCommonName];
     DisplayName = (String)template.Property[EnrollmentTemplateProperty.TemplatePropFriendlyName];
     OID         = new Oid(((IObjectId)template.Property[EnrollmentTemplateProperty.TemplatePropOID]).Value);
     if (CryptographyUtils.TestOleCompat())
     {
         major         = (Int32)template.Property[EnrollmentTemplateProperty.TemplatePropMajorRevision];
         minor         = (Int32)template.Property[EnrollmentTemplateProperty.TemplatePropMinorRevision];
         SchemaVersion = (Int32)template.Property[EnrollmentTemplateProperty.TemplatePropSchemaVersion];
     }
     else
     {
         major         = Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropMajorRevision]);
         minor         = Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropMinorRevision]);
         SchemaVersion = Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropSchemaVersion]);
     }
 }
Beispiel #6
0
 void InitializeCom(IX509CertificateTemplate template)
 {
     if (CryptographyUtils.TestOleCompat())
     {
         try {
             pkf = (Int32)template.Property[EnrollmentTemplateProperty.TemplatePropPrivateKeyFlags];
         } catch { }
         MinimalKeyLength = (Int32)template.Property[EnrollmentTemplateProperty.TemplatePropMinimumKeySize];
         KeySpec          = (X509KeySpecFlags)(Int32)template.Property[EnrollmentTemplateProperty.TemplatePropKeySpec];
         try {
             CNGKeyUsage = (X509CNGKeyUsages)(Int32)template.Property[EnrollmentTemplateProperty.TemplatePropKeyUsage];
         } catch { }
     }
     else
     {
         try {
             pkf = Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropPrivateKeyFlags]);
         } catch { }
         MinimalKeyLength = Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropMinimumKeySize]);
         KeySpec          = (X509KeySpecFlags)Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropKeySpec]);
         try {
             CNGKeyUsage = (X509CNGKeyUsages)Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropKeyUsage]);
         } catch { }
     }
     try {
         CSPList = (String[])template.Property[EnrollmentTemplateProperty.TemplatePropCryptoProviders];
     } catch { }
     try {
         KeyAlgorithm = new Oid((String)template.Property[EnrollmentTemplateProperty.TemplatePropAsymmetricAlgorithm]);
     } catch {
         KeyAlgorithm = new Oid("RSA");
     }
     try {
         HashAlgorithm = new Oid((String)template.Property[EnrollmentTemplateProperty.TemplatePropHashAlgorithm]);
     } catch {
         HashAlgorithm = new Oid("SHA1");
     }
     try {
         PrivateKeySecuritySDDL = (String)template.Property[EnrollmentTemplateProperty.TemplatePropKeySecurityDescriptor];
     } catch { }
 }
Beispiel #7
0
 void InitializeCom(IX509CertificateTemplate template)
 {
     if (CryptographyUtils.TestOleCompat())
     {
         try {
             SignatureCount  = (Int32)template.Property[EnrollmentTemplateProperty.TemplatePropRASignatureCount];
             enrollmentFlags = (Int32)template.Property[EnrollmentTemplateProperty.TemplatePropEnrollmentFlags];
         } catch {
             SignatureCount  = 0;
             enrollmentFlags = 0;
         }
     }
     else
     {
         try {
             SignatureCount  = Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropRASignatureCount]);
             enrollmentFlags = Convert.ToInt32((UInt32)template.Property[EnrollmentTemplateProperty.TemplatePropEnrollmentFlags]);
         } catch {
             SignatureCount  = 0;
             enrollmentFlags = 0;
         }
     }
     if (SignatureCount > 0)
     {
         try {
             IObjectIds oids = (IObjectIds)template.Property[EnrollmentTemplateProperty.TemplatePropRAEKUs];
             ApplicationPolicy = new Oid(oids[0].Value);
         } catch { }
         try {
             OidCollection raoids = new OidCollection();
             IObjectIds    oids   = (IObjectIds)template.Property[EnrollmentTemplateProperty.TemplatePropRACertificatePolicies];
             foreach (IObjectId rapoid in oids)
             {
                 raoids.Add(new Oid(rapoid.Value));
             }
             CertificatePolicies = raoids;
         } catch { }
     }
 }
 internal CertificateTemplate(IX509CertificateTemplate template)
 {
     initializeCom(template);
     Settings = new CertificateTemplateSettings(template);
 }
Beispiel #9
0
 internal IssuanceRequirements(IX509CertificateTemplate template)
 {
     InitializeCom(template);
 }
Beispiel #10
0
 internal KeyArchivalOptions(IX509CertificateTemplate template)
 {
     InitializeCom(template);
 }
Beispiel #11
0
 internal CryptographyTemplateSettings(IX509CertificateTemplate template)
 {
     InitializeCom(template);
 }
        public bool enrollWithIX509EnrollmentHelper()
        {
            bool bRet = true;

            try
            {
                IX509EnrollmentPolicyServer objPolicyServer = null;
                IX509CertificateTemplates   objTemplates    = null;
                IX509CertificateTemplate    objTemplate     = null;

                IX509EnrollmentHelper objEnrollHelper = null;

                IX509Enrollment2 objEnroll2 = null;

                objPolicyServer = new CX509EnrollmentPolicyWebService();
                objPolicyServer.Initialize(
                    m_strPolicyServerUrl,
                    null,
                    m_PolicyServerAuthType,
                    true,
                    m_context);
                //This call sets authentication type and authentication credential
                //to policy server to the object referenced by objPolicyServer.
                //This call is necessary even for Kerberos authentication type.
                objPolicyServer.SetCredential(
                    0,
                    m_PolicyServerAuthType,
                    m_strPolicyServerUsername,
                    m_strPolicyServerPassword);

                objPolicyServer.LoadPolicy(X509EnrollmentPolicyLoadOption.LoadOptionDefault);
                objTemplates = objPolicyServer.GetTemplates();
                objTemplate  = objTemplates.get_ItemByName(m_strTemplateName);

                //There is no need to cache credential for Kerberos authentication type
                if (m_EnrollmentServerAuthType == X509EnrollmentAuthFlags.X509AuthUsername)
                {
                    objEnrollHelper = new CX509EnrollmentHelper();
                    objEnrollHelper.Initialize(m_context);
                    //This call caches the authentication credential to
                    //enrollment server in Windows vault
                    objEnrollHelper.AddEnrollmentServer(
                        m_strEnrollmentServerUrl,
                        m_EnrollmentServerAuthType,
                        m_strEnrollmentServerUsername,
                        m_strEnrollmentServerPassword);
                }

                objEnroll2 = new CX509Enrollment();
                objEnroll2.InitializeFromTemplate(
                    m_context,
                    objPolicyServer,
                    objTemplate);
                //This call reads authentication cache to
                //enrollment server from Windows vault
                objEnroll2.Enroll();
            }
            catch (Exception e)
            {
                bRet = false;
                Console.WriteLine("Error: {0}", e.Message);
            }

            if (bRet)
            {
                Console.WriteLine("Certificate enrollment succeeded.");
            }
            else
            {
                Console.WriteLine("Certificate enrollment failed.");
            }

            return(bRet);
        }