security in .net framework
TRANSCRIPT
welcome
.Net Security Issues
By :-
Amit Kumar Garg
Introduction
What is Security ?What is Cryptography?What are typical Aspects of Security?Why Security is Important ?How the .NET Framework Simplifies
Security?How do we Implement Security in .NET?
Typical Hazards
Leakage of Private Information. Unauthorized Access. Critical Data get Tempered Malicious code / Viruses can Attack. Secrete Information get destroyed.
Why Security is Important?
Typical Aspects of Security
Secrecy Whenever sensitive information must be protected from
being known by other people.
Authentication To know exactly whom you are communicating with.
Why Security is Important?
Integrity To know that the communicated information you send or
receive cannot be somehow manipulated or corrupted during transit or after receipt.
Non-Repudiation The possibility of someone reneging on an agreement that
you have already made with him or her.
What Security Can Do ?
Privacy of information Information privacy can be used to limit access to authorized users by
means of encryption.
Authentication of usersUser authentication can be used to ensure that users are who they claim to be, by means of password hash comparison or digital signature verification.
Integrity of informationInformation integrity can be used to ensure that only
authorized users can create or modify information based on digital signature verification.
What Security Can Do ?
Non-Repudiation of agreementNon -repudiation can be used to ensure that the author of a message cannot, after the fact, deny the existence of the message or abrogate an agreement defined in the message that he or she has digitally signed.
Access control of resourcesAccess control can be used to ensure that access to information resources are limited in specified ways to authorized users only.
Availability of serviceAvailability of service relates to how available a given server application is when needed.
What Security Can Not Do ?
Protection form Human ErrorsExposing keysPoor choice of passwordNot encrypting data
Poor software design and coding bugs
Inexperience and misplaced trust
Security features provided by .NET Framework
Evidence and security policy configuration administrative control over .NET security
Code Access Security Execution control based on evidence and security policy
Role-based Security Access control based on user identity and Role membership
Managed code Runtime verificationAddress range checking and Type checking
Application domainslightweight execution isolation
Cryptography classes Access to powerful cryptographic algorithms
Cryptography
Symmetric Cryptography
Example
The One-Time Pad cipher
Asymmetric Cryptography
Example
RSA (Rivest, Shamir, and Adelman)Assume that the random values for the primes p and q have been chosen as
p = 47 , q = 73
Then the product n of these two primes is calculated:
n = (p · q) = 3431
The Euler totient for these two primes is found easily using the following formula:
= (p – 1) · (q – 1) = 3312
Now that we have n and , we should discard p and q, and destroy any trace of their existence.
Now we randomly select a number e that is greater than 1, less than n.Assume that we choose the following value for e:
e = 425
Then the modular inverse of e is calculated to be the following:
d = 1769 (provided that d.e = 1(mod
We now keep d private and make e and n public.
Example
Encryption :-Assume that we have plaintext data represented by the following simple number:
plaintext = 707
The encrypted data is computed by c = me (mod n) as follows:
e = 425 and n = 3431 ( Public Key )
ciphertext = 707^425(mod 3431) = 2142
Decryption :-Using the secret Private Key d = 1769
Then the plaintext is easily retrieved using m = c d(mod n) as follows:
plaintext = 2142^1769(mod 3431) = 707
Code Access Security
Defines permissions and permission sets Enables administrators to configure security policy Enables code to request the permissions it requires in
order to run Grants permissions to each assembly that is loaded Enables code to demand that its callers have specific
permissions. Enforces restrictions on code at run time .
Security Stack Walk
Code Groups
Membership Conditions Zone – The region from which the code Originated Site – The web site from which the code originated. Strong Name – A unique, verifiable name for the code. Publisher – The Publisher of the code. URL – The specific location from which the code originated. Hash value – The hash value for the assembly. Application directory – The location of the assembly within the
application All Code – All code fulfills this condition. Custom – A user-specified condition.
Code Groups
Code Group : All CodePermission : NothingMembership Condition: All Code
Code Group : IntranetPermission : LocalIntranetMembership Condition: Zone
Code Group : My ComputerPermission : FullTrustMembership Condition: Zone
Code Group : IntranetPermission : IntranetMembership Condition: Zone
Code Group : http://intranet/Permission : FullTrustMembership Condition: Site
Code Group : Microsoft Corp.Permission : FullTrustMembership Condition: Publisher
Code Access Security Policy Tool
Run caspol.exe (Code Access Security Policy Tool)•To Find out all possible options of caspol.exe
caspol.exe -?
•To Check the security policy of your PC
caspol.exe -listdescription > c:\caspol.txt
•To Check the code Access Groups
caspol.exe –listgroups
•To shutdown/start security check while runtime
caspol.exe –execution on|off
•To View the code group of an assembly
caspol.exe –resolvegroup assembly.dll
.NET Security Programming
• Demanding PermissionsFileIOPermission fileioperm = new FileIOPermission(FileIOPermissionAccess.AllAccess,@"c:\" );
fileioperm.Demand();
• Requesting Permissions.using System.Security.Permissions;
[assembly:UIPermissionAttribute(SecurityAction.RequestMinimun, Unrestricted =true)]
• Denying Permissions.CodeAccessPermission permission = new
FileIOPermission(FileIOPermissionAccess.AllAccess,@"c:\");
permission.deny();
• Asserting Permissions.
Role-Based Security
Roles The Role represents the set of activity user can perform according to the
privileges assigned to group to which it belongs.
Identity Object The identity object encapsulates information about the user or entity
being validated. Identity objects contain a name and an authentication type.
Principal ObjectThe principal object represents the security context under which code is running. Applications that implement role-based security grant rights based on the role associated with a principal object.
Role-Based Security
Perform the following tasks to create an instance of the GenericPrincipal class.
1 . Create a new instance of the identity class and initialize it with the name you want it to hold. The following code creates a new GenericIdentity object and initializes it with the name MyUser. GenericIdentity MyIdentity = new GenericIdentity("MyUser");
2. Next, create a new instance of the GenericPrincipal class and initialize it with the previously created GenericIdentity object and an array of strings that represent the roles that you want associated with this principal. The following code example specifies an array of strings that represent an administrator role and a user role. The GenericPrincipal is then initialized with the previous GenericIdentity and the string array. String[] MyStringArray = {"Manager", "Teller"};GenericPrincipal MyPrincipal = new GenericPrincipal(MyIdentity, MyStringArray);
3. Finally, use the following code to attach the principal to the current thread. This is valuable in situations where the principal must be validated several times, it must be validated by other code running in your application, or it must be validated by a PrincipalPermission object. You can still perform role-based validation on the principal object without attaching it to the thread. For more information, see Replacing a Principal Object. Thread.CurrentPrincipal = MyPrincipal;
Strong Naming Assemblies
Assemblies Verification. Temper proofing assembly. Delay signing. Securing Libraries.
Strong Naming Assemblies
1. First generate a public/private key pairsn -k MyKeyPair.snk
2. Extracts the public key from MyKeyPair.snk and places it into MyPublicKey.snk.sn -p MyKeyPair.snk MyPublicKey.snk
3. Now sign a DLL or an EXE assembly with MyPublicKey.snk
using Assembly Linker utility Al.exe.al /out:WalkingThruEvidence.exe /keyfile:MyKeyPair.snk
4. Finally the following code to the source file named AssemblyInfo.cs,[assembly:AssemblyKeyFileAttribute(@"...\MyKeyPair.snk ")]
Any Questions !
?
Thank You !