Showing posts with label CAS. Show all posts
Showing posts with label CAS. Show all posts

Sunday, August 2, 2009

Chapter 11-Lesson 2

  • We may use declarative CAS for methods using almost the same approach as used for namespaces.
  • The difference is only in the location where they are declared (ofcourse before a method) and the names of attribute enumerations.
  • Declarative CAS for methods check those mthods for security Permissions which would be calling our method. (refer to Diagram 11-9 and 11-10)
  • SecurityAction.Demand would require every caller in the stack to have enough Permissions, while SecurityAction.LinkDemand only checks the immediate caller for enough Permissions.
  • We may use Imperative CAS demands (i.e. using C# method calls rather than attributes) if we wish to catch the exceptions raised by Demand/DemandLink inour own method. (refer to page 678 code example)
  • If we just wish to pass exception to the caller method (for not having enough Permissions) we may use Declarative CAS.
  • Demand is designed to check an assembly’s caller for permission, not the assembly itself. Instead, use the System.Security.SecurityManager.IsGranted method.
  • Most .NET built-in classes use Demand to ensure that callers have Permissions required to use them, e.g. StreamWriter itself checks for FileIOPermission.
  • SecurityAction.Deny reduces Permission such that it removes Permissions only for the specified set, while SecurityAction.PermitOnly reduces Permission such that it allows only the specified set and nothing else.
  • Deny performs a similar function to RequestRefuse, whereas PermitOnly is similar to RequestOptional.
  • CodeAccessPermission is a class which provides (also all the classes that derive from it) static methods Deny( ), PermitOnly( ), RevertDeny( ) and RevertPermitOnly( ) for imperative method CAS.
  • Best Practice is to use imperative security in error-handling routine, such as in a catch block. Acquire the bare minimum permissions for say, log an event, log it, and finally revert the permission limitation.
  • An assembly decorated with AllowPartiallyTrustedCallers attribute allows partially trusted code to access the assembly.
  • We may call Assert( ) static method only once in a given method, so if we wish to assert multiple Permissions, we'll use Assert on PermissionSet object.

Tuesday, July 28, 2009

Chapter 11-Lesson 1

  • Code Access Security (CAS) may be used by .NET applications to put restriction on code regarding certain actions.
  • An Application is called partially trusted when some kind of CAS is applied on it, others are called fully trusted.
  • Evidence is something that proves as an identity and describes an individual as deserving a certain level of trust.
  • Permissions determine which applications are trusted to what extent.
  • There are 19 pre-defined Permissions in NET 2.0 (pertaining to different areas such as Web Access, Registry Access, File IO Access, etc.)
  • Permission Sets combine a set of Permissions to represent particular level of security e.g. FullTrust, Internet, LocalIntranet, etc.
  • Applications are brought under CAS using Code Groups which define a set of Permissions (and their respective settings/levels).
  • Each Code Group requires an Evidence object. The assemblies that provide a particular Evidence become eligible to Permissions defined by the code group.
  • Code Groups may be nested within one another and therefore may require more than one Evidence. (e.g My_Computer_Zone is a Code Group that requires a Zone:My Computer type of Evidence and grants FullTrust Permissions to assemblies bearing that Evidence.)
  • Nesting one code group into another would result in a Union Code Group with all the Permissions set by both of them.
  • There are four configurable Security Policies (Unions of Code Groups) built-in for .NET applications; Enterprise, Machine, User and Application Domain.
  • However, if an Assembly falls under more than one Security Policy, the CLR uses the most restrictive one.