LoginSignup
1
0

More than 1 year has passed since last update.

Android HMS端末にインストールされたアプリのセキュリティを確認する方法

Posted at

HMS端末にインストールされたアプリに悪意があるアプリが含まれているかどうかを検出する方法を紹介します。

利用ライブラリ

Safety Detect

対応端末

すべてのHMS端末

対応OS

EMUI 5.0以上

実装手順

前準備

(1) Huaweu Developerを登録します。

(2) AppGallery Connectでアプリのプロジェクトを登録します。
スクリーンショット 2020-10-01 155726.png
スクリーンショット 2020-10-01 155747.png
スクリーンショット 2020-10-01 155822.png
スクリーンショット 2020-10-01 155911.png
スクリーンショット 2020-10-01 155946.png

(3) keytoolで生成したSHA256をAppGallery Connectのアプリプロジェクトに登録します。
スクリーンショット 2020-10-01 160111.png

(4) agconnect-services.jsonをダウンロードし、appフォルダに配置します。
スクリーンショット 2020-10-01 161111.png
スクリーンショット 2020-10-01 162011.png

(5) Safety Detectを有効にします。
スクリーンショット 2020-10-01 160111.png

HMS SDKを導入

(1) プロジェクトのbuild.gradleを開き、mavenとclasspathを追加します。
スクリーンショット 2020-10-01 162820.png

build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()

        // こちらの行を追加
        maven {url 'http://developer.huawei.com/repo/'}
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // こちらの行を追加
        classpath 'com.huawei.agconnect:agcp:1.3.1.300'
    }
}

allprojects {
    repositories {
        google()
        jcenter()

        // こちらの行を追加
        maven { url 'http://developer.huawei.com/repo/' }
    }
}

(2) モジュールのbuild.gradleを開き、次のようにを追加します。
スクリーンショット 2020-10-01 162842.png

build.gradle
plugins {
    id 'com.android.application'
    id 'kotlin-android'

    // こちらの行を追加
    id 'com.huawei.agconnect'
}

android {
    // signingConfigsを追加
    signingConfigs {
        debug {
            storePassword 'My password'
            keyAlias 'My keyAlias'
            keyPassword 'My password'
            storeFile file('My keystore file.jks')
            v1SigningEnabled true
            v2SigningEnabled true
        }
        release {
            storePassword 'My password'
            keyAlias 'My keyAlias'
            keyPassword 'My password'
            storeFile file('My keystore file.jks')
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }

    buildTypes {
        release {
            // signingConfigを追加
            signingConfig signingConfigs.release

            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

        debug {
            // signingConfigを追加
            signingConfig signingConfigs.debug

            debuggable true
        }
    }

    buildFeatures {
        dataBinding true
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    // こちらの1行を追加
    implementation 'com.huawei.hms:safetydetect:6.3.0.301'
}

(3) proguard-rules.proを開き、次のようにを追加します。
スクリーンショット 2020-10-01 162901.png

proguard-rules.pro
-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.huawei.hianalytics.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}

ライブラリの使用

private fun getMaliciousApps() {
    SafetyDetect.getClient(this)
            .maliciousAppsList
            .addOnSuccessListener { maliciousAppsListResp ->
                val appsDataList: List<MaliciousAppsData> = maliciousAppsListResp.maliciousAppsList
                if (maliciousAppsListResp.rtnCode == CommonCode.OK) {
                    if (appsDataList.isEmpty()) {
                        val text = "No known potentially malicious apps are installed."
                        Toast.makeText(this!!.applicationContext, text, Toast.LENGTH_SHORT).show()
                    } else {
                        for (maliciousApp in appsDataList) {
                            Log.e(TAG, "Information about a malicious app:")
                            Log.e(TAG, "  APK: " + maliciousApp.apkPackageName)
                            Log.e(TAG, "  SHA-256: " + maliciousApp.apkSha256)
                            Log.e(TAG, "  Category: " + maliciousApp.apkCategory)
                        }
                    }
                } else {
                    val msg = ("Get malicious apps list failed! Message: " + maliciousAppsListResp.errorReason)
                    Log.e(TAG, msg)
                }
            }
            .addOnFailureListener { error ->
                error?.printStackTrace()
            }
}

appsDataListに悪意があるアプリのリストが入っています。

GitHub

https://github.com/Rei2020GitHub/MyPublicProject/tree/master/SafetyDetectDemo

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0