|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
General Java Implementing a Security Policy
Implementing a Security Policy
By: Qusay H. Mahmoud
Aug. 1, 1997 12:00 AM
"Java is the language of network computing," said Lawrence J. Ellison, Chairman and Chief Executive Officer of Oracle Corporation. Basically, there are two main reasons as to why Java is the language of choice for network computing: Security issues are a major concern in every client/server system. This is mainly due to the fact that the client will be interacting directly with the server. Thus, the client will have access to all the resources and the ability to read files from the machine on which the server is running. In order to protect the server's machine from malicious clients' requests, there is a need for devising a security policy that states what the client can and cannot do on the server's machine.
Security in Java This article concentrates on the third layer. For more information on the other two layers, please see references at the end of this article.
The Java Language
The Java Compiler
The Security Manager This is just one kind of malicious instruction that the first two layers do not protect the server's host system against. However, given that Java code will adhere to the restrictions imposed by the Java runtime system, a security policy can be devised and implemented at the application level. This will allow us to state what sort of requests a Java client program can or cannot perform. For example, it will allow us to state if a client is allowed to read the sensitive file "/etc/passwd".
Building a Security Policy The SecurityManager class is an abstract class (non-instantiable) that allows application developers to implement a security policy. The SecurityManager class provides you with a mechanism to establish a specific security policy that is suitable for the level of trust for a particular program. It provides the ability to create objects to determine if an operation that a program may perform is permitted. The SecurityManager class provides many methods for performing acts to enforce a security policy, some of which are shown in Table 1. As you can see in table 1, most of the methods in the SecurityManager class start with the word check. When your application uses one of the Java APIs to perform some tasks (say reading files), the methods that start with the word check are actually called by the Java APIs before performing certain sensitive operations (such as reading, writing or deleting files). If an operation is not allowed, a SecurityException will be thrown. When writing a client/server application, make sure you devise a coherent security policy that states what the client is allowed to do with the server. For example, make sure that the server's machine file system is not at risk when performing clients' requests. Take into account any request that a client may perform. For example, if you are building an HTTP server, you must make sure that clients cannot get the file "etc/passwd" if they request it!
Building a Security Manager
Example DiBella wrote a nice article about how to implement a simple Web server in Java. Having written a Web server myself and taking into account that Security is a state of mind, the first thing I asked myself after reading Joseph's article was: "Is this HTTP server secure?" The answer was no. If you are up for some pure experimentation, try to compile the code and run it. Then, via your favorite Web browser (I use Netscape), try to fetch some documents that the server should not be allowed to ship to clients. For example, on my workstation, I ran the above server and I wanted to see if I could get the password file (which is normally located at /etc/passwd), so I constructed the following URL and gave it to Netscape to fetch: http://myHostName:8080/../../../../../etc/passwd. The HTTP server found the file and shipped it back to the client (Netscape) and I got it displayed on the screen. Note that the number of ".." depends on how far I am from the root directory and the countdown starts from the directory you ran the Web server from.
However, this is not all. A client's request may look like this:
A Security Policy
Building Our SecurityManager It is important to note that when defining a custom security manager, you must override some or all of the permission checking methods depending on the policies enforced by the security manager. By default, all of the methods will simply throw a SecurityException, meaning that the operation is not allowed, with the exception of the checkTopLevelWindow() method which returns a boolean value. It is important to note that when you include a method, such as checkAccess(), with an empty implementation body, as shown in Listing 1, then that means the operation is allowed. If, on the other hand, you would like to allow an operation but in a more restricted form, then you must provide your own implementation. For example, if your security manager allows clients to read files, then it must provide its own implementation for checkRead(), as shown in Listing 1. The implementation provided overrides the existing checkRead(String) and allows the client to read files from the server, provided that the path to the file does not contain ".." and the requested file does not start with a slash.
Installing Our Security Manager System.setSecurityManager(new ServeSecurityManager()); The ServeSecurityManager class, also shown in Listing 1, throws a security exception once a user is trying to read a file they do not have access to. Thus, we need to catch that security exception. This new exception must be caught in the fileOpened() method in the HTTP server code.
Conclusion
References Reader Feedback: Page 1 of 1
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||