- 判断设备环境是否安全,比如是否被越狱、被模拟等,您可基于结果评估如何响应。
- 判断用户访问的URL是否为恶意网址,对于恶意网址,由您评估提示或拦截用户的访问风险。
起始版本: 5.0.0(12)
导入模块
import { safetyDetect } from '@kit.DeviceSecurityKit';
SysIntegrityRequest
系统完整性检测的请求参数。
元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Security.SafetyDetect
起始版本: 5.0.0(12)
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| nonce | string | 否 | 否 | 开发者应用传入的一个随机生成的nonce值,用于防重放攻击,在检测结果中会包含该值。 |
SysIntegrityResponse
系统完整性检测返回值。
元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Security.SafetyDetect
起始版本: 5.0.0(12)
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| result | string | 否 | 否 | JWS格式的系统完整性检测结果。 |
UrlCheckRequest
URL检测请求参数。
元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Security.SafetyDetect
起始版本: 5.0.0(12)
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| urls | Array | 否 | 否 | 被检测的URL列表 |
UrlCheckResponse
URL检测返回值。
元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Security.SafetyDetect
起始版本: 5.0.0(12)
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| results | Array<[UrlCheckResult]> | 否 | 否 | URL检测返回的检测结果 |
UrlCheckResult
URL检测结果详情。
元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Security.SafetyDetect
起始版本: 5.0.0(12)
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| url | string | 否 | 否 | 对应到输入参数中被检测的URL |
| threat | [UrlThreatType] | 否 | 否 | URL的威胁类型 |
UrlThreatType
枚举URL威胁类型。
元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Security.SafetyDetect
起始版本: 5.0.0(12)
| 名称 | 值 | 说明 |
|---|---|---|
| NORMAL | 0 | 未发现威胁。 |
| MALWARE | 1 | 恶意类型的URL。 |
| PHISHING | 2 | 钓鱼类型的URL |
| OTHERS | 3 | 其他威胁类型的URL |
checkSysIntegrity
checkSysIntegrity(req: [SysIntegrityRequest]): Promise<[SysIntegrityResponse]>
获取本设备的系统完整性。使用Promise异步回调。
元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Security.SafetyDetect
起始版本: 5.0.0(12)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| req | [SysIntegrityRequest] | 是 | 请求参数,包含nonce。nonce长度必须16至66字节之间,有效值为base64编码范围。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<[SysIntegrityResponse]> | Promise对象,返回系统完整性检测结果。 |
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission denied. |
| 401 | Invalid parameters.Possible causes:1. Mandatory parameters are left unspecified.2. Incorrect parameter types.3. Parameter verification failed. |
| 1010800001 | Internal error |
| 1010800002 | The network is unreachable. |
| 1010800003 | Access cloud server fail. |
示例:
import { safetyDetect } from '@kit.DeviceSecurityKit';
import { BusinessError} from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = "SafetyDetectJsTest";
// 请求系统完整性检测,并处理结果
let req : safetyDetect.SysIntegrityRequest = {
nonce : 'imEe1PCRcjGkBCAhOCh6ImADztOZ8ygxlWRs' // 从服务器生成的随机的nonce值
};
try {
hilog.info(0x0000, TAG, 'CheckSysIntegrity begin.');
const data: safetyDetect.SysIntegrityResponse = await safetyDetect.checkSysIntegrity(req);
hilog.info(0x0000, TAG, 'Succeeded in checkSysIntegrity: %{public}s', data.result);
} catch (err) {
let e: BusinessError = err as BusinessError;
hilog.error(0x0000, TAG, 'CheckSysIntegrity failed: %{public}d %{public}s', e.code, e.message);
}
checkUrlThreat
checkUrlThreat(req: [UrlCheckRequest]): Promise<[UrlCheckResponse]>
检测URL是否为恶意网址。使用Promise异步回调。
元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Security.SafetyDetect
起始版本: 5.0.0(12)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| req | [UrlCheckRequest] | 是 | 请求参数,包含被检测的URL列表。传入的URL数量最多10个并且每个URL长度不大于4096字节。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<[UrlCheckResponse]> | Promise对象,返回URL检测结果。 |
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission denied |
| 401 | Invalid parameters.Possible causes:1. Mandatory parameters are left unspecified.2. Incorrect parameter types.3. Parameter verification failed. |
| 1010800001 | Internal error |
| 1010800002 | The network is unreachable. |
| 1010800003 | Access cloud server fail. |
示例:
import { safetyDetect } from '@kit.DeviceSecurityKit';
import { BusinessError} from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = "SafetyDetectJsTest";
// 请求URL检测,并处理结果
let req : safetyDetect.UrlCheckRequest = {
urls : ['https://test1.com']
};
try {
hilog.info(0x0000, TAG, 'CheckUrlThreat begin.');
const data: safetyDetect.UrlCheckResponse = await safetyDetect.checkUrlThreat(req);
hilog.info(0x0000, TAG, 'Succeeded in checkUrlThreat: %{public}s %{public}d', data.results[0].url, data.results[0].threat);
} catch (err) {
let e: BusinessError = err as BusinessError;
hilog.error(0x0000, TAG, 'CheckUrlThreat failed: %{public}d %{public}s', e.code, e.message);
}

被折叠的 条评论
为什么被折叠?



