Subject : JAVA ¾Ïȣȭ ¿¹Á¦

Solution Description:
=====================

applet¿¡¼­´Â ·ÎÄÃÆÄÀϽýºÅÛ¿¡ Á¢±ÙÇÏ´Â°Ô º¸¾ÈÀÇ Ãë¾àÁ¡¶§¹®¿¡ ±ÝÁöµÇ¾îÀÖ´Ù.
±×·¯ÇÑ Á¡À» ±Øº¹Çϱâ À§ÇØ java¿¡¼­´Â ¾Ïȣȭ±â¹ýÀ» »ç¿ëÇÑ´Ù.
±×¸®°í ¾Ïȣȭ ¹× ÀüÀÚ»çÀεîÀº jdk1.1¿¡¼­ Áö¿øÀÌ °¡´ÉÇÏ°Ô µÇ¾ú´Ù.
ÇÊ¿äÇÏ´Ù¸é °ü·Ã tool Áï javakey, jarµîÀÇ ¿É¼ÇµîÀÇ »ó¼¼ÇÑ ¿ë¹ý¿¡ ´ëÇؼ± º°µµÀÇ 
¾ð±ÞÀ» ¾Ê°Ú´Ù.

  - ¸ÕÀú Web Server ¹× jdk1.1.x ȯ°æ »ó¿¡¼­

# Step 1.

javakey -cs Duke true

¸ÕÀú Duke¶ó´Â ÀÓÀÇÀÇ ¹ÏÀ»¸¸ÇÑ È®ÀÎÀÚ(identity)¸¦ »ý¼ºÇÑ´Ù.
±×·¯¸é java home directory¿¡ identitydb.obj¶ó´Â db fileÀÌ »ý¼ºµÈ´Ù.

# Step 2.

javakey -gk Duke DSA 512 Duke_pub Duke_priv

Duke¿¡ ´ëÇÏ¿© °³ÀÎÅ°(private key) ¹× °ø¿ëÅ°(public key)¸¦ »ý¼ºÇÑ´Ù.

# Step 3.

javakey -gc cert_directive_Duke 

ÀÎÁõÈ­Àϸ¦ »ý¼ºÇÑ´Ù.cert_directive_Duke¶ó´Â È­ÀÏÀº ÀÎÁõ¼­¸¦ ¸¸µé¾îÁÖ´Â
templeteÀÌ´Ù. ¿©±â ¿¹¿¡¼­´Â Duke.x509¶ó´Â È­ÀÏÀ» »ý¼ºÇÏ¿´´Ù.

# Step 4.

jar cf signedWriteFile.jar writeFile.class writeFile.html

archive¸¦ »ý¼ºÇÑ´Ù.

# Step 5.

javakey -gs sign_directive_Duke signedWriteFile.jar
mv signedWriteFile.jar.sig signedWriteFile.jar
jar tvf signedWriteFile.jar

»ý¼ºµÈ archive¾Ö ¼­¸íÀ» ÇÑ´Ù. 
sign_directive_DukeÀº ¼­¸í¿¡ °ü·ÃµÈ templete fileÀÌ´Ù.
±×¸®°í ´Ù½Ã .jar È®ÀåÀÚ¸íÀ¸·Î ¹Ù²Ù¾îÁØ´Ù.
´ÙÀ½ ¼­¸íµÈ ¾ÆÄ«À̺êÀÇ ³»¿ëÀ» È®ÀÎÇÑ´Ù.

# Step 6.

javakey -ld

¸¶Áö¸·À¸·Î identity databaseÀÇ ³»¿ëÀ» È®ÀÎÇ϶ó.



  - ´ÙÀ½Àº ´ç½ÅÀÇ ½Ã½ºÅÛ¿¡¼­ À§¿¡¼­ ±â¼úÇÑ web server¿¡ ¾×¼¼½ºÇÏ´Â test ¿¹Á¦.

appletviewer http://www.svc.hei.co.kr/~java/security/writeFile.html ¸¦ ½ÇÇàÇϸé

'writeFile: caught security exception'¿Í °°Àº exception message°¡ ³ªÅ¸³¯ °ÍÀÌ´Ù.

# Step 1.

¸ÕÀú À§¿¡¼­ »ý¼ºµÈ Duke.x509¶ó´Â ÀÎÁõ ÆÄÀÏÀ» ¾ò´Â´Ù.
 
# Step 2.

javakey -c Duke true

Duke¶ó´Â È®ÀÎÀÚ(identity)¸¦ »ý¼ºÇÑ´Ù.

# Step 3.

javakey -ic Duke Duke.x509

Duke.x509¸¦ Duke¶ó´Â identity db¿¡ importÇÑ´Ù

# Step 4.

appletviewer http://www.svc.hei.co.kr/~java/security/signedWriteFile.html

°á°ú¸¦ È®ÀÎÇغ¸¸é ´ç½ÅÀÇ ½Ã½ºÅÛÀÇ /tmp/fooÀÌ ÀÖÀ½À» ¾Ë¼ö ÀÖÀ» °ÍÀÌ´Ù.


  - ´ÙÀ½Àº À§ÀÇ ¿¹Á¦¿¡¼­ »ç¿ëµÈ file ¿¹Á¦µéÀÌ´Ù.

----
. writeFile.java


/**
  * By default, this applet raises a security exception.
  *
  * With JDK 1.1 appletviewer, 
  *  if you configure your system to allow applets signed by "Duke"
  *  to run on your system, then this applet can run and write a file
  *  to your /tmp directory.    (or to the file named "tmpfoo" on a 
  *  Windows system)
  *  
  * @version JDK 1.1
  * @author  Marianne Mueller
  */

import java.awt.*;
import java.io.*;
import java.lang.*;
import java.applet.*;

public class writeFile extends Applet {
    String myFile = "/tmp/foo";
    File f = new File(myFile);
    DataOutputStream dos;

  public void init() {
    
    String osname = System.getProperty("os.name");
    if (osname.indexOf("Windows") != -1) {
      myFile="tmpfoo";
    }
  }

  public void paint(Graphics g) {
	try {
  	  dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(myFile),128));
	  dos.writeChars("Cats can hypnotize you when you least expect it\n");
	  dos.flush();
	  g.drawString("Successfully wrote to the file named " + myFile + " -- go take a look at it!", 10, 10);

	  String name = System.getProperty("user.name");
	  g.drawString("And, successfully got user.name ..." + name, 10, 30);
	}


	catch (SecurityException e) {
	  g.drawString("writeFile: caught security exception", 10, 10);
        }
	catch (IOException ioe) {
		g.drawString("writeFile: caught i/o exception", 10, 10);
        }
   }
}

----
. writeFile.html



 Java Security Example: Writing Files

Java Security Example: Writing Files


Here's an applet that tries to write to the file /tmp/foo on a Solaris system (or to the file named "tmpfoo" on a Windows 95 or Windows NT system.)

Here's the source.

This applet is signed by Duke - if you've configured your system to allow applets signed by Duke to run, go and check your /tmp area! (Or your c: drive, if you're running on a PC.) You'll find a file there named foo, with an important message from Duke :-)


Back to the Java Security Page - Signed Applet Example ---- . cert_directive_Duke # # 96/11/11 @(#)cert_directive 1.3 # # # This is a sample certificate directive file. # # the id of the signer issuer.name=Duke # the cert to use for the signing (this is where it gets it DN) issuer.cert=1 # the id of the subject subject.name=Duke # the components of the X500 name for the subject subject.real.name=Marianne Mueller subject.org.unit=JavaSoft subject.org=Sun MicroSystems subject.country=US # Various parameters: start and end date for validity and expiration # of the certificate. Serial number. FIle to which to output the # certificate (optional). start.date=10 Dec 1996 end.date=1 Sept 1997 serial.number=1001 out.file=Duke.x509 ---- . sign_directive_Duke # # 96/09/22 @(#)sigdir 1.1 # # # Jar signing directive. This is the directive file used by javakey to # sign a jar file. # # Which signer to use. This must be in the system's database. signer=Duke # Cert number to use for this signer. This determines which # certificate will be included in the PKCS7 block. This is mandatory # and is 1 based. cert=1 # Cert chain depth of a chain of certificate to include. This is # currently not supported. chain=0 # The name to give to the signature file and associated signature # block. (i.e. DUKESIGN.SF and DUKESIGN.DSA). This must be 8 # characters or less. signature.file=DukeSig ---- . signedWriteFile.html Java Security Example: Writing Files

Java Security Example: Writing Files


Here's an applet that tries to write to the file /tmp/foo:

and here's the source.

This applet is signed by Duke - if you've configured your system to allow applets signed by Duke to run, go and check your /tmp area! (Or your c: drive, if you're running on a PC.) You'll find a file there named duke.txt, with an important message from Duke :-)


Back to the Java Security Page/a> ---------------------------------------------------------------------------- Revision History ÀÛ¼ºÀÏÀÚ : 97.06.16 ÀÛ¼ºÀÚ : À̹ÎÈ£ ¼öÁ¤ÀÏÀÚ : ¼öÁ¤ÀÚ :