영구 객체의 보안
BlackBerry Device Software는 영구 저장소에 있는 객체를 보호하기 위한 두 가지 주요 방법을 제공합니다.
- net.rim.device.api.system.ControlledAccess 클래스와 코드 서명 키를 갖는 객체에 대한 액세스를 제한
- net.rim.device.api.system.PersistentContent 클래스를 갖는 객체를 암호화 및 암호 해독
프로그램의 필요에 따라 두 방법을 모두 사용하거나, 한 방법만 사용하거나, 모두 사용하지 않을 수 있습니다.
영구 객체에 대한 액세스 제한
영구 저장소를 사용하여 저장된 객체는 원시 유형 long의 값을 가진 고유 키로 확인됩니다. 영구 저장소에서 객체를 읽어들이려면 저장할 때 객체와 연결된 키가 메소드 호출에서 제공되어야 합니다. 예를 들면 다음과 같습니다.
long key = 0x52834c0559055c3L; PersistentObject rec = PersistentStore.getPersistentObject(key); String stored_value = (String) rec.getContents();
알려지지 않은 키 값에 의존하는 것은 저장된 정보에 적절한 개인 정보를 제공하지 않을 수 있습니다. 프로그램 데이터에 승인된 특정 프로그램만 액세스하도록 허용하려면 net.rim.device.api.system.ControlledAccess 클래스 안에 PersistentObject를 래핑해서 키 생성 및 키 서명 절차와 함께 사용해야 합니다.
- BlackBerry Signing Authority Tool을 사용하여 서명 키를 만듭니다.
- 서명 키를 ControlledAccess 객체와 연결합니다.
- PersistentObject를 ControlledAccess 객체에 래핑합니다.
- 데이터를 보호하는 동일한 서명 키를 사용하여 보호된 데이터에 액세스를 필요로 하는 프로그램에 서명합니다.
ControlledAccess 클래스로 보호된 데이터를 읽어들이는 방법의 예는 다음과 같습니다.
long key = 0x52834c0559055c3L;
try {
PersistentObject rec = PersistentStore.getPersistentObject(key);
int moduleHandle = ApplicationDescriptor.currentApplicationDescriptor().getModuleHandle();
CodeSigningKey codeSigningKey = CodeSigningKey.get( moduleHandle, "MDW" );
String b = (String) rec.getContents( codeSigningKey );
Dialog.inform("Read PersistentObject. Value="+b);
} catch (ControlledAccessException e) {
Dialog.alert("ControlledAccessException - not authorised to read this data");
}
영구 객체에 대한 액세스를 제한하는 방법에 대한 자세한 내용은 승인되지 않은 프로그램의 영구 객체 액세스 방지를 참조하십시오.
코드 서명에 대한 자세한 정보는 BlackBerry Java SDK 보안 개발 가이드(www.blackberry.com/go/devguides에서 제공)를 참조하십시오.
코드 샘플
다음 코드의 .cod 파일은 데이터를 보호하기 위해 CodeSigningKey로 사용된 키를 사용하여 서명되어야만 합니다.
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.CodeSigningKey;
import net.rim.device.api.system.ControlledAccess;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.*;
public class ControlledAccessCreator extends UiApplication {
public static void main(String[] args) {
ControlledAccessCreator cac = new ControlledAccessCreator();
cac.enterEventDispatcher();
}
private ControlledAccessCreator() {
ControlledAccessCreatorScreen screen = new ControlledAccessCreatorScreen();
pushScreen(screen);
}
}
class ControlledAccessCreatorScreen extends MainScreen {
private MenuItem _initialiseMenuItem = new MenuItem("Initialise", 100, 10) {
public void run() {
String a = "Hello";
long key = 0x52834c0559055c3L;
PersistentObject rec = PersistentStore.getPersistentObject(key);
int moduleHandle = ApplicationDescriptor.currentApplicationDescriptor().getModuleHandle();
CodeSigningKey codeSigningKey = CodeSigningKey.get( moduleHandle, "MDW" );
rec.setContents(new ControlledAccess(a,codeSigningKey));
rec.commit();
String b = (String) rec.getContents( codeSigningKey );
Dialog.inform("Initialised... now try to acccess the data from another app");
invalidate();
}
};
ControlledAccessCreatorScreen() {
setTitle(new LabelField("ControlledAccess Demo",
LabelField.USE_ALL_WIDTH));
addMenuItem(_initialiseMenuItem);
}
public boolean onSavePrompt() {
return true;
}
public void close() {
super.close();
}
}
다음 코드의 .cod 파일은 위 샘플 코드에 사용된 키를 사용하여 서명되어야만 합니다.
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.CodeSigningKey;
import net.rim.device.api.system.ControlledAccess;
import net.rim.device.api.system.ControlledAccessException;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.*;
public class ControlledAccessAuthorisedUser extends UiApplication {
public static void main(String[] args) {
ControlledAccessAuthorisedUser caau = new ControlledAccessAuthorisedUser();
caau.enterEventDispatcher();
}
private ControlledAccessAuthorisedUser() {
ControlledAccessAuthorisedUserScreen screen = new ControlledAccessAuthorisedUserScreen();
pushScreen(screen);
}
}
class ControlledAccessAuthorisedUserScreen extends MainScreen {
private MenuItem _readMenuItem = new MenuItem("Read protected data", 100, 10) {
public void run() {
long key = 0x52834c0559055c3L;
try {
PersistentObject rec = PersistentStore.getPersistentObject(key);
int moduleHandle = ApplicationDescriptor.currentApplicationDescriptor().getModuleHandle();
CodeSigningKey codeSigningKey = CodeSigningKey.get( moduleHandle, "MDW" );
String b = (String) rec.getContents( codeSigningKey );
Dialog.inform("Read PersistentObject. Value="+b);
} catch (ControlledAccessException e) {
Dialog.alert("ControlledAccessException - not authorised to read this data");
}
}
};
ControlledAccessAuthorisedUserScreen() {
setTitle(new LabelField("ControlledAccess Demo",
LabelField.USE_ALL_WIDTH));
addMenuItem(_readMenuItem);
}
public boolean onSavePrompt() {
return true;
}
public void close() {
super.close();
}
}