gpt4 book ai didi

.net - C# : What are Partially Trusted Callers?

转载 作者:行者123 更新时间:2023-12-03 14:59:23 25 4
gpt4 key购买 nike

我还没有在一页中清楚地看到这一点:部分受信任的调用者。

我正在研究 APTCA,这总是被提及,但 MSDN 没有关于它的文章。

我只有一些线索,但我不是 100% 确定。

  • 从网络共享执行的代码是否符合“部分受信任的调用者”的条件?即使我们以管理员身份运行它(Windows UAC)?
  • .NET 应用程序作为“部分受信任”运行的其他方式是什么?
  • 什么是 ASP.net 环境中的“部分受信任的调用者”?

  • 我遇到过很多文章都提到了部分可信调用者的业务,但没有直接定义它们本身。

    最佳答案

    任何具有除 FullTrust 以外的信任级别的调用方都是部分信任调用方。

    MSDN library for the AllowPartiallyTrustedCallersAttribute Class :

    Allows an assembly to be called by partially trusted code. Without this declaration, only fully trusted callers are able to use the assembly.



    所以,如果你正在创建将由任何大会未经 FullTrust水平消耗库,则必须使用显式声明它 APTCA ( 一个 llow P artially 牛逼生锈 Ç阿勒斯 一个 ttribute) .

    那么,当应用程序以完全信任或部分信任的方式运行时,它是如何确定的?

    信任级别与 AppDomain 相关联,它是根据所谓的证据确定的。这是 .NET 代码访问安全性的全部内容。 This article provides a great overview of its components。从那里:

    CAS identifies assemblies using evidence, there are a few elements by which an assembly can be identified, such as location, hash code and signature of the assembly. Evidence is the information that the runtime gathers about an assembly to determine which code group the assembly belongs to. Code groups in turn grant an assembly a permission set.

    Permissions Sets are unique combinations of security configurations that determine what each user with access to a machine can do on that machine. There are several permission sets shipped with the .NET Framework as in the following table:

    • FullTrust: Allow full access to all resources.
    • Everything: Allow full access to all resources (group isn't added to assembly list)
    • Internet: Grant Default rights.
    • SkipVerification: Bypass all security verification
    • Nothing: Denies all access including Execution
    • Execution: Allows execution-only access.


    因此,通过检查正在执行的程序集,CLR 将确定应用程序是完全信任还是部分信任。这对允许应用程序执行的操作有影响,例如访问文件系统,或允许调用哪些库(如果它是部分信任应用程序,则标记为 APTCA)。

    但是, .NET 4 introduced significant changes in security :

    By default, unhosted applications are not subject to managed security policy when run under v4.0. Effectively, this means any managed application that you launch from the command prompt or by double clicking the .exe in Windows Explorer will run fully trusted, as will all of the assemblies that it loads (including assemblies that it loads from a location other than the the directory where the executable lives).



    事实上, most of CAS was deprecated except for sand-boxed applications such as ASP.NET and ClickOnce :

    (...) in v4 of the CLR, CAS policy has been deprecated and policy decisions are instead left entirely up to the host of an application. However, the other security mechanisms that fell under the name CAS, which allow hosts to configure AppDomains to host sandboxed code and allow library authors to write a safe APTCA library exposing services to partial trust absolutely still exist and are supported.



    因此,在 .NET 4 更改之后, ASP.NET 4 security also changed 和 ASP.NET 应用程序默认是完全受信任的应用程序。然而,这可以通过将 trustLevel 属性设置为不同于 Full 的值在配置中进行更改。

    总而言之,从 .NET 4 及更高版本开始,您可以假设您的应用程序默认以完全信任的方式运行,除非您通过配置文件中的 LegacyCasPolicy 选择加入 CAS。这同样适用于 ASP.NET 应用程序,除非您选择设置不同的信任级别。

    关于.net - C# : What are Partially Trusted Callers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23882770/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com