240 likes | 502 Views
Foundations of Java Security. Java Applet Security. 자바 애플릿 보안. What is an Applet?. PIG. PIGLET. APPLE. APPLET. An Applet is a graphical Java program, downloadable over a network, that executes inside a web browser or applet viewer. Applet Security refers to various requirements
E N D
Foundations of Java Security Java Applet Security 자바 애플릿 보안
PIG PIGLET
APPLE APPLET
An Applet is a graphical Java program, downloadable over a network, that executes inside a web browser or applet viewer Applet Security refers to various requirements for securely running Java code downloaded from a network
JDK 1.0 Sandbox approach Trust all standalone Java applications Does not trust any applet downloaded from the network
JDK 1.1 Enhanced the original sandbox approach Trust all standalone Java applications Certain applets can be trusted. Trusted applets are given unrestricted access
JDK 1.2 Method of Least Privilege Specify a security policy that determines what an applet or application is allowed to do based on: • Source • Identities of those who signed it
Example: The ReadFileApplet What it does: • Read C:\autoexec.bat • Display the contents of C:\autoexec.bat • into a text area inside the applet
Java Code import java.applet.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class ReadFileApplet extends Applet { TextArea text = new TextArea(); Button goButton = new Button("Read Local File"); Panel panel = new Panel(); String fileName = ""; public void init() { fileName = getParameter("fileName"); setLayout(new BorderLayout()); goButton.addActionListener(new ButtonHandler()); panel.add(goButton); add("North",panel); add("Center",text); }
class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e){ String s = e.getActionCommand(); if("Read Local File".equals(s)){ try { FileInputStream inStream = new FileInputStream(fileName); int inBytes = inStream.available(); byte inBuf[] = new byte[inBytes]; int bytesRead = inStream.read(inBuf,0,inBytes); text.setText(new String(inBuf)); }catch(Exception ex){ text.setText(ex.toString()); } } } } } // End of Code
HTML Code <HTML> <HEAD> <TITLE>An Applet that reads local files</TITLE> </HEAD> <BODY> <H1>An Applet that reads local files.</H1> <APPLET CODE="ReadFileApplet.class" HEIGHT=300 WIDTH=600> <PARAM NAME="fileName" VALUE="C:\AUTOEXEC.BAT"> Text displayed by browsers that are not Java-enabled. </APPLET> </BODY> </HTML>
3 Steps: • Create the JAR file • Sign the JAR file • Specify the applet security policy
Create the JAR File JAR: Java ARchive The JAR tool provides similar functions to a normal compression utility, except that it makes it more efficient for Java-enabled browsers to load files used by an applet, application or API, by combining multiple files into one JAR file Only one HTTP connection is required Reduces the time to download an applet jar cf rfa.jar ReadFileApplet*.class
Sign the JAR File Important concepts: The keystoreThe keystore is a password-protected database that holds private keys and certificates (located in user.home directory Eg. C:\Windows) Keystore entry A private key and a X.509 certificate chain that authenticates the associated public key keytool –genkey –alias “someone” Enter Passphrase for keystore: 123456 jarsigner rfa.jar “someone” Enter Passphrase for keystore: 123456
Specify the Applet Security Policy Add the following lines to .java.policy (located in java.home\lib\security eg. C:\jdk1.2.2\jre\lib\security\) Keystore “file:/C:/Windows/.keystore”; grant { permission java.io.FilePermission “/AUTOEXEC.BAT”, “read”, signedBy “someone”; };
HTML Code <HTML> <HEAD> <TITLE>An Applet that reads local files</TITLE> </HEAD> <BODY> <H1>An Applet that reads local files.</H1> <APPLET CODE="ReadFileApplet.class" ARCHIVE=“rfa.jar” HEIGHT=300 WIDTH=600> <PARAM NAME="fileName" VALUE="C:\AUTOEXEC.BAT"> Text displayed by browsers that are not Java-enabled. </APPLET> </BODY> </HTML>
Applet Deployment under Java 2 Version 1.2 • By default, the ReadFileApplet generated a security exception • due to the restrictions placed on downloaded code. • We had to create a signed JAR file using our own key pair • To overcome the restrictions placed, we placed • permissions based on the signer. • Finally, we were able to run the code without generating • an exception. • Be aware that to run applet code that is signed from the Internet, • we have to import the public key of the signer into the keystore • and give it privileges before we can run the code.
Evolution to Java 2 Version 1.3 • Every class loaded from a JAR file has a codesource, which contain: • Location (URL) • Certificates • The PluginClassLoader will extract the certificates and pass them to • the browser, which will verify them • If verification is successful, the browser will prompt • the user as follows: • Grant permission for this session • Don’t grant permission • Grant permission always • More information • usePolicy permission: only the permissions specified in the • security policy will be granted, and no prompting will take place
Conclusion Applet security is an integral part in forming a flexible and secure environment to run downloaded code from the Internet