BLOG ARTICLE Java | 2 ARTICLE FOUND

  1. 2008/03/25 Java Security Model
  2. 2008/03/19 자바 디버깅 방법

사용자 삽입 이미지
▶ JDK1.0 Security Model - Sandbox Model
JVM에 ClassLoader 객체는 사용되어지는 class file을 Memory로 Loading하는 작업을 한다.
Applet을 실행 시키는 JVM은 classpath(Browser내에 내장된 class Library)에서 Loading한 class와 외부로 부터 downloading한 class의 Naming Space를 다르게 관리를 한다.
외부로 부터 downloading된 class, 즉 Untrusted Code는 SecurityManager객체에 의해 활동이 제한이 되어 진다.
JDK1.0 Security Model은 Sandbox Model이라고 하는데, Untrusted Code에 대해서는 Naming Space를 다르게 관리 함으로써, SecurityManager객체에 의해 활동이 제한되는 Sandbox라는 Boundary 영역내에서만 활동하는 구조를 말한다.


▶ JDK1.1 Security Model - Sandbox Model + Signed Applet
JDK1.1 Security Model은 1.0의 Sandbox Model에 Signed 개념이 추가가 되었다.
Untrusted Code가 Sign만 되면, Sandbox boundary를 벗어나 local의 classpath에서 loading된 class처럼 활동할 수 있다. SecurityManager 객체의 제한은 않받는다는 것이지요.
지금 현재의 Browser는 JDK1.1의 Security Model을 사용하고 있다.


▶ JDK1.2 Security Model - Sandbox Model + Protection Domain
JDK1.2 Security Model은 JDK1.1 Security Model(Sandbox + Signed)에 Protection Domain개념을 추가시킨 구조이다.
1.1 version에서 Signed code는 1.2 version에서 Domain
으로 관리가 되고, 각 Domain별로 Sandbox boundary를 다르게 설정할 수가 있어, Sandbox boundary가 Domain별로 가변적이라는 특성을 갖게 된다.
Domain은 Signer와 Codebase에 의해 결정이 되고, client의 policy file에 각 Domain이 활동 가능한 Sandbox boundary를 설정하게끔 되어있다.
JDK1.2 version에서는 jdk1.2\jre\lib\security\ directory에 java.security file은 master security properties file을 제공하는데, 이것은 Security에 관련된 Configuration file이다. 이 file내에 Domain의 활동 영역을 설정하는 policy file을 지정할 수 있는 부분이 있다.

 # The default is to have a single system-wide policy file,
 # and a policy file in the user's home directory.
 policy.url.1=file:${java.home}/lib/security/java.policy
 policy.url.2=file:${user.home}/.java.policy
 # User Policy File
 policy.url.3=file:/D:/javaLab/signedApplet1.2/MyPrint.jp
 
 java.home : jre directory
 java.policy file : System policy file
 .java.policy file : user default policy file(c:\windows\ 생성)
 MyPrint.js file : user define policy file
java.policy file은 JDK1.2 version, JRE1.2 version을 Installation하면 ~jre/lib/security/ 자동 생성되고, .java.policy file은 c:\windows directory에 필요하다면 생성 할 수가 있다.
policy file은 editor tool로 작성가능하지만, JDK에서 제공하는 policytool로 edit하는 것이 편리하다. 일단 System policy file인 java.policy file의 내용은 아래와 같다.

// Standard extensions get all permissions by default

grant codeBase "file:${java.home}/lib/ext/-" {
 permission java.security.AllPermission;
};

// default permissions granted to all domains
// 모든 domain에 대해 System properties를 read 할 수 있는 permission을 설정하고 있다.
grant {
 // Allows any thread to stop itself using the java.lang.Thread.stop()
 // method that takes no argument.
 // Note that this permission is granted by default only to remain
 // backwards compatible.
 // It is strongly recommended that you either remove this permission
 // from this policy file or further restrict it to code sources
 // that you specify, because Thread.stop() is potentially unsafe.
 // See "
http://java.sun.com/notes" for more information.
 permission java.lang.RuntimePermission "stopThread";

 // allows anyone to listen on un-privileged ports
 permission java.net.SocketPermission "localhost:1024-", "listen";

 // "standard" properies that can be read by anyone

 permission java.util.PropertyPermission "java.version", "read";
 permission java.util.PropertyPermission "java.vendor", "read";
 permission java.util.PropertyPermission "java.vendor.url", "read";
 permission java.util.PropertyPermission "java.class.version", "read";
 permission java.util.PropertyPermission "os.name", "read";
 permission java.util.PropertyPermission "os.version", "read";
 permission java.util.PropertyPermission "os.arch", "read";
 permission java.util.PropertyPermission "file.separator", "read";
 permission java.util.PropertyPermission "path.separator", "read";
 permission java.util.PropertyPermission "line.separator", "read";

 permission java.util.PropertyPermission "java.specification.version", "read";
 permission java.util.PropertyPermission "java.specification.vendor", "read";
 permission java.util.PropertyPermission "java.specification.name", "read";

 permission java.util.PropertyPermission "java.vm.specification.version", "read";
 permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
 permission java.util.PropertyPermission "java.vm.specification.name", "read";
 permission java.util.PropertyPermission "java.vm.version", "read";
 permission java.util.PropertyPermission "java.vm.vendor", "read";
 permission java.util.PropertyPermission "java.vm.name", "read";
};
 
위의 내용은 보면, jre\lib\ext\ directory에서 loading된 class는 AllPermission을 갖는다. 즉 SecurityManager의 제한이 없다는 것을 의미한다. 그리고, 두번째 항목은 모든 Domain에 대해 System.getProperty("java.version") method를 통해 System Property를 read할 수 있는 Permission을 설정한 사항이다.
policytool을 이용해 위와 같은 내용으로 Domain별 Sandbox boundary를 설정한 file을 생성할 수가 있고, 그 file을 JVM이 loading될때 policy file로 인식하게 하기 위해 java.security file에 설정할 수가 있다.

크리에이티브 커먼즈 라이센스
Creative Commons License
2008/03/25 09:04 2008/03/25 09:04

사용자 삽입 이미지
본격적인 자바 프로그램에 앞서 미리 익혀야 할 사항은 디버깅 방법입니다.  디버깅없는 프로그램은 한마디로 무기없이 전쟁터에 나가는 것과 같습니다.  특히 자바를 소개하는 대부분의 지면에서 디버거 사용에 소홀한 것 같습니다.

 따라서 이번 기회에 확실히 자바 디버깅 방법을 익히도록 합니다.

디버거 컴파일 옵션
먼저 자바 디버깅을 위해 사용자는 -g 옵션을 주어 컴파일해야 합니다.

% javac -g HelloWorld.java [ 유닉스 ]

c:\> javac -g HelloWorld.java [ PC ]

애플릿뷰어 디버거 옵션
HelloWorld.html 파일의 자바 애플릿에 대해 디버거를 사용하기 위해
다음과 같이 애플릿 뷰어를 실행시킨다.

% appletviewer -debug HelloWorld.html


자바 디버거 명령어 이해
다음은 실제 HelloWorld.html 이라는 애플릿을 디버깅하면서
자바 디버깅시 필요한 명령어를 익혀본다.

- 디버거를 구동합니다.

% appletviewer -debug HelloWorld.html

Initializing jdb...
0xee311280:class(sun.applet.AppletViewer)

 

- 디버거에서 제공하는 명령어에 무엇이 있는지 조회하기 위해 help를 입력해본다.
다음과 같이 명령어와 해당 명령어의 설명이 출력된다.
> help
** command list **

threads [threadgroup] -- list threads
thread  -- set default thread
suspend [thread id(s)] -- suspend threads (default: all)
resume [thread id(s)] -- resume threads (default: all)
where [thread id] | all -- dump a thread's stack
threadgroups -- list threadgroups
threadgroup  -- set current threadgroup

print  [id(s)] -- print object or field
dump  [id(s)] -- print all object information
locals -- print all local variables in current stack frame classes -- list currently known classes

methods  -- list a class's methods
stop in . -- set a breakpoint in a method
stop at : -- set a breakpoint at a line
up [n frames] -- move up a thread's stack
down [n frames] -- move down a thread's stack
clear : -- clear a breakpoint
step -- execute current line
cont -- continue execution from breakpoint

catch  -- break for the specified exception
ignore  -- ignore when the specified exception
list [line number] -- print source code
use [source file path] -- display or change the source path
memory -- report memory usage
gc -- free unused objects
load classname -- load Java class to be debugged

run  [args] -- start execution of a loaded Java class
!! -- repeat last command
help (or ?) -- list commands
exit (or quit) -- exit debugger

이 명령어중 자주 사용하는 중요한 것은 다음과 같습니다.
- threadgroups , 현재 수행중인 뜨레드 그룹의 목록을 보여준다.
> threadgroups
1. (java.lang.ThreadGroup)0xee3000b8 system
2. (java.lang.ThreadGroup)0xee300aa8 main

threads, 수행중인 모든 스레드의 목록을 보여준다.
> threads

Group system:
1. (java.lang.Thread)0xee3001f8 clock handler cond.
2. (java.lang.Thread)0xee3002a0 Idle thread runni
3. (java.lang.Thread)0xee300318 Async Garbage Collector cond.
4. (java.lang.Thread)0xee300370 Finalizer thread cond.
5. (java.lang.Thread)0xee300a18 Debugger agent runni
6. (sun.tools.debug.BreakpointHandler)0xee30f708 Breakpoint handler cond.
Group main:
7. (java.lang.Thread)0xee3000a0 main suspended

>
run , 애플릿뷰어를 수행시켜준다.
> run
run sun.applet.AppletViewer HelloWorld.html
running ...

main[1] threads
Group sun.applet.AppletViewer.main:

1. (sun.awt.motif.InputThread)0xee313090 AWT-Input running

2. (java.lang.Thread)0xee3130b8 AWT-Motif cond. waiting

3. (sun.awt.ScreenUpdater)0xee300858 Screen Updater cond. waiting

Group group applet-HelloWorld.class:

4. (java.lang.Thread)0xee312f40 class cond. waiting

main[1] exit

pid 1247 status 0

Received sigchild for 1247 exit=0

% exit

stop , breakpoing 지정
% appletviewer -debug HelloWorld.html

Initializing jdb...
0xee311280:class(sun.applet.AppletViewer)
stop in HelloWorld.paint
Breakpoint set in HelloWorld.paint

run
run sun.applet.AppletViewer HelloWorld.html
running ...
main[1]

Breakpoint hit: HelloWorld.paint (HelloWorld:10)

list , 현재 수행중인 소스코드의 breakpoing를 보여준다.
AWT-Motif[1]

AWT-Motif[1] list

6 int i;
7
8 public void paint(Graphics g)
9 {
10 => i = 10;
11 g.drawString("Hellow world!" , 25 , 25);
12 }
13 }
14

where , 현재 실행 스택을 보여준다.
AWT-Motif[1] where

[1] HelloWorld.paint (HelloWorld:10)
[2] sun.awt.motif.MComponentPeer.paint (MComponentPeer:122)
sun.awt.motif.MComponentPeer.handleExpose (MComponentPeer:246)
 
use , 자바가 소스파일을 찾기위한 경로를 보여준다. 기본적으로 CLASSPATH가 사용된다.
AWT-Motif[1] use
.:/usr/local/httpd/java/lib/classes.zip:/usr/local/httpd/java/bin
/../classes:/usr/local/httpd/java/bin/../lib/classes.zip:/usr/local/httpd/java/bin/../bin/
../classes:/usr/local/httpd/java/bin/../bin/../lib/classes.zip

dump , 객체에 대한 정보를 얻을 때 사용된다.
AWT-Motif[1] dump g

g = (sun.awt.motif.X11Graphics)0xee310d58 {
int pData = 1476744
Color foreground = (java.awt.Color)0xee300300
Font font = (java.awt.Font)0xee300268
int originX = 0
int originY = 0
Image image = null
}

step , 현재 소스코드중 한 라인만을 수행합니다.
AWT-Motif[1] step
AWT-Motif[1]
Breakpoint hit: HelloWorld.paint (HelloWorld:11)

AWT-Motif[1] list
7
8 public void paint(Graphics g)
9 {
10 i = 10;
11 => g.drawString("Hellow world!" , 25 , 25);
12 }
13 }
14

 

load 클래스이름 , 해당 클래스를 로드해준다.
> load HelloWorld
0xee310ea8:class(HelloWorld)
memory , 사용중인 메모리의 상황을 보여준다.
main[1] memory
Free: 577856, total: 1048568

gc , 사용하지 않은 객체를 프리해준다.
main[1] gc
main[1] memory
Free: 578904, total: 1048568


2001-06-20

크리에이티브 커먼즈 라이센스
Creative Commons License
2008/03/19 16:28 2008/03/19 16:28