We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesSystemSecurityEnterprise Data Guard KitHierarchical File ManagementSetting HDC Authentication Keys

Setting HDC Authentication Keys

NOTE

Since version 6.1.1(24), the API for setting HDC authentication keys is available for security debugging on enterprise devices, enabling more robust device security.

Use Case

This API sets HDC authentication keys for both upper and lower devices, ensuring that connections and debugging are permitted only when both parties belong to the same enterprise. This effectively prevents enterprise assets from being tampered with or disclosed.

API Description

For details about these APIs, please refer to the API Reference.

Expand
API Description
setHdcAuthenticationKey(devType: AuthenticateDeviceType, keyType: AuthenticateKeyType, key: Uint8Array): Promise<void> Sets HDC authentication keys between the upper and lower devices using a promise.

Development Procedure

  1. Generate a 3072-bit RSA key pair locally using OpenSSL.

    Generate a private key using OpenSSL:

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. openssl genpkey -algorithm RSA -out private_key_3072.pem -pkeyopt rsa_keygen_bits:3072

    Generate a public key based on the private key:

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. openssl rsa -in private_key_3072.pem -pubout -out public_key_3072.pem
  2. Import the required modules.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { fileGuard } from '@kit.EnterpriseDataGuardKit';
  3. Initialize the guard object of FileGuard and call the setHdcAuthenticationKey API to set the HDC authentication key between the upper and lower devices. The upper device must issue the private key, while the lower device issues the public key, enabling secure debugging of the lower device by the upper device.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. function testSetHdcAuthenticationKey() {
    2. let guard: fileGuard.FileGuard = new fileGuard.FileGuard();
    3. let devType: fileGuard.AuthenticateDeviceType = fileGuard.AuthenticateDeviceType.UPPER;
    4. let keyType: fileGuard.AuthenticateKeyType = fileGuard.AuthenticateKeyType.PUBLIC_KEY;
    5. // Convert the key into the Uint8Array type.
    6. let key: Uint8Array = new Uint8Array([0]);
    7. guard.setHdcAuthenticationKey(devType, keyType, key).then(() => {
    8. console.info(`Succeeded in setting the HDC authentication key.`);
    9. }).catch((error: BusinessError) => {
    10. console.error(`Failed to set the HDC authentication key. Code: ${error.code}, message: ${error.message}.`);
    11. })
    12. }
Search in Guides
Enter a keyword.