internal static extern byte[] _GetPublicKeyParameters(SafeCertContextHandle safeCertContext);
 internal static extern byte[] _GetPublicKeyValue(SafeCertContextHandle safeCertContext);
Пример #3
0
 internal static extern bool CertGetCertificateContextProperty(SafeCertContextHandle pCertContext,
                                                               CertificateProperty dwPropId,
                                                               [Out] out IntPtr pvData,
                                                               [In, Out] ref int pcbData);
 internal static extern string _GetPublicKeyOid(SafeCertContextHandle safeCertContext);
 internal static extern void _LoadCertFromFile(string fileName, IntPtr password, uint dwFlags, bool persistKeySet, ref SafeCertContextHandle pCertCtx);
Пример #6
0
#pragma warning restore 618
        public virtual void Reset () {
            m_subjectName = null;
            m_issuerName = null;
            m_serialNumber = null;
            m_publicKeyParameters = null;
            m_publicKeyValue = null;
            m_publicKeyOid = null;
            m_rawData = null;
            m_thumbprint = null;
            m_notBefore = DateTime.MinValue;
            m_notAfter = DateTime.MinValue;
            if (!m_safeCertContext.IsInvalid) {
                // Free the current certificate handle
                if (!m_certContextCloned) {
                    m_safeCertContext.Dispose();
                }
                m_safeCertContext = SafeCertContextHandle.InvalidHandle;
            }
            m_certContextCloned = false;
        }
 internal static extern void _AddCertificateToStore(SafeCertStoreHandle safeCertStoreHandle, SafeCertContextHandle safeCertContext);
 internal static extern byte[] _GetThumbprint(SafeCertContextHandle safeCertContext);
Пример #9
0
 internal static extern bool CryptAcquireCertificatePrivateKey(SafeCertContextHandle pCert,
                                                               AcquireCertificateKeyOptions dwFlags,
                                                               IntPtr pvReserved,        // void *
                                                               [Out] out SafeNCryptKeyHandle phCryptProvOrNCryptKey,
                                                               [Out] out int dwKeySpec,
                                                               [Out, MarshalAs(UnmanagedType.Bool)] out bool pfCallerFreeProvOrNCryptKey);
 protected override bool ReleaseHandle()
 {
     SafeCertContextHandle._FreePCertContext(this.handle);
     return(true);
 }
Пример #11
0
 internal static extern bool CertSetCertificateContextProperty(SafeCertContextHandle pCertContext,
                                                               CertificateProperty dwPropId,
                                                               CertSetPropertyFlags dwFlags,
                                                               [In] SafeNCryptKeyHandle pvData);
Пример #12
0
 internal static extern bool CertSetCertificateContextProperty(SafeCertContextHandle pCertContext,
                                                               CertificateProperty dwPropId,
                                                               CertSetPropertyFlags dwFlags,
                                                               [In] ref CRYPT_KEY_PROV_INFO pvData);
Пример #13
0
        internal static SafeNCryptKeyHandle TryAcquireCngPrivateKey(
            SafeCertContextHandle certificateContext,
            out CngKeyHandleOpenOptions openOptions)
        {
            Debug.Assert(certificateContext != null, "certificateContext != null");
            Debug.Assert(!certificateContext.IsClosed && !certificateContext.IsInvalid,
                         "!certificateContext.IsClosed && !certificateContext.IsInvalid");

            IntPtr privateKeyPtr;

            // If the certificate has a key handle instead of a key prov info, return the
            // ephemeral key
            {
                int cbData = IntPtr.Size;

                if (UnsafeNativeMethods.CertGetCertificateContextProperty(
                        certificateContext,
                        CertificateProperty.NCryptKeyHandle,
                        out privateKeyPtr,
                        ref cbData))
                {
                    openOptions = CngKeyHandleOpenOptions.EphemeralKey;
                    return(new SafeNCryptKeyHandle(privateKeyPtr, certificateContext));
                }
            }

            openOptions = CngKeyHandleOpenOptions.None;

            bool freeKey = true;
            SafeNCryptKeyHandle privateKey = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
                int keySpec = 0;
                if (!UnsafeNativeMethods.CryptAcquireCertificatePrivateKey(certificateContext,
                                                                           AcquireCertificateKeyOptions.AcquireOnlyNCryptKeys,
                                                                           IntPtr.Zero,
                                                                           out privateKey,
                                                                           out keySpec,
                                                                           out freeKey))
                {
                    // The documentation for CryptAcquireCertificatePrivateKey says that freeKey
                    // should already be false if "key acquisition fails", and it can be presumed
                    // that privateKey was set to 0.  But, just in case:
                    freeKey = false;
                    privateKey?.SetHandleAsInvalid();
                    return(null);
                }
            }
            finally {
                // It is very unlikely that Windows will tell us !freeKey other than when reporting failure,
                // because we set neither CRYPT_ACQUIRE_CACHE_FLAG nor CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, which are
                // currently the only two success situations documented. However, any !freeKey response means the
                // key's lifetime is tied to that of the certificate, so re-register the handle as a child handle
                // of the certificate.
                if (!freeKey && privateKey != null && !privateKey.IsInvalid)
                {
                    var newKeyHandle = new SafeNCryptKeyHandle(privateKey.DangerousGetHandle(), certificateContext);
                    privateKey.SetHandleAsInvalid();
                    privateKey = newKeyHandle;
                    freeKey    = true;
                }
            }

            return(privateKey);
        }
Пример #14
0
 internal static extern string _GetSubjectInfo(SafeCertContextHandle safeCertContext, uint displayType, bool legacyV1Mode);
Пример #15
0
 internal static extern void _DuplicateCertContext(IntPtr handle, ref SafeCertContextHandle safeCertContext);
Пример #16
0
 internal static extern byte[] _GetSerialNumber(SafeCertContextHandle safeCertContext);
Пример #17
0
 internal static extern byte[] _GetCertRawData(SafeCertContextHandle safeCertContext);
Пример #18
0
 internal static extern void _LoadCertFromBlob(byte[] rawData, IntPtr password, uint dwFlags, bool persistKeySet, ref SafeCertContextHandle pCertCtx);
Пример #19
0
 internal static extern void _GetDateNotBefore(SafeCertContextHandle safeCertContext, ref Win32Native.FILE_TIME fileTime);
Пример #20
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public X509Certificate (X509Certificate cert):this() {
            if (cert == null)
                throw new ArgumentNullException("cert");
            Contract.EndContractBlock();

            if (cert.m_safeCertContext.pCertContext != IntPtr.Zero) {
                m_safeCertContext = cert.GetCertContextForCloning();
                m_certContextCloned = true;
            }
        }
Пример #21
0
 internal static extern string _GetIssuerName(SafeCertContextHandle safeCertContext, bool legacyV1Mode);
Пример #22
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 private void Init()
 {
     m_safeCertContext = SafeCertContextHandle.InvalidHandle;
 }
Пример #23
0
 internal static extern bool CertGetCertificateContextProperty(SafeCertContextHandle pCertContext,
                                                               CertificateProperty dwPropId,
                                                               [Out, MarshalAs(UnmanagedType.LPArray)] byte[] pvData,
                                                               [In, Out] ref int pcbData);