Start version: 5.0.0(12)
Request parameter for system integrity check.
System capability: SystemCapability.Security.SafetyDetect
Start version: 5.0.0(12)
Parameter | Type | Read-only | Optional | Description |
|---|---|---|---|---|
nonce | string | No | No | A randomly generated nonce value passed by your app, which is used to prevent replay attacks. The check result contains this value. |
Return value of system integrity check.
System capability: SystemCapability.Security.SafetyDetect
Start version: 5.0.0(12)
Parameter | Type | Read-only | Optional | Description |
|---|---|---|---|---|
result | string | No | No | System integrity check result in JWS format. |
Request parameter for URL check.
System capability: SystemCapability.Security.SafetyDetect
Start version: 5.0.0(12)
Parameter | Type | Read-only | Optional | Description |
|---|---|---|---|---|
urls | Array<string> | No | No | List of URLs to be checked. |
Return value of URL check.
System capability: SystemCapability.Security.SafetyDetect
Start version: 5.0.0(12)
Parameter | Type | Read-only | Optional | Description |
|---|---|---|---|---|
results | Array<UrlCheckResult> | No | No | URL check result. |
URL check result details.
System capability: SystemCapability.Security.SafetyDetect
Start version: 5.0.0(12)
Parameter | Type | Read-only | Optional | Description |
|---|---|---|---|---|
url | string | No | No | Corresponds to the URL to be checked in the request parameter. |
threat | No | No | URL threat type. |
Enumerated URL threat types.
Name | Value | Description |
|---|---|---|
NORMAL | 0 | No threat detected. |
MALWARE | 1 | Malicious URL. |
PHISHING | 2 | Phishing URL. |
OTHERS | 3 | Other URL threats. |
checkSysIntegrity(req: SysIntegrityRequest): Promise<SysIntegrityResponse>
Obtains the system integrity of a device. This API returns the result asynchronously through a promise.
System capability: SystemCapability.Security.SafetyDetect
Start version: 5.0.0(12)
Parameters:
Parameter | Type | Mandatory | Description |
|---|---|---|---|
req | Yes | Request parameter, including the nonce value. The nonce value must contain 16 to 66 bytes. |
Returns:
Type | Description |
|---|---|
Promise<SysIntegrityResponse> | Promise used to return the system integrity check result. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
Error Code | Message |
|---|---|
201 | Permission denied. |
401 | Invalid parameters. |
1010800001 | Internal error |
1010800002 | The network is unreachable. |
1010800003 | Access cloud server fail. |
Example:
import { safetyDetect } from '@kit.DeviceSecurityKit';
import { BusinessError} from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = "SafetyDetectJsTest";
// Request system integrity check and process the result.
let req : safetyDetect.SysIntegrityRequest = {
nonce : 'imEe1PCRcjGkBCAhOCh6ImADztOZ8ygxlWRs' // Random nonce value generated by the server.
};
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(req: UrlCheckRequest): Promise<UrlCheckResponse>
Checks whether a URL is malicious. This API returns the result asynchronously through a promise.
System capability: SystemCapability.Security.SafetyDetect
Start version: 5.0.0(12)
Parameters:
Parameter | Type | Optional | Description |
|---|---|---|---|
req | No | Request parameter, including the list of URLs to be checked. A maximum of 10 URLs can be passed in, and the length of each URL cannot exceed 4096 bytes. |
Returns:
Type | Description |
|---|---|
Promise<UrlCheckResponse> | Promise used to return the URL check result. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
Error Code | Message |
|---|---|
201 | Permission denied |
401 | Invalid parameters. |
1010800001 | Internal error |
1010800002 | The network is unreachable. |
1010800003 | Access cloud server fail. |
Example:
import { safetyDetect } from '@kit.DeviceSecurityKit';
import { BusinessError} from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = "SafetyDetectJsTest";
// Request URL check and process the result.
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);
}