Chapter Three Java - Security
Chapter Three Java - Security
Java security
Outline
components of Java
Java security models
main components of the Java security architecture
– class loaders
– byte code verification
– the Security Manager
2
Components of Java
the development environment
development lifecycle
Java language features
class files and byte-code
the execution environment
the Java Virtual Machine (JVM)
interfaces and architectures
e.g., Java beans, RMI(Remote Interface), JDBC, etc.
Components of Java
3
Components of Java / The Development Environment Development lifecycle
Java Java
compiler
source code bytecode
programmer
notes
Java is a high-level programming language
source code is English-like (syntax is similar to C)
Java is compiled and interpreted
• source code is compiled into byte-code (low-level, platform independent code)
• Byte-code is interpreted (real machine code produced at run time)
fast and portable (“write once run anywhere”)
dynamic linking (no link phase at compile time)
• program consists of class definitions
• each class is compiled into a separate class file
• classes may refer to each other, references are resolved at run-time
4
Java language features
object-oriented
Components of Java / The Development Environment
multi-threaded
strongly typed
exception handling
very similar to C/C++, but cleaner and simpler
no more struct and union
no more (stand alone) functions
no more multiple inheritance
no more operator overloading
no more pointers
garbage collection
objects no longer in use are removed automatically from memory
5
Class files
contain
Components of Java / The Development Environment
6
The Java Virtual Machine (JVM)
JVM
Components of Java / The Execution Environment
trusted classes
native method native method Security
native methods loader area Manager
operating system
native code
Java code
7
JVM cont’d
class loaders
– locate and load classes into the JVM
Components of Java / The Execution Environment
9
JVM cont’d
Security Manager
– enforces access control at run-time (e.g., prevents applets from reading or
Components of Java / The Execution Environment
10
Java security models
the need for Java security
the sandbox (Java 1.0)
the concept of trusted code (Java 1.1)
fine grained access control (Java 2)
Java security models
11
The need for Java security
code mobility can be useful (though not indispensable)
– may reduce bandwidth requirements
– improve functionality of web services
but downloaded executable content is dangerous
– the source may be unknown hence untrusted
– hostile applets may modify or destroy data in your file system
– hostile applets may read private data from your file system
– hostile applets may install other hostile code on your system (e.g., virus,
back-door, keyboard sniffer, …)
– hostile applets may try to attack someone else from your system (making you
Java security models
12
The sandbox
idea: limit the resources that can be accessed by applets
JVM
remote code
(applets)
resources
13
The concept of trusted code
idea: applets that originate from a trusted source could be trusted
JVM
local code
resources
Java security models
policy
file
resources
Java security models
– introduced in Java 2
– a protection domain is an association of a code source and the permissions granted
– the code source consists of a URL and an optional signature
– permissions granted to a code source are specified in the policy file
grant CodeBase “http://java.sun.com”, SignedBy “Sun” {
permission java.io.FilePermission “${user.home}${/}*”, “read, write”;
permission java.net.SocketPermission “localhost:1024-”, “listen”;};
15
The three pillars of Java security
the Security Manager
class loaders
the bytecode verifier
Components of the Java security architecture
16
The Security Manager
ensures that the permissions specified in the policy file are not
overridden
implements a checkPermission() method, which
Components of the Java security architecture
18
Class loaders
separate name spaces
– classes loaded by a class loader instance belong to the same name space
– since classes with the same name may exist on different Web sites, different
Components of the Java security architecture
Web sites are handled by different instances of the applet class loader
– a class in one name space cannot access a class in another name space
classes from different Web sites cannot access each other
establish the protection domain (set of permissions) for a loaded
class
enforce a search order that prevents trusted system classes from
being replaced by classes from less trusted sources
– see next two slide …
19
Class loading process
when a class is referenced
JVM: invokes the class loader associated with the requesting program
class loader: has the class already been loaded?
Components of the Java security architecture
– yes:
• does the program have permission to access the class?
– yes: return object reference
– no: security exception
– no:
• does the program have permission to create the requested class?
– yes:
» first delegate loading task to parent
» if parent returns success, then return (class is loaded)
» if parent returned failure, then load class and return
– no: security exception
20
Class loading task delegation
3 4b failure
2 5b success / failure
1
class request
21
Byte code verifier
performs static analysis of the bytecode
– syntactic analysis
• all arguments to flow control instructions must cause branches to the start of a
valid instruction
Components of the Java security architecture
22
Comparison with ActiveX
ActiveX controls contain native code
security is based on the concept of trusted code
– ActiveX controls are signed
– if signer is trusted, then the control is trusted too
– once trusted, the control has full access to resources
not suitable to run untrusted code
– no sandbox mechanism
23
Thank you
End of Chapter Three
any Q.
24