Ejemplo n.º 1
0
 internal static extern byte[] _GetPublicKeyParameters(SafeCertContextHandle safeCertContext);
Ejemplo n.º 2
0
 internal static extern byte[] _GetPublicKeyValue(SafeCertContextHandle safeCertContext);
Ejemplo n.º 3
0
 internal static extern bool CertGetCertificateContextProperty(SafeCertContextHandle pCertContext,
                                                               CertificateProperty dwPropId,
                                                               [Out] out IntPtr pvData,
                                                               [In, Out] ref int pcbData);
Ejemplo n.º 4
0
 internal static extern string _GetPublicKeyOid(SafeCertContextHandle safeCertContext);
Ejemplo n.º 5
0
 internal static extern void _LoadCertFromFile(string fileName, IntPtr password, uint dwFlags, bool persistKeySet, ref SafeCertContextHandle pCertCtx);
Ejemplo n.º 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;
        }
Ejemplo n.º 7
0
 internal static extern void _AddCertificateToStore(SafeCertStoreHandle safeCertStoreHandle, SafeCertContextHandle safeCertContext);
Ejemplo n.º 8
0
 internal static extern byte[] _GetThumbprint(SafeCertContextHandle safeCertContext);
Ejemplo n.º 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);
 }
Ejemplo n.º 11
0
 internal static extern bool CertSetCertificateContextProperty(SafeCertContextHandle pCertContext,
                                                               CertificateProperty dwPropId,
                                                               CertSetPropertyFlags dwFlags,
                                                               [In] SafeNCryptKeyHandle pvData);
Ejemplo n.º 12
0
 internal static extern bool CertSetCertificateContextProperty(SafeCertContextHandle pCertContext,
                                                               CertificateProperty dwPropId,
                                                               CertSetPropertyFlags dwFlags,
                                                               [In] ref CRYPT_KEY_PROV_INFO pvData);
Ejemplo n.º 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);
        }
Ejemplo n.º 14
0
 internal static extern string _GetSubjectInfo(SafeCertContextHandle safeCertContext, uint displayType, bool legacyV1Mode);
Ejemplo n.º 15
0
 internal static extern void _DuplicateCertContext(IntPtr handle, ref SafeCertContextHandle safeCertContext);
Ejemplo n.º 16
0
 internal static extern byte[] _GetSerialNumber(SafeCertContextHandle safeCertContext);
Ejemplo n.º 17
0
 internal static extern byte[] _GetCertRawData(SafeCertContextHandle safeCertContext);
Ejemplo n.º 18
0
 internal static extern void _LoadCertFromBlob(byte[] rawData, IntPtr password, uint dwFlags, bool persistKeySet, ref SafeCertContextHandle pCertCtx);
Ejemplo n.º 19
0
 internal static extern void _GetDateNotBefore(SafeCertContextHandle safeCertContext, ref Win32Native.FILE_TIME fileTime);
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 21
0
 internal static extern string _GetIssuerName(SafeCertContextHandle safeCertContext, bool legacyV1Mode);
Ejemplo n.º 22
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 private void Init()
 {
     m_safeCertContext = SafeCertContextHandle.InvalidHandle;
 }
Ejemplo n.º 23
0
 internal static extern bool CertGetCertificateContextProperty(SafeCertContextHandle pCertContext,
                                                               CertificateProperty dwPropId,
                                                               [Out, MarshalAs(UnmanagedType.LPArray)] byte[] pvData,
                                                               [In, Out] ref int pcbData);