| By Maha Sengottiyan | Article Rating: |
|
| December 8, 2008 06:30 PM EST | Reads: |
5,149 |
<jsp:plugin type="applet" codebase="/appletclasslocation/"
code="org.identity.protection.DataDownloader.class"
jreversion="1.4"
name="safeguard" align="top" width="550" height="350">
<jsp:params>
<jsp:param name="scriptable" value="true" />
<jsp:param name="MAYSCRIPT" value="true" />
<jsp:param name="archive" value="<%=str%>" />
<jsp:param name="Java_archive" value="<%=str%>" />
</jsp:params>
<jsp:fallback>Unable to start Java plug-in for applet.
</jsp:fallback>
</jsp:plugin>
By setting the MAYSCRIPT attribute to true, the applet can access the JavaScript functions on the page, which gives your applet more flexibility.
Stepping Out of the Sandbox: What, Why, and How
The security manager acts as a guard in the JVM. Its job is to prevent access to resources that aren't authorized by the system to the JVM. The security manager would allow the process to access the resources provided it is given the proper privileges.
Listing 3 is an example applet and it fails do the job it's intended do because it can't step out of the sandbox.
You're coding an applet to be used as part of a Web application. In your code you're saving data to the file system. Do you know if this works? You deploy the application and try to test your applet and it fails. It didn't work because you violated Java security by trying to access the client file system. This is when you need a way to step out of the sandbox to perform this operation.
Listing 4 shows the stack trace of the exception that caused the applet to fail to save a file on the client system.
Stepping out of the sandbox involves making your applet code-trustworthy. What does this really means? It means packaging the applet code in a .jar file and signing the JAR using a code-signing certificate from a trusted authority before putting it on the wire for the client.
When the user gets to the page where the applet is coded to run, he will be prompted to give the applet access to step out of the sandbox. Since the code is signed, the user will see the certificate and the origin information of the applet.
Signing the Java Code: Why and How
One reason to sign the Java code is to ensure the origin of the applet for the user. It also means the binary code isn't tampered with in transition or in other ways.
A signed applet can access the client system resources if the user accepts the signer's certificate.
The signing process involves requesting a certificate from a trusted third-party source like VeriSign and using it to sign the code.
Signing Java code involves these steps:
- Obtaining a code-signing certificate
- Importing the certificate into the key store
- Signing the Java code and archive it using a sign tool
Code-Signing Certificate: What and Why
A code-signing certificate is a file issued by an authorized third-party company, such as VeriSign and Thawte, certifying the company to which they issued the certificate.
Companies issuing code-signing certificates take steps to ensure the authenticity of the company to which they issue the certificate.
Some of the things that certificate companies do to validate a company or entity are:
- They ask for the DUNS number in the certificate request. Dun and Bradstreet (D&B) is a company that provides business information for credit, marketing, and purchasing decisions. Its "data universal numbering system," known as a DUNS, issues unique nine-digit numbers used by businesses and the federal government to keep track of more than 70 million businesses worldwide.
- They ask for the organizational contact other than the person requesting the certificate. Phone verification is done through that contact.
Figure 2 shows a VeriSign Class 3 code-signing certificate. As you can see it's valid for 10 years from the date of issue. VeriSign offers you the option of buying code-signing certificates with longer validity.
Why do you need to buy a certificate. Why can't I use one I generate myself?
It's because VeriSign and other well-known companies are trusted entities that most people know and can trust. You can't trust a self-generated certificate.
As you can see from the certificate in Figure 2, it makes sure the entity or company to which it is issued is legal and authentic.
Process of Getting a Code-Signing Certificate: How
These are the steps involved in creating a certificate:
- Using the keytool, a utility that comes with the JDK from Sun Microsystems, generate a CSR file. CSR stands for certificate-signing request.
- Then submit the CSR file to your preferred certificate vendor.
- Get the signed certificate from the vendor.
- Import the certificate into your keystore. Now you're ready to use your certificate to sign Java code.
Automating Code-Signing Process Using Ant: Why and How
The Java code that runs an applet will change. That means every time you have to compile or make a JAR you have to sign it and then deploy it with your Web application.
It makes perfect sense to automate the process of compiling the applet code, making the JAR, and then signing the JAR. This way any code changes in the applet are automatically incorporated in the application.
See Listing 3 for an Ant build target that makes and signs the JAR. This target uses JDK 1.4 jarsigner. As you can see this target also verifies the JAR after signing.
Summary
This article took you on a journey where I hope you have learned how you can make an applet step out of the sandbox. It also discussed code-signing certificates and how to automate the process of signing the code using an Ant build.
Stepping out of the sandbox methodology is useful in advanced web applications. It allows access to client resources so users have a better experience with web application.
References
- Lesson: API and Tools Use for Secure Code and File Exchanges
- Code Signing for Digital IDs - VeriSign
Published December 8, 2008 Reads 5,149
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Maha Sengottiyan
Maha Sengottiyan is a manager of software engineering for TriZetto. He has been working with Java technology for the last 8 years. Maha holds an MS in computer science and engineering and has the following certifications: PMP (Project Management Professional), SCEA (Sun Certified Enterprise Architect), SCBCD, SCWCD, SCJP and Microsoft Certified Professional (MCP).
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- How PowerBuilder Got Its Groove Back
- The Cloud Has Cross-Border Ambitions
- Ulitzer Named "New Media" Partner of Greatly Anticipated iStrategy Event in Berlin
- Risks and Enterprise Mobility?
- Steps for Success in Enterprise Mobility?
- Are Mobile Luddites Resisting Mobility?
- Hot Event in Santa Clara Becomes Cool with the iPhone
- The Difference Between Web Hosting and Cloud Computing
- Sybase CTO to Speak at 4th International Cloud Computing Expo
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- Five Reasons to Choose a Private Cloud
- Seeding The Cloud: The Future of Data Management
- The Threat Behind the Firewall
- Economy Drives Adoption of Virtual Lab Technology
- Tips for Efficient PaaS Application Design
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- The Top 250 Players in the Cloud Computing Ecosystem
- Custom Common Dialogs Using SetWindowsHookEx
- DDDW Tips and Tricks
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form
- Book Excerpt: Sybase Adaptive Server Anywhere
- Sybase ASE 12.5 Performance and Tuning
- Working with SOA & Web Services in PowerBuilder
- Office 2003 Toolbar: A New Look For Your Old PowerBuilder App
- Dynamically Creating DataWindow Objects
































