예제 #1
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        private void LoadCertificateFromBlob(byte[] rawData, object password, X509KeyStorageFlags keyStorageFlags)
        {
            if (rawData == null || rawData.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_EmptyOrNullArray"), "rawData");
            }
            Contract.EndContractBlock();

            X509ContentType contentType = X509Utils.MapContentType(X509Utils._QueryCertBlobType(rawData));

#if !FEATURE_CORECLR && !FEATURE_PAL
            if (contentType == X509ContentType.Pkcs12 &&
                (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) == X509KeyStorageFlags.PersistKeySet)
            {
                KeyContainerPermission kp = new KeyContainerPermission(KeyContainerPermissionFlags.Create);
                kp.Demand();
            }
#endif // !FEATURE_CORECLR && !FEATURE_PAL
            uint   dwFlags    = X509Utils.MapKeyStorageFlags(keyStorageFlags);
            IntPtr szPassword = IntPtr.Zero;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
                szPassword = X509Utils.PasswordToHGlobalUni(password);
                X509Utils._LoadCertFromBlob(rawData,
                                            szPassword,
                                            dwFlags,
#if FEATURE_CORECLR
                                            false,
#else // FEATURE_CORECLR
                                            (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) == 0 ? false : true,
#endif // FEATURE_CORECLR else
                                            ref m_safeCertContext);
            }
            finally {
                if (szPassword != IntPtr.Zero)
                {
                    Marshal.ZeroFreeGlobalAllocUnicode(szPassword);
                }
            }
        }
예제 #2
0
 private static void AddToStore(SafeCertStoreHandle safeCertStoreHandle, X509Certificate2Collection collection)
 {
     //
     // We use CertAddCertificateLinkToStore to keep a link to the original store, so any property changes get
     // applied to the original store. This has a limit of 99 links per cert context however.
     //
     // X509Store.Add(Range) uses CertAddCertificateContextToStore, which would lose information like ephemeral
     // private key associations.
     foreach (X509Certificate2 x509 in collection)
     {
         using (SafeCertContextHandle ctx = X509Utils.GetCertContext(x509)) {
             if (!CAPI.CertAddCertificateLinkToStore(safeCertStoreHandle,
                                                     ctx,
                                                     CAPI.CERT_STORE_ADD_ALWAYS,
                                                     SafeCertContextHandle.InvalidHandle))
             {
                 throw new CryptographicException(Marshal.GetLastWin32Error());
             }
         }
     }
 }
예제 #3
0
        private byte[] ExportHelper(X509ContentType contentType, object password)
        {
            switch (contentType)
            {
            case X509ContentType.Cert:
            case X509ContentType.SerializedCert:
                break;

            case X509ContentType.Pfx:
                new KeyContainerPermission(KeyContainerPermissionFlags.Export | KeyContainerPermissionFlags.Open).Demand();
                break;

            default:
                throw new CryptographicException(Environment.GetResourceString("Cryptography_X509_InvalidContentType"));
            }
            IntPtr zero = IntPtr.Zero;

            byte[] buffer = null;
            SafeCertStoreHandle safeCertStoreHandle = X509Utils.ExportCertToMemoryStore(this);

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                zero   = X509Utils.PasswordToHGlobalUni(password);
                buffer = X509Utils._ExportCertificatesToBlob(safeCertStoreHandle, contentType, zero);
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    Marshal.ZeroFreeGlobalAllocUnicode(zero);
                }
                safeCertStoreHandle.Dispose();
            }
            if (buffer == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_X509_ExportFailed"));
            }
            return(buffer);
        }
예제 #4
0
        private static unsafe byte[] EncodeExtension(OidCollection enhancedKeyUsages)
        {
            if (enhancedKeyUsages == null)
            {
                throw new ArgumentNullException("enhancedKeyUsages");
            }

            SafeLocalAllocHandle safeLocalAllocHandle = X509Utils.CopyOidsToUnmanagedMemory(enhancedKeyUsages);

            byte[] encodedEnhancedKeyUsages = null;
            using (safeLocalAllocHandle) {
                CAPI.CERT_ENHKEY_USAGE pEnhKeyUsage = new CAPI.CERT_ENHKEY_USAGE();
                pEnhKeyUsage.cUsageIdentifier     = (uint)enhancedKeyUsages.Count;
                pEnhKeyUsage.rgpszUsageIdentifier = safeLocalAllocHandle.DangerousGetHandle();
                if (!CAPI.EncodeObject(CAPI.szOID_ENHANCED_KEY_USAGE, new IntPtr(&pEnhKeyUsage), out encodedEnhancedKeyUsages))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }
            }

            return(encodedEnhancedKeyUsages);
        }
예제 #5
0
        private byte[] ExportHelper(X509ContentType contentType, object password)
        {
            switch (contentType)
            {
            case X509ContentType.Cert:
            case X509ContentType.SerializedCert:
                IntPtr num      = IntPtr.Zero;
                byte[] numArray = (byte[])null;
                SafeCertStoreHandle memoryStore = X509Utils.ExportCertToMemoryStore(this);
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    num      = X509Utils.PasswordToHGlobalUni(password);
                    numArray = X509Utils._ExportCertificatesToBlob(memoryStore, contentType, num);
                }
                finally
                {
                    if (num != IntPtr.Zero)
                    {
                        Marshal.ZeroFreeGlobalAllocUnicode(num);
                    }
                    memoryStore.Dispose();
                }
                if (numArray == null)
                {
                    throw new CryptographicException(Environment.GetResourceString("Cryptography_X509_ExportFailed"));
                }
                return(numArray);

            case X509ContentType.Pfx:
                new KeyContainerPermission(KeyContainerPermissionFlags.Open | KeyContainerPermissionFlags.Export).Demand();
                goto case X509ContentType.Cert;

            default:
                throw new CryptographicException(Environment.GetResourceString("Cryptography_X509_InvalidContentType"));
            }
        }
예제 #6
0
        private static CRYPT_OID_INFO FindOidInfo(OidKeyType keyType, string key, OidGroup group)
        {
            IntPtr num = IntPtr.Zero;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                num = keyType != OidKeyType.Oid ? Marshal.StringToCoTaskMemUni(key) : Marshal.StringToCoTaskMemAnsi(key);
                if (!X509Utils.OidGroupWillNotUseActiveDirectory(group))
                {
                    OidGroup dwGroupId = group | OidGroup.DisableSearchDS;
                    IntPtr   oidInfo   = X509Utils.CryptFindOIDInfo(keyType, num, dwGroupId);
                    if (oidInfo != IntPtr.Zero)
                    {
                        return((CRYPT_OID_INFO)Marshal.PtrToStructure(oidInfo, typeof(CRYPT_OID_INFO)));
                    }
                }
                IntPtr oidInfo1 = X509Utils.CryptFindOIDInfo(keyType, num, group);
                if (oidInfo1 != IntPtr.Zero)
                {
                    return((CRYPT_OID_INFO)Marshal.PtrToStructure(oidInfo1, typeof(CRYPT_OID_INFO)));
                }
                if (group != OidGroup.AllGroups && X509Utils.CryptFindOIDInfo(keyType, num, OidGroup.AllGroups) != IntPtr.Zero)
                {
                    return((CRYPT_OID_INFO)Marshal.PtrToStructure(oidInfo1, typeof(CRYPT_OID_INFO)));
                }
                return(new CRYPT_OID_INFO());
            }
            finally
            {
                if (num != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(num);
                }
            }
        }
예제 #7
0
        private static unsafe SafeLocalAllocHandle EncodePublicKey(PublicKey key)
        {
            SafeLocalAllocHandle publicKeyInfo = SafeLocalAllocHandle.InvalidHandle;

            CAPI.CERT_PUBLIC_KEY_INFO2 *pPublicKeyInfo = null;
            string objId = key.Oid.Value;

            byte[] encodedParameters = key.EncodedParameters.RawData;
            byte[] encodedKeyValue   = key.EncodedKeyValue.RawData;

            uint cbPublicKeyInfo = (uint)(Marshal.SizeOf(typeof(CAPI.CERT_PUBLIC_KEY_INFO2)) +
                                          X509Utils.AlignedLength((uint)(objId.Length + 1)) +
                                          X509Utils.AlignedLength((uint)encodedParameters.Length) +
                                          encodedKeyValue.Length);

            publicKeyInfo  = CAPI.LocalAlloc(CAPI.LPTR, new IntPtr(cbPublicKeyInfo));
            pPublicKeyInfo = (CAPI.CERT_PUBLIC_KEY_INFO2 *)publicKeyInfo.DangerousGetHandle();
            IntPtr pszObjId     = new IntPtr((long)pPublicKeyInfo + Marshal.SizeOf(typeof(CAPI.CERT_PUBLIC_KEY_INFO2)));
            IntPtr pbParameters = new IntPtr((long)pszObjId + X509Utils.AlignedLength(((uint)(objId.Length + 1))));
            IntPtr pbPublicKey  = new IntPtr((long)pbParameters + X509Utils.AlignedLength((uint)encodedParameters.Length));

            pPublicKeyInfo->Algorithm.pszObjId = pszObjId;
            byte[] szObjId = new byte[objId.Length + 1];
            Encoding.ASCII.GetBytes(objId, 0, objId.Length, szObjId, 0);
            Marshal.Copy(szObjId, 0, pszObjId, szObjId.Length);
            if (encodedParameters.Length > 0)
            {
                pPublicKeyInfo->Algorithm.Parameters.cbData = (uint)encodedParameters.Length;
                pPublicKeyInfo->Algorithm.Parameters.pbData = pbParameters;
                Marshal.Copy(encodedParameters, 0, pbParameters, encodedParameters.Length);
            }
            pPublicKeyInfo->PublicKey.cbData = (uint)encodedKeyValue.Length;
            pPublicKeyInfo->PublicKey.pbData = pbPublicKey;
            Marshal.Copy(encodedKeyValue, 0, pbPublicKey, encodedKeyValue.Length);
            return(publicKeyInfo);
        }
예제 #8
0
        public void Open(OpenFlags flags)
        {
            if (m_location != StoreLocation.CurrentUser && m_location != StoreLocation.LocalMachine)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Arg_EnumIllegalVal), "m_location"));
            }

            uint storeFlags = X509Utils.MapX509StoreFlags(m_location, flags);

            if (!m_safeCertStoreHandle.IsInvalid)
            {
                // Free the current store handle
                m_safeCertStoreHandle.Dispose();
            }

            m_safeCertStoreHandle = CAPI.CertOpenStore(new IntPtr(CAPI.CERT_STORE_PROV_SYSTEM),
                                                       CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING,
                                                       IntPtr.Zero,
                                                       storeFlags,
                                                       m_storeName);

            if (m_safeCertStoreHandle == null || m_safeCertStoreHandle.IsInvalid)
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }

            //
            // We want the store to auto-resync when requesting a snapshot so that
            // updates to the store will be taken into account.
            //

            CAPI.CertControlStore(m_safeCertStoreHandle,
                                  0,
                                  CAPI.CERT_STORE_CTRL_AUTO_RESYNC,
                                  IntPtr.Zero);
        }
예제 #9
0
        private void DecodeExtension()
        {
            uint cbDecoded = 0;
            SafeLocalAllocHandle decoded = null;

            SafeLocalAllocHandle pb = X509Utils.StringToAnsiPtr(CAPI.szOID_SUBJECT_KEY_IDENTIFIER);
            bool result             = CAPI.DecodeObject(pb.DangerousGetHandle(),
                                                        m_rawData,
                                                        out decoded,
                                                        out cbDecoded);

            if (!result)
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }

            CAPI.CRYPTOAPI_BLOB pSubjectKeyIdentifier = (CAPI.CRYPTOAPI_BLOB)Marshal.PtrToStructure(decoded.DangerousGetHandle(), typeof(CAPI.CRYPTOAPI_BLOB));
            byte[] hexArray = CAPI.BlobToByteArray(pSubjectKeyIdentifier);
            m_subjectKeyIdentifier = X509Utils.EncodeHexString(hexArray);

            m_decoded = true;
            decoded.Dispose();
            pb.Dispose();
        }
        //
        // Builds a certificate chain.
        //

        internal static unsafe int BuildChain(IntPtr hChainEngine,
                                              SafeCertContextHandle pCertContext,
                                              X509Certificate2Collection extraStore,
                                              OidCollection applicationPolicy,
                                              OidCollection certificatePolicy,
                                              X509RevocationMode revocationMode,
                                              X509RevocationFlag revocationFlag,
                                              DateTime verificationTime,
                                              TimeSpan timeout,
                                              ref SafeCertChainHandle ppChainContext)
        {
            if (pCertContext == null || pCertContext.IsInvalid)
            {
                throw new ArgumentException(SR.GetString(SR.Cryptography_InvalidContextHandle), "pCertContext");
            }

            SafeCertStoreHandle hCertStore = SafeCertStoreHandle.InvalidHandle;

            if (extraStore != null && extraStore.Count > 0)
            {
                hCertStore = X509Utils.ExportToMemoryStore(extraStore);
            }

            CAPI.CERT_CHAIN_PARA ChainPara = new CAPI.CERT_CHAIN_PARA();

            // Initialize the structure size.
            ChainPara.cbSize = (uint)Marshal.SizeOf(ChainPara);

            SafeLocalAllocHandle applicationPolicyHandle = SafeLocalAllocHandle.InvalidHandle;
            SafeLocalAllocHandle certificatePolicyHandle = SafeLocalAllocHandle.InvalidHandle;

            try {
                // Application policy
                if (applicationPolicy != null && applicationPolicy.Count > 0)
                {
                    ChainPara.RequestedUsage.dwType = CAPI.USAGE_MATCH_TYPE_AND;
                    ChainPara.RequestedUsage.Usage.cUsageIdentifier = (uint)applicationPolicy.Count;
                    applicationPolicyHandle = X509Utils.CopyOidsToUnmanagedMemory(applicationPolicy);
                    ChainPara.RequestedUsage.Usage.rgpszUsageIdentifier = applicationPolicyHandle.DangerousGetHandle();
                }

                // Certificate policy
                if (certificatePolicy != null && certificatePolicy.Count > 0)
                {
                    ChainPara.RequestedIssuancePolicy.dwType = CAPI.USAGE_MATCH_TYPE_AND;
                    ChainPara.RequestedIssuancePolicy.Usage.cUsageIdentifier = (uint)certificatePolicy.Count;
                    certificatePolicyHandle = X509Utils.CopyOidsToUnmanagedMemory(certificatePolicy);
                    ChainPara.RequestedIssuancePolicy.Usage.rgpszUsageIdentifier = certificatePolicyHandle.DangerousGetHandle();
                }

                ChainPara.dwUrlRetrievalTimeout = (uint)Math.Floor(timeout.TotalMilliseconds);

                _FILETIME ft = new _FILETIME();
                *((long *)&ft) = verificationTime.ToFileTime();

                uint flags = X509Utils.MapRevocationFlags(revocationMode, revocationFlag);

                // Build the chain.
                if (!CAPI.CertGetCertificateChain(hChainEngine,
                                                  pCertContext,
                                                  ref ft,
                                                  hCertStore,
                                                  ref ChainPara,
                                                  flags,
                                                  IntPtr.Zero,
                                                  ref ppChainContext))
                {
                    return(Marshal.GetHRForLastWin32Error());
                }
            }
            finally {
                applicationPolicyHandle.Dispose();
                certificatePolicyHandle.Dispose();
            }

            return(CAPI.S_OK);
        }
        internal static X509ChainStatus[] GetChainStatusInformation(uint dwStatus)
        {
            if (dwStatus == 0)
            {
                return(new X509ChainStatus[0]);
            }

            int count = 0;

            for (uint bits = dwStatus; bits != 0; bits = bits >> 1)
            {
                if ((bits & 0x1) != 0)
                {
                    count++;
                }
            }

            X509ChainStatus[] chainStatus = new X509ChainStatus[count];

            int index = 0;

            if ((dwStatus & CAPI.CERT_TRUST_IS_NOT_SIGNATURE_VALID) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.TRUST_E_CERT_SIGNATURE);
                chainStatus[index].Status            = X509ChainStatusFlags.NotSignatureValid;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_IS_NOT_SIGNATURE_VALID;
            }

            if ((dwStatus & CAPI.CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.TRUST_E_CERT_SIGNATURE);
                chainStatus[index].Status            = X509ChainStatusFlags.CtlNotSignatureValid;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID;
            }

            if ((dwStatus & CAPI.CERT_TRUST_IS_UNTRUSTED_ROOT) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_UNTRUSTEDROOT);
                chainStatus[index].Status            = X509ChainStatusFlags.UntrustedRoot;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_IS_UNTRUSTED_ROOT;
            }

            if ((dwStatus & CAPI.CERT_TRUST_IS_PARTIAL_CHAIN) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_CHAINING);
                chainStatus[index].Status            = X509ChainStatusFlags.PartialChain;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_IS_PARTIAL_CHAIN;
            }

            if ((dwStatus & CAPI.CERT_TRUST_IS_REVOKED) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CRYPT_E_REVOKED);
                chainStatus[index].Status            = X509ChainStatusFlags.Revoked;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_IS_REVOKED;
            }

            if ((dwStatus & CAPI.CERT_TRUST_IS_NOT_VALID_FOR_USAGE) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_WRONG_USAGE);
                chainStatus[index].Status            = X509ChainStatusFlags.NotValidForUsage;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_IS_NOT_VALID_FOR_USAGE;
            }

            if ((dwStatus & CAPI.CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_WRONG_USAGE);
                chainStatus[index].Status            = X509ChainStatusFlags.CtlNotValidForUsage;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE;
            }

            if ((dwStatus & CAPI.CERT_TRUST_IS_NOT_TIME_VALID) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_EXPIRED);
                chainStatus[index].Status            = X509ChainStatusFlags.NotTimeValid;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_IS_NOT_TIME_VALID;
            }

            if ((dwStatus & CAPI.CERT_TRUST_CTL_IS_NOT_TIME_VALID) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_EXPIRED);
                chainStatus[index].Status            = X509ChainStatusFlags.CtlNotTimeValid;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_CTL_IS_NOT_TIME_VALID;
            }

            if ((dwStatus & CAPI.CERT_TRUST_INVALID_NAME_CONSTRAINTS) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_INVALID_NAME);
                chainStatus[index].Status            = X509ChainStatusFlags.InvalidNameConstraints;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_INVALID_NAME_CONSTRAINTS;
            }

            if ((dwStatus & CAPI.CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_INVALID_NAME);
                chainStatus[index].Status            = X509ChainStatusFlags.HasNotSupportedNameConstraint;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT;
            }

            if ((dwStatus & CAPI.CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_INVALID_NAME);
                chainStatus[index].Status            = X509ChainStatusFlags.HasNotDefinedNameConstraint;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT;
            }

            if ((dwStatus & CAPI.CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_INVALID_NAME);
                chainStatus[index].Status            = X509ChainStatusFlags.HasNotPermittedNameConstraint;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT;
            }

            if ((dwStatus & CAPI.CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_INVALID_NAME);
                chainStatus[index].Status            = X509ChainStatusFlags.HasExcludedNameConstraint;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT;
            }

            if ((dwStatus & CAPI.CERT_TRUST_INVALID_POLICY_CONSTRAINTS) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_INVALID_POLICY);
                chainStatus[index].Status            = X509ChainStatusFlags.InvalidPolicyConstraints;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_INVALID_POLICY_CONSTRAINTS;
            }

            if ((dwStatus & CAPI.CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_INVALID_POLICY);
                chainStatus[index].Status            = X509ChainStatusFlags.NoIssuanceChainPolicy;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY;
            }

            if ((dwStatus & CAPI.CERT_TRUST_INVALID_BASIC_CONSTRAINTS) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.TRUST_E_BASIC_CONSTRAINTS);
                chainStatus[index].Status            = X509ChainStatusFlags.InvalidBasicConstraints;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_INVALID_BASIC_CONSTRAINTS;
            }

            if ((dwStatus & CAPI.CERT_TRUST_IS_NOT_TIME_NESTED) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CERT_E_VALIDITYPERIODNESTING);
                chainStatus[index].Status            = X509ChainStatusFlags.NotTimeNested;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_IS_NOT_TIME_NESTED;
            }

            if ((dwStatus & CAPI.CERT_TRUST_REVOCATION_STATUS_UNKNOWN) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CRYPT_E_NO_REVOCATION_CHECK);
                chainStatus[index].Status            = X509ChainStatusFlags.RevocationStatusUnknown;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_REVOCATION_STATUS_UNKNOWN;
            }

            if ((dwStatus & CAPI.CERT_TRUST_IS_OFFLINE_REVOCATION) != 0)
            {
                chainStatus[index].StatusInformation = X509Utils.GetSystemErrorString(CAPI.CRYPT_E_REVOCATION_OFFLINE);
                chainStatus[index].Status            = X509ChainStatusFlags.OfflineRevocation;
                index++;
                dwStatus &= ~CAPI.CERT_TRUST_IS_OFFLINE_REVOCATION;
            }

            int shiftCount = 0;

            for (uint bits = dwStatus; bits != 0; bits = bits >> 1)
            {
                if ((bits & 0x1) != 0)
                {
                    chainStatus[index].Status            = (X509ChainStatusFlags)(1 << shiftCount);
                    chainStatus[index].StatusInformation = SR.GetString(SR.Unknown_Error);
                    index++;
                }
                shiftCount++;
            }

            return(chainStatus);
        }
예제 #12
0
 public virtual string GetName()
 {
     this.ThrowIfContextInvalid();
     return(X509Utils._GetSubjectInfo(this.m_safeCertContext, 2U, true));
 }
예제 #13
0
 internal static string GetOidFromFriendlyName(string friendlyName, OidGroup oidGroup)
 {
     return(X509Utils.FindOidInfo(OidKeyType.Name, friendlyName, oidGroup).pszOID);
 }
예제 #14
0
 internal static string GetFriendlyNameFromOid(string oid, OidGroup oidGroup)
 {
     return(X509Utils.FindOidInfo(OidKeyType.Oid, oid, oidGroup).pwszName);
 }
예제 #15
0
        internal static string GetOidFromFriendlyName(string friendlyName, OidGroup oidGroup)
        {
            CRYPT_OID_INFO crypt_OID_INFO = X509Utils.FindOidInfo(OidKeyType.Name, friendlyName, oidGroup);

            return(crypt_OID_INFO.pszOID);
        }
예제 #16
0
        public virtual string GetIssuerName()
        {
            ThrowIfContextInvalid();

            return(X509Utils._GetIssuerName(m_safeCertContext, true));
        }
예제 #17
0
        public virtual string GetName()
        {
            ThrowIfContextInvalid();

            return(X509Utils._GetSubjectInfo(m_safeCertContext, X509Constants.CERT_NAME_RDN_TYPE, true));
        }
예제 #18
0
        internal static string GetFriendlyNameFromOid(string oid, OidGroup oidGroup)
        {
            CRYPT_OID_INFO crypt_OID_INFO = X509Utils.FindOidInfo(OidKeyType.Oid, oid, oidGroup);

            return(crypt_OID_INFO.pwszName);
        }