Inheritance: EvidenceBase, IIdentityPermissionFactory
        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;

            if (evidence == null)
            {
                return(false);
            }

            StrongName name = evidence.GetDelayEvaluatedHostEvidence <StrongName>();

            if (name != null)
            {
                bool publicKeyMatch = PublicKey != null && PublicKey.Equals(name.PublicKey);
                bool nameMatch      = Name == null || (name.Name != null && StrongName.CompareNames(name.Name, Name));
                bool versionMatch   = (object)Version == null || ((object)name.Version != null && name.Version.CompareTo(Version) == 0);

                if (publicKeyMatch && nameMatch && versionMatch)
                {
                    // Note that we explicitly do not want to mark the strong name evidence as used at
                    // this point, since we could be a child code group where our parent provides more
                    // trust than we do.  For instance, if we're in a setup like this:
                    //
                    //   AllCode -> FullTrust
                    //     StrongName -> FullTrust
                    //
                    // the StrongName code group didn't add anything to the final grant set and therefore
                    // does not need to be evaluated.
                    usedEvidence = name;
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
 internal bool IsSupersetOf(StrongName sn)
 {
     return((this.PublicKey != null && this.PublicKey.Equals(sn.PublicKey)) &&
            (this.Name == null || (sn.Name != null && CompareNames(sn.Name, this.Name))) &&
            ((Object)this.Version == null || ((Object)sn.Version != null &&
                                              sn.Version.CompareTo(this.Version) == 0)));
 }
Exemplo n.º 3
0
        public bool Check(Evidence evidence)
        {
            if (evidence == null)
            {
                return(false);
            }

            IEnumerator e = evidence.GetHostEnumerator();

            while (e.MoveNext())
            {
                StrongName sn = (e.Current as StrongName);
                if (sn != null)
                {
                    if (!sn.PublicKey.Equals(blob))
                    {
                        return(false);
                    }
                    if ((name != null) && (name != sn.Name))
                    {
                        return(false);
                    }
                    if ((assemblyVersion != null) && !assemblyVersion.Equals(sn.Version))
                    {
                        return(false);
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        //------------------------------------------------------
        //
        // IMEMBERSHIPCONDITION IMPLEMENTATION
        //
        //------------------------------------------------------

        /// <include file='doc\StrongNameMembershipCondition.uex' path='docs/doc[@for="StrongNameMembershipCondition.Check"]/*' />
        public bool Check(Evidence evidence)
        {
            if (evidence == null)
            {
                return(false);
            }

            IEnumerator enumerator = evidence.GetHostEnumerator();

            while (enumerator.MoveNext())
            {
                if (enumerator.Current is StrongName)
                {
                    StrongName name = (StrongName)enumerator.Current;

                    if ((this.PublicKey != null && this.PublicKey.Equals(name.PublicKey)) &&
                        (this.Name == null || (name.Name != null && StrongName.CompareNames(name.Name, this.Name))) &&
                        ((Object)this.Version == null || ((Object)name.Version != null && name.Version.CompareTo(this.Version) == 0)))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        public CrossAppDomainCleanUp(AppDomain toWatch, IPrinter printer)
        {
            if (toWatch == null) throw new ArgumentNullException("toWatch");
            if (printer == null) throw new ArgumentNullException("printer");

            (new PermissionSet(PermissionState.Unrestricted)).Assert();
            var current = toWatch;

            AppDomainSetup adSetup = new AppDomainSetup();
            adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            //#if RAZOR4 // currently not signed!
            var strongNames = new StrongName[0];
            //#else
            //            var strongNames = new[] {
            //                FromAssembly(typeof(RazorEngine.Templating.RazorEngineService).Assembly),
            //                FromAssembly(typeof(System.Web.Razor.RazorTemplateEngine).Assembly)
            //            };
            //#endif

            _domain = AppDomain.CreateDomain(
                "CleanupHelperDomain_" + Guid.NewGuid().ToString(), null,
                current.SetupInformation, new PermissionSet(PermissionState.Unrestricted),
                strongNames);

            var initHelper = new InitHelper() { Domain = _domain, Current = current };
            _helper = ExecutionContextLessThread.DefaultCallFunc(new Func<CleanupHelper>(initHelper.CreateHelper));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates an AppDomain.
        /// </summary>
        /// <param name="applicationName">The application name for the new AppDomain, or null if none.</param>
        /// <param name="applicationBaseDirectory">The application base directory for the new AppDomain, or null to use the current one.</param>
        /// <param name="configurationFile">The configuration file for the new AppDomain, or null to use the current one.</param>
        /// <param name="enableShadowCopy">If true, enables shadow copying within the AppDomain.</param>
        /// <returns>The new AppDomain.</returns>
        public static AppDomain CreateAppDomain(string applicationName, string applicationBaseDirectory, string configurationFile, bool enableShadowCopy)
        {
            AppDomainSetup appDomainSetup = new AppDomainSetup();

            appDomainSetup.ApplicationName = applicationName ?? string.Empty;
            appDomainSetup.ApplicationBase = applicationBaseDirectory ?? AppDomain.CurrentDomain.BaseDirectory;

            if (configurationFile != null)
            {
                // NOTE: We can also use AppDomainSetup.SetConfigurationBytes but it only applies to
                //       CLR-internal configuration settings such as the assembly binding policy.
                //       In order for other configuration mechanisms to operate correctly, we must
                //       use a real configuration file on disk instead.
                appDomainSetup.ConfigurationFile = configurationFile;
            }

            if (enableShadowCopy)
            {
                appDomainSetup.ShadowCopyFiles = @"true";
                appDomainSetup.ShadowCopyDirectories = null;
            }

            // TODO: Might need to be more careful about how the Evidence is derived.
            Evidence evidence = AppDomain.CurrentDomain.Evidence;
            if (DotNetRuntimeSupport.IsUsingMono)
            {
                return AppDomain.CreateDomain(appDomainSetup.ApplicationName, evidence, appDomainSetup);
            }
            else
            {
                PermissionSet defaultPermissionSet = new PermissionSet(PermissionState.Unrestricted);
                StrongName[] fullTrustAssemblies = new StrongName[0];
                return AppDomain.CreateDomain(appDomainSetup.ApplicationName, evidence, appDomainSetup, defaultPermissionSet, fullTrustAssemblies);
            }
        }
 public void AddFullTrustAssembly(StrongName sn)
 {
     if (sn == null)
     {
         throw new ArgumentNullException("sn");
     }
     this.AddFullTrustAssembly(new StrongNameMembershipCondition(sn.PublicKey, sn.Name, sn.Version));
 }
        public override bool Equals(Object o)
        {
            StrongName that = (o as StrongName);

            return((that != null) &&
                   Equals(this.m_publicKeyBlob, that.m_publicKeyBlob) &&
                   Equals(this.m_name, that.m_name) &&
                   Equals(this.m_version, that.m_version));
        }
Exemplo n.º 9
0
 // Add an entry to the "full trust assembly" list.
 public void AddFullTrustAssembly(StrongName sn)
 {
     if (sn == null)
     {
         throw new ArgumentNullException("sn");
     }
     AddFullTrustAssembly
         (new StrongNameMembershipCondition
             (sn.PublicKey, sn.Name, sn.Version));
 }
Exemplo n.º 10
0
        public void RemoveFullTrustAssembly(StrongName sn)
        {
            if (sn == null)
            {
                throw new ArgumentNullException("sn");
            }
            StrongNameMembershipCondition snMC = new StrongNameMembershipCondition(sn.PublicKey, sn.Name, sn.Version);

            this.RemoveFullTrustAssembly(snMC);
        }
Exemplo n.º 11
0
        /// <summary>确定指定的强名称是否等于当前强名称。</summary>
        /// <returns>如果指定的强名称等于当前强名称,则为 true;否则为 false。</returns>
        /// <param name="o">与当前强名称进行比较的强名称。</param>
        public override bool Equals(object o)
        {
            StrongName strongName = o as StrongName;

            if (strongName != null && object.Equals((object)this.m_publicKeyBlob, (object)strongName.m_publicKeyBlob) && object.Equals((object)this.m_name, (object)strongName.m_name))
            {
                return(object.Equals((object)this.m_version, (object)strongName.m_version));
            }
            return(false);
        }
		public void AddFullTrustAssembly () 
		{
			PolicyLevel pl = Load (minimal, PolicyLevelType.Machine);
			int n = pl.FullTrustAssemblies.Count;

			StrongName sn = new StrongName (new StrongNamePublicKeyBlob (snPublicKey), "First", new Version (1, 2, 3, 4)); 
			pl.AddFullTrustAssembly (sn);
			Assert.AreEqual (n + 1, pl.FullTrustAssemblies.Count, "FullTrustAssemblies.Count+1");

			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (new StrongNamePublicKeyBlob (snPublicKey), "Second", new Version ("0.1.2.3"));
			pl.AddFullTrustAssembly (snmc);
			Assert.AreEqual (n + 2, pl.FullTrustAssemblies.Count, "FullTrustAssemblies.Count+2");
		}
Exemplo n.º 13
0
        // Determine if two objects are equal.
        public override bool Equals(Object obj)
        {
            StrongName other = (obj as StrongName);

            if (other != null)
            {
                return(other.blob.Equals(blob) &&
                       other.name == name &&
                       other.version.Equals(version));
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 14
0
        private void LoadReport()
        {
            StreamReader report = null;
            ReportDataTableAdapters.LoanDetailsTableAdapter LoanAdapter = new ReportDataTableAdapters.LoanDetailsTableAdapter();
            DataSet ds = new DataSet();

            try
            {
                ds.Tables.Add(LoanAdapter.GetLoans());
                rvMain.LocalReport.Dispose();
                ReportDataSource datasource = new
                  ReportDataSource("dsLoans", ds.Tables[0]);

                rvMain.LocalReport.DataSources.Clear();
                rvMain.LocalReport.DataSources.Add(datasource);

                rvMain.ReportError += rvMain_ReportError;
                report = File.OpenText(MapPath("~/LoanPayments.rdlc"));

                rvMain.LocalReport.LoadReportDefinition(report);

                //PermissionSet permissions = new PermissionSet(PermissionState.None);
                //permissions.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
                //permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
                //rvMain.LocalReport.SetBasePermissionsForSandboxAppDomain(permissions);

                Assembly asm = Assembly.Load("ReportHelper, Culture=neutral, PublicKeyToken=null");
                AssemblyName asm_name = asm.GetName();
                StrongName sn = new StrongName(new StrongNamePublicKeyBlob(asm_name.GetPublicKeyToken()), asm_name.Name, asm_name.Version);
                rvMain.LocalReport.AddFullTrustModuleInSandboxAppDomain(sn);

                rvMain.LocalReport.Refresh();
            }
            //Yes, I'm being really lazy here, we could send an alert back to the user or something else
            //but I'm just using it for debugging
            catch (Exception ex)
            {
                string s = ex.ToString();
            }
            finally
            {
                ds.Dispose();
                LoanAdapter.Dispose();
                if (report != null)
                    report.Close();

            }
        }
Exemplo n.º 15
0
        public override bool Equals(object o)
        {
            StrongName sn = (o as StrongName);

            if (sn == null)
            {
                return(false);
            }
            if (name != sn.Name)
            {
                return(false);
            }
            if (!Version.Equals(sn.Version))
            {
                return(false);
            }
            return(PublicKey.Equals(sn.PublicKey));
        }
Exemplo n.º 16
0
        private static void SwitchDomainForRazorEngine()
        {
            if (AppDomain.CurrentDomain.IsDefaultAppDomain())
            {
                // RazorEngine cannot clean up from the default appdomain...
                //Console.WriteLine("Switching to secound AppDomain, for RazorEngine...");
                AppDomainSetup adSetup = new AppDomainSetup();
                adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                var current = AppDomain.CurrentDomain;
                // You only need to add strongnames when your appdomain is not a full trust environment.
                var strongNames = new StrongName[0];

                var domain = AppDomain.CreateDomain(
                    "MyMainDomain", null,
                    current.SetupInformation, new PermissionSet(PermissionState.Unrestricted),
                    strongNames);
                domain.ExecuteAssembly(Assembly.GetExecutingAssembly().Location);
            }
        }
        /// <summary>Determines whether the specified evidence satisfies the membership condition.</summary>
        /// <returns>true if the specified evidence satisfies the membership condition; otherwise, false.</returns>
        /// <param name="evidence">The <see cref="T:System.Security.Policy.Evidence" /> against which to make the test. </param>
        public bool Check(Evidence evidence)
        {
            if (evidence == null)
            {
                return(false);
            }
            IEnumerator hostEnumerator = evidence.GetHostEnumerator();

            while (hostEnumerator.MoveNext())
            {
                object     obj        = hostEnumerator.Current;
                StrongName strongName = obj as StrongName;
                if (strongName != null)
                {
                    return(strongName.PublicKey.Equals(this.blob) && (this.name == null || !(this.name != strongName.Name)) && (!(this.assemblyVersion != null) || this.assemblyVersion.Equals(strongName.Version)));
                }
            }
            return(false);
        }
 bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
 {
     usedEvidence = null;
     if (evidence != null)
     {
         StrongName delayEvaluatedHostEvidence = evidence.GetDelayEvaluatedHostEvidence <StrongName>();
         if (delayEvaluatedHostEvidence != null)
         {
             bool flag  = (this.PublicKey != null) && this.PublicKey.Equals(delayEvaluatedHostEvidence.PublicKey);
             bool flag2 = (this.Name == null) || ((delayEvaluatedHostEvidence.Name != null) && StrongName.CompareNames(delayEvaluatedHostEvidence.Name, this.Name));
             bool flag3 = (this.Version == null) || ((delayEvaluatedHostEvidence.Version != null) && (delayEvaluatedHostEvidence.Version.CompareTo(this.Version) == 0));
             if ((flag && flag2) && flag3)
             {
                 usedEvidence = delayEvaluatedHostEvidence;
                 return(true);
             }
         }
     }
     return(false);
 }
        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = (object)null;
            if (evidence == null)
            {
                return(false);
            }
            StrongName evaluatedHostEvidence = evidence.GetDelayEvaluatedHostEvidence <StrongName>();

            if (evaluatedHostEvidence != null)
            {
                int  num1  = this.PublicKey == null ? 0 : (this.PublicKey.Equals(evaluatedHostEvidence.PublicKey) ? 1 : 0);
                bool flag1 = this.Name == null || evaluatedHostEvidence.Name != null && StrongName.CompareNames(evaluatedHostEvidence.Name, this.Name);
                bool flag2 = this.Version == null || evaluatedHostEvidence.Version != null && evaluatedHostEvidence.Version.CompareTo(this.Version) == 0;
                int  num2  = flag1 ? 1 : 0;
                if ((num1 & num2 & (flag2 ? 1 : 0)) != 0)
                {
                    usedEvidence = (object)evaluatedHostEvidence;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 20
0
        public override void BeforeTest(TestDetails testDetails)
        {
            var evidence = new Evidence();
            evidence.AddHostEvidence(new Zone(SecurityZone.Intranet));
            var permissions = SecurityManager.GetStandardSandbox(evidence);
            // var permissions = new PermissionSet(PermissionState.Unrestricted);

            var setup = new AppDomainSetup
            {
                ApplicationBase = Path.GetDirectoryName(Assembly.GetAssembly(typeof(SandboxHost)).Location)
            };

            var fullTrustAssemblies = new StrongName[]
            {
                typeof(SandboxHost).Assembly.Evidence.GetHostEvidence<StrongName>(),
                typeof(Entity).Assembly.Evidence.GetHostEvidence<StrongName>(),
                testDetails.Method.DeclaringType.Assembly.Evidence.GetHostEvidence<StrongName>()
            };

            var domain = AppDomain.CreateDomain(testDetails.FullName, evidence, setup, permissions, fullTrustAssemblies);

            var type = typeof(SandboxHost);

            var handle = Activator.CreateInstanceFrom(domain, type.Assembly.ManifestModule.FullyQualifiedName, type.FullName);

            var sandbox = (SandboxHost)handle.Unwrap();

            var exception = sandbox.Execute(new SandboxTest(testDetails));

            if (exception == null)
            {
                Assert.Pass();
            }

            throw exception;
        }
Exemplo n.º 21
0
        public void RemoveFullTrustAssembly(StrongName sn) {
            if (sn == null)
                throw new ArgumentNullException("assembly");
            Contract.EndContractBlock();

            RemoveFullTrustAssembly(new StrongNameMembershipCondition(sn.PublicKey, sn.Name, sn.Version));
        }
Exemplo n.º 22
0
        internal static void MakeResourceAssemblyEvidence( Evidence input, out Evidence output, out StrongName outputSn )
        {
            IEnumerator eviEnumerator = input.GetHostEnumerator();

            output = new Evidence();
            outputSn = null;

            while (eviEnumerator.MoveNext())
            {
                if (eviEnumerator.Current is StrongName)
                {
                    StrongName inputSn = (StrongName)eviEnumerator.Current;

                    outputSn = new StrongName( inputSn.PublicKey, inputSn.Name + ".resource", inputSn.Version );

                    output.AddHost( outputSn );
                }
                else
                {
                    output.AddHost( eviEnumerator.Current );
                }
            }

            eviEnumerator = input.GetAssemblyEnumerator();

            while (eviEnumerator.MoveNext())
            {
                output.AddAssembly( eviEnumerator.Current );
            }
        }
 internal ApplicationTrust (PermissionSet defaultGrantSet, StrongName[] fullTrustAssemblies) {
     DefaultGrantSet = new PolicyStatement(defaultGrantSet);
     FullTrustAssemblies = fullTrustAssemblies;
 }
 private static StrongName MakeVersionIndependent(StrongName sn) {
     return new StrongName(sn.PublicKey, sn.Name, new Version(0,0,0,0));
 }
 public void FromXml(SecurityElement element)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (string.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
     }
     this.m_appTrustedToRun = false;
     string strA = element.Attribute("TrustedToRun");
     if ((strA != null) && (string.Compare(strA, "true", StringComparison.Ordinal) == 0))
     {
         this.m_appTrustedToRun = true;
     }
     this.m_persist = false;
     string str2 = element.Attribute("Persist");
     if ((str2 != null) && (string.Compare(str2, "true", StringComparison.Ordinal) == 0))
     {
         this.m_persist = true;
     }
     this.m_appId = null;
     string applicationIdentityFullName = element.Attribute("FullName");
     if ((applicationIdentityFullName != null) && (applicationIdentityFullName.Length > 0))
     {
         this.m_appId = new System.ApplicationIdentity(applicationIdentityFullName);
     }
     this.m_psDefaultGrant = null;
     this.m_grantSetSpecialFlags = 0;
     SecurityElement element2 = element.SearchForChildByTag("DefaultGrant");
     if (element2 != null)
     {
         SecurityElement et = element2.SearchForChildByTag("PolicyStatement");
         if (et != null)
         {
             PolicyStatement statement = new PolicyStatement(null);
             statement.FromXml(et);
             this.m_psDefaultGrant = statement;
             this.m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(statement.PermissionSet, null);
         }
     }
     List<StrongName> list = new List<StrongName>();
     SecurityElement element4 = element.SearchForChildByTag("FullTrustAssemblies");
     if ((element4 != null) && (element4.InternalChildren != null))
     {
         IEnumerator enumerator = element4.Children.GetEnumerator();
         while (enumerator.MoveNext())
         {
             StrongName item = new StrongName();
             item.FromXml(enumerator.Current as SecurityElement);
             list.Add(item);
         }
     }
     this.m_fullTrustAssemblies = list.AsReadOnly();
     this.m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
 }
		public void RemoveFullTrustAssembly_UnknownStrongName () {
			PolicyLevel pl = Load (minimal, PolicyLevelType.Machine);
			StrongName sn = new StrongName (new StrongNamePublicKeyBlob (snPublicKey), "First", new Version (1, 2, 3, 4)); 
			pl.RemoveFullTrustAssembly (sn);
		}
        public void FromXml(SecurityElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            }

            m_psDefaultGrant      = null;
            m_fullTrustAssemblies = null;
            m_appTrustedToRun     = false;

            string isAppTrustedToRun = element.Attribute("TrustedToRun");

            if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0)
            {
                m_appTrustedToRun = true;
            }
            string persist = element.Attribute("Persist");

            if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0)
            {
                m_persist = true;
            }

            string fullName = element.Attribute("FullName");

            if (fullName != null && fullName.Length > 0)
            {
                m_appId = new ApplicationIdentity(fullName);
            }

            SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");

            if (elDefaultGrant != null)
            {
                SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
                if (elDefaultGrantPS != null)
                {
                    PolicyStatement ps = new PolicyStatement(null);
                    ps.FromXml(elDefaultGrantPS);
                    m_psDefaultGrant = ps;
                }
            }

            SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies");

            if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null)
            {
                m_fullTrustAssemblies = new StrongName[elFullTrustAssemblies.Children.Count];
                IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
                int         index      = 0;
                while (enumerator.MoveNext())
                {
                    m_fullTrustAssemblies[index] = new StrongName();
                    m_fullTrustAssemblies[index].FromXml(enumerator.Current as SecurityElement);
                    index++;
                }
            }

            m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
        }
Exemplo n.º 28
0
 public void RemoveFullTrustAssembly(StrongName sn)
 {
 }
Exemplo n.º 29
0
        public void FromXml(SecurityElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (string.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            }
            this.m_appTrustedToRun = false;
            string strA = element.Attribute("TrustedToRun");

            if ((strA != null) && (string.Compare(strA, "true", StringComparison.Ordinal) == 0))
            {
                this.m_appTrustedToRun = true;
            }
            this.m_persist = false;
            string str2 = element.Attribute("Persist");

            if ((str2 != null) && (string.Compare(str2, "true", StringComparison.Ordinal) == 0))
            {
                this.m_persist = true;
            }
            this.m_appId = null;
            string applicationIdentityFullName = element.Attribute("FullName");

            if ((applicationIdentityFullName != null) && (applicationIdentityFullName.Length > 0))
            {
                this.m_appId = new System.ApplicationIdentity(applicationIdentityFullName);
            }
            this.m_psDefaultGrant       = null;
            this.m_grantSetSpecialFlags = 0;
            SecurityElement element2 = element.SearchForChildByTag("DefaultGrant");

            if (element2 != null)
            {
                SecurityElement et = element2.SearchForChildByTag("PolicyStatement");
                if (et != null)
                {
                    PolicyStatement statement = new PolicyStatement(null);
                    statement.FromXml(et);
                    this.m_psDefaultGrant       = statement;
                    this.m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(statement.PermissionSet, null);
                }
            }
            List <StrongName> list     = new List <StrongName>();
            SecurityElement   element4 = element.SearchForChildByTag("FullTrustAssemblies");

            if ((element4 != null) && (element4.InternalChildren != null))
            {
                IEnumerator enumerator = element4.Children.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    StrongName item = new StrongName();
                    item.FromXml(enumerator.Current as SecurityElement);
                    list.Add(item);
                }
            }
            this.m_fullTrustAssemblies = list.AsReadOnly();
            this.m_elExtraInfo         = element.SearchForChildByTag("ExtraInfo");
        }
        public void FromXml (SecurityElement element) {
            if (element == null)
                throw new ArgumentNullException("element");
            if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));

            m_psDefaultGrant = null;
            m_fullTrustAssemblies = null;
            m_appTrustedToRun = false;

            string isAppTrustedToRun = element.Attribute("TrustedToRun");
            if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0)
                m_appTrustedToRun = true;
            string persist = element.Attribute("Persist");
            if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0)
                m_persist = true;

            string fullName = element.Attribute("FullName");
            if (fullName != null && fullName.Length > 0)
                m_appId = new ApplicationIdentity(fullName);

            SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
            if (elDefaultGrant != null) {
                SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
                if (elDefaultGrantPS != null) {
                    PolicyStatement ps = new PolicyStatement(null);
                    ps.FromXml(elDefaultGrantPS);
                    m_psDefaultGrant = ps;
                }
            }

            SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies");
            if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) {
                m_fullTrustAssemblies = new StrongName[elFullTrustAssemblies.Children.Count];
                IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
                int index = 0;
                while (enumerator.MoveNext()) {
                    m_fullTrustAssemblies[index] = new StrongName();
                    m_fullTrustAssemblies[index].FromXml(enumerator.Current as SecurityElement);
                    index++;
                }
            }

            m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
        }
        /// <summary>Determines whether the specified strong name is equal to the current strong name.</summary>
        /// <param name="o">The strong name to compare against the current strong name. </param>
        /// <returns>
        ///     <see langword="true" /> if the specified strong name is equal to the current strong name; otherwise, <see langword="false" />.</returns>
        // Token: 0x06002A3E RID: 10814 RVA: 0x0009CFC4 File Offset: 0x0009B1C4
        public override bool Equals(object o)
        {
            StrongName strongName = o as StrongName;

            return(strongName != null && object.Equals(this.m_publicKeyBlob, strongName.m_publicKeyBlob) && object.Equals(this.m_name, strongName.m_name) && object.Equals(this.m_version, strongName.m_version));
        }
 public void AddFullTrustAssembly(StrongName sn)
 {
     Contract.Requires(sn != null);
 }
Exemplo n.º 33
0
		static Evidence CreateAssemblyEvidence(string fileName)
		{
			//HACK: I am unsure whether 'Hash' evidence is required - since this will be difficult to obtain, we will not supply it...
 
			Evidence newEvidence = new Evidence();

			//We must have zone evidence, or we will get a policy exception
			Zone zone = new Zone(SecurityZone.MyComputer);
			newEvidence.AddHost(zone);

			//If the assembly is strong-named, we must supply this evidence
			//for StrongNameIdentityPermission demands
			AssemblyName assemblyName = AssemblyName.GetAssemblyName(fileName);
			byte[] pk = assemblyName.GetPublicKey();
			if (pk!=null && pk.Length != 0)
			{
				StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(pk);
				StrongName strongName = new StrongName(blob, assemblyName.Name, assemblyName.Version);
				newEvidence.AddHost(strongName);
			}

			return newEvidence;
		}
Exemplo n.º 34
0
        public void FromXml(SecurityElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            }

#if FEATURE_CLICKONCE
            m_appTrustedToRun = false;
            string isAppTrustedToRun = element.Attribute("TrustedToRun");
            if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0)
            {
                m_appTrustedToRun = true;
            }

            m_persist = false;
            string persist = element.Attribute("Persist");
            if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0)
            {
                m_persist = true;
            }

            m_appId = null;
            string fullName = element.Attribute("FullName");
            if (fullName != null && fullName.Length > 0)
            {
                m_appId = new ApplicationIdentity(fullName);
            }
#endif // FEATURE_CLICKONCE

            m_psDefaultGrant       = null;
            m_grantSetSpecialFlags = 0;
            SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
            if (elDefaultGrant != null)
            {
                SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
                if (elDefaultGrantPS != null)
                {
                    PolicyStatement ps = new PolicyStatement(null);
                    ps.FromXml(elDefaultGrantPS);
                    m_psDefaultGrant       = ps;
                    m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(ps.PermissionSet, null);
                }
            }

            List <StrongName> fullTrustAssemblies   = new List <StrongName>();
            SecurityElement   elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies");
            if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null)
            {
                IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    StrongName fullTrustAssembly = new StrongName();
                    fullTrustAssembly.FromXml(enumerator.Current as SecurityElement);
                    fullTrustAssemblies.Add(fullTrustAssembly);
                }
            }

            m_fullTrustAssemblies = fullTrustAssemblies.AsReadOnly();

#if FEATURE_CLICKONCE
            m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
#endif // FEATURE_CLICKONCE
        }
Exemplo n.º 35
0
		public void EmptyNameConstructor ()
		{
			StrongName sn = new StrongName (snpkb, String.Empty, version);
		}
Exemplo n.º 36
0
 public void AddFullTrustAssembly(StrongName sn)
 {
 }
Exemplo n.º 37
0
		public void NullVersionConstructor () 
		{
			StrongName sn = new StrongName (snpkb, name, null);
		}
Exemplo n.º 38
0
        internal Evidence(char[] buffer)
        {
            int position = 0;

            while (position < buffer.Length)
            {
                switch (buffer[position++])
                {
                case BuiltInEvidenceHelper.idApplicationDirectory:
                {
                    IBuiltInEvidence ad = new ApplicationDirectory();
                    position = ad.InitFromBuffer(buffer, position);
                    AddAssembly(ad);
                    break;
                }

                case BuiltInEvidenceHelper.idPublisher:
                {
                    IBuiltInEvidence p = new Publisher();
                    position = p.InitFromBuffer(buffer, position);
                    AddHost(p);
                    break;
                }

                case BuiltInEvidenceHelper.idStrongName:
                {
                    IBuiltInEvidence sn = new StrongName();
                    position = sn.InitFromBuffer(buffer, position);
                    AddHost(sn);
                    break;
                }

                case BuiltInEvidenceHelper.idZone:
                {
                    IBuiltInEvidence z = new Zone();
                    position = z.InitFromBuffer(buffer, position);
                    AddHost(z);
                    break;
                }

                case BuiltInEvidenceHelper.idUrl:
                {
                    IBuiltInEvidence u = new Url();
                    position = u.InitFromBuffer(buffer, position);
                    AddHost(u);
                    break;
                }

                case BuiltInEvidenceHelper.idSite:
                {
                    IBuiltInEvidence s = new Site();
                    position = s.InitFromBuffer(buffer, position);
                    AddHost(s);
                    break;
                }

                case BuiltInEvidenceHelper.idPermissionRequestEvidence:
                {
                    IBuiltInEvidence pre = new PermissionRequestEvidence();
                    position = pre.InitFromBuffer(buffer, position);
                    AddHost(pre);
                    break;
                }

                case BuiltInEvidenceHelper.idHash:
                {
                    IBuiltInEvidence h = new Hash();
                    position = h.InitFromBuffer(buffer, position);
                    AddHost(h);
                    break;
                }

                default:
                    throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFixup"));
                } // switch
            }     // while
        }
Exemplo n.º 39
0
		public void CompleteConstructor () 
		{
			StrongName sn = new StrongName (snpkb, name, version);

			Assert.AreEqual (name, sn.Name, "Name");
			Assert.AreEqual (snpkb.ToString (), sn.PublicKey.ToString (), "PublicKey");
			Assert.AreEqual (version.ToString (), sn.Version.ToString (), "Version");

			// same as StrongNamePublicKeyBlob
			Assert.AreEqual (snpkb.GetHashCode (), sn.GetHashCode (), "GetHashCode");

			IPermission ip = sn.CreateIdentityPermission (null);
			Assert.IsTrue ((ip is StrongNameIdentityPermission), "CreateIdentityPermission");

			string s = String.Format ("<StrongName version=\"1\"{0}{1}Key=\"00240000048000009400000006020000002400005253413100040000010001003DBD7208C62B0EA8C1C058072B635F7C9ABDCB22DB20B2A9DADAEFE800642F5D8DEB7802F7A5367728D7558D1468DBEB2409D02B131B926E2E59544AAC18CFC909023F4FA83E94001FC2F11A27477D1084F514B861621A0C66ABD24C4B9FC90F3CD8920FF5FFCED76E5C6FB1F57DD356F96727A4A5485B079344004AF8FFA4CB\"{0}{1}Name=\"StrongNameName\"{0}{1}Version=\"1.2.3.4\"/>{0}",
				Environment.NewLine,
				String.Empty);
			Assert.AreEqual (s, sn.ToString (), "ToString");
		}
		public void AddFullTrustAssembly_DuplicateStrongName () 
		{
			PolicyLevel pl = Load (minimal, PolicyLevelType.Machine);
			StrongName sn = new StrongName (new StrongNamePublicKeyBlob (snPublicKey), "First", new Version (1, 2, 3, 4)); 
			pl.AddFullTrustAssembly (sn);
			pl.AddFullTrustAssembly (sn);
		}
        public void AddFullTrustAssembly (StrongName sn) {
            Contract.Requires(sn != null);

        }
		public void Reset () 
		{
			PolicyLevel pl = PolicyLevel.CreateAppDomainLevel ();

			int n = pl.FullTrustAssemblies.Count;
			StrongName sn = new StrongName (new StrongNamePublicKeyBlob (snPublicKey), "First", new Version (1, 2, 3, 4)); 
			pl.AddFullTrustAssembly (sn);
			Assert.AreEqual (n + 1, pl.FullTrustAssemblies.Count, "FullTrustAssemblies.Count+1");

			int m = pl.NamedPermissionSets.Count;

			NamedPermissionSet nps = new NamedPermissionSet ("Mono");
			pl.AddNamedPermissionSet (nps);
			Assert.AreEqual (m + 1, pl.NamedPermissionSets.Count, "NamedPermissionSets.Count+1");

			pl.Reset ();
			Assert.AreEqual (n, pl.FullTrustAssemblies.Count, "FullTrustAssemblies.Count");
			Assert.AreEqual (m, pl.NamedPermissionSets.Count, "NamedPermissionSets.Count");
		}
Exemplo n.º 43
0
        /// <summary>从 XML 编码重新构造具有给定状态的 <see cref="T:System.Security.Policy.ApplicationTrust" /> 对象。</summary>
        /// <param name="element">用于重新构造 <see cref="T:System.Security.Policy.ApplicationTrust" /> 对象的 XML 编码。</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="element" /> 为 null。</exception>
        /// <exception cref="T:System.ArgumentException">用于 <paramref name="element" /> 的 XML 编码无效。</exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
        /// </PermissionSet>
        public void FromXml(SecurityElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (string.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            }
            this.m_appTrustedToRun = false;
            string strA1 = element.Attribute("TrustedToRun");

            if (strA1 != null && string.Compare(strA1, "true", StringComparison.Ordinal) == 0)
            {
                this.m_appTrustedToRun = true;
            }
            this.m_persist = false;
            string strA2 = element.Attribute("Persist");

            if (strA2 != null && string.Compare(strA2, "true", StringComparison.Ordinal) == 0)
            {
                this.m_persist = true;
            }
            this.m_appId = (ApplicationIdentity)null;
            string applicationIdentityFullName = element.Attribute("FullName");

            if (applicationIdentityFullName != null && applicationIdentityFullName.Length > 0)
            {
                this.m_appId = new ApplicationIdentity(applicationIdentityFullName);
            }
            this.m_psDefaultGrant       = (PolicyStatement)null;
            this.m_grantSetSpecialFlags = 0;
            SecurityElement securityElement1 = element.SearchForChildByTag("DefaultGrant");

            if (securityElement1 != null)
            {
                SecurityElement et = securityElement1.SearchForChildByTag("PolicyStatement");
                if (et != null)
                {
                    PolicyStatement policyStatement = new PolicyStatement((PermissionSet)null);
                    policyStatement.FromXml(et);
                    this.m_psDefaultGrant       = policyStatement;
                    this.m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(policyStatement.PermissionSet, (PermissionSet)null);
                }
            }
            List <StrongName> strongNameList   = new List <StrongName>();
            SecurityElement   securityElement2 = element.SearchForChildByTag("FullTrustAssemblies");

            if (securityElement2 != null && securityElement2.InternalChildren != null)
            {
                foreach (object child in securityElement2.Children)
                {
                    StrongName strongName = new StrongName();
                    strongName.FromXml(child as SecurityElement);
                    strongNameList.Add(strongName);
                }
            }
            this.m_fullTrustAssemblies = (IList <StrongName>)strongNameList.AsReadOnly();
            this.m_elExtraInfo         = element.SearchForChildByTag("ExtraInfo");
        }
Exemplo n.º 44
0
 public void RemoveFullTrustAssembly(StrongName sn)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 45
0
                public void RemoveFullTrustAssembly (StrongName sn)
                {
			if (sn == null)
				throw new ArgumentNullException ("sn");

			StrongNameMembershipCondition s = new StrongNameMembershipCondition (sn.PublicKey, sn.Name, sn.Version);
                        RemoveFullTrustAssembly (s);
                }
Exemplo n.º 46
0
        public void FromXml (SecurityElement element) {
            if (element == null)
                throw new ArgumentNullException("element"); 
            if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML")); 
 
#if FEATURE_CLICKONCE
            m_appTrustedToRun = false; 
            string isAppTrustedToRun = element.Attribute("TrustedToRun");
            if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0) {
                m_appTrustedToRun = true;
            } 

            m_persist = false; 
            string persist = element.Attribute("Persist"); 
            if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0) {
                m_persist = true; 
            }

            m_appId = null;
            string fullName = element.Attribute("FullName"); 
            if (fullName != null && fullName.Length > 0) {
                m_appId = new ApplicationIdentity(fullName); 
            } 
#endif // FEATURE_CLICKONCE
 
            m_psDefaultGrant = null;
            m_grantSetSpecialFlags = 0;
            SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
            if (elDefaultGrant != null) { 
                SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
                if (elDefaultGrantPS != null) { 
                    PolicyStatement ps = new PolicyStatement(null); 
                    ps.FromXml(elDefaultGrantPS);
                    m_psDefaultGrant = ps; 
                    m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(ps.PermissionSet, null);
                }
            }
 
            List<StrongName> fullTrustAssemblies = new List<StrongName>();
            SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies"); 
            if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) { 
                IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
                while (enumerator.MoveNext()) { 
                    StrongName fullTrustAssembly = new StrongName();
                    fullTrustAssembly.FromXml(enumerator.Current as SecurityElement);
                    fullTrustAssemblies.Add(fullTrustAssembly);
                } 
            }
 
            m_fullTrustAssemblies = fullTrustAssemblies.AsReadOnly(); 

#if FEATURE_CLICKONCE 
            m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
#endif // FEATURE_CLICKONCE
        }
 public void AddFullTrustAssembly(StrongName sn)
 {
 }
        public override bool Equals(object o)
        {
            StrongName name = o as StrongName;

            return((((name != null) && object.Equals(this.m_publicKeyBlob, name.m_publicKeyBlob)) && object.Equals(this.m_name, name.m_name)) && object.Equals(this.m_version, name.m_version));
        }
 public void RemoveFullTrustAssembly(StrongName sn)
 {
 }
Exemplo n.º 50
0
		public void StrongName_GetRequiredSize ()
		{
			byte[] pk = { 0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3D, 0xBD, 0x72, 0x08, 0xC6, 0x2B, 0x0E, 0xA8, 0xC1, 0xC0, 0x58, 0x07, 0x2B, 0x63, 0x5F, 0x7C, 0x9A, 0xBD, 0xCB, 0x22, 0xDB, 0x20, 0xB2, 0xA9, 0xDA, 0xDA, 0xEF, 0xE8, 0x00, 0x64, 0x2F, 0x5D, 0x8D, 0xEB, 0x78, 0x02, 0xF7, 0xA5, 0x36, 0x77, 0x28, 0xD7, 0x55, 0x8D, 0x14, 0x68, 0xDB, 0xEB, 0x24, 0x09, 0xD0, 0x2B, 0x13, 0x1B, 0x92, 0x6E, 0x2E, 0x59, 0x54, 0x4A, 0xAC, 0x18, 0xCF, 0xC9, 0x09, 0x02, 0x3F, 0x4F, 0xA8, 0x3E, 0x94, 0x00, 0x1F, 0xC2, 0xF1, 0x1A, 0x27, 0x47, 0x7D, 0x10, 0x84, 0xF5, 0x14, 0xB8, 0x61, 0x62, 0x1A, 0x0C, 0x66, 0xAB, 0xD2, 0x4C, 0x4B, 0x9F, 0xC9, 0x0F, 0x3C, 0xD8, 0x92, 0x0F, 0xF5, 0xFF, 0xCE, 0xD7, 0x6E, 0x5C, 0x6F, 0xB1, 0xF5, 0x7D, 0xD3, 0x56, 0xF9, 0x67, 0x27, 0xA4, 0xA5, 0x48, 0x5B, 0x07, 0x93, 0x44, 0x00, 0x4A, 0xF8, 0xFF, 0xA4, 0xCB };
			StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob (pk);
			StrongName sn = new StrongName (snpkb, "mono", new Version ());

			Assert.AreEqual (97, GetRequiredSize (sn, true), "GetRequiredSize-true");
			Assert.AreEqual (93, GetRequiredSize (sn, false), "GetRequiredSize-false");
		}
Exemplo n.º 51
0
		public void Copy () 
		{
			StrongName sn = new StrongName (snpkb, name, version);
			StrongName snCopy = (StrongName) sn.Copy ();

			Assert.IsNotNull (snCopy, "Copy");
			Assert.IsTrue (sn.Equals (snCopy), "Copy-Equals");
			Assert.AreEqual (sn.GetHashCode (), snCopy.GetHashCode (), "Copy-GetHashCode");
			Assert.AreEqual (sn.ToString (), snCopy.ToString (), "Copy-ToString");
		}
Exemplo n.º 52
0
        public static AppDomain CreateDomain (string friendlyName,
                                              Evidence securityInfo,
                                              AppDomainSetup info,
                                              PermissionSet grantSet,
                                              params StrongName[] fullTrustAssemblies)
        {
            if (info == null)
                throw new ArgumentNullException("info");
            if (info.ApplicationBase == null)
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AppDomainSandboxAPINeedsExplicitAppBase"));
            Contract.EndContractBlock();

            if (fullTrustAssemblies == null)
            {
                fullTrustAssemblies = new StrongName[0];
            }

            info.ApplicationTrust = new ApplicationTrust(grantSet, fullTrustAssemblies);
            return CreateDomain(friendlyName, securityInfo, info);
        }
Exemplo n.º 53
0
		public void NullPublicKeyConstructor () 
		{
			StrongName sn = new StrongName (null, name, version);
		}
Exemplo n.º 54
0
		public void NullNameConstructor () 
		{
			StrongName sn = new StrongName (snpkb, null, version);
		}
Exemplo n.º 55
0
        /// <summary>Determines whether the specified strong name is equal to the current strong name.</summary>
        /// <returns>true if the specified strong name is equal to the current strong name; otherwise, false.</returns>
        /// <param name="o">The strong name to compare against the current strong name. </param>
        public override bool Equals(object o)
        {
            StrongName strongName = o as StrongName;

            return(strongName != null && !(this.name != strongName.Name) && this.Version.Equals(strongName.Version) && this.PublicKey.Equals(strongName.PublicKey));
        }