mscorlib(4.0.0.0) API with additions
ApplicationSecurityInfo.cs
6 using System.Security.Util;
7 using System.Threading;
8 
10 {
12  [SecurityCritical]
13  [ComVisible(true)]
14  [SecurityPermission(SecurityAction.Assert, Flags = SecurityPermissionFlag.UnmanagedCode)]
15  public sealed class ApplicationSecurityInfo
16  {
17  private ActivationContext m_context;
18 
19  private object m_appId;
20 
21  private object m_deployId;
22 
23  private object m_defaultRequest;
24 
25  private object m_appEvidence;
26 
32  {
33  get
34  {
35  if (m_appId == null && m_context != null)
36  {
37  ICMS applicationComponentManifest = m_context.ApplicationComponentManifest;
38  ApplicationId value = ParseApplicationId(applicationComponentManifest);
39  Interlocked.CompareExchange(ref m_appId, value, null);
40  }
41  return m_appId as ApplicationId;
42  }
43  set
44  {
45  if (value == null)
46  {
47  throw new ArgumentNullException("value");
48  }
49  m_appId = value;
50  }
51  }
52 
58  {
59  get
60  {
61  if (m_deployId == null && m_context != null)
62  {
63  ICMS deploymentComponentManifest = m_context.DeploymentComponentManifest;
64  ApplicationId value = ParseApplicationId(deploymentComponentManifest);
65  Interlocked.CompareExchange(ref m_deployId, value, null);
66  }
67  return m_deployId as ApplicationId;
68  }
69  set
70  {
71  if (value == null)
72  {
73  throw new ArgumentNullException("value");
74  }
75  m_deployId = value;
76  }
77  }
78 
84  {
85  get
86  {
87  if (m_defaultRequest == null)
88  {
90  if (m_context != null)
91  {
92  ICMS applicationComponentManifest = m_context.ApplicationComponentManifest;
93  string defaultPermissionSetID = ((IMetadataSectionEntry)applicationComponentManifest.MetadataSectionEntry).defaultPermissionSetID;
94  object ppUnknown = null;
95  if (defaultPermissionSetID != null && defaultPermissionSetID.Length > 0)
96  {
97  ((ISectionWithStringKey)applicationComponentManifest.PermissionSetSection).Lookup(defaultPermissionSetID, out ppUnknown);
98  IPermissionSetEntry permissionSetEntry = ppUnknown as IPermissionSetEntry;
99  if (permissionSetEntry != null)
100  {
101  SecurityElement securityElement = SecurityElement.FromString(permissionSetEntry.AllData.XmlSegment);
102  string text = securityElement.Attribute("temp:Unrestricted");
103  if (text != null)
104  {
105  securityElement.AddAttribute("Unrestricted", text);
106  }
107  string strA = securityElement.Attribute("SameSite");
108  if (string.Compare(strA, "Site", StringComparison.OrdinalIgnoreCase) == 0)
109  {
110  Url url = new Url(m_context.Identity.CodeBase);
111  URLString uRLString = url.GetURLString();
112  NetCodeGroup netCodeGroup = new NetCodeGroup(new AllMembershipCondition());
113  SecurityElement securityElement2 = netCodeGroup.CreateWebPermission(uRLString.Host, uRLString.Scheme, uRLString.Port, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
114  if (securityElement2 != null)
115  {
116  securityElement.AddChild(securityElement2);
117  }
118  if (string.Compare("file:", 0, m_context.Identity.CodeBase, 0, 5, StringComparison.OrdinalIgnoreCase) == 0)
119  {
121  PolicyStatement policyStatement = fileCodeGroup.CalculatePolicy(url);
122  if (policyStatement != null)
123  {
124  PermissionSet permissionSet = policyStatement.PermissionSet;
125  if (permissionSet != null)
126  {
127  securityElement.AddChild(permissionSet.GetPermission(typeof(FileIOPermission)).ToXml());
128  }
129  }
130  }
131  }
132  value = new ReadOnlyPermissionSet(securityElement);
133  }
134  }
135  }
136  Interlocked.CompareExchange(ref m_defaultRequest, value, null);
137  }
138  return m_defaultRequest as PermissionSet;
139  }
140  set
141  {
142  if (value == null)
143  {
144  throw new ArgumentNullException("value");
145  }
146  m_defaultRequest = value;
147  }
148  }
149 
155  {
156  get
157  {
158  if (m_appEvidence == null)
159  {
160  Evidence evidence = new Evidence();
161  if (m_context != null)
162  {
163  evidence = new Evidence();
164  Url evidence2 = new Url(m_context.Identity.CodeBase);
165  evidence.AddHostEvidence(evidence2);
166  evidence.AddHostEvidence(Zone.CreateFromUrl(m_context.Identity.CodeBase));
167  if (string.Compare("file:", 0, m_context.Identity.CodeBase, 0, 5, StringComparison.OrdinalIgnoreCase) != 0)
168  {
169  evidence.AddHostEvidence(Site.CreateFromUrl(m_context.Identity.CodeBase));
170  }
171  evidence.AddHostEvidence(new StrongName(new StrongNamePublicKeyBlob(DeploymentId.m_publicKeyToken), DeploymentId.Name, DeploymentId.Version));
172  evidence.AddHostEvidence(new ActivationArguments(m_context));
173  }
174  Interlocked.CompareExchange(ref m_appEvidence, evidence, null);
175  }
176  return m_appEvidence as Evidence;
177  }
178  set
179  {
180  if (value == null)
181  {
182  throw new ArgumentNullException("value");
183  }
184  m_appEvidence = value;
185  }
186  }
187 
188  internal ApplicationSecurityInfo()
189  {
190  }
191 
196  public ApplicationSecurityInfo(ActivationContext activationContext)
197  {
198  if (activationContext == null)
199  {
200  throw new ArgumentNullException("activationContext");
201  }
202  m_context = activationContext;
203  }
204 
205  private static ApplicationId ParseApplicationId(ICMS manifest)
206  {
207  if (manifest.Identity == null)
208  {
209  return null;
210  }
211  return new ApplicationId(Hex.DecodeHexString(manifest.Identity.GetAttribute("", "publicKeyToken")), manifest.Identity.GetAttribute("", "name"), new Version(manifest.Identity.GetAttribute("", "version")), manifest.Identity.GetAttribute("", "processorArchitecture"), manifest.Identity.GetAttribute("", "culture"));
212  }
213  }
214 }
Version Version
Gets the version of the application.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
FileIOPermissionAccess
Specifies the type of file access requested.
ApplicationSecurityInfo(ActivationContext activationContext)
Initializes a new instance of the T:System.Security.Policy.ApplicationSecurityInfo class using the pr...
Provides the strong name of a code assembly as evidence for policy evaluation. This class cannot be i...
Definition: StrongName.cs:12
Provides the security zone of a code assembly as evidence for policy evaluation. This class cannot be...
Definition: Zone.cs:10
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
PermissionSet DefaultRequestSet
Gets or sets the default permission set.
PermissionSet PermissionSet
Gets or sets the T:System.Security.PermissionSet of the policy statement.
Provides the Web site from which a code assembly originates as evidence for policy evaluation....
Definition: Site.cs:11
Identifies the activation context for the current application. This class cannot be inherited.
Represents a read-only collection that can contain many different types of permissions.
Definition: __Canon.cs:3
static Site CreateFromUrl(string url)
Creates a new T:System.Security.Policy.Site object from the specified URL.
Definition: Site.cs:40
Grants Web permission to the site from which the assembly was downloaded. This class cannot be inheri...
Definition: NetCodeGroup.cs:13
Provides the URL from which a code assembly originates as evidence for policy evaluation....
Definition: Url.cs:10
Represents the statement of a T:System.Security.Policy.CodeGroup describing the permissions and other...
void AddChild(SecurityElement child)
Adds a child element to the XML element.
static Zone CreateFromUrl(string url)
Creates a new zone with the specified URL.
Definition: Zone.cs:70
SecurityAction
Specifies the security actions that can be performed using declarative security.
Grants permission to manipulate files located in the code assemblies to code assemblies that match th...
Represents a collection that can contain many different types of permissions.
Represents the XML object model for encoding security objects. This class cannot be inherited.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
ApplicationId DeploymentId
Gets or sets the top element in the application, which is described in the deployment identity.
Represents the version number of an assembly, operating system, or the common language runtime....
Definition: Version.cs:11
Represents a membership condition that matches all code. This class cannot be inherited.
SecurityElement ToXml()
Creates an XML encoding of the security object and its current state.
Provides data for manifest-based activation of an application. This class cannot be inherited.
static SecurityElement FromString(string xml)
Creates a security element from an XML-encoded string.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
Defines the set of information that constitutes input to security policy decisions....
Definition: Evidence.cs:17
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
string Name
Gets the name of the application.
Contains information used to uniquely identify a manifest-based application. This class cannot be inh...
ApplicationId ApplicationId
Gets or sets the application identity information.
Controls the ability to access files and folders. This class cannot be inherited.
SecurityPermissionFlag
Specifies access flags for the security permission object.
Provides atomic operations for variables that are shared by multiple threads.
Definition: Interlocked.cs:10
Evidence ApplicationEvidence
Gets or sets the evidence for the application.
Holds the security evidence for an application. This class cannot be inherited.
Represents the public key information (called a blob) for a strong name. This class cannot be inherit...