簡體   English   中英

用戶10200和當前進程都沒有com.huawei.permission.SECURITY_DIAGNOSE

[英]Neither user 10200 nor current process has com.huawei.permission.SECURITY_DIAGNOSE

在嘗試實施 SafetyNet 時,我添加了以下依賴項:

implementation 'com.huawei.hms:safetydetect:6.3.0.301'

並且還添加了對AndroidManifest.xml的權限:

<uses-permission android:name="com.huawei.permission.SECURITY_DIAGNOSE"/>

但這不知何故無法按預期工作:

E/RootDetect: `isRoot` exception : Must have `com.huawei.permission.SECURITY_DIAGNOSE` permission.
Neither user `10200` nor current process has `com.huawei.permission.SECURITY_DIAGNOSE`.

同樣在Apps & services > Permissions > View all permissions ,它沒有列出 - 所有其他的都被合並了。 合並時是否有任何進一步的條件或許可可能被剝奪? AGP 版本為 7.1.2。

奇怪的是,在注釋掉依賴項時,我仍然收到錯誤消息。

必須有com.huawei.permission.SECURITY_DIAGNOSE權限。

此自定義權限不需要添加到 SafeDetect 套件中。 另外,自定義的權限在權限管理頁面是不顯示的。 一般在權限管理頁面顯示系統級權限。

華為安全檢測套件不需要以下權限“SECURITYDIAGNOSE”,而只需要“INTE.NET”和“ACCESSWIFI_STATE”。 請參考下面的 URL 示例代碼示例和指南。

使用權限 android:name="com.huawei.permission.SECURITY_DIAGNOSE

<uses-permission android:name="android.permission.INTERNET" />
<!-- Access WiFi State -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

https://developer.huawei.com/consumer/zh/doc/development/Security-Examples/sample-code-0000001050157020

https://developer.huawei.com/consumer/zh/doc/development/Security-Guides/dysintegritydevelopment-0000001050156331

String alg未定義; 這是示例的工作版本:

SafetyDetectClient mClient = SafetyDetect.getClient(this);
// TODO: Change the nonce generation to include your own,
//       used once value, ideally from your remote server.
byte[] nonce = ("Sample" + System.currentTimeMillis()).getBytes();
SysIntegrityRequest sysintegrityrequest = new SysIntegrityRequest();
sysintegrityrequest.setAppId("3*******");  // TODO: set your appId.
sysintegrityrequest.setNonce(nonce);
sysintegrityrequest.setAlg("RS256"); // or "PS256"

Task<SysIntegrityResp> task = mClient.sysIntegrity(sysintegrityrequest);
task.addOnSuccessListener(response -> {

    // Indicates that communication with the service was successful.
    String jwsStr = response.getResult();
    Log.d(LOG_TAG, "SysIntegrityResp: " + jwsStr);

}).addOnFailureListener(e -> {

    // An error occurred during communication with the service.
    if (e instanceof ApiException) {

        // An error with the HMS API contains some additional details.
        ApiException apiException = (ApiException) e;

        // You can retrieve the status code using the apiException.getStatusCode() method.
        Log.e(LOG_TAG, "Error: " + SafetyDetectStatusCodes.getStatusCodeString(
                apiException.getStatusCode()) + ": " + apiException.getMessage()
        );

    } else {
        // A different, unknown type of error occurred.
        Log.e(LOG_TAG, "ERROR: " + e.getMessage());
    }
});

現在我不知道如何獲取或驗證nonce或如何處理jwsStr ,但我得到一個SysIntegrityResp - 但這是另一個問題。 文檔中建議添加權限的部分似乎有點誤導 - 日志中的錯誤消息也是如此。 剛找到這個 Java server example source ,這對理解很有幫助。 過濾hmssafetydetect的日志時,可以看到發生了什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM