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