<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>A BULL's view of LIFE and TECHNOLOGY : Security</title><link>http://blogs.msdn.com/ashishme/archive/tags/Security/default.aspx</link><description>Tags: Security</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>NTLM vs KERBEROS - Windows Communication Foundation</title><link>http://blogs.msdn.com/ashishme/archive/2006/11/10/ntlm-vs-kerberos-windows-communication-foundation.aspx</link><pubDate>Sat, 11 Nov 2006 01:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1056053</guid><dc:creator>ashishme</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/ashishme/comments/1056053.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ashishme/commentrss.aspx?PostID=1056053</wfw:commentRss><description>&lt;P&gt;To understand the windows authentication mechanism better please refer: &lt;A href="http://msdn2.microsoft.com/en-us/library/aa480475" mce_href="http://msdn2.microsoft.com/en-us/library/aa480475"&gt;http://msdn2.microsoft.com/en-us/library/aa480475....&lt;/A&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;The Scenario:&lt;/H3&gt;
&lt;P&gt;A&amp;nbsp;Web Application and WCF web service on Windows XP, where the Web Application uses services provided by WCF layer. Further, the WCF (or coarse grained services) talks to various Web Services (or fine grained web services), massages the data received and pass it to Web Application. The Web Service that WCF connects is hosted on Windows 2003 with NTAuthenticationProviders in IIS metabase set as NTLM. &lt;/P&gt;
&lt;P&gt;You can view the IIS metabase using a tool called METAEDIT (download from &lt;A href="http://download.microsoft.com/download/iis50/utility/5.0/nt45/en-us/mtaedt22.exe" target=_blank mce_href="http://download.microsoft.com/download/iis50/utility/5.0/nt45/en-us/mtaedt22.exe"&gt;here&lt;/A&gt;). You can also check the NTAuthenticationProviders on the machine by using the following script:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#0000a0&gt;cscript %systemdrive%\inetpub\adminscripts\adsutil.vbs&amp;nbsp; get /w3svc/1/NTAuthenticationProviders&lt;/FONT&gt; &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;(here "1" is the web site sequence internal to IIS, for XP it will always by "1")&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000a0&gt;&lt;STRONG&gt;cscript %systemdrive%\inetpub\adminscripts\adsutil.vbs&amp;nbsp; get /w3svc/NTAuthenticationProviders&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now when Web application makes a call to WCF with binding configured as Windows (i.e. basicHttpBinding with bindingConfiguration specifying &lt;STRONG&gt;&lt;FONT color=#800080&gt;&amp;lt;security mode="TransportCredentialOnly"&amp;gt; &amp;lt;transport clientCredentialType="Windows"&amp;gt;&amp;lt;/transport&amp;gt;&amp;lt;/security&amp;gt;&lt;/FONT&gt;&lt;/STRONG&gt;) and WCF calls the fine grained web services with same bindingConfiguration an obvious error would be thrown - that &lt;FONT color=#ff0000&gt;&lt;EM&gt;Client authentication header was passed as Negotiate where as the Server authentication header received is NTLM&lt;/EM&gt;&lt;/FONT&gt;. The solution to the problem is changing the clientCredentialType to Ntlm&amp;nbsp;in the config file of the WCF layer for the binding that is utilized for connecting to fine grained web services. &lt;/P&gt;
&lt;P&gt;But now when you run the Web Application again you will encounter the following error - &lt;FONT color=#ff0000&gt;&lt;EM&gt;Client authentication header was passed as Ntlm where as the Server authentication header received is NTLM. &lt;/EM&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt;By looking it seem that client is passing Ntlm and server is expecting NTLM (note the case), but the real reason for this is that NTLM identity is not passed across virtual folders / remote processes when NTLM authentication is used, thus it fails. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;H3&gt;&lt;FONT color=#000000&gt;The Workaround:&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;The solutions to this (assuming you don't have control over the third party / fine grained web services) are:&lt;/FONT&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;FONT color=#000000&gt;At WCF layer before making a call to fine grained service impersonate your windows identity (you need to specify the password and userName)&lt;/FONT&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;FONT color=#000000&gt;In machine.config there is a tag &amp;lt;processModel&amp;gt;(read about processModel &lt;A href="http://msdn2.microsoft.com/en-us/library//7w2sway1.aspx" target=_blank mce_href="http://msdn2.microsoft.com/en-us/library//7w2sway1.aspx"&gt;here&lt;/A&gt;) which let you configure IIS worker process settings. The default setting for this is &amp;lt;processModel autoConfig="true" /&amp;gt;, you need to change it to &amp;lt;processModel userName="somedomain\someuser" password="somepassword" /&amp;gt;&lt;/FONT&gt; &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;EM&gt;(can use any one though I would suggest the 2nd approach as there are no code changes)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;Reset the IIS and now the Identity is able to flow from the WCF to fine grained web service as you explicitly impersonated the same before calling the service or at worker process level.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/H3&gt;
&lt;H3&gt;&lt;FONT color=#000000&gt;The Resolution:&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;If you have a&amp;nbsp;control over fine grained web services that are hosted on Windows Server 2003, configure the IIS to use Kerberos instead of NTLM, by setting the NTAuthenticationProvider property of IIS metabase to "Negotiate" or "Negotiate,NTLM". The command for the same:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#0000a0&gt;cscript %systemdrive%\inetpub\adminscripts\adsutil.vbs set /w3svc/1/NTAuthenticationProviders "Negotiate,NTLM"&lt;/FONT&gt;&lt;/STRONG&gt; (Where the no. 1 depends on the internal sequence used by IIS for different web sites)&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;As&amp;nbsp;the Kerberos is enabled on Windows Server and following conditions are true for your IIS web site configurations:&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#000000&gt;
&lt;P&gt;• The IIS 6.0 Web site is part of an IIS application pool. &lt;/P&gt;
&lt;P&gt;• The application pool is running under a local account or under a domain user account. &lt;/P&gt;
&lt;P&gt;• The Web site is configured to use Integrated Windows authentication only.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;FONT color=#000000&gt;Now try accessing the fine grained web service (from a web browser) you will receive the error&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT color=#000000&gt;&lt;FONT color=#ff0000&gt;"HTTP Error 401.1 - Unauthorized: Access is denied due to invalid credentials.", &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;&lt;FONT color=#ff0000&gt;which is thrown after browser challenges you 3 times for supplying the credntials.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Assuming this&amp;nbsp;is the case with all the conditions mentioned above are&amp;nbsp;true,then when Integrated Windows authentication tries to use Kerberos, Kerberos authentication may not work. To use Kerberos authentication, a service must register its service principal name (SPN) under the account in the Active Directory directory service that the service is running under. By default, Active Directory registers the network basic input/output system (NetBIOS) computer name. Active Directory also permits the Network Service or the Local System account to use Kerberos.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To resolve this behavior when the application pool is running under a domain user account, set up an HTTP SPN with the NetBIOS name and the fully qualified domain name (FQDN) of the domain user account that the application pool is running under.&lt;/P&gt;
&lt;P&gt;1. Install the Setspn.exe tool. (for &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=5fd831fd-ab77-46a3-9cfe-ff01d29e5c46&amp;amp;displaylang=en" target=_blank mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=5fd831fd-ab77-46a3-9cfe-ff01d29e5c46&amp;amp;displaylang=en"&gt;Windows 2000&lt;/A&gt; / &lt;A href="http://support.microsoft.com/kb/892777" target=_blank mce_href="http://support.microsoft.com/kb/892777"&gt;Windows 2003&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;2. Start a command prompt, and then change to the directory where you installed Setspn.exe.&lt;/P&gt;
&lt;P&gt;3. At the command prompt, type the following commands. Press ENTER after each command: &lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000a0&gt;setspn.exe -a http/&lt;VAR&gt;IIS_computer's_NetBIOS_name&lt;/VAR&gt;&lt;VAR&gt; DomainName&lt;/VAR&gt;\&lt;VAR&gt;UserName&lt;/VAR&gt; &lt;BR&gt;setspn.exe -a http/&lt;VAR&gt;IIS_computer's_FQDN &lt;/VAR&gt;&lt;VAR&gt;DomainName&lt;/VAR&gt;\&lt;VAR&gt;UserName&lt;/VAR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;FONT color=#804000&gt;Note &lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#804000&gt;&lt;VAR&gt;UserName&lt;/VAR&gt; is the user account that the application pool is running under.&lt;/FONT&gt;&lt;/P&gt;
&lt;H4&gt;&lt;FONT color=#804000&gt;&lt;STRONG&gt;&lt;EM&gt;This command can only be executed by domain administrators.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/H4&gt;
&lt;P&gt;After you set the SPN for the HTTP service to the domain user account that the application pool is running under, you can successfully connect to the Web site without being prompted for your user credentials and WCF will also be able to connect to the fine grained web services.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1056053" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ashishme/archive/tags/Indigo/default.aspx">Indigo</category><category domain="http://blogs.msdn.com/ashishme/archive/tags/Security/default.aspx">Security</category></item><item><title>Use of APTCA</title><link>http://blogs.msdn.com/ashishme/archive/2006/06/09/623840.aspx</link><pubDate>Fri, 09 Jun 2006 17:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623840</guid><dc:creator>ashishme</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/ashishme/comments/623840.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ashishme/commentrss.aspx?PostID=623840</wfw:commentRss><description>&lt;P class=NumHeading2 style="MARGIN: 12pt 0in 6pt 39.7pt"&gt;&lt;FONT color=#333333&gt;&lt;SPAN lang=EN-AU&gt;&lt;STRONG&gt;&lt;FONT face=Arial size=5&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=2&gt;The .Net Framework provides a number of security features that enables in secure applications, and one of the features is evidence based that works on the top of operating system security. The evidence based security gathers evidences regarding the assembly and determine whether the code has permissions to execute. Any assembly that gets installed in Global Assembly Cache (GAC) is considered by .Net Framework to have Full Trust i.e. the &lt;SPAN style="mso-bidi-font-weight: bold"&gt;code has unrestricted access to all protected resources&lt;/SPAN&gt; and these assemblies can only be called by other Full Trust assemblies. However the partial trust assemblies cannot call the Full Trust assemblies therefore .NET Framework 1.1 introduced an assembly-level custom attribute AllowPartiallyTrustedCallers. The Full Trust assemblies marked with AllowPartiallyTrustedCallersAttribute can be called by partially trusted assemblies and the implicit demand is not called. The improper usage of this attribute can introduce vulnerabilities that can lead to luring attack. The solution presented in this document discusses the proper usage of AllowPartiallyTrustedCallersAttribute.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;A name=_Toc135760958&gt;&lt;FONT color=#333333&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=4&gt;&lt;STRONG&gt;Trust Levels&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;SPAN lang=EN-AU&gt;&lt;STRONG&gt;&lt;FONT face=Arial color=#333333 size=4&gt; &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=2&gt;In managed world an Assembly can belong to one of the following trust models:&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU style="mso-bidi-font-weight: bold"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Arial size=2&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;Full Trust&lt;BR&gt;Any assembly that has been strong named and installed in GAC is Full Trust Assembly, unless someone has lock down the security policy by changing the grant set of local machine to something less than full trust. &lt;SPAN style="mso-bidi-font-weight: bold"&gt;This permission set gives code unrestricted access to all protected resources. This can be a very dangerous permission set; it allows full access to your computer's resources such as the file system or network access, potentially operating outside the control of the security system. If you are modifying security policy, be sure to set policy such that only assemblies you fully trust could possibly get this permission set.&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Arial size=2&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=2&gt;Partial Trust&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=2&gt;Code that does not get full trust will have partial trust. Partial trust code will have to call framework code, and hence an assembly with full trust will be called by an assembly with partial trust.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;A name=_Toc135760959&gt;&lt;FONT color=#333333&gt;&lt;SPAN lang=EN-AU&gt;&lt;STRONG&gt;&lt;FONT face=Arial size=4&gt;Why Full Trust is required?&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;SPAN lang=EN-AU style="mso-bidi-font-weight: bold"&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU style="mso-bidi-font-weight: bold"&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;Full Trust is required: &lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU style="mso-bidi-font-weight: bold"&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=2&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=2&gt;To call Unmanaged Code&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=2&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=2&gt;To create COM objects &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=2&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=2&gt;To use OLEdb or ODBC&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU&gt;&lt;/SPAN&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;&lt;SPAN lang=EN-AU style="mso-bidi-font-weight: bold"&gt;A partial trust assembly cannot perform the above mentioned operations and &lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;most core .Net assemblies don’t have the AllowPartiallyTrustedCallersAttribute(APTCA) applied, hence limiting partial trust assemblies.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;&lt;SPAN lang=EN-AU&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;&lt;SPAN lang=EN-AU&gt;&lt;A name=_Toc135760961&gt;&lt;FONT color=#333333&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Arial Black" size=5&gt;The Problem&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;SPAN lang=EN-AU&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;&lt;SPAN lang=EN-AU&gt;&lt;SPAN lang=EN-AU&gt;A class library needs to perform some privileged operations (example: reading contents of some system file) and the assembly needs to be shared among various applications in the organization. To make the assembly be shared among various applications we need to strong name our assembly and host it in GAC. Now this library can only be called by strong named assemblies or assemblies with full trust. To make the assembly accessible by other partially trusted assemblies we need to add APTCA to the assembly. &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;P class=NumHeading2 style="MARGIN: 12pt 0in 6pt; TEXT-INDENT: 0in"&gt;&lt;A name=_Toc135760962&gt;&lt;FONT color=#333333&gt;&lt;SPAN lang=EN-AU&gt;&lt;STRONG&gt;&lt;FONT size=5&gt;The Luring Attack&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU style="FONT-SIZE: 10pt; LINE-HEIGHT: 110%; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial; mso-ansi-language: EN-AU; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;The result of adding APTCA any un-trusted / partially trusted code can call the trusted code. The trusted code then executes the privileged code on the behalf of the un-trusted code. This is known as Luring Attack where an attacker can take advantage of use of APTCA to lure a Fully Trusted assembly to execute un-trusted code on its behalf like calling the privileged operation on the victim machine. &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU style="FONT-SIZE: 10pt; LINE-HEIGHT: 110%; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial; mso-ansi-language: EN-AU; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU style="FONT-SIZE: 10pt; LINE-HEIGHT: 110%; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial; mso-ansi-language: EN-AU; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;&lt;SPAN lang=EN-AU style="FONT-SIZE: 10pt; LINE-HEIGHT: 110%; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial; mso-ansi-language: EN-AU; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU style="FONT-SIZE: 10pt; LINE-HEIGHT: 110%; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial; mso-ansi-language: EN-AU; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;&lt;SPAN lang=EN-AU style="FONT-SIZE: 10pt; LINE-HEIGHT: 110%; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial; mso-ansi-language: EN-AU; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;
&lt;P class=NumHeading2 style="MARGIN: 12pt 0in 6pt; TEXT-INDENT: 0in"&gt;&lt;A name=_Toc135760963&gt;&lt;FONT color=#333333&gt;&lt;SPAN lang=EN-AU&gt;&lt;STRONG&gt;&lt;FONT size=5&gt;Code Sample: The Luring Attack&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=NumHeading2 style="MARGIN: 12pt 0in 6pt; TEXT-INDENT: 0in"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 11.35pt; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div"&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// The Trusted Code &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System.Security;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System.Security.Permissions;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System.Reflection;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// This assembly executes with full trust and &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// allows partially trusted callers and would reside in GAC&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// Applying APTCA to assembly&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: red"&gt;&lt;FONT face="Courier New"&gt;[assembly:AllowPartiallyTrustedCallers]&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;namespace TrustedCodeWithImproperAPTCA&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;public class PerformPrivilgedOperations&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;SPAN style="mso-tab-count: 9"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;public static void PrivilgedOperations()&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;// Some Call to Privileged Code&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;_______________________________________________________________________________________________&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// The Un-trusted / Attacker Code&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using TrustedCodeWithImproperAPTCA;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// If this test is run from the local computer, it gets full trust by &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;// default. So Remove full trust&lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;[assembly:System.Security.Permissions.PermissionSetAttribute(&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;System.Security.Permissions.SecurityAction.RequestRefuse, Name="FullTrust")]&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;namespace TestSecLibrary&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;class TestApctaMethodRule&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;public static void &lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;&lt;st1:place w:st="on"&gt;Main&lt;/st1:place&gt;()&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Indirectly calls PrivilgedOperations.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;PerformPrivilgedOperations.PrivilgedOperations();&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;o:p&gt;&lt;A name=_Toc135760964&gt;&lt;FONT color=#333333&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Arial Black" size=5&gt;Solution design&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;APTCA only removes the implicit Link demands; any demands explicitly placed in your assembly will still be enforced. This means that even once an assembly has been marked with APTCA, it could still have some types in it that are not usable from partial trust by use of Explicit Demands. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU style="FONT-SIZE: 10pt; LINE-HEIGHT: 110%; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial; mso-ansi-language: EN-AU; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;Using the above stated fact we can use the APTCA properly with Explicit Demands. Thus we can mark the Full trust assemblies with APTCA and also have explicit demands to prevent the Luring attack. A better design would be not to have APTCA directly applied on the Trusted Code, but introduce a Façade assembly. The Façade assembly / code will have the full trust as the trusted code with APTCA applied to it, and will have explicit demand calls, thus making it non-vulnerable for the luring attack. This allows the Trusted Code to take advantage of Link Demands as well as protection from luring attack with help on explicit demands through Façade. &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU style="FONT-SIZE: 10pt; LINE-HEIGHT: 110%; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial; mso-ansi-language: EN-AU; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU style="FONT-SIZE: 10pt; LINE-HEIGHT: 110%; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial; mso-ansi-language: EN-AU; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;
&lt;P class=NumHeading2 style="MARGIN: 12pt 0in 6pt; TEXT-INDENT: 0in"&gt;&lt;A name=_Toc135760966&gt;&lt;FONT color=#333333&gt;&lt;SPAN lang=EN-AU&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-AU&gt;&lt;STRONG&gt;&lt;FONT size=5&gt;Code Sample: The proper use of APTCA&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 11.35pt; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div"&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// The Trusted Code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;namespace TrustedCode&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;public class PerformPrivilgedOperations&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;public static void PrivilgedOperations()&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Some Call to Privileged Code.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;_______________________________________________________________________________________________&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;U&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;SPAN style="TEXT-DECORATION: none"&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// The Façade Code (with APTCA applied) &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System.Security;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System.Security.Permissions;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System.Reflection;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using TrustedCodeWithImproperAPTCA;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// Applying APTCA to assembly&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN lang=EN-AU style="COLOR: #339966"&gt;&lt;FONT face="Courier New"&gt;[assembly:AllowPartiallyTrustedCallers]&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;namespace FacadeWithAPTCACallingTrustedCode&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;public class FacadeCallingTrustedCode&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;public static void CallingTrustedCode()&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in; TEXT-INDENT: 24.65pt"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// This security check fails if the caller &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// does not have full trust. &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;NamedPermissionSet pset= &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; NamedPermissionSet("FullTrust");&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// This try-catch block shows the caller's permissions.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Correct code would either not catch the exception,&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// or would rethrow it.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;try&lt;/SPAN&gt; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pset.Demand();&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;catch&lt;/SPAN&gt; (SecurityException e)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Console.WriteLine("Demand &lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt; full trust:{0}", e.Message);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// Calls PrivilgedOperations()&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;PerformPrivilgedOperations.PrivilgedOperations();&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;// The Un-trusted / Partial Code&lt;/SPAN&gt;&lt;U&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using System;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;using FacadeWithAPTCACallingTrustedCode;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// If this test is run from the local computer, it gets full trust by default.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU style="COLOR: green"&gt;&lt;FONT face="Courier New"&gt;// Remove full trust.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;[assembly:System.Security.Permissions.PermissionSetAttribute(&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;System.Security.Permissions.SecurityAction.RequestRefuse, Name="FullTrust")]&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;namespace TestSecLibrary&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;class TestApctaMethodRule&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;public static void &lt;st1:place w:st="on"&gt;Main&lt;/st1:place&gt;()&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;FacadeCallingTrustedCode.CallingTrustedCode();&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Courier New"&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=CodeBlock style="MARGIN: 1pt 0in"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;A name=_Toc135760967&gt;&lt;FONT color=#333333&gt;&lt;SPAN lang=EN-AU&gt;&lt;FONT face="Arial Black" size=5&gt;References&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;Introduction to Code Access Security - &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconintroductiontocodeaccesssecurity.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconintroductiontocodeaccesssecurity.asp&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;Code Access Security Basics - &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcodeaccesssecuritybasics.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcodeaccesssecuritybasics.asp&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;Using Libraries from Partially Trusted Code - &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconUsingLibrariesFromPartiallyTrustedCode.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconUsingLibrariesFromPartiallyTrustedCode.asp&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in 3pt 11.35pt"&gt;&lt;SPAN lang=EN-AU&gt;APTCA methods should only call APTCA methods - &lt;A href="http://msdn2.microsoft.com/en-us/library/ms182297.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms182297.aspx&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN lang=EN-AU style="FONT-SIZE: 10pt; LINE-HEIGHT: 110%; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial; mso-ansi-language: EN-AU; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=623840" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ashishme/archive/tags/Security/default.aspx">Security</category></item></channel></rss>