Docsity

Java Security - Java and the Web - Lecture Slides, Slides of Java Programming

Partial preview of the text

Download Java Security - Java and the Web - Lecture Slides and more Slides Java Programming in PDF only on Docsity!

Java Security

Overview of Java Security features

Java Technology uses three mechanisms to ensure safety.

  • Language design features(bounds checking on arrays,legal type conversions etc).
  • An access control mechanism that controls what the code can do(file access, network access etc).
  • Code signing: code authors can use standard cryptographic algorithms to authenticate java programming language code. Users of the code can determine who created the code and whether the code is altered or not after it was signed.

Byte Code Verifier

Checks a classfile for validity:

  • Code should have only valid instructions and register use.
  • Code does not overflow/underflow stack.
  • Does not convert data types illegally.
  • Accesses objects correct types.
  • Method calls use correct number and types of

parameters.

  • References to other classes use legal names.

Class Loaders

  • Is an important link in security chain and loads java byte codes into the JVM.
  • It works in conjunction with the security manager and access controller to enforce security rules.
  • It is involved in enforcing some security decisions earlier in an objects lifetime than the security manager.
  • Information about the URL from which the code is originated and the code’s signers is initially available to the ClassLoader.

Code Source

  • Java Code is downloaded over a network, so the code's

signature and author are critical to maintain a secure environment.

  • The object java.security.CodeSource describes a piece of

code.

  • CodeSource encapsulates the code's origin, which is

specified as an URL.

  • Set of digital certificates containing public keys

corresponding to the set of private keys are used to sign the code

Security Policy Files

• SecureClassLoader assigns permissions when

loading classes, by asking policy object to look

up the permissions for the code source of

each class.

• Own Policy class can be installed to carry out

mapping from code sources to permissions.

Security Policy Files

Policy files can be installed in standard locations and the two default locations are

  • The file java.policy in the java platform home directory.
  • The file .java.policy in the user home directory.

The locations of these files in the java.security configuration files can be changed

Security Policy Files

  • During testing standard files are not modified and hence policy file is required for each application.
  • For this purpose place permissions into a separate file such as MyApp.policy and start the interpreter as java –Djava.security.policy=MyApp.policy MyApp For applets appletviewer –J-Djava.security.policy=MyApplet.policy MyApplet.html

Security Policy Files

  • Policy file contains a sequence of grant entries. Each entry has

the following form. grant codesource { permission_1; permission_ ……….. }

  • The code source contains a code base and the names of trusted certificate signers.
  • The code base is specified as Codebase “url”

Security Policy Files

• If the code base url ends with a /, it refers to a

directory, otherwise it is taken as a JAR file.

grant codebase “www.horstmann.com/classes/”{…} grant codebase “www.horstmann.com/classes/MyApp.jar” {…}

• The code base is an url and should always

contain forward slashes as file separators,

even for url’s in windows.

Permission Subclasses

File permission class.

  • Gives rights to local files/directories.
  • Path name/pattern.

Specific path:file,directory,directory/file.

All files in directory: directory/*.

All files recursively in directory: directory/-.

For current directory, omit "directory/."

For all files (dangerous), "<>."

  • Rights set (1+): read,write,execute,delete.

Socket Permission

  • Host.

Local Machine: "local host." Given machine: IP address or hostname. All hosts in a domain: *.domain. All hosts: *.

  • Portrange.

Single port: portnumber. Port range: port1-port2, port1-,-port2.

  • Actions(1+): accept,connect,listen,resolve.

Other Permission SubClasses

  • Runtime Permission: string with permission name
    • createClassLoader
    • getClassLoader
    • setSecurityManager
    • exitVM

Policy Files for Homework

  • On your homework assignments, you will want to think about permissions for the client and server, and make sure you give permissions for both the host name or IP address and the port number. You may also need access to ports on the local host to access utilities like HTTP for an applet. Example: grant { permission java.net.SocketPermission "afs1.njit.edu:1950-2000","connect,accept,resolve"; permission java.net.SocketPermission "afs1.njit.edu:80","connect"; };