Docsity

Java Applet Security: Protecting Users from Malicious Code, Slides of Java Programming

Partial preview of the text

Download Java Applet Security: Protecting Users from Malicious Code and more Slides Java Programming in PDF only on Docsity!

Applet Security

What is Applet Security?

  • One of the most important features of Java is its security model.

It allows untrusted code, such as applets downloaded from arbitrary web sites, to be run in a restricted environment that prevents that code from doing anything malicious, like deleting files or sending fake email.

  • Applet security is implemented to protect users from

unknowingly loading a malicious program that can be hidden on a Web page.

What Applets can do? (contd.)

• Applets that are loaded from the local file

system (from a directory in the user's

CLASSPATH) have none of the restrictions that

applets loaded over the network do.

• Although most applets stop running once you

leave their page, they don’t have to.

What Applets cannot do?

• An Applet cannot load libraries or define

native methods.

• It cannot ordinarily read or write files on the

host that’s executing it.

• It cannot make network connections except to

the host that it came from.

Trusted and Untrusted Applets

In Java-enabled web browsers, untrusted applets cannot read or write files at all. By default, downloaded applets are considered untrusted. There are two ways for an applet to be considered trusted:

  • The applet is installed on the local hard disk, in a directory on the CLASSPATH used by the program that you are using to run the applet.
  • The applet is signed by the identity marked as trusted in your identity database.

Local and Signed Applets

  • Local Applets

When an applet is loaded from the local file system, instead of through a network protocol, web browsers and applet viewers may relax some, or even many, of the restrictions mentioned in the previous slides. The reason for this is that local applets are assumed to be more trustworthy than anonymous applets from the network.

Applet Class Loader

  • Applets loaded over the net are loaded by the applet class loader. For example, the appletviewer's applet class loader is implemented by the class sun.applet.AppletClassLoader.
  • The class loader enforces the Java name space hierarchy. It guarantees that a unique namespace exists for classes that come from the local file system, and that a unique namespace exists for each network source.

Applet Class Loader (contd.)

• Classes loaded by the class loader are passed

through the verifier. The verifier ensures that:

  • There are no stack overflows or underflows.
  • All register accesses and stores are valid.
  • The parameters to all byte code instructions are

correct.

  • There is no illegal data conversion.

Security Manager (contd.)

The Security Manager has the following duties:

  • Prevent installation of new class loaders.
  • Protect threads and thread groups from each other.
  • Control the execution of other application programs.
  • Control the ability to shut down the VM.
  • Control access to other application processes.

Security Manager (contd.)

  • Control access to system resources such as print queues, clipboards, event queues, system properties, and windows.
  • Control file system operations such as read, write, and delete. Access to local files is strictly controlled.
  • Control network socket operations such as connect and accept.
  • Control access to Java packages (or groups of classes), including access to security enforcement classes.

Writing a Security Manager

(contd.)

  • To write your own security manager, you must create a subclass of the SecurityManager class. Your SecurityManager subclass overrides various methods from SecurityManager to customize the verifications and approvals needed in your Java application.
  • Detailed instructions about writing a security manager can be found at: http://java.sun.com/docs/books/tutorial/essential/system/wri tingSMgr.html

Installing the Security Manager

  • Once you've completed writing your SecurityManager subclass, you can install it as the current security manager for your Java application. You do this with the setSecurityManager() method from the System class.
  • The detailed instructions about installing a security manager can be found at: http://java.sun.com/docs/books/tutorial/essential/system/ins tallSMgr.html

Allowing an Applet to read a

file (contd.)

  • For example, to allow any files in the directory home/me to be read by applets loaded into the appletviewer, add this line to your ~/.hotjava/properties file. acl.read=/home/me
  • Use " : " to separate entries: acl.read=/home/foo:/home/me/somedir/somefile Note: Allowing an applet to read a directory means that it can read all the files in that directory, including any files in any subdirectories.

Allowing an Applet to write a file

  • Applets loaded into a Java-enabled browser can't write files.
  • Sun's appletviewer allows applets to write files that are

named on the access control list for writing. The access control list for writing is empty by default.

  • You can allow applets to write to your /tmp directory by

setting the acl.write property in your ~/.hotjava/properties file: