當前位置: 首頁>>代碼示例>>C#>>正文


C# Permissions.StorePermission類代碼示例

本文整理匯總了C#中System.Security.Permissions.StorePermission的典型用法代碼示例。如果您正苦於以下問題:C# StorePermission類的具體用法?C# StorePermission怎麽用?C# StorePermission使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StorePermission類屬於System.Security.Permissions命名空間,在下文中一共展示了StorePermission類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: PermissionState_None_Copy

        public void PermissionState_None_Copy ()
        {
            // both will return null under 2.0 final
            // StorePermission sp1 = new StorePermission (PermissionState.None).Copy();
            // StorePermission sp2 = new StorePermission (StorePermissionFlags.NoFlags).Copy ();
            StorePermission sp = new StorePermission (PermissionState.None);

            StorePermission copy = (StorePermission) sp.Copy ();
            Assert.IsFalse (Object.ReferenceEquals (sp, copy), "ReferenceEquals");
            Assert.AreEqual (sp.Flags, copy.Flags, "Copy Flags");
            Assert.AreEqual (sp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:12,代碼來源:StorePermissionTest.cs

示例2: ConstructorLevel_Deny_Unrestricted

        public void ConstructorLevel_Deny_Unrestricted ()
        {
            StorePermission p = new StorePermission (StorePermissionFlags.AllFlags);
            Assert.AreEqual (StorePermissionFlags.AllFlags, p.Flags, "Flags");
            Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
            Assert.IsNotNull (p.Copy (), "Copy");
            SecurityElement se = p.ToXml ();
            Assert.IsNotNull (se, "ToXml");
            p.FromXml (se);
            Assert.IsNotNull (p.Intersect (p), "Intersect");
            Assert.IsTrue (p.IsSubsetOf (p), "IsSubsetOf");
            Assert.IsNotNull (p.Union (p), "Union");
        }
開發者ID:Profit0004,項目名稱:mono,代碼行數:13,代碼來源:StorePermissionCas.cs

示例3: ConstructorState_Deny_Unrestricted

        public void ConstructorState_Deny_Unrestricted ()
        {
            StorePermission p = new StorePermission (PermissionState.None);
            Assert.AreEqual (StorePermissionFlags.NoFlags, p.Flags, "Flags");
            Assert.IsFalse (p.IsUnrestricted (), "IsUnrestricted");
            SecurityElement se = p.ToXml ();
            Assert.IsNotNull (se, "ToXml");
            p.FromXml (se);
            Assert.IsTrue (p.IsSubsetOf (p), "IsSubsetOf");
            // strange behaviour of Copy under MS fx 2.0 (returns null for NoFlags)
            p.Copy ();
            p.Intersect (p);
            p.Union (p);
        }
開發者ID:Profit0004,項目名稱:mono,代碼行數:14,代碼來源:StorePermissionCas.cs

示例4: PermissionState_None

        public void PermissionState_None ()
        {
            PermissionState ps = PermissionState.None;
            StorePermission sp = new StorePermission (ps);
            Assert.AreEqual (StorePermissionFlags.NoFlags, sp.Flags, "Flags");
            Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");

            SecurityElement se = sp.ToXml ();
            // only class and version are present
            Assert.AreEqual ("NoFlags", se.Attribute ("Flags"), "Xml-Flags");
            Assert.IsNull (se.Children, "Xml-Children");

            StorePermission copy = (StorePermission) sp.Copy ();
            Assert.IsNull (copy, "Copy");
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:15,代碼來源:StorePermissionTest.cs

示例5: PermissionState_Unrestricted

        public void PermissionState_Unrestricted ()
        {
            PermissionState ps = PermissionState.Unrestricted;
            StorePermission sp = new StorePermission (ps);
            Assert.AreEqual (StorePermissionFlags.AllFlags, sp.Flags, "Flags");
            Assert.IsTrue (sp.IsUnrestricted (), "IsUnrestricted");

            SecurityElement se = sp.ToXml ();
            Assert.IsNotNull (se.Attribute ("Unrestricted"), "Xml-Unrestricted");
            Assert.IsNull (se.Attribute ("Level"), "Xml-Flags");
            Assert.IsNull (se.Children, "Xml-Children");

            StorePermission copy = (StorePermission) sp.Copy ();
            Assert.IsFalse (Object.ReferenceEquals (sp, copy), "ReferenceEquals");
            Assert.AreEqual (sp.Flags, copy.Flags, "Copy Flags");
            Assert.AreEqual (sp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:17,代碼來源:StorePermissionTest.cs

示例6: InstallCertificateFromResource

        /// <summary>  
        /// 安裝資源文件中的證書  
        /// </summary>  
        public static string InstallCertificateFromResource(StoreName sn, byte[] certificatefile)
        {
            try
            {
                StorePermission sp = new StorePermission(StorePermissionFlags.AllFlags);
                sp.Demand();
                X509Certificate2 certificate = new X509Certificate2(certificatefile);

                if (TryGetCertificate(sn, certificatefile) == null)
                {
                    X509Store AuthRoot = new X509Store(sn, StoreLocation.LocalMachine);
                    AuthRoot.Open(OpenFlags.ReadWrite);
                    //AuthRoot.Remove(certificate);
                    AuthRoot.Add(certificate);
                    AuthRoot.Close();
                }
                return string.Empty;
            }
            catch(Exception ex)
            {
                return ex.Message;
            }
        }
開發者ID:baidang201,項目名稱:ProductExcel,代碼行數:26,代碼來源:CertificateHelper.cs

示例7: Intersect

 public override IPermission Intersect(IPermission target)
 {
     IPermission permission2;
     if (target == null)
     {
         return null;
     }
     try
     {
         StorePermission permission = (StorePermission) target;
         StorePermissionFlags flag = permission.m_flags & this.m_flags;
         if (flag == StorePermissionFlags.NoFlags)
         {
             return null;
         }
         permission2 = new StorePermission(flag);
     }
     catch (InvalidCastException)
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.GetString("Argument_WrongType"), new object[] { base.GetType().FullName }));
     }
     return permission2;
 }
開發者ID:pritesh-mandowara-sp,項目名稱:DecompliedDotNetLibraries,代碼行數:23,代碼來源:StorePermission.cs

示例8: BuildBagOfCerts

        internal static X509Certificate2Collection BuildBagOfCerts (KeyInfoX509Data keyInfoX509Data, CertUsageType certUsageType) {
            X509Certificate2Collection collection = new X509Certificate2Collection();
            ArrayList decryptionIssuerSerials = (certUsageType == CertUsageType.Decryption ? new ArrayList() : null);
            if (keyInfoX509Data.Certificates != null) {
                foreach (X509Certificate2 certificate in keyInfoX509Data.Certificates) {
                    switch (certUsageType) {
                    case CertUsageType.Verification:
                        collection.Add(certificate);
                        break;
                    case CertUsageType.Decryption:
                        decryptionIssuerSerials.Add(new X509IssuerSerial(certificate.IssuerName.Name, certificate.SerialNumber));
                        break;
                    }
                }
            }

            if (keyInfoX509Data.SubjectNames == null && keyInfoX509Data.IssuerSerials == null &&
                keyInfoX509Data.SubjectKeyIds == null && decryptionIssuerSerials == null)
                return collection;

            // Open LocalMachine and CurrentUser "Other People"/"My" stores.

            // Assert OpenStore since we are not giving back any certificates to the user.
            StorePermission sp = new StorePermission(StorePermissionFlags.OpenStore);
            sp.Assert();

            X509Store[] stores = new X509Store[2];
            string storeName = (certUsageType == CertUsageType.Verification ? "AddressBook" : "My");
            stores[0] = new X509Store(storeName, StoreLocation.CurrentUser);
            stores[1] = new X509Store(storeName, StoreLocation.LocalMachine);

            for (int index=0; index < stores.Length; index++) {
                if (stores[index] != null) {
                    X509Certificate2Collection filters = null;
                    // We don't care if we can't open the store.
                    try {
                        stores[index].Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                        filters = stores[index].Certificates;
                        stores[index].Close();
                        if (keyInfoX509Data.SubjectNames != null) {
                            foreach (string subjectName in keyInfoX509Data.SubjectNames) {
                                filters = filters.Find(X509FindType.FindBySubjectDistinguishedName, subjectName, false);
                            }
                        }
                        if (keyInfoX509Data.IssuerSerials != null) {
                            foreach (X509IssuerSerial issuerSerial in keyInfoX509Data.IssuerSerials) {
                                filters = filters.Find(X509FindType.FindByIssuerDistinguishedName, issuerSerial.IssuerName, false);
                                filters = filters.Find(X509FindType.FindBySerialNumber, issuerSerial.SerialNumber, false);
                            }
                        }
                        if (keyInfoX509Data.SubjectKeyIds != null) {
                            foreach (byte[] ski in keyInfoX509Data.SubjectKeyIds) {
                                string hex = X509Utils.EncodeHexString(ski);
                                filters = filters.Find(X509FindType.FindBySubjectKeyIdentifier, hex, false);
                            }
                        }
                        if (decryptionIssuerSerials != null) {
                            foreach (X509IssuerSerial issuerSerial in decryptionIssuerSerials) {
                                filters = filters.Find(X509FindType.FindByIssuerDistinguishedName, issuerSerial.IssuerName, false);
                                filters = filters.Find(X509FindType.FindBySerialNumber, issuerSerial.SerialNumber, false);
                            }
                        }
                    }
                    catch (CryptographicException) {}

                    if (filters != null) 
                        collection.AddRange(filters);
                }
            }

            return collection;
        }
開發者ID:mind0n,項目名稱:hive,代碼行數:72,代碼來源:utils.cs

示例9: Build

        public bool Build (X509Certificate2 certificate) {
            lock (m_syncRoot) {
                if (certificate == null || certificate.CertContext.IsInvalid)
                    throw new ArgumentException(SR.GetString(SR.Cryptography_InvalidContextHandle), "certificate");

                // Chain building opens and enumerates the root store to see if the root of the chain is trusted.
                StorePermission sp = new StorePermission(StorePermissionFlags.OpenStore | StorePermissionFlags.EnumerateCertificates);
                sp.Demand();

                X509ChainPolicy chainPolicy = this.ChainPolicy;
                if (chainPolicy.RevocationMode == X509RevocationMode.Online) {
                    if (certificate.Extensions[CAPI.szOID_CRL_DIST_POINTS] != null ||
                        certificate.Extensions[CAPI.szOID_AUTHORITY_INFO_ACCESS] != null) {
                        // If there is a CDP or AIA extension, we demand unrestricted network access and store add permission
                        // since CAPI can download certificates into the CA store from the network.
                        PermissionSet ps = new PermissionSet(PermissionState.None);
                        ps.AddPermission(new WebPermission(PermissionState.Unrestricted));
                        ps.AddPermission(new StorePermission(StorePermissionFlags.AddToStore));
                        ps.Demand();
                    }
                }

                Reset();
                int hr = BuildChain(m_useMachineContext ? new IntPtr(CAPI.HCCE_LOCAL_MACHINE) : new IntPtr(CAPI.HCCE_CURRENT_USER),
                                    certificate.CertContext,
                                    chainPolicy.ExtraStore,
                                    chainPolicy.ApplicationPolicy,
                                    chainPolicy.CertificatePolicy,
                                    chainPolicy.RevocationMode,
                                    chainPolicy.RevocationFlag,
                                    chainPolicy.VerificationTime,
                                    chainPolicy.UrlRetrievalTimeout,
                                    ref m_safeCertChainHandle);

                if (hr != CAPI.S_OK)
                    return false;

                // Init.
                Init();

                // Verify the chain using the specified policy.
                CAPI.CERT_CHAIN_POLICY_PARA PolicyPara = new CAPI.CERT_CHAIN_POLICY_PARA(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_POLICY_PARA)));
                CAPI.CERT_CHAIN_POLICY_STATUS PolicyStatus = new CAPI.CERT_CHAIN_POLICY_STATUS(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_POLICY_STATUS)));

                PolicyPara.dwFlags = (uint) chainPolicy.VerificationFlags;

                if (!CAPI.CertVerifyCertificateChainPolicy(new IntPtr(CAPI.CERT_CHAIN_POLICY_BASE),
                                                           m_safeCertChainHandle,
                                                           ref PolicyPara,
                                                           ref PolicyStatus))
                    // The API failed.
                    throw new CryptographicException(Marshal.GetLastWin32Error());

                CAPI.SetLastError(PolicyStatus.dwError);
                return (PolicyStatus.dwError == 0);
            }
        }
開發者ID:stormleoxia,項目名稱:referencesource,代碼行數:57,代碼來源:x509chain.cs

示例10: Import

        public void Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags) {
            uint dwFlags = X509Utils.MapKeyStorageFlags(keyStorageFlags);
            SafeCertStoreHandle safeCertStoreHandle = SafeCertStoreHandle.InvalidHandle;

            //
            // We need to Assert all StorePermission flags since this is a memory store and we want 
            // semi-trusted code to be able to import certificates to a memory store.
            //

            StorePermission sp = new StorePermission(StorePermissionFlags.AllFlags);
            sp.Assert();

            safeCertStoreHandle = LoadStoreFromBlob(rawData, password, dwFlags, (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) != 0);

            X509Certificate2Collection collection = X509Utils.GetCertificates(safeCertStoreHandle);

            safeCertStoreHandle.Dispose();
            X509Certificate2[] x509Certs = new X509Certificate2[collection.Count];
            collection.CopyTo(x509Certs, 0);
            this.AddRange(x509Certs);
        }
開發者ID:JokerMisfits,項目名稱:linux-packaging-mono,代碼行數:21,代碼來源:x509certificate2collection.cs

示例11: Import

        public void Import(string fileName, string password, X509KeyStorageFlags keyStorageFlags) {
            uint dwFlags = X509Utils.MapKeyStorageFlags(keyStorageFlags);
            Cryptography.SafeCertStoreHandle safeCertStoreHandle = Cryptography.SafeCertStoreHandle.InvalidHandle;

#if !FEATURE_CORESYSTEM
            //
            // We need to Assert all StorePermission flags since this is a memory store and we want 
            // semi-trusted code to be able to import certificates to a memory store.
            //

            StorePermission sp = new StorePermission(StorePermissionFlags.AllFlags);
            sp.Assert();
#endif

            safeCertStoreHandle = LoadStoreFromFile(fileName, password, dwFlags, (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) != 0);

            X509Certificate2Collection collection = X509Utils.GetCertificates(safeCertStoreHandle);

            safeCertStoreHandle.Dispose();
            X509Certificate2[] x509Certs = new X509Certificate2[collection.Count];
            collection.CopyTo(x509Certs, 0);
            this.AddRange(x509Certs);
        }
開發者ID:iskiselev,項目名稱:JSIL.NetFramework,代碼行數:23,代碼來源:x509certificate2collection.cs

示例12: CertOpenStore

        SafeCertStoreHandle CertOpenStore(
            [In]    IntPtr  lpszStoreProvider,
            [In]    uint    dwMsgAndCertEncodingType,
            [In]    IntPtr  hCryptProv,
            [In]    uint    dwFlags,
            [In]    string  pvPara) {

            if (lpszStoreProvider != new IntPtr(CERT_STORE_PROV_MEMORY) && lpszStoreProvider != new IntPtr(CERT_STORE_PROV_SYSTEM))
                throw new ArgumentException(SR.GetString(SR.Security_InvalidValue), "lpszStoreProvider");

#if !FEATURE_CORESYSTEM
            if ((dwFlags & CERT_SYSTEM_STORE_LOCAL_MACHINE) == CERT_SYSTEM_STORE_LOCAL_MACHINE ||
                (dwFlags & CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY) == CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY ||
                (dwFlags & CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE) == CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE) {
                // We do not allow opening remote local machine stores if in semi-trusted environment.
                if (pvPara != null && pvPara.StartsWith(@"\\", StringComparison.Ordinal))
                    new PermissionSet(PermissionState.Unrestricted).Demand();
            }

            if ((dwFlags & CERT_STORE_DELETE_FLAG) == CERT_STORE_DELETE_FLAG) {
                StorePermission sp = new StorePermission(StorePermissionFlags.DeleteStore);
                sp.Demand();
            } else {
                StorePermission sp = new StorePermission(StorePermissionFlags.OpenStore);
                sp.Demand();
            }

            if ((dwFlags & CERT_STORE_CREATE_NEW_FLAG) == CERT_STORE_CREATE_NEW_FLAG) {
                StorePermission sp = new StorePermission(StorePermissionFlags.CreateStore);
                sp.Demand();
            }

            if ((dwFlags & CERT_STORE_OPEN_EXISTING_FLAG) == 0) {
                StorePermission sp = new StorePermission(StorePermissionFlags.CreateStore);
                sp.Demand();
            }
#endif

            return CAPIMethods.CertOpenStore(lpszStoreProvider, 
                                             dwMsgAndCertEncodingType, 
                                             hCryptProv, 
                                             dwFlags | CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, 
                                             pvPara);
        }
開發者ID:REALTOBIZ,項目名稱:mono,代碼行數:44,代碼來源:cryptoapi.cs

示例13: FromXml_WrongClass

        public void FromXml_WrongClass ()
        {
            StorePermission sp = new StorePermission (PermissionState.None);
            SecurityElement se = sp.ToXml ();

            SecurityElement w = new SecurityElement (se.Tag);
            w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
            w.AddAttribute ("version", se.Attribute ("version"));
            sp.FromXml (w);
            // doesn't care of the class name at that stage
            // anyway the class has already be created so...
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:12,代碼來源:StorePermissionTest.cs

示例14: FromXml_Null

        public void FromXml_Null ()
        {
            StorePermission sp = new StorePermission (PermissionState.None);
            sp.FromXml (null);
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:5,代碼來源:StorePermissionTest.cs

示例15: CertAddCertificateLinkToStore

        bool CertAddCertificateLinkToStore (
            [In]     SafeCertStoreHandle        hCertStore,
            [In]     SafeCertContextHandle      pCertContext,
            [In]     uint                       dwAddDisposition,
            [In,Out] SafeCertContextHandle      ppStoreContext) {

            if (hCertStore == null)
                throw new ArgumentNullException("hCertStore");
            if (hCertStore.IsInvalid)
                throw new CryptographicException(SR.GetString(SR.Cryptography_InvalidHandle), "hCertStore");

            if (pCertContext == null)
                throw new ArgumentNullException("pCertContext");
            if (pCertContext.IsInvalid)
                throw new CryptographicException(SR.GetString(SR.Cryptography_InvalidHandle), "pCertContext");

#if !FEATURE_CORESYSTEM
            StorePermission sp = new StorePermission(StorePermissionFlags.AddToStore);
            sp.Demand();
#endif

            return CAPIMethods.CertAddCertificateLinkToStore(hCertStore, 
                                                             pCertContext, 
                                                             dwAddDisposition, 
                                                             ppStoreContext);
        }
開發者ID:REALTOBIZ,項目名稱:mono,代碼行數:26,代碼來源:cryptoapi.cs


注:本文中的System.Security.Permissions.StorePermission類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。