App Safer iOS SDKの適用ガイド
App Safer iOSは、NAVERクラウドプラットフォームが提供するモバイルセキュリティソリューションとして、モバイル機器やサービスへの脅威になる行為を検知するAPIを提供します。iOS用のApp Saferライブラリは一つのフレームワークとして構成されており、Bitcode Enable/Disable環境の両方をサポートします。
App Safer iOSの機能
- Jailbreak検知
- Simulator検知
- Debugging検知
- Memory Tampered検知
- Unauthorized Signature検知
App Safer iOSのサポート環境
ファイル名 | OSバージョン |
---|---|
AppSaferFramework.framework | iOS 8.0以上 |
App Safer iOS SDKの適用ガイド
AppSaferFrameworkを適用する方法は次のとおりです。
ビルドの推奨環境は、Xcode 8.0以上です。
AppSaferFramework.frameworkをプロジェクトの最上段に位置付けます。
プロジェクト設定でGeneral > Frameworks, Libraries, and Embedded Contentにすべてのフレームワークを追加します。
- AppSaferFramework.framework及び下位フォルダ内のフレームワーク(Nelo2SDK、CrashReporter)
- Bitcode Enableバージョンの場合、Build Settings > Enable Bitcodeを「Yes」に設定します。
- Bitcode Disableバージョンの場合、Build Settings > Enable Bitcodeを「No」に設定します。
(任意事項) Build Settings > Framework Search PathsをAppSaferFramework.frameworkファイルのあるパスに設定します。
App Safer iOS のAPIリスト
クラス名 | API名 | APIの説明 |
---|---|---|
AppSafer |
- (int) initAppSafer:(id serviceCode:(NSString *)serviceCode key:(NSString *)appsaferKey |
App Saferを使用するために初期化 |
- (int)checkTampering | リアルタイムセキュリティ検知
|
|
- (int)setUserId:(NSString *)userId | ユーザーIDを設定 |
Delegate名 | 必須有無 | API名 | APIの説明 |
---|---|---|---|
AppSaferDelegate | Required | - (void)appSaferDidInitFinish:(NSUInteger)result msg:(NSString *)message | App Saferの初期化結果を受け取る |
Required | - (void)appSaferDidCheckTamperingFinish:(int)result | checkTampering関数の実行が完了すると結果を転送 | |
Optional | - (void)appSaferDetectedJailbreak | Jailbreakが検知された時点で呼び出し | |
Optional | - (void)appSaferDetectedSimulator | Simulatorが検知された時点で呼び出し | |
Optional | - (void)appSaferDetectedDebugging | Debuggingが検知された時点で呼び出し | |
Optional | - (void)appSaferDetectedMemoryTampered | Memory Tamperedが検知された時点で呼び出し |
App Safer iOS APIの説明
- (int) initAppSafer:(id)delegate serviceCode:(NSString )serviceCode key:(NSString )appsaferKey
App Saferを使用するために初期化します。ログの伝送に必要な情報及びグローバル変数として使われる変数を初期化します。
- App SaferのすべてのAPIは、initAppSafer()の呼び出しに成功した場合に使用できます。
- 初期化の成功有無を受け取るには、AppSaferDelegateを実装する必要があります。
パラメータ
パラメータ | 説明 |
---|---|
delegate | AppSaferDelegateが実装されたインスタンス |
serviceCode | App Saferサービスを利用するためのコード NAVERクラウドプラットフォームのユーザーは必ず「ncloud」を転送する必要がある |
appsaferKey | コンソールでアプリの登録時に作成されたappsaferKey値 |
戻り値
戻り値 | 説明 |
---|---|
SUCCESS(0) | 成功 |
FAIL(-1) | 失敗 |
例
#import <AppSaferFramework/AppSaferFramework.h>
@implementation ViewController
- (IBAction)initAppSafer:(id)sender {
AppSafer *appSafer = [[AppSafer alloc] init];
int res = FAIL;
if(appSafer != nil) {
// APP_SAFER_KEY generated when registering an app to the Console
res = [appSafer initAppSafer:self serviceCode:@"ncloud" key:"<APP_SAFER_KEY>"];
NSLog(@"initAppSafer result %d", res);
if(res == SUCCESS) {
// init success
} else if(res == FAIL) {
// init fail
}
} else {
NSLog(@"AppSafer is nil");
}
}
- (int)checkTampering
リアルタイムセキュリティ検知(Jailbreak検知、Simulator検知、Debugging検知、Memory Tampered検知、Unauthorized Signature検知)を行います。 検査結果を受け取るには、AppSaferDelegateを設定する必要があります。
戻り値
戻り値 | 説明 |
---|---|
SUCCESS(0) | 検査開始成功 |
FAIL(-1) | 検査開始失敗 |
BLOCK(2) | セキュリティポリシーの違反により遮断 |
BEFOREINIT(3) | App Saferが初期化されていない |
例
#import <AppSaferFramework/AppSaferFramework.h>
@implementation ViewController
- (IBAction)checkAppSafer:(id)sender {
AppSafer *appSafer = [[AppSafer alloc] init];
if(appSafer != nil) {
int res = [appSafer checkTampering];
switch(res) {
case FAIL:
NSLog(@"Failed to check tampering");
break;
case SUCCESS:
NSLog(@"Check Tampering Success");
break;
case BLOCK:
NSLog(@"Device is blocked");
break;
case BEFOREINIT:
NSLog(@"AppSafer is not initialized");
break;
}
} else {
NSLog(@"AppSafer is nil");
}
}
@end
- (int)setUserId:(NSString *)userId
初期化及び検知イベントの発生時にApp Saferサーバに伝送されるログにユーザーIDを含む場合に設定します。
パラメータ
パラメータ | 説明 |
---|---|
userId | 設定するユーザー識別子 |
戻り値
戻り値 | 説明 |
---|---|
SUCCESS(0) | 設定成功 |
FAIL(-1) | 設定失敗 |
例
#import <AppSaferFramework/AppSaferFramework.h>
@implementation ViewController
- (IBAction)setUserId:(id)sender {
AppSafer *appSafer = [[AppSafer alloc] init];
if(appSafer != nil) {
NSLog(@"setUserId text %@", [self.useridText text]);
int res = [appSafer setUserId:[self.useridText text]];
switch(res) {
case FAIL:
NSLog(@"Failed to set userId");
break;
case SUCCESS:
NSLog(@"setUserId Success");
break;
}
} else {
NSLog(@"AppSafer is nil");
}
}
App Safer iOSのコールバック関数に関する説明
App Saferの検査関数はすべて非同期で動作し、結果の処理はAppSaferDelegateを通じて委任されます。
もし検査結果の受け取りを希望する場合、App Saferにより提供されるAppSaferDelegateを実装し、initAppSafer()関数を用いて登録する必要があります。
- (void)appSaferDidInitFinish:(int)result
initAppSafer()関数を呼び出した後、初期化が完了したら結果を転送します。
パラメータ
パラメータ | 説明 |
---|---|
SUCCESS(0) | 初期化成功 |
FAIL(-1) | 初期化失敗 |
BLOCK(2) | セキュリティポリシーの違反により遮断 |
例
#import <AppSaferFramework/AppSaferFramework.h>
@implementation ViewController
- (void)appSaferDidInitFinish:(NSUInteger)result msg:(NSString *)message {
NSLog(@"appSaferDidInitFinish result %d", result);
if(result == BLOCK) {
NSLog(@"Device is blocked!");
// add to exit application logic
}
}
- (void)appSaferDidCheckTamperingFinish:(int)result
checkTampering関数を呼び出した後、検査が完了したら検査結果を転送するために呼び出されます。
パラメータ
パラメータ | 説明 |
---|---|
FAIL(-1) | 検査失敗 |
SAFE(0) | イベント未検知 |
DETECT(1) | イベント検知 |
BLOCK(2) | 遮断 |
例
#import <AppSaferFramework/AppSaferFramework.h>
@implementation ViewController
- (void)appSaferDidCheckTamperingFinish:(int)result {
NSLog(@"appSaferDidCheckTamperingFinish result %@",
result == FAIL ? @"FAIL" :
result == SAFE ? @"SAFE" :
result == DETECT ? @"DETECT" :
result == BLOCK ? @"BLOCK": @"UNKNOWN");
if(result == BLOCK) {
NSLog(@"Device is blocked!");
// add to exit application logic
}
}
- (void)appSaferDetectedJailbreak
checkTampering()関数を呼び出した後、脱獄が検知される時点で呼び出されます。
checkTampering()関数の動作が完了していない場合でも、結果の受け取りを希望する場合に使用します。
例
#import <AppSaferFramework/AppSaferFramework.h>
@implementation ViewController
- (void)appSaferDetectedJailbreak {
NSLog(@"[DETECT] appSaferDetectedJailbreak");
}
- (void)appSaferDetectedSimulator
checkTampering()関数を呼び出した後、仮想マシンが検知される時点で呼び出されます。
checkTampering()関数の動作が完了していない場合でも、結果の受け取りを希望する場合に使用します。
例
#import <AppSaferFramework/AppSaferFramework.h>
@implementation ViewController
- (void)appSaferDetectedSimulator {
NSLog(@"[DETECT] appSaferDetectedSimulator");
}
- (void)appSaferDetectedDebugging
checkTampering()関数を呼び出した後、デバッギングが検知される時点で呼び出されます。
checkTampering()関数の動作が完了していない場合でも、結果の受け取りを希望する場合に使用します。
例
#import <AppSaferFramework/AppSaferFramework.h>
@implementation ViewController
- (void)appSaferDetectedDebugging {
NSLog(@"[DETECT] appSaferDetectedDebugging");
}
- (void)appSaferDetectedMemoryTampered
checkTampering()関数を呼び出した後、メモリ偽造が検知される時点で呼び出されます。
checkTampering()関数の動作が完了していない場合でも、結果の受け取りを希望する場合に使用します。
例
#import <AppSaferFramework/AppSaferFramework.h>
@implementation ViewController
- (void)appSaferDetectedMemoryTampered {
NSLog(@"[DETECT] appSaferDetectedMemoryTampered");
}
App Safer iOS Use Case
初期化
#import <AppSaferFramework/AppSaferFramework.h>
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
AppSafer *appSafer = [[AppSafer alloc] init];
int res = FAIL;
if(appSafer != nil) {
// APP_SAFER_KEY generated when registering an app to the Console
res = [appSafer initAppSafer:self serviceCode:@"ncloud" key:"<APP_SAFER_KEY>"];
NSLog(@"initAppSafer result %d", res);
if(res == SUCCESS) {
// init success
} else if(res == FAIL) {
// init fail
}
} else {
NSLog(@"AppSafer is nil");
}
}
- (void)appSaferDidInitFinish:(NSUInteger)result msg:(NSString *)message {
NSLog(@"appSaferDidInitFinish result %d", result);
if(result == BLOCK) {
NSLog(@"Device is blocked!");
// add to exit application logic
}
}
リアルタイムセキュリティ検知
@implementation ViewController
- (IBAction)checkAppSafer:(id)sender {
AppSafer *appSafer = [[AppSafer alloc] init];
if(appSafer != nil) {
int res = [appSafer checkTampering];
switch(res) {
case FAIL:
NSLog(@"Failed to check tampering");
break;
case SUCCESS:
NSLog(@"Check Tampering Success");
break;
case BLOCK:
NSLog(@"Device is blocked");
break;
case BEFOREINIT:
NSLog(@"AppSafer is not initialized");
break;
}
} else {
NSLog(@"AppSafer is nil");
}
}
- (void)appSaferDidCheckTamperingFinish:(int)result {
if(result == BLOCK) {
[self.msgbox setText:@"Device is blocked!"];
// add to exit application
}
NSLog(@"appSaferDidCheckTamperingFinish result %@",
result == FAIL ? @"FAIL" :
result == SAFE ? @"SAFE" :
result == DETECT ? @"DETECT" :
result == BLOCK ? @"BLOCK": @"UNKNOWN");
}
- (void)appSaferDetectedJailbreak {
NSLog(@"[DETECT] appSaferDetectedJailbreak");
}
- (void)appSaferDetectedSimulator {
NSLog(@"[DETECT] appSaferDetectedSimulator");
}
- (void)appSaferDetectedDebugging {
NSLog(@"[DETECT] appSaferDetectedDebugging");
}
- (void)appSaferDetectedMemoryTampered {
NSLog(@"[DETECT] appSaferDetectedMemoryTampered");
}
参考事項
本商品は、グローバルリージョンサービスとしても提供されています。
関連情報に移動する
下記のガイドから関連情報を確認できます。