|
Security and Mobile Code tutorial
IntroductionAs discussed in the lecture stream, security is a major concern in modern distributed systems particularly with the increasingly open nature of the Internet, coupled with emerging capabilities such as mobile code. Java is fairly unique in the programming language domain by making security an integral part of the language design. This practical session will examine the nature of security support in Java.
For further information on Java security and ongoing developments in this fast evolving area, please refer to the links found in: Java security links.
Java security actually covers a series of diverse areas, including authentication, access control (authorisation), confidentiality, containment, etc. We look at the key features below.
Security in JavaOverview
Java's approach to security is based on the concept of the sandbox. The sandbox is actually a set of cooperating system components that together offer the desired level of security. Effectively, the sandbox restricts the scope of executing code; Java programs execute in the protected environment of the sandbox and do not have the capability to cause damage outside this sandbox.
In more detail, the sandbox consists of 3 key components:
We examine each in turn below.
The Class Loader
The class loader in Java provides the capability to fetch code from a remote machine. Crucially, however, this loader enforces a strict security model, providing a first line of defence against attack. The class loader achieves this by enforcing a namespace hierarchy. A Java namespace is divided into local and remote classes, with remote classes again being divided according to the level of trust in the source. This is depicted below:
|
|
For more information read the following links: |
All the systems you have implemented so far have executed within the same directory, to avoid dealing with security issues. However, in a distributed environment it is unlikely that users will execute the client from the same directory as the server. Therefore, this task illustrates how to run an application across different directories and machines.
Follow the steps described to make the Shares Service execute across different directories:
|
|
You will receive an error message - " |
The error message means that the client was unable to find and download the stub class from its current location, because no security manager was in place to control the access. There are two ways to solve this problem: (1) copy the class file to the client directory, or (2) add a security manager to your code. The second is the preferred solution in a distributed environment and therefore, will be demonstrated next.
|
|
|
![]() |
To find out more about using the security manager and policy files:
1. Security, Overview of Security in JDK 1.2 2. Policy Files in JDK 1.2 |
Presently, it is possible for any client to call any of the methods available from the Share service. Your task is to ensure that only authentic users are allowed to add new shares to the remote service. To do this you must add a simple authentication protocol that is utilised when a client attempts to add a share. You may implement any authentication protocol that you feel is suitable, however, the following pseudocode is given as a sample (N.b. it is not a completely secure method and should not be treated as such).
Pseudocode for simple authentication
Additions to the server side:
String getTicket(ID){
// Test to see if the ID exists - throw exception if doesn't
if (listOfUsers contains(ID)) throw new RemoteException("User does not exist");
//retrieve Private key of user
Key = ListofUsers(ID).key
// Encrypt the sent Authentication code with the local server key (hint: reuse - caesar)
TempTicket = Encrypt(ID, Server_Key);
// Encrypt the encrypted message with the user's private key and return it to them
return Encrypt(TempTicket, Key);
}
// Decrypt ticket
String User = Decrypt(Ticket, Server_Key);
//The decrypted ticket should hold an ID - test to see if it is an authentic user
if (ListOfUsers doesn't contain User) throw new RemoteException("Unauthorised User");
// Otherwise Add new share
....
Additions to the client side: