<?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>.NET Security Blog : Windows</title><link>http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx</link><description>Tags: Windows</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Disabling the FIPS Algorithm Check</title><link>http://blogs.msdn.com/shawnfa/archive/2008/03/14/disabling-the-fips-algorithm-check.aspx</link><pubDate>Fri, 14 Mar 2008 17:00:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8191587</guid><dc:creator>shawnfa</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/8191587.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=8191587</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/shawnfa/archive/2005/05/16/417975.aspx"&gt;.NET 2.0 introduced a check for FIPS certified algorithms&lt;/a&gt; if your local security policy was configured to require them.&amp;nbsp; This resulted in algorithms which are not FIPS compliant (or implementations which were not FIPS certified) throwing an InvalidOperationException from their constructors.&lt;/p&gt; &lt;p&gt;In some cases this isn't a desirable behavior.&amp;nbsp; For instance, some applications need to use the MD5 hashing algorithm for compatibility with an older communication protocol or file format.&amp;nbsp; Prior to .NET 3.5, the AES algorithm was only available in an implementation which was not FIPS certified, and if you needed to use that algorithm the FIPS check could also block you.&lt;/p&gt; &lt;p&gt;To help these cases, we added a configuration file switch to .NET 2.0 SP 1 (and therefore .NET 3.5) which allows an application to say "I know what I'm doing, please don't enforce FIPS for me".&amp;nbsp; For these applications, they can setup a configuration file similar to:&lt;/p&gt; &lt;p&gt; &lt;div style="border-right: black thin inset; padding-right: 1em; border-top: black thin inset; padding-left: 1em; font-size: 10pt; background: lightgrey; padding-bottom: 1em; margin: 1em 1em 1em 2em; border-left: black thin inset; color: black; padding-top: 1em; border-bottom: black thin inset; font-family: monospace"&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;configuration&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;runtime&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;enforceFIPSPolicy&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;enabled&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;false&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;runtime&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;configuration&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Which will prevent the CLR from throwing InvalidOperationExceptions from the constructor of uncertified algorithms and implementations.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8191587" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Cryptography/default.aspx">Cryptography</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Orcas/default.aspx">Orcas</category></item><item><title>Which Groups Does WindowsIdentity.Groups Return?</title><link>http://blogs.msdn.com/shawnfa/archive/2008/02/07/which-groups-does-windowsidentity-groups-return.aspx</link><pubDate>Thu, 07 Feb 2008 20:00:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7501559</guid><dc:creator>shawnfa</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/7501559.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=7501559</wfw:commentRss><description>&lt;p&gt;WindowsIdentity exposes a &lt;a href="http://msdn2.microsoft.com/en-us/library/system.security.principal.windowsidentity.groups.aspx"&gt;Groups property&lt;/a&gt; which returns a collection of IdentityReferences for the groups that a particular user is a member of.&amp;nbsp; However, if you look closely, you'll find that these returned groups won't necessarily include all of the groups that the user is a member of.&lt;/p&gt; &lt;p&gt;Under the covers, WindowsIdentity populates the groups collection by querying Windows for information on the groups that the user token is a member of.&amp;nbsp; However, before returning this list, the Groups property filters out some of the returned groups.&lt;/p&gt; &lt;p&gt;Specifically, any groups which were on the token for deny-only will not be returned in the Groups collection.&amp;nbsp; Similarly, a group which is the SE_GROUP_LOGON_ID will not be returned.&lt;/p&gt; &lt;p&gt;Generally, this is exactly the behavior you want.&amp;nbsp; For instance, if your application is going allow a specific action because the user is a member of a group, you don't want to allow it if the user is a member of the group for deny-only.&lt;/p&gt; &lt;p&gt;If you want to retrieve all of the groups however, there's not an easy built-in way for you to do this.&amp;nbsp; Instead, you'll have to P/Invoke to the &lt;a href="http://msdn2.microsoft.com/en-us/library/aa446671.aspx"&gt;GetTokenInformation&lt;/a&gt; API to retrieve the groups yourself.&lt;/p&gt; &lt;p&gt;It can be interesting to dump out the groups that specific users are part of -- here's a simple little snippet of code that does just that.&amp;nbsp; (And uses some of those fancy new C# 3.0 features to display them grouped by domain):&lt;/p&gt; &lt;p&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;\red163\green21\blue21;}??\fs20     \cf3 public\cf0  \cf3 static\cf0  \cf3 void\cf0  Main()\par ??    \{\par ??        \cf3 using\cf0  (\cf4 WindowsIdentity\cf0  currentIdentity = \cf4 WindowsIdentity\cf0 .GetCurrent())\par ??        \{                \par ??            \cf3 var\cf0  groups = \cf5 // Get all of the groups from our account, and translate them from IdentityReferences to NTAccounts   \par ??\cf0                          \cf3 from\cf0  groupIdentity \cf3 in\cf0  currentIdentity.Groups\par ??                         \cf3 where\cf0  groupIdentity.IsValidTargetType(\cf3 typeof\cf0 (\cf4 NTAccount\cf0 ))\par ??                         \cf3 select\cf0  groupIdentity.Translate(\cf3 typeof\cf0 (\cf4 NTAccount\cf0 )) \cf3 as\cf0  \cf4 NTAccount\cf0  \cf3 into\cf0  ntAccounts\par ??\par ??                         \cf5 // Sort the NTAccounts by their account name\par ??\cf0                          \cf3 let\cf0  domainName = ntAccounts.GetDomainName()\par ??                         \cf3 let\cf0  groupName = ntAccounts.GetAccountName()\par ??                         \cf3 orderby\cf0  domainName\par ??\par ??                         \cf5 // Group the sorted accounts by the domain they belong to, and sort the grouped groups by domain name\par ??\cf0                          \cf3 group\cf0  ntAccounts \cf3 by\cf0  domainName \cf3 into\cf0  domainGroups\par ??                         \cf3 orderby\cf0  domainGroups.Key\par ??                         \cf3 select\cf0  domainGroups;\par ??\par ??            \cf3 foreach\cf0  (\cf3 var\cf0  domainGroups \cf3 in\cf0  groups)\par ??            \{\par ??                \cf4 Console\cf0 .WriteLine(\cf6 "Groups from domain '\{0\}'"\cf0 , domainGroups.Key);\par ??\par ??                \cf3 foreach\cf0  (\cf3 var\cf0  group \cf3 in\cf0  domainGroups)\par ??                \{\par ??                    \cf4 Console\cf0 .WriteLine(\cf6 "    '\{0\}'"\cf0 , group.GetAccountName());\par ??                \}\par ??            \}\par ??        \}\par ??    \}\par ??\par ??    \cf3 private\cf0  \cf3 static\cf0  \cf3 string\cf0  GetDomainName(\cf3 this\cf0  \cf4 NTAccount\cf0  account)\par ??    \{\par ??        \cf3 string\cf0 [] split = account.Value.Split(\cf6 '\\\\'\cf0 );\par ??        \cf3 return\cf0  split.Length == 1 ? \cf4 String\cf0 .Empty : split[0];\par ??    \}\par ??\par ??    \cf3 private\cf0  \cf3 static\cf0  \cf3 string\cf0  GetAccountName(\cf3 this\cf0  \cf4 NTAccount\cf0  account)\par ??    \{\par ??        \cf3 string\cf0 [] split = account.Value.Split(\cf6 '\\\\'\cf0 );\par ??        \cf3 return\cf0  split[split.Length - 1];\par ??    \}\par ??}
--&gt; &lt;div style="border-right: black thin inset; padding-right: 1em; border-top: black thin inset; padding-left: 1em; font-size: 10pt; background: lightgrey; padding-bottom: 1em; margin: 1em 1em 1em 2em; border-left: black thin inset; color: black; padding-top: 1em; border-bottom: black thin inset; font-family: monospace"&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Main()&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;WindowsIdentity&lt;/span&gt; currentIdentity = &lt;span style="color: #2b91af"&gt;WindowsIdentity&lt;/span&gt;.GetCurrent())&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;/p&gt; &lt;p style="margin: 0px"&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 style="color: blue"&gt;var&lt;/span&gt; groups = &lt;span style="color: green"&gt;// Get all of the groups from our account, and translate them from IdentityReferences to NTAccounts&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: blue"&gt;from&lt;/span&gt; groupIdentity &lt;span style="color: blue"&gt;in&lt;/span&gt; currentIdentity.Groups&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: blue"&gt;where&lt;/span&gt; groupIdentity.IsValidTargetType(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;NTAccount&lt;/span&gt;))&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: blue"&gt;select&lt;/span&gt; groupIdentity.Translate(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;NTAccount&lt;/span&gt;)) &lt;span style="color: blue"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;NTAccount&lt;/span&gt; &lt;span style="color: blue"&gt;into&lt;/span&gt; ntAccounts&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: green"&gt;// Sort the NTAccounts by their account name&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: blue"&gt;let&lt;/span&gt; domainName = ntAccounts.GetDomainName()&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: blue"&gt;let&lt;/span&gt; groupName = ntAccounts.GetAccountName()&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: blue"&gt;orderby&lt;/span&gt; domainName&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: green"&gt;// Group the sorted accounts by the domain they belong to, and sort the grouped groups by domain name&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: blue"&gt;group&lt;/span&gt; ntAccounts &lt;span style="color: blue"&gt;by&lt;/span&gt; domainName &lt;span style="color: blue"&gt;into&lt;/span&gt; domainGroups&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: blue"&gt;orderby&lt;/span&gt; domainGroups.Key&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: blue"&gt;select&lt;/span&gt; domainGroups;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&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 style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; domainGroups &lt;span style="color: blue"&gt;in&lt;/span&gt; groups)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Groups from domain: {0}"&lt;/span&gt;, domainGroups.Key);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; group &lt;span style="color: blue"&gt;in&lt;/span&gt; domainGroups)&lt;/p&gt; &lt;p style="margin: 0px"&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; {&lt;/p&gt; &lt;p style="margin: 0px"&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; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"&amp;nbsp;&amp;nbsp;&amp;nbsp; {0}"&lt;/span&gt;, group.GetAccountName());&lt;/p&gt; &lt;p style="margin: 0px"&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; }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; GetDomainName(&lt;span style="color: blue"&gt;this&lt;/span&gt; &lt;span style="color: #2b91af"&gt;NTAccount&lt;/span&gt; account)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;string&lt;/span&gt;[] split = account.Value.Split(&lt;span style="color: #a31515"&gt;'\\'&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;return&lt;/span&gt; split.Length == 1 ? &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Empty : split[0];&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; GetAccountName(&lt;span style="color: blue"&gt;this&lt;/span&gt; &lt;span style="color: #2b91af"&gt;NTAccount&lt;/span&gt; account)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;string&lt;/span&gt;[] split = account.Value.Split(&lt;span style="color: #a31515"&gt;'\\'&lt;/span&gt;);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;return&lt;/span&gt; split[split.Length - 1];&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7501559" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Using the MMC Snap-In to Configure 64 Bit CAS Policy</title><link>http://blogs.msdn.com/shawnfa/archive/2007/03/15/using-the-mmc-snap-in-to-configure-64-bit-cas-policy.aspx</link><pubDate>Thu, 15 Mar 2007 19:51:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1888442</guid><dc:creator>shawnfa</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/1888442.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=1888442</wfw:commentRss><description>&lt;p&gt;The &lt;a href="http://blogs.msdn.com/shawnfa/archive/2006/02/08/527663.aspx"&gt;.NET Framework SDK ships with a MMC Snap-In&lt;/a&gt; which enables you to, among other things, avoid using caspol to modify your local security policy.&lt;/p&gt; &lt;p&gt;Since each &lt;a href="http://blogs.msdn.com/shawnfa/archive/2006/07/11/661769.aspx"&gt;runtime installed on your machine has independent security policy&lt;/a&gt;,&amp;nbsp;the MMC&amp;nbsp;Snap-In will only modify policy for&amp;nbsp;the version of the CLR it is running against, and you may&amp;nbsp;need to have multiple MMC&amp;nbsp;sessions to change&amp;nbsp;the various versions of policy on your machine.&lt;/p&gt; &lt;p&gt;This is pretty obvious when it comes to changing the v1.1 policy vs changing the v2.0 policy, you&amp;nbsp;just choose the correct link&amp;nbsp;from&amp;nbsp;Control Panel.&amp;nbsp; However, things&amp;nbsp;get a lot trickier when it comes to configuring v2.0 32 bit policy vs&amp;nbsp;v2.0 64 bit policy.&lt;/p&gt; &lt;p&gt;The snap-in only modifies the&amp;nbsp;security policy of&amp;nbsp;the runtime that it is running against.&amp;nbsp;&amp;nbsp;Since the snap-in itself&amp;nbsp;is&amp;nbsp;running within the MMC process, this means that the policy that is being changed depends on the bitness of the MMC process.&amp;nbsp; (Remember a 32 bit process cannot load 64 bit components, and vice-versa).&amp;nbsp; Since the snap-in is processor neutral, it will happily load in both a 32 and 64 bit MMC -- leading to the surprising result that running the&amp;nbsp;version of the snap-in&amp;nbsp;that ships&amp;nbsp;with the 64 bit SDK in a&amp;nbsp;32 bit MMC will result in changes to the 32 bit policy, not&amp;nbsp;the 64 bit &amp;nbsp;one.&lt;/p&gt; &lt;p&gt;Further muddying the waters is the fact that MMC has somewhat surprising behavior when launching it from the command line.&amp;nbsp; One of our testers put together this table to help figure out which bitness of MMC is being launched:&lt;/p&gt; &lt;p&gt; &lt;table cellspacing="0" cellpadding="2" width="400" border="1" unselectable="on"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top"&gt;&lt;strong&gt;Command&lt;/strong&gt;&lt;/td&gt; &lt;td valign="top"&gt;&lt;strong&gt;Bitness&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt;%WinDir%\System32\mmc.exe&lt;/td&gt; &lt;td valign="top"&gt;64&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt;%WinDir%\SysWOW64\mmc.exe&lt;/td&gt; &lt;td valign="top"&gt;64&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt;%WinDir%\System32\mmc.exe &amp;lt;sdk_path&amp;gt;\bin\mscorcfg.msc&lt;/td&gt; &lt;td valign="top"&gt;32&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt;%WinDir%\SysWOW64\mmc.exe &amp;lt;sdk_path&amp;gt;\bin\mscorcfg.msc&lt;/td&gt; &lt;td valign="top"&gt;32&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt;%WinDir%\System32\mmc.exe /32 &amp;lt;sdk_path&amp;gt;\bin\mscorcfg.exe&lt;/td&gt; &lt;td valign="top"&gt;32&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt;%WinDir%\SysWOW64\mmc.exe /32 &amp;lt;sdk_path&amp;gt;\bin\mscorcfg.exe&lt;/td&gt; &lt;td valign="top"&gt;32&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt;%WinDir%\System32\mmc.exe /64 &amp;lt;sdk_path&amp;gt;\bin\mscorcfg.exe&lt;/td&gt; &lt;td valign="top"&gt;64&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt;%WinDir%\SysWOW64\mmc.exe /64 &amp;lt;sdk_path&amp;gt;\bin\mscorcfg.exe&lt;/td&gt; &lt;td valign="top"&gt;64&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;MMC will actually occasionally terminate the version that you stared and relaunch a verison with a different bitness (&lt;a href="http://technet2.microsoft.com/WindowsServer/en/library/808bb91b-0933-4bd5-9740-45356872b7761033.mspx?mfr=true"&gt;details can be found here&lt;/a&gt;).&amp;nbsp; What this means is that it doesn't really matter if you launch the 32 or 64 bit version directly when using the .NET Configuration Snap-In.&amp;nbsp; Instead, you should be sure to pass the /32 or /64 command line switch to MMC in order to ensure that you get the version that you intend.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1888442" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Policy/default.aspx">Policy</category></item><item><title>Kenny Kerr Explores UAC</title><link>http://blogs.msdn.com/shawnfa/archive/2006/10/10/Kenny-Kerr-Explores-UAC.aspx</link><pubDate>Tue, 10 Oct 2006 18:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:813254</guid><dc:creator>shawnfa</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/813254.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=813254</wfw:commentRss><description>&lt;A class="" href="http://weblogs.asp.net/kennykerr" mce_href="http://weblogs.asp.net/kennykerr"&gt;Kenny Kerr&lt;/A&gt;, one of our Security MVPs, has updated his Windows Vista for Developers series with &lt;A class="" href="http://weblogs.asp.net/kennykerr/archive/2006/09/29/Windows-Vista-for-Developers-_1320_-Part-4-_1320_-User-Account-Control.aspx" mce_href="http://weblogs.asp.net/kennykerr/archive/2006/09/29/Windows-Vista-for-Developers-_1320_-Part-4-_1320_-User-Account-Control.aspx"&gt;Part4 - User Account Control.&lt;/A&gt;&amp;nbsp; Kenny takes an in-depth look at what UAC means for developers and covers areas that a lot of other sources don't touch on, such as integrety levels.&amp;nbsp; This is absolutely worth a read once you begin to write software for Vista.&amp;nbsp; (As are the rest of the articles in his series).&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=813254" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Adding a UAC Manifest to Managed Code</title><link>http://blogs.msdn.com/shawnfa/archive/2006/04/06/568563.aspx</link><pubDate>Thu, 06 Apr 2006 17:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:568563</guid><dc:creator>shawnfa</dc:creator><slash:comments>12</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/568563.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=568563</wfw:commentRss><description>&lt;P&gt;The &lt;A HREF="/uac"&gt;UAC&lt;/A&gt; feature of Vista is one of my favorite new features -- it really makes running as a non-admin much less painful than it has been in the past.&amp;nbsp; One of the requirements that UAC puts on developers is that we must mark our applications with manifests which declare if the application would like to run elevated or not.&amp;nbsp; Documentation for this manifest format can be found on &lt;A href="http://msdn.microsoft.com/windowsvista/default.aspx?pull=/library/en-us/dnlong/html/AccProtVista.asp#accprotvista_topic8"&gt;MSDN&lt;/A&gt;, where you can find the schema and information about what the various settings mean.&lt;/P&gt;
&lt;P&gt;If you'd like to add one of these manifests to your managed application, the steps are relatively straight forward:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create a manifest resource&lt;/LI&gt;
&lt;LI&gt;Compile the resource&lt;/LI&gt;
&lt;LI&gt;Embed it in your application&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;FONT size=4&gt;1. Create a manifest resource&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The first step is to create a resource file containing your manifest.&amp;nbsp; The manifest should be of type RT_MANIFEST, and have id 1 for an exe (id 2 for a dll).&amp;nbsp; For instance, the resource script for an exe that does not need to elevate might be saved in UacManifest.rc and look like this:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;&lt;SPAN style="COLOR: blue"&gt;#include&lt;/SPAN&gt; &amp;lt;winuser.h&amp;gt;&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;#define&lt;/SPAN&gt; IDR_MANIFEST 1 &lt;SPAN style="COLOR: green"&gt;// 2 for a DLL&lt;/SPAN&gt;&lt;BR&gt;&lt;BR&gt;IDR_MANIFEST RT_MANIFEST MOVEABLE PURE&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;assembly xmlns=""urn:schemas-microsoft-com:asm.v1"" manifestVersion=""1.0""&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asmv3:trustInfo xmlns:asmv3=""urn:schemas-microsoft-com:asm.v3""&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asmv3:security&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asmv3:requestedPrivileges&amp;gt;&lt;BR&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;lt;asmv3:requestedExecutionLevel&lt;BR&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; level=""asInvoker""&lt;BR&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; uiAccess=""false"" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/asmv3:requestedPrivileges&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/asmv3:security&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/asmv3:trustInfo&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/assembly&amp;gt;"&lt;BR&gt;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT size=4&gt;2. Compile the resource&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=4&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;You'll need to install the &lt;A href="http://msdn.microsoft.com/platformsdk"&gt;Platform SDK&lt;/A&gt; for this step so that you have access to the rc tool and the winuser.h header.&amp;nbsp; Once you've gotten the SDK setup, you can then compile your resource script into a .res file:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;C:\src\App&amp;gt;rc.exe UacManifest.rc&lt;/DIV&gt;
&lt;P&gt;Which will create a UacManifest.res for you.&lt;/P&gt;
&lt;P&gt;&lt;FONT size=4&gt;3. Embed it in your application&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Now that you've compiled your .res file, you can pass it to your managed compiler when building your application&amp;nbsp;to embed in your exe.&amp;nbsp;&amp;nbsp;The exact switch will vary depending on your compiler:&lt;/P&gt;
&lt;P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;STRONG&gt;Compiler&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;Switch&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;C#&lt;/TD&gt;
&lt;TD&gt;/win32res&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;VB&lt;/TD&gt;
&lt;TD&gt;/win32resource&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ILAsm&lt;/TD&gt;
&lt;TD&gt;/resource&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AL&lt;/TD&gt;
&lt;TD&gt;/win32res&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;You can also select&amp;nbsp;the resource file in the project properties in Visual Studio.&lt;/P&gt;
&lt;DIV&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=568563" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Other/default.aspx">Other</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Return of the Mailbag</title><link>http://blogs.msdn.com/shawnfa/archive/2006/03/21/556987.aspx</link><pubDate>Tue, 21 Mar 2006 23:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:556987</guid><dc:creator>shawnfa</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/556987.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=556987</wfw:commentRss><description>&lt;P&gt;Over the last week or so I've seen a few questions pop up multiple times.&amp;nbsp; In no particular order:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Q:&lt;/STRONG&gt; Is calling a virtual method with a non-virtual call verifiable?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;A:&lt;/STRONG&gt; It depends :-)&amp;nbsp; In v1.x of the CLR this was verifiable.&amp;nbsp; We made a change in v2.0 which disallows a non-virtual call to a virtual method.&amp;nbsp; Joe Duffy has &lt;A href="http://www.bluebytesoftware.com/blog/PermaLink.aspx?guid=c33b0dbc-a696-4b3d-a136-4bee2d86be2a"&gt;a good writeup about this change&lt;/A&gt; and why we made it on his blog.&amp;nbsp; Note that going the other way is verifiable -- using a callvirt to call a non-virtual function works just fine.&amp;nbsp; In fact ildasm shows that the C# compiler always emits a callvirt regardless of the target being virtual or not.&lt;/P&gt;
&lt;HR&gt;

&lt;P&gt; &lt;STRONG&gt;Q:&lt;/STRONG&gt; I want to create a signature using RSA and SHA-256, is that possible with the managed classes?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;A:&lt;/STRONG&gt; Not as of v2.0.&amp;nbsp; The&amp;nbsp;fundamental problem is that our only RSA implementation, RSACryptoServiceProvider, uses CAPI to do its work.&amp;nbsp; However our only SHA-256 implementation, SHA256Managed is unknown to CAPI.&amp;nbsp; This is on our radar for the next CLR release though.&lt;/P&gt;
&lt;HR&gt;

&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;Q:&lt;/STRONG&gt; Is there any way to use &lt;A HREF="/shawnfa/archive/2005/10/06/478009.aspx"&gt;ADMHost&lt;/A&gt; with a WinForms app so that the console window doesn't show up?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;A:&lt;/STRONG&gt; Sure.&amp;nbsp; The underlying issue here is that in Windows, a&amp;nbsp;PE image&amp;nbsp;has its subsystem burned into&amp;nbsp;its&amp;nbsp;IMAGE_OPTIONAL_HEADER.&amp;nbsp; Generally this is one of IMAGE_SUBSYSTEM_CUI or IMAGE_SUBSYSTEM_GUI ... although there are other options (they're listed under the comment "subsystem values" in winnt.h of the platform SDK if you're interested).&amp;nbsp; Applications with a CUI subsystem always run with a console, weather or not they use it.&amp;nbsp; (Windows has no way of knowing ahead of time if you do plan on using it or not).&amp;nbsp; The opposite is true of GUI apps, which by default will not have a console window.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ADMHost.exe by default is compiled as a console application, using the CUI subsystem. Switch it to a Windows application and the console will go away.&amp;nbsp; You can do this in the ADMHost.exe properties -- change the subsystem type to Windows.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=556987" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Cryptography/default.aspx">Cryptography</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Other/default.aspx">Other</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Impersonation and Exception Filters in v2.0</title><link>http://blogs.msdn.com/shawnfa/archive/2006/03/03/542430.aspx</link><pubDate>Fri, 03 Mar 2006 18:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:542430</guid><dc:creator>shawnfa</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/542430.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=542430</wfw:commentRss><description>&lt;P&gt;A while back, &lt;A HREF="/shawnfa/archive/2005/03/22/400749.aspx"&gt;I wrote about&lt;/A&gt; &lt;A HREF="/shawnfa/archive/2005/03/24/401905.aspx"&gt;a potential security hole&lt;/A&gt; &lt;A HREF="/shawnfa/archive/2005/03/31/404320.aspx"&gt;when malicious code can set up an&amp;nbsp;exception filter before calling your code which does impersonation&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;In the final release of v2.0, we've added a feature to help mitigate this problem.&amp;nbsp; The CLR records that you've begun impersonation on the stack frame where you make the call to Impersonate().&amp;nbsp; If an exception is thrown, when the CLR walks the call stack looking for handlers, it will see this note and revert the impersonation when it moves past the frame.&lt;/P&gt;
&lt;P&gt;This means that the following&amp;nbsp;sample from my previous post would just work under v2.0:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;&lt;SPAN style="COLOR: blue"&gt;public void&lt;/SPAN&gt; SomeApi()&lt;BR&gt;{&lt;BR&gt;&lt;SPAN style="COLOR: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Call LogonUser to get a token for the user&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IntPtr&amp;nbsp;userHandle&amp;nbsp;=&amp;nbsp;IntPtr.Zero();&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool&lt;/SPAN&gt;&amp;nbsp;loggedOn&amp;nbsp;=&amp;nbsp;LogonUser(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;user,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;domain,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LogonType.Interactive,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LogonProvider.Default,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;out&lt;/SPAN&gt;&amp;nbsp;userHandle);&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt;(!loggedOn)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;throw&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;Win32Exception(Marshal.GetLastWin32Error());&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Begin impersonating the user&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WindowsImpersonationContext&amp;nbsp;impersonationContext&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WindowsIdentity.Impersonate(userHandle.Token);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DoSomeWorkWhileImpersonating();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; finally&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&lt;SPAN style="COLOR: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Clean up&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CloseHandle(userHandle);&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt;(impersonationContext != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; impersonationContext.Undo();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;When the call to Impersonate() is made, the CLR notes that on SomeApi()'s stack frame and if DoSomeWorkWhileImpersonating() happens to throw, the impersonation is reverted before any callers of the SomeApi() have their exception filters run.&lt;/P&gt;
&lt;P&gt;Note that since this state is tied to the stack frame, you won't get this benefit if you impersonate in one method and revert in another:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;&lt;SPAN style="COLOR: blue"&gt;public void&lt;/SPAN&gt; SomeOtherApi()&lt;BR&gt;{&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Begin impersonating the user&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WindowsImpersonationContext&amp;nbsp;impersonationContext&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; impersonationContext&amp;nbsp;= BeginImpersonating();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DoSomeWorkWhileImpersonating();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; finally&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&lt;SPAN style="COLOR: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Clean up&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt;(impersonationContext != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; impersonationContext.Undo();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Here, the impersonation is done in the BeginImpersonating() method, but is reverted in SomeOtherApi().&amp;nbsp; In this case, the stack frame for BeginImpersonating() is gone if DoSomeWorkWhileImpersonating() throws an exception.&amp;nbsp; Since the BeginImpersonating() stack frame is the one which contained the annotation that impersonation needed to be undone, you lose the automatic revert behavior.&lt;/P&gt;
&lt;P&gt;Obviously getting the undo for free is a much better option than having to go through all the work of protecting your code manually, so as you begin upgrading your code to run with&amp;nbsp;v2.0 of the framework, you might want to look for places where you don't both&amp;nbsp;impersonate and undo the impersonation in the same method.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=542430" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>UAC Policy Settings</title><link>http://blogs.msdn.com/shawnfa/archive/2006/01/27/518336.aspx</link><pubDate>Fri, 27 Jan 2006 19:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:518336</guid><dc:creator>shawnfa</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/518336.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=518336</wfw:commentRss><description>&lt;P&gt;The new&amp;nbsp;&lt;a href="http://blogs.msdn.com/uac"&gt;UAC blog&lt;/A&gt; (formerly LUA, formerly UAP) has up a &lt;a href="http://blogs.msdn.com/uac/archive/2006/01/22/516066.aspx"&gt;good post on the six security policy settings&lt;/A&gt; that have been introduced to control how UAC works.&amp;nbsp; As the Vista betas start coming out and people can start to play with UAC, knowing that some of these knobs are available can certainly be helpful.&lt;/P&gt;
&lt;P&gt;I've been spending time lately driving putting UAC manifests in all of the CLR tools, so I've got a bit of experience with this feature.&amp;nbsp; It's certainly much easier to use than running as non-admin today, and is something that I can see being able to teach non-techie people how to use properly.&amp;nbsp; From my experience, I think the security setting that's going to be most interesting is number six, "Virtualize file and registry write failures to per-user locations".&lt;/P&gt;
&lt;P&gt;I'm sure the UAC blog is going to have future posts on virtuilization and how it works, and not being on that team I'm not going to cover those details.&amp;nbsp; However, virtuilization can have some interesting and unexpected side effects, so if you've found that the applications that work on your machine can run without virtuilization it might be one option to consider turning it off.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=518336" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>PrincipalPermission and Finalizers</title><link>http://blogs.msdn.com/shawnfa/archive/2006/01/09/510844.aspx</link><pubDate>Mon, 09 Jan 2006 22:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:510844</guid><dc:creator>shawnfa</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/510844.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=510844</wfw:commentRss><description>&lt;P&gt;&lt;A href="http://spaces.msn.com/members/calinoiu/"&gt;Nicole Calinoiu&lt;/A&gt;, one of our developer security MVPs, has just posted a good description of &lt;A href="http://spaces.msn.com/members/calinoiu/Blog/cns!1pYmj2Kpn4Oz9CW9IKwXQF8A!154.entry"&gt;the problems that occur when using PrincipalPermission with impersonation and finalizers&lt;/A&gt;.&amp;nbsp; The key thing to take away from this is that impersonation occurs on a per-thread basis and finalizers run on a thread that the GC controls, not on the main thread of your application.&amp;nbsp; This means that if you're impersonating on your application's thread, your finalizers will not run under the impersonated context.&lt;/P&gt;
&lt;P&gt;While Nicole gives a general solution to the problem, she also points out that if you're doing something that requires impersonation on the finalizer thread you might want to think about the design of your class.&amp;nbsp; Definitely worth a read.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=510844" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Mike Rousos on Registry Security</title><link>http://blogs.msdn.com/shawnfa/archive/2006/01/09/510843.aspx</link><pubDate>Mon, 09 Jan 2006 20:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:510843</guid><dc:creator>shawnfa</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/510843.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=510843</wfw:commentRss><description>&lt;P&gt;Over the weekend, Mike Rousos (a BCL tester who's been temporarily drafted onto the security team) posted an interesting piece about the &lt;a href="http://blogs.msdn.com/bclteam/archive/2006/01/06/509867.aspx"&gt;new BCL registry security support&lt;/A&gt; on the &lt;a href="http://blogs.msdn.com/bclteam"&gt;BCL blog&lt;/A&gt;.&amp;nbsp; While the title mentions RegistryPermission, the post is actually about the NT security features of the registry classes rather than CAS permissions.&amp;nbsp; Mike covers the difference between RegistryRights and RegistryPermissionCheck -- two features that are nice additions to the BCL registry support.&amp;nbsp; Worth checking out if you spend much time working with NT security on the registry.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=510843" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Adding SignatureProperties to SignedXml</title><link>http://blogs.msdn.com/shawnfa/archive/2005/11/03/488807.aspx</link><pubDate>Thu, 03 Nov 2005 23:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:488807</guid><dc:creator>shawnfa</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/488807.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=488807</wfw:commentRss><description>&lt;P&gt;One of the optional portions of the &lt;A href="http://www.w3.org/TR/xmldsig-core"&gt;W3C XML digital signature specification&lt;/A&gt; allows for a set of &lt;A href="http://www.w3.org/TR/xmldsig-core/#sec-SignatureProperties"&gt;SignatureProperties&lt;/A&gt; to be assigned to a signature.&amp;nbsp; SignatureProperties allow the signer to place some metadata into the signature itself, such as the time the signature was created and the name of the person creating the signature.&amp;nbsp; Since the XML digital signature specification does not lay out specific properties, you are free to create as many domain specific properties as you'd like.&amp;nbsp; Although the SignedXml class does not support this feature, it's easy enough to add on your own by deriving from the default SignedXml implementation.&lt;/P&gt;
&lt;P&gt;Signature properties exist as a&amp;nbsp;SignatureProperties element in the signature itself, embedded as a DataObject.&amp;nbsp; The signature's references contain a pointer to this element with a Type of&amp;nbsp; "http://www.w3.org/2000/02/xmldsig#SignatureProperty", as specified in the W3C spec.&amp;nbsp; The SignatureProperties element will contain as many SignatureProperty elements as needed.&amp;nbsp; Each SignatureProperty will have a Target pointing to the signature that we're creating and will contain arbitrary XML (which should be in a different namespace to be valid).&lt;/P&gt;
&lt;P&gt;In order to implement this, we'll first create a SignaturePropertiesSignedXml class which derives from SignedXml&amp;nbsp;and takes the typical XmlDocument constructor parameter, as well as an ID for the signature (which is needed for the SignatureProperty Target attribute), and the ID of the SignatureProperties element itself (which is needed for the reference to work).&amp;nbsp; We then use this information to create the SignatureProperties element, and place it into a DataObject.&amp;nbsp; Finally we create and add the reference to the SignatureProperties element:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: green"&gt;/// XML signature class which enables SignatureProperties&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;sealed&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt;&amp;nbsp;SignaturePropertiesSignedXml&amp;nbsp;:&amp;nbsp;SignedXml&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt;&amp;nbsp;XmlDocument&amp;nbsp;doc&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt;&amp;nbsp;XmlElement&amp;nbsp;signaturePropertiesRoot&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// Create a SignedXml class which can have SignatureProperties&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;param name="doc"&amp;gt;XML document the signature belongs in&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;param name="signatureId"&amp;gt;ID of the signature to create&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;param name="propertiesId"&amp;gt;ID of the SignatureProperties to create&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&amp;nbsp;SignaturePropertiesSignedXml(XmlDocument&amp;nbsp;doc,&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;nbsp;signatureId,&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;nbsp;propertiesId)&amp;nbsp;:&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;base&lt;/SPAN&gt;(doc)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;(String.IsNullOrEmpty(signatureId))&lt;BR&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;&lt;SPAN style="COLOR: blue"&gt;throw&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;ArgumentException("signatureId cannot be empty",&amp;nbsp;"signatureId");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;(String.IsNullOrEmpty(propertiesId))&lt;BR&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;&lt;SPAN style="COLOR: blue"&gt;throw&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;ArgumentException("propertiesId cannot be empty",&amp;nbsp;"propertiesId");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc&amp;nbsp;=&amp;nbsp;doc;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Signature.Id&amp;nbsp;=&amp;nbsp;signatureId;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;// create a root element to hold the properties&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;signaturePropertiesRoot&amp;nbsp;=&amp;nbsp;doc.CreateElement("SignatureProperties",&amp;nbsp;XmlDsigNamespaceUrl);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;signaturePropertiesRoot.SetAttribute("Id",&amp;nbsp;propertiesId);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;// create a data object for the properties to go into&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DataObject&amp;nbsp;signatureProperties&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;DataObject();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;signatureProperties.Data&amp;nbsp;=&amp;nbsp;signaturePropertiesRoot.SelectNodes(".");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AddObject(signatureProperties);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;// and add a reference to the data object&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Reference&amp;nbsp;propertiesRef&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;Reference("#"&amp;nbsp;+&amp;nbsp;propertiesId);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;propertiesRef.Type&amp;nbsp;=&amp;nbsp;"http://www.w3.org/2000/02/xmldsig#SignatureProperty";&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AddReference(propertiesRef);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Now that the constructor has done the work of setting up the signature properties, we'll need a simple method to add individual properties.&amp;nbsp; This is easily accomplished by taking the XML content of the property, creating a SignatureProperty element with a Target of the containing signature, and adding the input XML to the SignatureProperty:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// Add a signature property to the document&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;param name="content"&amp;gt;XML contents of the property&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt;&amp;nbsp;AddProperty(XmlElement&amp;nbsp;content)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;(content&amp;nbsp;==&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;BR&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;&lt;SPAN style="COLOR: blue"&gt;throw&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;ArgumentNullException("content");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;(String.Compare(content.NamespaceURI,&amp;nbsp;XmlDsigNamespaceUrl)&amp;nbsp;==&amp;nbsp;0)&lt;BR&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;&lt;SPAN style="COLOR: blue"&gt;throw&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;InvalidOperationException("Signature properties must not be in the XML Digital Signature namespace");&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;// wrap the content in a SignatureProperty element&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;XmlElement&amp;nbsp;property&amp;nbsp;=&amp;nbsp;doc.CreateElement("SignatureProperty",&amp;nbsp;XmlDsigNamespaceUrl);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;property.SetAttribute("Target",&amp;nbsp;"#"&amp;nbsp;+&amp;nbsp;Signature.Id);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;property.AppendChild(content);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;signaturePropertiesRoot.AppendChild(property);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Finally, we need to override GetIdElement (see &lt;a href="http://blogs.msdn.com/shawnfa/archive/2004/04/05/108098.aspx"&gt;my previous post on doing this&lt;/A&gt; for more information), since the default GetIdElement implementation does not search DataObjects and we have a reference that points to our SignatureProperties which is contained within a DataObject.&amp;nbsp; In the override, we just check to see if we're searching for the signature properties, and if not fall back to default behavior.&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// Get an element refered to by its ID&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;param name="doc"&amp;gt;XML document to search for the element in&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;param name="id"&amp;gt;element to search for&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;/// &amp;lt;returns&amp;gt;Element with the given ID, null if it could not be found&amp;lt;/returns&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt;&amp;nbsp;XmlElement&amp;nbsp;GetIdElement(XmlDocument&amp;nbsp;doc,&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;nbsp;id)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;(id&amp;nbsp;==&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;BR&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;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;// see if this is the signature properties being referenced, otherwise fall back to default behavior&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;(String.Compare(id,&amp;nbsp;signaturePropertiesRoot.GetAttribute("Id"),&amp;nbsp;StringComparison.OrdinalIgnoreCase)&amp;nbsp;==&amp;nbsp;0)&lt;BR&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;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&amp;nbsp;signaturePropertiesRoot;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt;&lt;BR&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;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;base&lt;/SPAN&gt;.GetIdElement(doc,&amp;nbsp;id);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;And that's it!&amp;nbsp; We can now pretty easily use this class to add metadata to the signature.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;XmlDocument&amp;nbsp;doc&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;XmlDocument();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;doc.Load("order.xml");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SignaturePropertiesSignedXml&amp;nbsp;signer&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;SignaturePropertiesSignedXml(doc,&amp;nbsp;"orderSignature",&amp;nbsp;"signatureProperties");&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RSA&amp;nbsp;key&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;RSACryptoServiceProvider();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;signer.SigningKey&amp;nbsp;=&amp;nbsp;key;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;// create a timestamp property&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;XmlElement&amp;nbsp;timestamp&amp;nbsp;=&amp;nbsp;doc.CreateElement("TimeStamp",&amp;nbsp;"http://www.example.org/#signatureProperties");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;timestamp.InnerText&amp;nbsp;=&amp;nbsp;DateTime.Now.ToUniversalTime().ToString();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;signer.AddProperty(timestamp);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;// create a signed by property&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;XmlElement&amp;nbsp;signedBy&amp;nbsp;=&amp;nbsp;doc.CreateElement("SignedBy",&amp;nbsp;"http://www.example.org/#signatureProperties");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;signedBy.InnerText&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;WindowsPrincipal(WindowsIdentity.GetCurrent()).Identity.Name;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;signer.AddProperty(signedBy);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Reference&amp;nbsp;orderRef&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;Reference("");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;orderRef.AddTransform(&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;XmlDsigEnvelopedSignatureTransform());&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;signer.AddReference(orderRef);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;signer.ComputeSignature();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;doc.DocumentElement.AppendChild(signer.GetXml());&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;doc.Save("order-signed.xml");&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Will produce a signature that contains the time and person who signed the document:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;Signature&amp;nbsp;Id="orderSignature"&amp;nbsp;xmlns="http://www.w3.org/2000/09/xmldsig#"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;SignedInfo&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;CanonicalizationMethod&amp;nbsp;Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"&amp;nbsp;/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;SignatureMethod&amp;nbsp;Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"&amp;nbsp;/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;Reference&amp;nbsp;URI="#signatureProperties"&amp;nbsp;Type="http://www.w3.org/2000/02/xmldsig#SignatureProperty"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;DigestMethod&amp;nbsp;Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"&amp;nbsp;/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;DigestValue&amp;gt;KfpRjNAGP47ZKX/RZ9hFEpKo9u8=&amp;lt;/DigestValue&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/Reference&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;Reference&amp;nbsp;URI=""&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;Transforms&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;Transform&amp;nbsp;Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"&amp;nbsp;/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/Transforms&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;DigestMethod&amp;nbsp;Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"&amp;nbsp;/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;DigestValue&amp;gt;BPoz+CmKZyTATOhskqke3iOXmvA=&amp;lt;/DigestValue&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/Reference&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/SignedInfo&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;SignatureValue&amp;gt;CmMm&amp;nbsp;...&amp;nbsp;JKU=&amp;lt;/SignatureValue&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;Object&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;SignatureProperties&amp;nbsp;Id="signatureProperties"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;SignatureProperty&amp;nbsp;Target="#orderSignature"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;TimeStamp&amp;nbsp;xmlns="http://www.example.org/#signatureProperties"&amp;gt;11/3/2005&amp;nbsp;9:35:37&amp;nbsp;PM&amp;lt;/TimeStamp&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/SignatureProperty&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;SignatureProperty&amp;nbsp;Target="#orderSignature"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;SignedBy&amp;nbsp;xmlns="http://www.example.org/#signatureProperties"&amp;gt;REDMOND\ShawnFa&amp;lt;/SignedBy&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/SignatureProperty&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/SignatureProperties&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/Object&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/Signature&amp;gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;To verify this signature you don't even have to use the custom SignaturePropertiesSignedXml&amp;nbsp;class -- since the SignatureProperties element is now a child of the XML document (since we made this an enveloped signature), the standard SignedXml class will be able to find it to verify the signature.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=488807" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Cryptography/default.aspx">Cryptography</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/XML/default.aspx">XML</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Enforcing FIPS Certified Cryptography</title><link>http://blogs.msdn.com/shawnfa/archive/2005/05/16/417975.aspx</link><pubDate>Mon, 16 May 2005 19:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:417975</guid><dc:creator>shawnfa</dc:creator><slash:comments>28</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/417975.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=417975</wfw:commentRss><description>&lt;P&gt;Certain types of software, such as code written for a government contract,&amp;nbsp;require adhering to a strict set of guidelines, especially when it comes to security.&amp;nbsp; To better enable this type of software, v2.0 of the CLR provides the ability for you to enforce that only cryptograhic algorithms that have been &lt;A href="http://csrc.nist.gov/publications/fips/fips140-1/fips1401.pdf"&gt;FIPS 140-1&lt;/A&gt; certified can be used.&amp;nbsp; Even if you're not developing government applications, it's good to prepare your application for a new exception that could result from creating a crypto object.&lt;/P&gt;
&lt;P&gt;On Windows XP and higher this switch, which showed up for the first time in beta 2, is settable via Windows security settings or the registry.&amp;nbsp; To enable the setting in the Windows security settings, you should set the "System cryptography: Use FIPS compliant algorithms for encryption, hashing, and signing" security option to enabled.&lt;/P&gt;
&lt;P&gt;&lt;IMG alt="Enabling FIPS via Windows Security Policy" src="http://shawnmsdn.members.winisp.net/images/FIPSSecuritySetting.png"&gt;&lt;/P&gt;
&lt;P&gt;In the registry, you can toggle this switch on by setting the DWORD FIPSAlgorithmPolicy under HKLM\System\CurrentControlSet\Control\Lsa to be equal to 1.&lt;/P&gt;
&lt;P&gt;After enabling this seting, only cryptographic algorithms which are FIPS compliant will be allowed to be created in your managed applications.&amp;nbsp; As a general rule of thumb, this means that none of the *Managed algorithms can be created, but you can create the *CryptoServiceProvider algorithms.&amp;nbsp; Lets take a look at some quick sample code:&lt;/P&gt;
&lt;P&gt;
&lt;DIV&gt;&lt;SPAN&gt;try&lt;/SPAN&gt;&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MD5&amp;nbsp;md5&amp;nbsp;=&amp;nbsp;&lt;SPAN&gt;new&lt;/SPAN&gt;&amp;nbsp;MD5CryptoServiceProvider();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.WriteLine("Created algorithm");&lt;BR&gt;}&lt;BR&gt;&lt;SPAN&gt;catch&lt;/SPAN&gt;(Exception&amp;nbsp;e)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.WriteLine(e);&lt;BR&gt;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;If this code is run with the FIPS setting disabled, you'll see "Created algorithm" printed to the console as you would expect.&amp;nbsp; However, if the code is run with FIPS enforcement enabled, you'll get an InvalidOperationException:&lt;/P&gt;
&lt;P&gt;
&lt;DIV&gt;System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Note that you'll get this exception no matter how you attempt to create the algorithm. That means that even if you don't directly construct the alogrithm, but instead attempt to use one of the various Create() methods, you'll still be blocked.&lt;/P&gt;
&lt;P&gt;Before enabling this setting, you should be aware that it will affect your entire system.&amp;nbsp; So any&amp;nbsp;managed application running on the v2.0 framework which attempts to use a cryptographic algorithm that is not FIPS compliant will throw the InvalidOperationException.&amp;nbsp; Additionally, this setting affects other parts of Windows, &lt;A href="http://support.microsoft.com/default.aspx?scid=kb;en-us;811833"&gt;including SSL/TLS in both IE and IIS, Terminal Server, and&amp;nbsp;EFS&lt;/A&gt;.&amp;nbsp; &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=417975" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Cryptography/default.aspx">Cryptography</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Forcing Security to Stay On</title><link>http://blogs.msdn.com/shawnfa/archive/2005/05/04/414686.aspx</link><pubDate>Wed, 04 May 2005 20:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:414686</guid><dc:creator>shawnfa</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/414686.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=414686</wfw:commentRss><description>&lt;P&gt;Last time we looked at how the &lt;a href="http://blogs.msdn.com/shawnfa/archive/2005/04/28/412998.aspx"&gt;Whidbey version of CasPol uses a mutex&lt;/A&gt; to indicate the state of the security system.&amp;nbsp; One of the more interesting fallouts from this model is that is that we can actually use this information to prevent security from being turned off in the first place.&lt;/P&gt;
&lt;P&gt;As I mentioned in the last post, the CLR looks for a mutex named \BaseNamedObjects\CLR_CASOFF_MUTEX, and if this mutex exists, is not abandoned, and is owned by the BUILTIN\Administrators group, it considers security to be in an off state.&amp;nbsp; The obvious CasPol -s off implementation given that information is to acquire the named mutex and set the ACL such that the CLR will recognize it.&amp;nbsp; From there, it's pretty easy to see that in order to prevent CasPol from successfully turning off security, we need to prevent it from acquiring the mutex.&lt;/P&gt;
&lt;P&gt;How would we go about doing that?&amp;nbsp; According to &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createmutex.asp"&gt;the MSDN documentation&lt;/A&gt;, if CreateMutex is called with a non-NULL lpName parameter, it will return either a new mutex with the given name, or if the mutex already exists, it will return a handle to the existing object while setting the last error to ERROR_ALREADY_EXISTS.&amp;nbsp; Basically that's saying that Windows only allows one mutex with a given name on each system.&lt;/P&gt;
&lt;P&gt;This means that if we create the mutex before CasPol does, we'll have a handle to the same mutex that CasPol and the CLR use to determine the security state.&amp;nbsp; If we're on Windows NT, we can make use of the Windows security system to prevent anyone else from having access to that object.&amp;nbsp; For CasPol,&amp;nbsp;not having&amp;nbsp;access to the mutex means that&amp;nbsp;it can't possibly set it to the state the CLR is looking for.&amp;nbsp; More importantly if the CLR doesn't have access to the mutex, it can't use it to determine that security is off.&lt;/P&gt;
&lt;P&gt;So our strategy is to simply create the mutex before anyone else on the machine, and ACL it down such that nobody is allowed access to it.&amp;nbsp; We can pull this off in less than 20 lines of code:&lt;/P&gt;
&lt;P&gt;
&lt;DIV&gt;&lt;SPAN&gt;&lt;FONT color=#0000ff&gt;int&lt;/FONT&gt;&lt;/SPAN&gt; _tmain()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT color=#008000&gt;&lt;I&gt;// setup security attributes for the Mutex&lt;/I&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SECURITY_ATTRIBUTES sa;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ZeroMemory(&amp;amp;sa, &lt;SPAN&gt;&lt;FONT color=#0000ff&gt;sizeof&lt;/FONT&gt;&lt;/SPAN&gt;(sa));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sa.nLength = &lt;SPAN&gt;&lt;FONT color=#0000ff&gt;sizeof&lt;/FONT&gt;&lt;/SPAN&gt;(sa);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sa.bInheritHandle = FALSE;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT color=#008000&gt;&lt;I&gt;// create a DACL to deny all access to the Everyone group&lt;/I&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TCHAR *securityDescriptor = _T(&lt;SPAN&gt;&lt;FONT color=#000080&gt;"D:(D;OICI;GA;;;WD)"&lt;/FONT&gt;&lt;/SPAN&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;BOOL createdSecurity = ConvertStringSecurityDescriptorToSecurityDescriptor(&lt;BR&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;securityDescriptor,&lt;BR&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;SDDL_REVISION_1,&lt;BR&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;amp;sa.lpSecurityDescriptor,&lt;BR&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;&lt;SPAN&gt;&lt;FONT color=#000080&gt;NULL&lt;/FONT&gt;&lt;/SPAN&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt;&lt;/SPAN&gt;(!createdSecurity)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;std::cout &amp;lt;&amp;lt; &lt;SPAN&gt;&lt;FONT color=#000080&gt;"Could not create security descriptor."&lt;/FONT&gt;&lt;/SPAN&gt; &amp;lt;&amp;lt; std::endl;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT color=#0000ff&gt;return&lt;/FONT&gt;&lt;/SPAN&gt; &lt;SPAN&gt;&lt;FONT color=#000080&gt;0&lt;/FONT&gt;&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT color=#008000&gt;&lt;I&gt;// create the security off mutex with the handle&lt;/I&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HANDLE hMutex = CreateMutex(&amp;amp;sa, FALSE, _T(&lt;SPAN&gt;&lt;FONT color=#000080&gt;"CLR_CASOFF_MUTEX"&lt;/FONT&gt;&lt;/SPAN&gt;));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt;&lt;/SPAN&gt;(hMutex == &lt;SPAN&gt;&lt;FONT color=#000080&gt;NULL&lt;/FONT&gt;&lt;/SPAN&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;std::cout &amp;lt;&amp;lt; &lt;SPAN&gt;&lt;FONT color=#000080&gt;"Could not acquire mutex, security may already be off."&lt;/FONT&gt;&lt;/SPAN&gt; &amp;lt;&amp;lt; std::endl;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT color=#0000ff&gt;return&lt;/FONT&gt;&lt;/SPAN&gt; &lt;SPAN&gt;&lt;FONT color=#000080&gt;0&lt;/FONT&gt;&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT color=#008000&gt;&lt;I&gt;// wait to unlock&lt;/I&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;std::cout &amp;lt;&amp;lt; &lt;SPAN&gt;&lt;FONT color=#000080&gt;"Security is locked on.&amp;nbsp;&amp;nbsp;Press any key to unlock."&lt;/FONT&gt;&lt;/SPAN&gt; &amp;lt;&amp;lt; std::endl;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_getch();&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CloseHandle(hMutex);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT color=#0000ff&gt;return&lt;/FONT&gt;&lt;/SPAN&gt; &lt;SPAN&gt;&lt;FONT color=#000080&gt;0&lt;/FONT&gt;&lt;/SPAN&gt;;&lt;BR&gt;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;First we setup a SECURITY_ATTRIBUTES structure that does not allow handles to inherit, and attach a DACL containing a single ACE&amp;nbsp;which denies all access to the Everyone group.&amp;nbsp; To create the DACL, we use the &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/convertstringsecuritydescriptortosecuritydescriptor.asp"&gt;ConvertStringSecurityDescriptorToSecurityDescriptor&lt;/A&gt; function, which is available on Windows XP and later, so you'll need to use an XP machine to run this code, and define &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/using_the_windows_headers.asp"&gt;_WIN32_WINNT and WINVER to 0x0501&lt;/A&gt; or higher before including windows.h and sddl.h&lt;/P&gt;
&lt;P&gt;The string parameter to ConvertStringSecurityDescriptorToSecurityDescriptor looks a little daunting at first, but it's easy to break down:&lt;/P&gt;
&lt;P&gt;
&lt;TABLE cellSpacing=1 cellPadding=1&gt;

&lt;TR&gt;
&lt;TD&gt;D&lt;/TD&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;Create a DACL&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;(&lt;/TD&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;Begin the first ACE&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;D;&lt;/TD&gt;
&lt;TD&gt;Deny&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;OICI;&lt;/TD&gt;
&lt;TD&gt;Object and container inherit&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;GA;&lt;/TD&gt;
&lt;TD&gt;GENERIC_ALL access&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;;;&lt;/TD&gt;
&lt;TD&gt;No object or inherit GUID&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;WD;&lt;/TD&gt;
&lt;TD&gt;Everyone group&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;)&lt;/TD&gt;
&lt;TD&gt;&lt;/TD&gt;
&lt;TD&gt;End ACE&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;After creating the security attributes, we attempt to create the mutex with them.&amp;nbsp; If that fails, then it is possible the mutex already exists, perhaps because security is already off.&amp;nbsp; Once we acquire the mutex, we just wait for the user to press any key to close it and exit.&lt;/P&gt;
&lt;P&gt;When running this code, you'll notice that attempting to turn security off with CasPol will fail, and security will always be enforced by the CLR.&lt;/P&gt;
&lt;P&gt;Now for the disclaimer.&amp;nbsp; This code is really for demonstration purposes only, and is not a silver bullet against security being turned off.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;For reasons we talked about last time, it does not affect the state of security on v1.x 
&lt;LI&gt;There's an obvious race with CasPol ... whoever gets the mutex first wins 
&lt;LI&gt;You cannot protect yourself against machine administrators.&amp;nbsp; If a machine administrator wants to turn security off, they can attack this code in several ways.&amp;nbsp; The most obvious being killing the process holding this mutex, or using one of several tools to just close the handle out from underneath it.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=414686" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Whidbey's Security Off Model</title><link>http://blogs.msdn.com/shawnfa/archive/2005/04/28/412998.aspx</link><pubDate>Thu, 28 Apr 2005 17:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:412998</guid><dc:creator>shawnfa</dc:creator><slash:comments>17</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/412998.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=412998</wfw:commentRss><description>&lt;P&gt;Although the v1.0 and v1.1 versions of CasPol provided a switch to disable the CLR's security system, running without CAS enforcement on was never a scenario that we encouraged for obvious reasons.&amp;nbsp; The choice to disable security was a system wide switch that affected any managed application on any version of the runtime, and made running managed code incredibly unsafe.&lt;/P&gt;
&lt;P&gt;As of Whidbey, you'll find that the switch to turn security off no longer works as it used to.&amp;nbsp; If you run caspol -s off with beta 2 or later of Whidbey installed, you'll see:&lt;/P&gt;
&lt;P&gt;
&lt;DIV&gt;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215&amp;gt;CasPol.exe -s off&lt;BR&gt;Microsoft (R) .NET Framework CasPol 2.0.50215.44&lt;BR&gt;Copyright (C) Microsoft Corporation. All rights reserved.&lt;BR&gt;&lt;BR&gt;CAS enforcement is being turned off temporarily. Press &amp;lt;ENTER&amp;gt; when you want to&lt;BR&gt;restore the setting back on.&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;Security will then be disabled as long as the CasPol process remains active.&amp;nbsp; When CasPol is terminated, it returns security to the on state.&amp;nbsp; Even abruptly terminating the CasPol process will still return security to its on state.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;This works because the implementation of the internal security off flag has changed.&amp;nbsp; Instead of using a registry key to indicate the status of CLR security, we now use a named mutex which CasPol holds to&amp;nbsp;indicate to the CLR that it should disable security.&amp;nbsp; Examining the the handles held by the&amp;nbsp;CasPol process&amp;nbsp;in a debugger will enable you to quickly identify this mutex: 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;
&lt;DIV&gt;0:000&amp;gt;!handle 0 4 Mutant&lt;BR&gt;Handle&amp;nbsp;4c&lt;BR&gt;&amp;nbsp;&amp;nbsp;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;\BaseNamedObjects\CLR_CASOFF_MUTEX&lt;BR&gt;Handle&amp;nbsp;428&lt;BR&gt;&amp;nbsp;&amp;nbsp;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;none&amp;gt;&lt;BR&gt;Handle&amp;nbsp;4a8&lt;BR&gt;&amp;nbsp;&amp;nbsp;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;\BaseNamedObjects\ShimCacheMutex&lt;BR&gt;Handle&amp;nbsp;624&lt;BR&gt;&amp;nbsp;&amp;nbsp;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;none&amp;gt;&lt;BR&gt;4 handles of type Mutant&lt;/DIV&gt;
&lt;P&gt;Since security is being disabled by this mutex, the CasPol process is resilient to being terminated unexpectedly, because Windows will just clean up the handle for CasPol when cleaning up the process.&amp;nbsp; Another side effect is that if the machine is rebooted, the security state will revert to on.&lt;/P&gt;
&lt;P&gt;If we fire up the kernel debugger, we can take a look at the ACL of the mutex:&lt;/P&gt;
&lt;P&gt;
&lt;DIV&gt;lkd&amp;gt;&amp;nbsp;!object&amp;nbsp;\BaseNamedObjects\CLR_CASOFF_MUTEX&lt;BR&gt;Object:&amp;nbsp;85088d88&amp;nbsp;&amp;nbsp;Type:&amp;nbsp;(8679f040)&amp;nbsp;Mutant&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ObjectHeader:&amp;nbsp;&lt;B&gt;85088d70&lt;/B&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HandleCount:&amp;nbsp;1&amp;nbsp;&amp;nbsp;PointerCount:&amp;nbsp;2&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Directory&amp;nbsp;Object:&amp;nbsp;e179f980&amp;nbsp;&amp;nbsp;Name:&amp;nbsp;CLR_CASOFF_MUTEX&lt;BR&gt;&lt;BR&gt;lkd&amp;gt;&amp;nbsp;dt&amp;nbsp;nt!_OBJECT_HEADER&amp;nbsp;85088d70&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x000&amp;nbsp;PointerCount&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;2&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x004&amp;nbsp;HandleCount&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;1&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x004&amp;nbsp;NextToFree&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;0x00000001&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x008&amp;nbsp;Type&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;0x8679f040&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x00c&amp;nbsp;NameInfoOffset&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;0x10&amp;nbsp;''&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x00d&amp;nbsp;HandleInfoOffset&amp;nbsp;:&amp;nbsp;0&amp;nbsp;''&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x00e&amp;nbsp;QuotaInfoOffset&amp;nbsp;&amp;nbsp;:&amp;nbsp;0&amp;nbsp;''&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x00f&amp;nbsp;Flags&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;0x20&amp;nbsp;'&amp;nbsp;'&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x010&amp;nbsp;ObjectCreateInfo&amp;nbsp;:&amp;nbsp;0x853e3678&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x010&amp;nbsp;QuotaBlockCharged&amp;nbsp;:&amp;nbsp;0x853e3678&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x014&amp;nbsp;SecurityDescriptor&amp;nbsp;:&amp;nbsp;&lt;B&gt;0xe2c57b2c&lt;/B&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;+0x018&amp;nbsp;Body&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;_QUAD&lt;BR&gt;&lt;BR&gt;lkd&amp;gt;&amp;nbsp;??&amp;nbsp;0xe2c57b2c&amp;nbsp;&amp;amp;&amp;nbsp;~0x7&lt;BR&gt;unsigned&amp;nbsp;int&amp;nbsp;0xe2c57b28&lt;BR&gt;&lt;BR&gt;lkd&amp;gt;&amp;nbsp;!sd&amp;nbsp;e2c57b28 1&lt;BR&gt;-&amp;gt;Revision:&amp;nbsp;0x1&lt;BR&gt;-&amp;gt;Sbz1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;0x0&lt;BR&gt;-&amp;gt;Control&amp;nbsp;:&amp;nbsp;0x8004&lt;BR&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;SE_DACL_PRESENT&lt;BR&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;SE_SELF_RELATIVE&lt;BR&gt;-&amp;gt;Owner&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;S-1-5-32-544&amp;nbsp;(Alias:&amp;nbsp;BUILTIN\Administrators)&lt;BR&gt;-&amp;gt;Group&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;S-1-5-21-2127521184-1604012920-1887927527-513&amp;nbsp;(Group:&amp;nbsp;REDMOND\Domain&amp;nbsp;Users)&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;AclRevision:&amp;nbsp;0x2&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Sbz1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;0x0&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;AclSize&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;0x34&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;AceCount&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;0x2&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Sbz2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;0x0&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Ace[0]:&amp;nbsp;-&amp;gt;AceType:&amp;nbsp;ACCESS_ALLOWED_ACE_TYPE&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Ace[0]:&amp;nbsp;-&amp;gt;AceFlags:&amp;nbsp;0x0&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Ace[0]:&amp;nbsp;-&amp;gt;AceSize:&amp;nbsp;0x18&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Ace[0]:&amp;nbsp;-&amp;gt;Mask&amp;nbsp;:&amp;nbsp;0x001f0001&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Ace[0]:&amp;nbsp;-&amp;gt;SID:&amp;nbsp;S-1-5-32-544&amp;nbsp;(Alias:&amp;nbsp;BUILTIN\Administrators)&lt;BR&gt;&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Ace[1]:&amp;nbsp;-&amp;gt;AceType:&amp;nbsp;ACCESS_ALLOWED_ACE_TYPE&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Ace[1]:&amp;nbsp;-&amp;gt;AceFlags:&amp;nbsp;0x0&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Ace[1]:&amp;nbsp;-&amp;gt;AceSize:&amp;nbsp;0x14&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Ace[1]:&amp;nbsp;-&amp;gt;Mask&amp;nbsp;:&amp;nbsp;0x001f0001&lt;BR&gt;-&amp;gt;Dacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;-&amp;gt;Ace[1]:&amp;nbsp;-&amp;gt;SID:&amp;nbsp;S-1-5-18&amp;nbsp;(Well&amp;nbsp;Known&amp;nbsp;Group:&amp;nbsp;NT&amp;nbsp;AUTHORITY\SYSTEM)&lt;BR&gt;&lt;BR&gt;-&amp;gt;Sacl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&amp;nbsp;&amp;nbsp;is&amp;nbsp;NULL&lt;BR&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That shows that the mutex is created with an ACL that prevents anyone who isn't an administrator from owning it.&amp;nbsp; And although Windows does not provide a way to prevent non-administrators from creating this mutex, internally the CLR will not respect the existence of the named mutex if it is abandoned or not owned by the BUILTIN\Administrators group.&amp;nbsp; This prevents a squatting attack where a malicious user could turn off security simply by creating this mutex himself.&lt;/P&gt;
&lt;P&gt;One of the more interesting&amp;nbsp;effects&amp;nbsp;to note&amp;nbsp;of disabling security with this mutex is that the v2.0 CLR will no longer respect the registry key used by older versions of the runtime, and those versions will not have their security disabled by the new CasPol switch.&lt;/P&gt;
&lt;P&gt;Although there still is the ability to turn off security, the ability to turn it off permanently has been removed.&amp;nbsp; The new switch is useful mostly for debugging purposes, to establish if a problem you're diagnosing is related to the security system or not.&amp;nbsp; The recommendation is still to avoid using this mechanism if at all possible.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=412998" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Under+the+Hood/default.aspx">Under the Hood</category></item><item><title>Happy Birthday Channel 9</title><link>http://blogs.msdn.com/shawnfa/archive/2005/04/06/406010.aspx</link><pubDate>Thu, 07 Apr 2005 01:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:406010</guid><dc:creator>shawnfa</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/406010.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=406010</wfw:commentRss><description>&lt;P&gt;&lt;A href="http://channel9.msdn.com/"&gt;Channel 9&lt;/A&gt; turns one year old today, and to celebrate they've been releasing quite a few interesting interviews.&amp;nbsp; One in particular that really stands out is the four parter with Windows &lt;A href="http://channel9.msdn.com/ShowPost.aspx?PostID=53470#53470"&gt;Kernel&lt;/A&gt; &lt;A href="http://channel9.msdn.com/ShowPost.aspx?PostID=53472"&gt;Architect&lt;/A&gt; &lt;A href="http://channel9.msdn.com/ShowPost.aspx?PostID=54611"&gt;Dave&lt;/A&gt; &lt;A href="http://channel9.msdn.com/ShowPost.aspx?PostID=54612"&gt;Probert&lt;/A&gt;.&amp;nbsp; Dave gives an overview of Windows organization, design decisions, and lots of ways that Windows solves different problems.&amp;nbsp; Along the way he gives various comparisons to how Unix operating systems approach the same issue, specifically referring back to his BSD roots.&amp;nbsp; If you're interested at all in how Windows works under the cover, this is a nice introduction.&amp;nbsp; People &lt;A href="http://www.amazon.com/exec/obidos/tg/detail/-/0735619174/qid=1112828594/sr=8-1/ref=pd_ka_1/104-0456166-7230303?v=glance&amp;amp;s=books&amp;amp;n=507846"&gt;more familiar with how Windows works&lt;/A&gt; will find this mostly an overview, but I still found some of the comparisons and anecdotes Dave shared to be interesting.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://channel9.msdn.com/ShowPost.aspx?PostID=53466"&gt;Another good spot they've got up is an interview&lt;/A&gt; with &lt;a href="http://blogs.msdn.com/ericlippert/"&gt;Eric Lippert&lt;/A&gt;, who was actually the second interview to ever appear on Channel 9 (Bill Hill was the first).&amp;nbsp; About 25% into this interview, Eric begins giving a 30,000 foot overview of CAS and then digs around through various other managed security issues, such as:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Strong Names vs Authenticode&lt;/LI&gt;
&lt;LI&gt;Code access security vs role based security&lt;/LI&gt;
&lt;LI&gt;Policy evaluation&lt;/LI&gt;
&lt;LI&gt;How VSTO makes trust decisions&lt;/LI&gt;
&lt;LI&gt;Assembly level declarative security&lt;/LI&gt;
&lt;LI&gt;PermCalc&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;One&amp;nbsp;&amp;nbsp;of the more interesting points he mentions is how VSTO refines the default CLR security policy, for instance by saying "being granted FullTrust via the Zone and AllCode membership conditions, is not good enough."&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=406010" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Other/default.aspx">Other</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Windows/default.aspx">Windows</category></item></channel></rss>