Пример #1
0
        private void LoadCertificateFromFile(string fileName, object password, X509KeyStorageFlags keyStorageFlags)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            new FileIOPermission(FileIOPermissionAccess.Read, Path.GetFullPathInternal(fileName)).Demand();
            if (X509Utils.MapContentType(X509Utils._QueryCertFileType(fileName)) == X509ContentType.Pfx && (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) == X509KeyStorageFlags.PersistKeySet)
            {
                new KeyContainerPermission(KeyContainerPermissionFlags.Create).Demand();
            }
            uint   dwFlags = X509Utils.MapKeyStorageFlags(keyStorageFlags);
            IntPtr num     = IntPtr.Zero;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                num = X509Utils.PasswordToHGlobalUni(password);
                X509Utils._LoadCertFromFile(fileName, num, dwFlags, (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) != X509KeyStorageFlags.DefaultKeySet, ref this.m_safeCertContext);
            }
            finally
            {
                if (num != IntPtr.Zero)
                {
                    Marshal.ZeroFreeGlobalAllocUnicode(num);
                }
            }
        }
Пример #2
0
        private void LoadCertificateFromBlob(byte[] rawData, object password, X509KeyStorageFlags keyStorageFlags)
        {
            if (rawData == null || rawData.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_EmptyOrNullArray"), "rawData");
            }
            if (X509Utils.MapContentType(X509Utils._QueryCertBlobType(rawData)) == X509ContentType.Pfx && (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) == X509KeyStorageFlags.PersistKeySet)
            {
                new KeyContainerPermission(KeyContainerPermissionFlags.Create).Demand();
            }
            uint   dwFlags = X509Utils.MapKeyStorageFlags(keyStorageFlags);
            IntPtr num     = IntPtr.Zero;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                num = X509Utils.PasswordToHGlobalUni(password);
                X509Utils._LoadCertFromBlob(rawData, num, dwFlags, (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) != X509KeyStorageFlags.DefaultKeySet, ref this.m_safeCertContext);
            }
            finally
            {
                if (num != IntPtr.Zero)
                {
                    Marshal.ZeroFreeGlobalAllocUnicode(num);
                }
            }
        }
Пример #3
0
        [System.Security.SecurityCritical]  // auto-generated
        private void LoadCertificateFromFile(string fileName, object password, X509KeyStorageFlags keyStorageFlags)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            Contract.EndContractBlock();

            string fullPath = Path.GetFullPathInternal(fileName);

            new FileIOPermission(FileIOPermissionAccess.Read, fullPath).Demand();
            X509ContentType contentType = X509Utils.MapContentType(X509Utils._QueryCertFileType(fileName));

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

            RuntimeHelpers.PrepareConstrainedRegions();
            try {
                szPassword = X509Utils.PasswordToHGlobalUni(password);
                X509Utils._LoadCertFromFile(fileName,
                                            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);
                }
            }
        }
Пример #4
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
            if (contentType == X509ContentType.Pkcs12 &&
                (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) == X509KeyStorageFlags.PersistKeySet)
            {
                KeyContainerPermission kp = new KeyContainerPermission(KeyContainerPermissionFlags.Create);
                kp.Demand();
            }
#endif // !FEATURE_CORECLR
            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);
                }
            }
        }