3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // <OWNER>[....]</OWNER>
7 namespace System.Security.Permissions
10 using System.Security.Util;
12 using System.Security.Policy;
14 using System.Security.AccessControl;
17 using System.Runtime.Serialization.Formatters;
18 using System.Threading;
19 using System.Runtime.InteropServices;
20 using System.Runtime.Remoting;
21 using System.Runtime.Serialization;
23 using System.Security.Cryptography.X509Certificates;
25 using System.Runtime.Versioning;
26 using System.Diagnostics.Contracts;
29 [System.Runtime.InteropServices.ComVisible(true)]
30 #if !FEATURE_CAS_POLICY
31 // The csharp compiler requires these types to be public, but they are not used elsewhere.
32 [Obsolete("SecurityAction is no longer accessible to application code.")]
34 public enum SecurityAction
36 // Demand permission of all caller
39 // Assert permission so callers don't need
42 // Deny permissions so checks will fail
43 [Obsolete("Deny is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
46 // Reduce permissions so check will fail
49 // Demand permission of caller
52 // Demand permission of a subclass
53 InheritanceDemand = 7,
55 // Request minimum permissions to run
56 [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
59 // Request optional additional permissions
60 [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
63 // Refuse to be granted these permissions
64 [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
70 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
71 [System.Runtime.InteropServices.ComVisible(true)]
72 #if !FEATURE_CAS_POLICY
73 // The csharp compiler requires these types to be public, but they are not used elsewhere.
74 [Obsolete("SecurityAttribute is no longer accessible to application code.")]
76 public abstract class SecurityAttribute : System.Attribute
79 internal SecurityAction m_action;
81 internal bool m_unrestricted;
82 #if FEATURE_LEGACYNETCF
87 SecurityAttribute( SecurityAction action )
92 public SecurityAction Action
94 get { return m_action; }
95 set { m_action = value; }
98 public bool Unrestricted
100 get { return m_unrestricted; }
101 set { m_unrestricted = value; }
104 abstract public IPermission CreatePermission();
106 [System.Security.SecurityCritical] // auto-generated
107 internal static unsafe IntPtr FindSecurityAttributeTypeHandle(String typeName)
109 PermissionSet.s_fullTrust.Assert();
110 Type t = Type.GetType(typeName, false, false);
113 IntPtr typeHandle = t.TypeHandle.Value;
119 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
120 [System.Runtime.InteropServices.ComVisible(true)]
121 #if !FEATURE_CAS_POLICY
122 // The csharp compiler requires these types to be public, but they are not used elsewhere.
123 [Obsolete("CodeAccessSecurityAttribute is no longer accessible to application code.")]
125 public abstract class CodeAccessSecurityAttribute : SecurityAttribute
127 #if FEATURE_LEGACYNETCF
132 CodeAccessSecurityAttribute( SecurityAction action )
138 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
139 [System.Runtime.InteropServices.ComVisible(true)]
141 #pragma warning disable 618
142 sealed public class EnvironmentPermissionAttribute : CodeAccessSecurityAttribute
143 #pragma warning restore 618
145 private String m_read = null;
146 private String m_write = null;
148 #pragma warning disable 618
149 public EnvironmentPermissionAttribute( SecurityAction action )
150 #pragma warning restore 618
156 get { return m_read; }
157 set { m_read = value; }
160 public String Write {
161 get { return m_write; }
162 set { m_write = value; }
166 get { throw new NotSupportedException( Environment.GetResourceString( "NotSupported_GetMethod" ) ); }
167 set { m_write = value; m_read = value; }
170 public override IPermission CreatePermission()
174 return new EnvironmentPermission(PermissionState.Unrestricted);
178 EnvironmentPermission perm = new EnvironmentPermission(PermissionState.None);
180 perm.SetPathList( EnvironmentPermissionAccess.Read, m_read );
182 perm.SetPathList( EnvironmentPermissionAccess.Write, m_write );
188 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
189 [System.Runtime.InteropServices.ComVisible(true)]
191 #pragma warning disable 618
192 sealed public class FileDialogPermissionAttribute : CodeAccessSecurityAttribute
193 #pragma warning restore 618
195 private FileDialogPermissionAccess m_access;
197 #pragma warning disable 618
198 public FileDialogPermissionAttribute( SecurityAction action )
199 #pragma warning restore 618
206 get { return (m_access & FileDialogPermissionAccess.Open) != 0; }
207 set { m_access = value ? m_access | FileDialogPermissionAccess.Open : m_access & ~FileDialogPermissionAccess.Open; }
212 get { return (m_access & FileDialogPermissionAccess.Save) != 0; }
213 set { m_access = value ? m_access | FileDialogPermissionAccess.Save : m_access & ~FileDialogPermissionAccess.Save; }
216 public override IPermission CreatePermission()
220 return new FileDialogPermission( PermissionState.Unrestricted );
224 return new FileDialogPermission( m_access );
230 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
231 [System.Runtime.InteropServices.ComVisible(true)]
233 #pragma warning disable 618
234 sealed public class FileIOPermissionAttribute : CodeAccessSecurityAttribute
235 #pragma warning restore 618
237 private String m_read = null;
238 private String m_write = null;
239 private String m_append = null;
240 private String m_pathDiscovery = null;
241 private String m_viewAccess = null;
242 private String m_changeAccess = null;
243 [OptionalField(VersionAdded = 2)] private FileIOPermissionAccess m_allLocalFiles = FileIOPermissionAccess.NoAccess;
244 [OptionalField(VersionAdded = 2)] private FileIOPermissionAccess m_allFiles = FileIOPermissionAccess.NoAccess;
246 #pragma warning disable 618
247 public FileIOPermissionAttribute( SecurityAction action )
248 #pragma warning restore 618
254 get { return m_read; }
255 set { m_read = value; }
258 public String Write {
259 get { return m_write; }
260 set { m_write = value; }
263 public String Append {
264 get { return m_append; }
265 set { m_append = value; }
268 public String PathDiscovery {
269 get { return m_pathDiscovery; }
270 set { m_pathDiscovery = value; }
273 public String ViewAccessControl {
274 get { return m_viewAccess; }
275 set { m_viewAccess = value; }
278 public String ChangeAccessControl {
279 get { return m_changeAccess; }
280 set { m_changeAccess = value; }
283 [Obsolete("Please use the ViewAndModify property instead.")]
285 set { m_read = value; m_write = value; m_append = value; m_pathDiscovery = value; }
286 get { throw new NotSupportedException( Environment.GetResourceString( "NotSupported_GetMethod" ) ); }
289 // Read, Write, Append, PathDiscovery, but no ACL-related permissions
290 public String ViewAndModify {
291 get { throw new NotSupportedException( Environment.GetResourceString( "NotSupported_GetMethod" ) ); }
292 set { m_read = value; m_write = value; m_append = value; m_pathDiscovery = value; }
295 public FileIOPermissionAccess AllFiles {
296 get { return m_allFiles; }
297 set { m_allFiles = value; }
300 public FileIOPermissionAccess AllLocalFiles {
301 get { return m_allLocalFiles; }
302 set { m_allLocalFiles = value; }
305 public override IPermission CreatePermission()
309 return new FileIOPermission(PermissionState.Unrestricted);
313 FileIOPermission perm = new FileIOPermission(PermissionState.None);
315 perm.SetPathList( FileIOPermissionAccess.Read, m_read );
317 perm.SetPathList( FileIOPermissionAccess.Write, m_write );
318 if (m_append != null)
319 perm.SetPathList( FileIOPermissionAccess.Append, m_append );
320 if (m_pathDiscovery != null)
321 perm.SetPathList( FileIOPermissionAccess.PathDiscovery, m_pathDiscovery );
323 if (m_viewAccess != null)
324 perm.SetPathList( FileIOPermissionAccess.NoAccess, AccessControlActions.View, new String[] { m_viewAccess }, false );
325 if (m_changeAccess != null)
326 perm.SetPathList( FileIOPermissionAccess.NoAccess, AccessControlActions.Change, new String[] { m_changeAccess }, false );
329 perm.AllFiles = m_allFiles;
330 perm.AllLocalFiles = m_allLocalFiles;
337 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
339 [System.Runtime.InteropServices.ComVisible(true)]
340 #pragma warning disable 618
341 public sealed class KeyContainerPermissionAttribute : CodeAccessSecurityAttribute {
342 #pragma warning restore 618
343 KeyContainerPermissionFlags m_flags = KeyContainerPermissionFlags.NoFlags;
344 private string m_keyStore;
345 private string m_providerName;
346 private int m_providerType = -1;
347 private string m_keyContainerName;
348 private int m_keySpec = -1;
350 #pragma warning disable 618
351 public KeyContainerPermissionAttribute(SecurityAction action) : base(action) {}
352 #pragma warning restore 618
354 public string KeyStore {
355 get { return m_keyStore; }
356 set { m_keyStore = value; }
359 public string ProviderName {
360 get { return m_providerName; }
361 set { m_providerName = value; }
364 public int ProviderType {
365 get { return m_providerType; }
366 set { m_providerType = value; }
369 public string KeyContainerName {
370 get { return m_keyContainerName; }
371 set { m_keyContainerName = value; }
375 get { return m_keySpec; }
376 set { m_keySpec = value; }
379 public KeyContainerPermissionFlags Flags {
380 get { return m_flags; }
381 set { m_flags = value; }
384 public override IPermission CreatePermission() {
385 if (m_unrestricted) {
386 return new KeyContainerPermission(PermissionState.Unrestricted);
388 if (KeyContainerPermissionAccessEntry.IsUnrestrictedEntry(m_keyStore, m_providerName, m_providerType, m_keyContainerName, m_keySpec))
389 return new KeyContainerPermission(m_flags);
391 // create a KeyContainerPermission with a single access entry.
392 KeyContainerPermission cp = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
393 KeyContainerPermissionAccessEntry accessEntry = new KeyContainerPermissionAccessEntry(m_keyStore, m_providerName, m_providerType, m_keyContainerName, m_keySpec, m_flags);
394 cp.AccessEntries.Add(accessEntry);
399 #endif // !FEATURE_PAL
402 // PrincipalPermissionAttribute currently derives from
403 // CodeAccessSecurityAttribute, even though it's not related to code access
404 // security. This is because compilers are currently looking for
405 // CodeAccessSecurityAttribute as a direct parent class rather than
406 // SecurityAttribute as the root class.
407 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = false )]
408 [System.Runtime.InteropServices.ComVisible(true)]
410 sealed public class PrincipalPermissionAttribute : CodeAccessSecurityAttribute
412 private String m_name = null;
413 private String m_role = null;
414 private bool m_authenticated = true;
416 public PrincipalPermissionAttribute( SecurityAction action )
423 get { return m_name; }
424 set { m_name = value; }
429 get { return m_role; }
430 set { m_role = value; }
433 public bool Authenticated
435 get { return m_authenticated; }
436 set { m_authenticated = value; }
440 public override IPermission CreatePermission()
444 return new PrincipalPermission( PermissionState.Unrestricted );
448 return new PrincipalPermission( m_name, m_role, m_authenticated );
452 #endif // !FEATURE_CORECLR
454 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
455 [System.Runtime.InteropServices.ComVisible(true)]
457 #pragma warning disable 618
458 sealed public class ReflectionPermissionAttribute : CodeAccessSecurityAttribute
459 #pragma warning restore 618
461 private ReflectionPermissionFlag m_flag = ReflectionPermissionFlag.NoFlags;
463 #pragma warning disable 618
464 public ReflectionPermissionAttribute( SecurityAction action )
465 #pragma warning restore 618
470 public ReflectionPermissionFlag Flags {
471 get { return m_flag; }
472 set { m_flag = value; }
475 [Obsolete("This API has been deprecated. http://go.microsoft.com/fwlink/?linkid=14202")]
476 public bool TypeInformation {
477 #pragma warning disable 618
478 get { return (m_flag & ReflectionPermissionFlag.TypeInformation) != 0; }
479 set { m_flag = value ? m_flag | ReflectionPermissionFlag.TypeInformation : m_flag & ~ReflectionPermissionFlag.TypeInformation; }
480 #pragma warning restore 618
483 public bool MemberAccess {
484 get { return (m_flag & ReflectionPermissionFlag.MemberAccess) != 0; }
485 set { m_flag = value ? m_flag | ReflectionPermissionFlag.MemberAccess : m_flag & ~ReflectionPermissionFlag.MemberAccess; }
488 [Obsolete("This permission is no longer used by the CLR.")]
489 public bool ReflectionEmit {
490 #pragma warning disable 618
491 get { return (m_flag & ReflectionPermissionFlag.ReflectionEmit) != 0; }
492 set { m_flag = value ? m_flag | ReflectionPermissionFlag.ReflectionEmit : m_flag & ~ReflectionPermissionFlag.ReflectionEmit; }
493 #pragma warning restore 618
496 public bool RestrictedMemberAccess
498 get { return (m_flag & ReflectionPermissionFlag.RestrictedMemberAccess) != 0; }
499 set { m_flag = value ? m_flag | ReflectionPermissionFlag.RestrictedMemberAccess : m_flag & ~ReflectionPermissionFlag.RestrictedMemberAccess; }
502 public override IPermission CreatePermission()
506 return new ReflectionPermission( PermissionState.Unrestricted );
510 return new ReflectionPermission( m_flag );
516 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
517 [System.Runtime.InteropServices.ComVisible(true)]
519 #pragma warning disable 618
520 sealed public class RegistryPermissionAttribute : CodeAccessSecurityAttribute
521 #pragma warning restore 618
523 private String m_read = null;
524 private String m_write = null;
525 private String m_create = null;
526 private String m_viewAcl = null;
527 private String m_changeAcl = null;
529 #pragma warning disable 618
530 public RegistryPermissionAttribute( SecurityAction action )
531 #pragma warning restore 618
537 get { return m_read; }
538 set { m_read = value; }
541 public String Write {
542 get { return m_write; }
543 set { m_write = value; }
546 public String Create {
547 get { return m_create; }
548 set { m_create = value; }
551 public String ViewAccessControl {
552 get { return m_viewAcl; }
553 set { m_viewAcl = value; }
556 public String ChangeAccessControl {
557 get { return m_changeAcl; }
558 set { m_changeAcl = value; }
561 // Read, Write, & Create, but no ACL's
562 public String ViewAndModify {
563 get { throw new NotSupportedException( Environment.GetResourceString( "NotSupported_GetMethod" ) ); }
564 set { m_read = value; m_write = value; m_create = value; }
567 [Obsolete("Please use the ViewAndModify property instead.")]
569 get { throw new NotSupportedException( Environment.GetResourceString( "NotSupported_GetMethod" ) ); }
570 set { m_read = value; m_write = value; m_create = value; }
573 public override IPermission CreatePermission()
577 return new RegistryPermission( PermissionState.Unrestricted );
581 RegistryPermission perm = new RegistryPermission(PermissionState.None);
583 perm.SetPathList( RegistryPermissionAccess.Read, m_read );
585 perm.SetPathList( RegistryPermissionAccess.Write, m_write );
586 if (m_create != null)
587 perm.SetPathList( RegistryPermissionAccess.Create, m_create );
589 if (m_viewAcl != null)
590 perm.SetPathList( AccessControlActions.View, m_viewAcl );
591 if (m_changeAcl != null)
592 perm.SetPathList( AccessControlActions.Change, m_changeAcl );
598 #endif // !FEATURE_PAL
600 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
601 [System.Runtime.InteropServices.ComVisible(true)]
603 #if !FEATURE_CAS_POLICY
604 // The csharp compiler requires these types to be public, but they are not used elsewhere.
605 [Obsolete("SecurityPermissionAttribute is no longer accessible to application code.")]
607 sealed public class SecurityPermissionAttribute : CodeAccessSecurityAttribute
609 private SecurityPermissionFlag m_flag = SecurityPermissionFlag.NoFlags;
611 public SecurityPermissionAttribute( SecurityAction action )
616 public SecurityPermissionFlag Flags {
617 get { return m_flag; }
618 set { m_flag = value; }
621 public bool Assertion {
622 get { return (m_flag & SecurityPermissionFlag.Assertion) != 0; }
623 set { m_flag = value ? m_flag | SecurityPermissionFlag.Assertion : m_flag & ~SecurityPermissionFlag.Assertion; }
626 public bool UnmanagedCode {
627 get { return (m_flag & SecurityPermissionFlag.UnmanagedCode) != 0; }
628 set { m_flag = value ? m_flag | SecurityPermissionFlag.UnmanagedCode : m_flag & ~SecurityPermissionFlag.UnmanagedCode; }
631 public bool SkipVerification {
632 get { return (m_flag & SecurityPermissionFlag.SkipVerification) != 0; }
633 set { m_flag = value ? m_flag | SecurityPermissionFlag.SkipVerification : m_flag & ~SecurityPermissionFlag.SkipVerification; }
636 public bool Execution {
637 get { return (m_flag & SecurityPermissionFlag.Execution) != 0; }
638 set { m_flag = value ? m_flag | SecurityPermissionFlag.Execution : m_flag & ~SecurityPermissionFlag.Execution; }
641 public bool ControlThread {
642 get { return (m_flag & SecurityPermissionFlag.ControlThread) != 0; }
643 set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlThread : m_flag & ~SecurityPermissionFlag.ControlThread; }
646 public bool ControlEvidence {
647 get { return (m_flag & SecurityPermissionFlag.ControlEvidence) != 0; }
648 set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlEvidence : m_flag & ~SecurityPermissionFlag.ControlEvidence; }
651 public bool ControlPolicy {
652 get { return (m_flag & SecurityPermissionFlag.ControlPolicy) != 0; }
653 set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlPolicy : m_flag & ~SecurityPermissionFlag.ControlPolicy; }
656 public bool SerializationFormatter {
657 get { return (m_flag & SecurityPermissionFlag.SerializationFormatter) != 0; }
658 set { m_flag = value ? m_flag | SecurityPermissionFlag.SerializationFormatter : m_flag & ~SecurityPermissionFlag.SerializationFormatter; }
661 public bool ControlDomainPolicy {
662 get { return (m_flag & SecurityPermissionFlag.ControlDomainPolicy) != 0; }
663 set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlDomainPolicy : m_flag & ~SecurityPermissionFlag.ControlDomainPolicy; }
666 public bool ControlPrincipal {
667 get { return (m_flag & SecurityPermissionFlag.ControlPrincipal) != 0; }
668 set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlPrincipal : m_flag & ~SecurityPermissionFlag.ControlPrincipal; }
671 public bool ControlAppDomain {
672 get { return (m_flag & SecurityPermissionFlag.ControlAppDomain) != 0; }
673 set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlAppDomain : m_flag & ~SecurityPermissionFlag.ControlAppDomain; }
676 public bool RemotingConfiguration {
677 get { return (m_flag & SecurityPermissionFlag.RemotingConfiguration) != 0; }
678 set { m_flag = value ? m_flag | SecurityPermissionFlag.RemotingConfiguration : m_flag & ~SecurityPermissionFlag.RemotingConfiguration; }
681 [System.Runtime.InteropServices.ComVisible(true)]
682 public bool Infrastructure {
683 get { return (m_flag & SecurityPermissionFlag.Infrastructure) != 0; }
684 set { m_flag = value ? m_flag | SecurityPermissionFlag.Infrastructure : m_flag & ~SecurityPermissionFlag.Infrastructure; }
687 public bool BindingRedirects {
688 get { return (m_flag & SecurityPermissionFlag.BindingRedirects) != 0; }
689 set { m_flag = value ? m_flag | SecurityPermissionFlag.BindingRedirects : m_flag & ~SecurityPermissionFlag.BindingRedirects; }
692 public override IPermission CreatePermission()
696 return new SecurityPermission( PermissionState.Unrestricted );
700 return new SecurityPermission( m_flag );
705 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
706 [System.Runtime.InteropServices.ComVisible(true)]
708 #pragma warning disable 618
709 sealed public class UIPermissionAttribute : CodeAccessSecurityAttribute
710 #pragma warning restore 618
712 private UIPermissionWindow m_windowFlag = UIPermissionWindow.NoWindows;
713 private UIPermissionClipboard m_clipboardFlag = UIPermissionClipboard.NoClipboard;
715 #pragma warning disable 618
716 public UIPermissionAttribute( SecurityAction action )
717 #pragma warning restore 618
722 public UIPermissionWindow Window {
723 get { return m_windowFlag; }
724 set { m_windowFlag = value; }
727 public UIPermissionClipboard Clipboard {
728 get { return m_clipboardFlag; }
729 set { m_clipboardFlag = value; }
732 public override IPermission CreatePermission()
736 return new UIPermission( PermissionState.Unrestricted );
740 return new UIPermission( m_windowFlag, m_clipboardFlag );
745 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
746 [System.Runtime.InteropServices.ComVisible(true)]
748 #pragma warning disable 618
749 sealed public class ZoneIdentityPermissionAttribute : CodeAccessSecurityAttribute
750 #pragma warning restore 618
752 private SecurityZone m_flag = SecurityZone.NoZone;
754 #pragma warning disable 618
755 public ZoneIdentityPermissionAttribute( SecurityAction action )
756 #pragma warning restore 618
761 public SecurityZone Zone {
762 get { return m_flag; }
763 set { m_flag = value; }
766 public override IPermission CreatePermission()
770 return new ZoneIdentityPermission(PermissionState.Unrestricted);
774 return new ZoneIdentityPermission( m_flag );
779 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
780 [System.Runtime.InteropServices.ComVisible(true)]
782 #pragma warning disable 618
783 sealed public class StrongNameIdentityPermissionAttribute : CodeAccessSecurityAttribute
784 #pragma warning restore 618
786 private String m_name = null;
787 private String m_version = null;
788 private String m_blob = null;
790 #pragma warning disable 618
791 public StrongNameIdentityPermissionAttribute( SecurityAction action )
792 #pragma warning restore 618
799 get { return m_name; }
800 set { m_name = value; }
803 public String Version
805 get { return m_version; }
806 set { m_version = value; }
809 public String PublicKey
811 get { return m_blob; }
812 set { m_blob = value; }
815 public override IPermission CreatePermission()
819 return new StrongNameIdentityPermission( PermissionState.Unrestricted );
823 if (m_blob == null && m_name == null && m_version == null)
824 return new StrongNameIdentityPermission( PermissionState.None );
827 throw new ArgumentException( Environment.GetResourceString("ArgumentNull_Key"));
829 StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob( m_blob );
831 if (m_version == null || m_version.Equals(String.Empty))
832 return new StrongNameIdentityPermission( blob, m_name, null );
834 return new StrongNameIdentityPermission( blob, m_name, new Version( m_version ) );
840 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
841 [System.Runtime.InteropServices.ComVisible(true)]
843 #pragma warning disable 618
844 sealed public class SiteIdentityPermissionAttribute : CodeAccessSecurityAttribute
845 #pragma warning restore 618
847 private String m_site = null;
849 #pragma warning disable 618
850 public SiteIdentityPermissionAttribute( SecurityAction action )
851 #pragma warning restore 618
857 get { return m_site; }
858 set { m_site = value; }
861 public override IPermission CreatePermission()
865 return new SiteIdentityPermission( PermissionState.Unrestricted );
870 return new SiteIdentityPermission( PermissionState.None );
872 return new SiteIdentityPermission( m_site );
877 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
878 [System.Runtime.InteropServices.ComVisible(true)]
879 #pragma warning disable 618
880 [Serializable] sealed public class UrlIdentityPermissionAttribute : CodeAccessSecurityAttribute
881 #pragma warning restore 618
883 private String m_url = null;
885 #pragma warning disable 618
886 public UrlIdentityPermissionAttribute( SecurityAction action )
887 #pragma warning restore 618
893 get { return m_url; }
894 set { m_url = value; }
897 public override IPermission CreatePermission()
901 return new UrlIdentityPermission( PermissionState.Unrestricted );
906 return new UrlIdentityPermission( PermissionState.None );
908 return new UrlIdentityPermission( m_url );
913 #if FEATURE_X509 && FEATURE_CAS_POLICY
914 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
915 [System.Runtime.InteropServices.ComVisible(true)]
917 sealed public class PublisherIdentityPermissionAttribute : CodeAccessSecurityAttribute
919 private String m_x509cert = null;
920 private String m_certFile = null;
921 private String m_signedFile = null;
923 public PublisherIdentityPermissionAttribute( SecurityAction action )
931 public String X509Certificate {
932 get { return m_x509cert; }
933 set { m_x509cert = value; }
936 public String CertFile {
937 get { return m_certFile; }
938 [ResourceExposure(ResourceScope.Machine)]
939 [ResourceConsumption(ResourceScope.Machine)]
940 set { m_certFile = value; }
943 public String SignedFile {
944 get { return m_signedFile; }
945 [ResourceExposure(ResourceScope.Machine)]
946 [ResourceConsumption(ResourceScope.Machine)]
947 set { m_signedFile = value; }
950 [ResourceExposure(ResourceScope.Machine)]
951 [ResourceConsumption(ResourceScope.Machine)]
952 public override IPermission CreatePermission()
956 return new PublisherIdentityPermission( PermissionState.Unrestricted );
960 if (m_x509cert != null)
962 return new PublisherIdentityPermission( new X509Certificate( System.Security.Util.Hex.DecodeHexString( m_x509cert ) ) );
964 else if (m_certFile != null)
966 return new PublisherIdentityPermission( System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromCertFile( m_certFile ) );
968 else if (m_signedFile != null)
970 return new PublisherIdentityPermission( System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile( m_signedFile ) );
974 return new PublisherIdentityPermission( PermissionState.None );
979 #endif // #if FEATURE_X509 && FEATURE_CAS_POLICY
983 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor
984 | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly,
985 AllowMultiple=true, Inherited=false)]
986 [System.Runtime.InteropServices.ComVisible(true)]
987 public abstract class IsolatedStoragePermissionAttribute : CodeAccessSecurityAttribute
990 internal long m_userQuota;
993 internal long m_machineQuota;
995 internal long m_expirationDays;
997 internal bool m_permanentData;
1000 internal IsolatedStorageContainment m_allowed;
1001 protected IsolatedStoragePermissionAttribute(SecurityAction action) : base(action)
1006 public long UserQuota {
1008 m_userQuota = value;
1015 internal long MachineQuota {
1017 m_machineQuota = value;
1020 return m_machineQuota;
1023 internal long ExpirationDays {
1025 m_expirationDays = value;
1028 return m_expirationDays;
1031 internal bool PermanentData {
1033 m_permanentData = value;
1036 return m_permanentData;
1040 public IsolatedStorageContainment UsageAllowed {
1051 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor
1052 | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly,
1053 AllowMultiple=true, Inherited=false)]
1054 [System.Runtime.InteropServices.ComVisible(true)]
1056 sealed public class IsolatedStorageFilePermissionAttribute : IsolatedStoragePermissionAttribute
1058 public IsolatedStorageFilePermissionAttribute(SecurityAction action) : base(action)
1062 public override IPermission CreatePermission()
1064 IsolatedStorageFilePermission p;
1065 if (m_unrestricted) {
1066 p = new IsolatedStorageFilePermission
1067 (PermissionState.Unrestricted);
1069 p = new IsolatedStorageFilePermission(PermissionState.None);
1070 p.UserQuota = m_userQuota;
1071 p.UsageAllowed = m_allowed;
1073 p.PermanentData = m_permanentData;
1074 p.MachineQuota = m_machineQuota;
1075 p.ExpirationDays = m_expirationDays;
1081 #endif // FEATURE_CORECLR
1083 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
1084 [System.Runtime.InteropServices.ComVisible(true)]
1086 #pragma warning disable 618
1087 sealed public class PermissionSetAttribute : CodeAccessSecurityAttribute
1088 #pragma warning restore 618
1090 private String m_file;
1091 private String m_name;
1092 private bool m_unicode;
1093 private String m_xml;
1094 private String m_hex;
1096 #pragma warning disable 618
1097 public PermissionSetAttribute( SecurityAction action )
1098 #pragma warning restore 618
1104 public String File {
1105 get { return m_file; }
1106 [ResourceExposure(ResourceScope.Machine)]
1107 [ResourceConsumption(ResourceScope.Machine)]
1108 set { m_file = value; }
1111 public bool UnicodeEncoded {
1112 get { return m_unicode; }
1113 set { m_unicode = value; }
1116 public String Name {
1117 get { return m_name; }
1118 set { m_name = value; }
1122 get { return m_xml; }
1123 set { m_xml = value; }
1127 get { return m_hex; }
1128 set { m_hex = value; }
1131 public override IPermission CreatePermission()
1136 #if FEATURE_CAS_POLICY
1137 private PermissionSet BruteForceParseStream(Stream stream)
1139 Encoding[] encodings = new Encoding[] { Encoding.UTF8,
1145 StreamReader reader = null;
1146 Exception exception = null;
1148 for (int i = 0; reader == null && i < encodings.Length; ++i)
1152 stream.Position = 0;
1153 reader = new StreamReader( stream, encodings[i] );
1155 return ParsePermissionSet( new Parser(reader) );
1157 catch (Exception e1)
1159 if (exception == null)
1167 private PermissionSet ParsePermissionSet(Parser parser)
1169 SecurityElement e = parser.GetTopElement();
1170 PermissionSet permSet = new PermissionSet( PermissionState.None );
1171 permSet.FromXml( e );
1175 #endif // FEATURE_CAS_POLICY
1177 #if FEATURE_CAS_POLICY
1178 [System.Security.SecuritySafeCritical] // auto-generated
1180 [ResourceExposure(ResourceScope.Machine)]
1181 [ResourceConsumption(ResourceScope.Machine)]
1182 public PermissionSet CreatePermissionSet()
1185 return new PermissionSet( PermissionState.Unrestricted );
1186 else if (m_name != null)
1187 #if FEATURE_CAS_POLICY
1188 return PolicyLevel.GetBuiltInSet( m_name );
1190 return NamedPermissionSet.GetBuiltInSet( m_name );
1191 #endif // FEATURE_CAS_POLICY
1192 #if FEATURE_CAS_POLICY
1193 else if (m_xml != null)
1194 return ParsePermissionSet( new Parser(m_xml.ToCharArray()) );
1195 else if (m_hex != null)
1196 return BruteForceParseStream( new MemoryStream(Util.Hex.DecodeHexString(m_hex)) );
1197 else if (m_file != null)
1198 return BruteForceParseStream( new FileStream( m_file, FileMode.Open, FileAccess.Read) );
1199 #endif // FEATURE_CAS_POLICY
1201 return new PermissionSet( PermissionState.None );