Java Security: David A. Wheeler
Java Security: David A. Wheeler
David A. Wheeler
[email protected] (703) 845-6662 April 24, 2000
Outline
Java Basics
Whats Java, Modes of Use, major components, implications, implementations, politics
Security-related capabilities (JDK 1.0, 1.1, 1.2) Selected upcoming developments Miscellaneous
Past breaches, malicious applets, advantages & disadvantages, key points
April 12, 2012 (C) 1999-2000 David A. Wheeler 2
Whats Java?
Java Technologies:
Java language Virtual machine (VM)/class file format Libraries Source code Compiler
Can use only VM or language Developed by Sun Not related to Javascript Cross-Platform (WORA)
(C) 1999-2000 David A. Wheeler
Class files
Libraries
Virtual Machine
3
User
Developer
Java Language
Modern object-oriented (OO) language
OO with single inheritance + multiple interfaces Classes grouped into hierarchical packages Strong static typing (no arbitrary pointers) Automatic garbage collection Exceptions Multithreaded
Before execution, VM usually runs bytecode verifier to check legality of class file
April 12, 2012 (C) 1999-2000 David A. Wheeler 6
Java Libraries
Set of built-in APIs, including:
GUIs Networking Computation
10
Microsoft
Intentionally polluted with incompatible unmarked extensions to fool developers into unportable code Sun sued & won court injunction partly forbidding this
Sun
Promised to support standardization (they have before) Customers trusted Sun & committed major resources Sun flirted with ISO & ECMA, then halted cooperation Greatly angered users: Sun lied Linux port taken without warning or acknowledgement Suddenly charged royalties on enterprise edition, even to those who had partially funded its development
(C) 1999-2000 David A. Wheeler 11
User best interests not in Sun/Microsoft interests To avoid total dependence on a capricious vendor:
Consider open source, Linux, standardized languages
April 12, 2012 (C) 1999-2000 David A. Wheeler 12
Security-Related Capabilities (1 of 2)
JDK 1.0 (Fall 1995)
Policy: Sandbox for applets; others unlimited Mechanisms: SecurityManager, Bytecode verifier, Classloader
Security-Related Capabilities (2 of 2)
Netscape & Microsoft Extensions
Enabled more flexible approaches Incompatible with each other and with Sun
SecurityManager
Class defines check methods called by system
E.G. checkRead(String filename) Method throws exception if invalid
Bytecode Verifier
Checks a classfile for validity:
Code only has valid instructions & register use Code does not overflow/underflow stack Does not convert data types illegally or forge pointers Accesses objects as correct type Method calls use correct number & types of arguments References to other classes use legal names
ClassLoader
Responsible for loading classes
given classname, locates/generates its definition always looks at standard classes first every class has a reference to the classloader instance that defined it keeps namespaces of different applets separate (different ClassLoader instances) each ClassLoader instance ~ OS process CLASSPATH classes trusted in JDK 1.0-1.1, system classes trusted, otherwise invokes bytecode verifier
April 12, 2012 (C) 1999-2000 David A. Wheeler 18
Manifest
In file META-INF/MANIFEST.MF Lists (some) JAR filenames, digests, digest algorithm(s) (MD5, SHA)
Signatures
Separate manifest-like file, separate signature
April 12, 2012 (C) 1999-2000 David A. Wheeler 19
20
Netscape Extensions
Navigator 4.0 added Capabilities API:
Call to request privilege enable (string) If not been granted before, UI asks if ok Privilege disabled when method returns, but can be reenabled without UI Can disable or revert, can select which certificate to use
Microsoft Extensions
Used CAB not JAR for signatures (incompatible) IE 3.0: Selected signed applets trusted IE 4.0: Fine-grained Trust-Based Security
User defines zones (stnd: Local, intranet, trusted sites, Internet, untrusted sites) Each zone given privileges; standard privilege sets: High, Medium (UI file I/O), Low security CAB file includes privilege request; query if beyond preapproved set (& okay with admin)
Permissions
Read/write file /home/daw/stocks Connect/accept bankofamerica.com ports 1-1023 Read file /home/daw/logo.png
(not required)
25
Class1 Instance1
...
1
Class2
...
Instance2
Asks
ClassLoader1
April 12, 2012
Policy
26
ProtectionDomain Class
ProtectionDomain class
Created from a CodeSource and a PermissionCollection Defines the set of permissions granted to classes; change the PermissionCollection to change permissions Each class belongs to ONE ProtectionDomain instance, set at class creation time (and never changed again) Access to these objects restricted; getting its reference requires RuntimePermission getProtectionDomain
CodeSource Class
Created from:
a source (base) URL and array of certificates
28
Policy Class
Provides interface to user policy
Given a CodeSource, returns a PermissionCollection Used during setup of ProtectionDomain to set a class permissions
29
Context
getContext() takes a snapshot of current execution context (stack trace)
snapshot includes ancestor threads stored in type AccessControlContext results can be stored & can used later to limit privileges (instead of enabling all privileges)
Algorithm Implications
Default privileges are the intersection (minimum) of all class permissions in call tree
Without doPrivilege, permissions only decrease
Permission Class
Permission class
Encapsulates a permission granted or requested Can be set readonly (from then on immutable) Can be grouped using classes PermissionCollection and Permissions
Portrange
Single port: portnumber Port range: port1-port2, port1-, -port2
Target
Specific property: os.name Pattern: java.*
39
SecurityManager Changes
New method checkPermission(P)
Throws exception if permission P not held, else returns All previous check methods rewritten in terms of checkPermission Permits creation of new Permissions without changing SecurityManager
41
GuardedObject (1 of 3)
To protect one method in all instances, use SecurityManager directly as shown so far To protect a reference to an individual instance, consider using GuardedObject:
requesting class
getObject()
1 3
reply with object-toguard
GuardedObject 2
checkGuard()
object-to-guard
Guard
(C) 1999-2000 David A. Wheeler 42
GuardedObject (2 of 3)
GuardedObject class encapsulates object-to-guard
asks Guard interface to determine if access ok Permission implements Guard by calling SecurityManager. checkPermission(self) PermissionCollection doesnt implement (Ive reported)
GuardedObject (3 of 3)
Clients who wish to use object-to-guard call GuardedObjects getObject()
GuardedObject instance calls its Guards checkGuard() if ok, object-to-guards reference returned if not ok, security exception thrown
44
46
48
Invasion of Privacy Annoyance: constant sound Flashing display (causes seizures in some users) Steal CPU cycles (e.g. crack encryption)
(C) 1999-2000 David A. Wheeler 50
Java Advantages
Permits controlled execution of less trusted code (vs. ActiveX) Permits fine-grained permission control Attention paid to security Portability Instant installation Suns source reviewable (not open source)
51
Many internal interdependencies (vs. reference monitors); often breaks all the way Complex dependencies on other systems
OS, browsers, network (DNS), PKI
April 12, 2012 (C) 1999-2000 David A. Wheeler 52
54
Key Points
Progression of Access Control Flexibility
JDK 1.0: Sandbox + total trust of local applications JDK 1.1: Above + optional total trust with signature SDK 1.2: Above + Fine-grained access control
Java 2 ProtectionDomains
Checks call tree, by default intersection of permissions doPrivilege permits permissions to be re-enabled
Useful References
Li Gong, Inside Java 2 Platform Security, 1999, Palo Alto, CA: Addison-Wesley. G. McGraw & E. Felten, Java Security: Hostile Applets, Holes, and Antidotes, 1997, NY: John Wiley & Sons. G. McGraw & E. Felten, Securing Java: Getting Down to Business with Mobile Code, 1999, NY: John Wiley & Sons, http://www.securingjava.com
April 12, 2012 (C) 1999-2000 David A. Wheeler 56
Useful Websites
Suns Java website: http://java.sun.com Existing Java programs/info available at:
http://www.gamelan.com http://www.jars.com (Java Applet Rating Service)
57
Backup Slides
59
Application
April 12, 2012
API
SPI
Service
60
61