Presented By:Ahmed ALSUMPhD Student
CS 895: .Net SecurityOld Dominion UniversityCollege of ScienceDepartment of Computer Science
Whats a PermissionPermissions limit what an assembly can dorun if code not verifiable?access file system?access the network?access certain environment variables?call native code (COM objects, DLLs)?access files or printers without asking user?
SecurityCode Access SecurityCode may require permissions to runSecurity policy determines what code is allowed to runBy machineWhere did this code come from?Who authored it?By userIf no permission then a SecurityException is thrown
SecurityCode Access SecurityCan specify the permissions needed by codeDeclarative, with attributesImperativeCreate a permission object, then call Demand()By default, the CLR will ensure that all code in call chain has the necessary permissions
SecurityCode Access SecuritySecurity checkVarying levels of trustBehavior constrained by least trustworthy component
Assembly A1Assembly A2Assembly A3Assembly A4G1G4G3G2PPPCall Chain
SecurityCode Access SecurityCan override security checksAssert() lets you and the code you call perform actions that you have permission to do, but your callers may not.Deny() lets you prevent downstream code from performing certain actionsPermitOnly() is like Deny(), but you specify the only permissions the downstream code will have.
SecurityPermissionsCode access permissionsProtect resources and operationsEx. DnsPermission, EnvironmentPermission, WebPermissionIdentity permissionsCharacteristics of an assemblys identityEx. URLIdentityPermission, ZoneIdentityPermissionRole-based permissionsDiscover a users role or identityEx. PrincipalPermissionCustom permissionsDesign and implement your own classes
Resources AccessedRequired PermissionsDPAPI encryptionDataProtectionPermissionDNS directoryDnsPermissionEnvironment variablesEnvironmentPermissionEvent logEventLogPermissionFile dialogFileDialogPermissionFile systemFileIOPermissionIsolated file storageIsolatedStoragePermissionKey containersKeyContainerPermissionMessage queuesMessageQueuePermissionNetwork information and traffic statisticsNetworkInformationPermissionOLE DB data sourcesOleDbPermissionPerformance countersPerformanceCounterPermission
Resources AccessedRequired PermissionsPrinters PrintingPermissionReflection ReflectionPermissionRegistry RegistryPermissionSecurity SecurityPermissionSMTP serversSmtpPermissionSockets SocketsPermissionSQL Server notificationsSqlNotificationPermissionSQL Server SqlClientPermissionStores containing X.509 certificatesStorePermissionUser interfaces and clipboardUIPermissionWeb services (and other HTTP Internet resources)WebPermission
Namespace: System.SecurityCodeAccessPermissionDefines the underlying structure of all code access permissionsWhen you inherit from CodeAccessPermission, you must also implement the IUnrestrictedPermission interface. The following CodeAccessPermission members must be overridden: Copy, Intersect, IsSubsetOf, ToXml, FromXml, and Union. You must also define a constructor that takes a PermissionState as its only parameter. You must apply the SerializableAttribute attribute to a class that inherits from CodeAccessPermission. Custom Permission Example
Namespace: System.Security.PermissionsCodeAccessSecurityAttributeThe security information declared by a security attribute is stored in the metadata of the attribute target and is accessed by the system at run time. Security attributes are used only for declarative security.All permission attributes derived from this class must have only a single constructor that takes a SecurityAction as its only parameter.Custom Attribute Example
Namespace: System.Security.PermissionsPermissionState EnumerationSpecifies whether a permission should have all or no access to resources at creation.Unrestricted: Full access to the resource protected by the permission. None: No access to the resource protected by the permission.Ex, the file permission constructor could create an object representing either no access to any files or all access to all files.Intermediate states can be set according to the specific permission semantics.
EnvironmentPermissionEnvironment variable names are designated by one or more case-insensitive name lists separated by semicolons, with separate lists for read and write access to the named variables. EnvironmentPermission class controls access to system and user environment variables. EnvironmentPermission tmpVariable = new EnvironmentPermission( EnvironmentPermissionAccess.Read, "TEMP"); tmpVariable.Deny();
FileIOPermissionControls the ability to access files and folders.This permission distinguishes between: Read, Write, Append, and PathDiscovery.All these permissions are independent, meaning that rights to one do not imply rights to another.
FileIOPermission fp = new FileIOPermission(PermissionState.None); fp.AllLocalFiles = FileIOPermissionAccess.Read; fp.Demand();
WebBrowserPermissionIt controls the ability to create the WebBrowser control.In the Windows Presentation Foundation (WPF), the Web browser control enables frames to navigate HTML. This permission uses the values of the WebBrowserPermission enumerations.WebBrowserPermission webBrowserPermission = new WebBrowserPermission(WebBrowserPermissionLevel.Unrestricted);
MediaPermissionThe MediaPermission describes a set of security permissions that controls the ability for audio, image, and video media to work in a partial-trust Windows Presentation Foundation (WPF) application.
RegistryPermissionRegistryPermission describes protected operations on registry variables. Registry variables should not be stored in memory locations where code without RegistryPermission can access them. If the registry object is passed to an untrusted caller it can be misused.
RegistryPermission f = new RegistryPermission( RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
PrincipalPermissionBy passing identity information (user name and role) to the constructor, PrincipalPermission can be used to demand that the identity of the active principal matches this information.It implements the IPermission interface. This is because PrincipalPermission is not a code access permission; that is, it is not granted based on the identity of the executing assembly. Instead, it allows code to perform actions (Demand, Union, Intersect, and so on) against the current user identity.AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); PrincipalPermission principalPerm = new PrincipalPermission(null, "Administrators"); principalPerm.Demand();
Namespace: System.NetWebPermissionWebPermission provides a set of methods and properties to control access to Internet resources. You can use a WebPermission to provide either restricted or unrestricted access to your resource, based on the PermissionState that is set when the WebPermission is created.Regex myRegex = new Regex(@"http://www\.microsoft\.com/.*");WebPermission wp = new WebPermission(NetworkAccess.Connect,myRegex);wp.AddPermission(NetworkAccess.Accept, "http://www.odu.edu/");wp.Demand();
Namespace: System.Data.OleDbOleDbPermissionEnables the .NET Framework Data Provider for OLE DB to help make sure that a user has a security level sufficient to access an OLE DB data source
Namespace: System.NetDnsPermissionControls rights to access Domain Name System (DNS) servers on the network.The default permissions allow all local and Intranet zone applications to access DNS services, and no DNS permission for Internet zone applications.DnsPermission permission = new DnsPermission(PermissionState.Unrestricted); permission.Demand();
ReferencesProgramming .NET Security, OReilly by Adam Freeman, Allen Jones .NET Framework Class Library - System.Security.Permissions Namespace URL: http://msdn.microsoft.com/en-us/library/24ed02w7.aspx.NETFrameworkDeveloper'sGuide - Key Security Concepts URL: http://msdn.microsoft.com/en-us/library/z164t8hs(v=VS.71).aspx