Improving the security of the .NET Framework applications by using the .NET Framework 2.0 security features

Improving the security of the .NET Framework applications by using the .NET Framework 2.0 security features

 

Q1: You are developing a class library that will open the network socket

connections to computers on the network. You will deploy the class library

to the global assembly cache and grant it full trust.

You write the following code to ensure usage of the socket connections.

 

SocketPermission permission = new SocketPermission(PermissionState.Unrestricted);

permission.Assert();

 

Some of the applications that use the class library might not have the

necessary permissions to open the network socket connections.

You need to cancel the assertion.

Which code segment should you use?

A. CodeAccessPermission.RevertAssert();

B. CodeAccessPermission.RevertDeny();

C. permission.Deny();

D. permission.PermitOnly();

Answer: A

 

Explanation:

CodeAccessPermission.RevertAssert causes any previous Assert for the current frame to be removed and no longer in effect.

CodeAccessPermission.RevertDeny causes any previous Deny for the current frame to be removed and no longer in effect.

SocketPermission.Deny method prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.

SocketPermission.PermitOnly Prevents callers higher in the call stack from using the code that calls this method to access all resources except for the resource specified by the current instance.

 

Q2: You are developing an application that will use custom authentication

and role-based security. You need to write a code segment to make the

runtime assign an unauthenticated principal object to each running thread.

Which code segment should you use?

 

A. AppDomain domain = AppDomain.CurrentDomain;

domain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

 

B. AppDomain domain = AppDomain.CurrentDomain;

domain.SetThreadPrincipal(new WindowsPrincipal(null));

 

C. AppDomain domain = AppDomain.CurrentDomain;

domain.SetAppDomainPolicy(PolicyLevel.CreateAppDomainLevel());

 

D. AppDomain domain = AppDomain.CurrentDomain;

domain.SetPrincipalPolicy(PrincipalPolicy.UnauthenticatedPrincipal);

 

 

Answer: D

Explanation: PrincipalPolicy.UnauthenticatedPrincipal represents principal and identity objects for the unauthenticated entity should be created. An unauthenticated entity has Name set to the empty string (”") and IsAuthenticated set to false.

 

Q3: You work as a developer at Company.com. You are creating an

assembly named Company1. Company1 contains a public method.

The global cache contains a second assembly named Company2.

You must ensure that the public method is only called from Company2.

Which permission class should you use?

 

 

A. GacIdentityPermission

 

B. PublisherIdentityPermission

 

C. DataProtectionPermission

 

D. StrongNameIdentityPermission

 

Answer: D

Explanation:

GacIdentityPermission defines the identity permission for files originating in the global assembly cache. Files are either in the global assembly cache, or they are not. There are no variations to the permission granted, so all GacIdentityPermission objects are equal.

PublisherIdentityPermission represents the identity of a software publisher.

DataProtectionPermission controls the ability to access encrypted data and memory.

StrongNameIdentityPermission defines the identity permission for strong names.

 

Q4: You are developing a method to hash data with the Secure Hash

Algorithm. The data is passed to your method as a byte array named

message. You need to compute the hash of the incoming parameter by

using SHA1. You also need to place the result into a byte array named

hash. Which code segment should you use?

 

A. SHA1 sha = new SHA1CryptoServiceProvider();

byte[] hash = null;

sha.TransformBlock(message, 0, message.Length, hash, 0);

 

B. SHA1 sha = new SHA1CryptoServiceProvider();

byte[] hash = BitConverter.GetBytes(sha.GetHashCode());

 

C. SHA1 sha = new SHA1CryptoServiceProvider();

byte[] hash = sha.ComputeHash(message);

 

D. SHA1 sha = new SHA1CryptoServiceProvider();

sha.GetHashCode();

byte[] hash = sha.Hash;

 

 

Answer: C

–Nikhil Kumar

For all dumps just visit and please leave your precious comments on it...
www.dotnetask.blog.co.in