15bbf6e98Sopenharmony_ci# device_attest_lite module<a name="EN-CN_TOPIC_001"></a> 25bbf6e98Sopenharmony_ci 35bbf6e98Sopenharmony_ci- [Introduction](#section100) 45bbf6e98Sopenharmony_ci- [Directory Structure](#section200) 55bbf6e98Sopenharmony_ci- [Architecture diagram](#section300) 65bbf6e98Sopenharmony_ci- [Constraints](#section400) 75bbf6e98Sopenharmony_ci- [Integration guidance](#section500) 85bbf6e98Sopenharmony_ci - [Terminology](#section501) 95bbf6e98Sopenharmony_ci - [Partner completes information registration](#section502) 105bbf6e98Sopenharmony_ci - [Dependent interface adaptation](#section503) 115bbf6e98Sopenharmony_ci - [External interface](#section504) 125bbf6e98Sopenharmony_ci - [Compilation instruction](#section505) 135bbf6e98Sopenharmony_ci- [Repositories Involved](#section600) 145bbf6e98Sopenharmony_ci 155bbf6e98Sopenharmony_ci 165bbf6e98Sopenharmony_ci## Introduction<a id="section100"></a> 175bbf6e98Sopenharmony_ci 185bbf6e98Sopenharmony_cixts_device_attest module: 195bbf6e98Sopenharmony_ci 205bbf6e98Sopenharmony_ci- The basic function of the xts_device_attest module is to take care of the OpenHarmony ecological device attest results, and achieve the goal of counting the number of OH ecological devices through the cloud of end data. The purpose is to count the number of OH equipment. xts_device_attest module applies to standard system. 215bbf6e98Sopenharmony_ci 225bbf6e98Sopenharmony_ci## Directory Structure<a id="section200"></a> 235bbf6e98Sopenharmony_ci 245bbf6e98Sopenharmony_ci``` 255bbf6e98Sopenharmony_ci/test/xts 265bbf6e98Sopenharmony_ci├── device_attest 275bbf6e98Sopenharmony_ci│ └── build # Compile configuration 285bbf6e98Sopenharmony_ci│ └── common # Public basic capacity 295bbf6e98Sopenharmony_ci│ └── figures 305bbf6e98Sopenharmony_ci│ └── interfaces # External interface 315bbf6e98Sopenharmony_ci│ └── sample # External interface example 325bbf6e98Sopenharmony_ci│ └── services # Service subject and business logic code 335bbf6e98Sopenharmony_ci│ └── core # Business logic code 345bbf6e98Sopenharmony_ci│ └── devattest_ability # Service framework 355bbf6e98Sopenharmony_ci│ └── etc # Startup configuration 365bbf6e98Sopenharmony_ci│ └── sa_profile # Process configuration 375bbf6e98Sopenharmony_ci│ └── test 385bbf6e98Sopenharmony_ci│ └── unittest # Test case 395bbf6e98Sopenharmony_ci``` 405bbf6e98Sopenharmony_ci 415bbf6e98Sopenharmony_ci## Architecture diagram<a id="section300"></a> 425bbf6e98Sopenharmony_ci 435bbf6e98Sopenharmony_ci 445bbf6e98Sopenharmony_ci 455bbf6e98Sopenharmony_ci## Constraints<a id="section400"></a> 465bbf6e98Sopenharmony_ci 475bbf6e98Sopenharmony_ciThe integration dependency library is shown in the following table:: 485bbf6e98Sopenharmony_ci 495bbf6e98Sopenharmony_ci| Library | Version | Function description | Note | 505bbf6e98Sopenharmony_ci| --------- | ---------------- | ----------------------------------------------- | ---------------------------------------- | 515bbf6e98Sopenharmony_ci| mbedtls | 2.16.11 | A lightweight implementation library of TLS protocol for embedded devices. | Library path..\third_party\mbedtls | 525bbf6e98Sopenharmony_ci| OpenSSL | 1.1.1 | TLS protocal(include SSLv3)and common password library. | Library path..\third_party\openssl | 535bbf6e98Sopenharmony_ci| cJSON | 1.7.15 | JSON file resolution library. | Library path..\third_party\cJSON\third_party | 545bbf6e98Sopenharmony_ci| libsec | 1.1.10 | Security function library. | Library path..\bounds_checking_function | 555bbf6e98Sopenharmony_ci| parameter | OpenHarmony 1.0+ | System interface for obtaining device information. | Library path ..\base\startup\init\interfaces\innerkits\include\syspara\parameter. | 565bbf6e98Sopenharmony_ci 575bbf6e98Sopenharmony_ci 585bbf6e98Sopenharmony_ci## Integration guidance<a id="section500"></a> 595bbf6e98Sopenharmony_ci 605bbf6e98Sopenharmony_ci### Terminology<a id="section501"></a> 615bbf6e98Sopenharmony_ci 625bbf6e98Sopenharmony_ci**table 1** 635bbf6e98Sopenharmony_ci**table 1** 645bbf6e98Sopenharmony_ci| Term | Explain | 655bbf6e98Sopenharmony_ci| ---------- | ------------------------------------------------------------ | 665bbf6e98Sopenharmony_ci| partners | Enterprises applying for OpenHarmony compatibility evaluation are hereinafter collectively referred to as "partners". It is required to integrate xts_device_attest module. | 675bbf6e98Sopenharmony_ci| manuKey | The secret key obtained by partners from the official website of the [OpenHarmony compatibility platform](https://openatom.cn/atomavatar/#/login?redirect=%2Fauthorize%3Fresponse_type%3Dcode%26client_id%3D6bdacef0a8bd11ec938bd9550d2decfd%26redirect_uri%3Dhttps%3A%2F%2Fcompatibility.openharmony.cn%2Fconsole%26appName%3DOpenHarmony%E8%AE%A4%E8%AF%81%E5%B9%B3%E5%8F%B0%26scope%3D0,1,2,3%26state%3D%2Fpersonal). It is used to encrypt and protect relevant data in the product. To ensure the compatibility of multiple products, manuKey should remain unchanged during the life cycle of all products. | 685bbf6e98Sopenharmony_ci| productId | When a partner applies for compatibility evaluation from the official website of the OpenHarmony compatibility platform, the platform assigns a unique product identifier to the evaluation product. The productId must remain unchanged throughout the product life cycle. | 695bbf6e98Sopenharmony_ci| productKey | When partners apply for compatibility evaluation from the official website of the OpenHarmony compatibility platform, the platform assigns the unique product secret key to the evaluation product. It corresponds to the productId one by one, and is used to encrypt and protect product level data. It is also necessary to ensure that it remains unchanged throughout the product life cycle. | 705bbf6e98Sopenharmony_ci| token | The partner obtains the device credentials allocated by the platform from the official website of the OpenHarmony compatibility platform, one for each device, to identify the device identity. It needs to be stored in the security partition, and cannot be cleared when the factory settings are restored or the image is upgraded. | 715bbf6e98Sopenharmony_ci 725bbf6e98Sopenharmony_ci 735bbf6e98Sopenharmony_ci### Partner completes information registration <a id="section502"></a> 745bbf6e98Sopenharmony_ci 755bbf6e98Sopenharmony_ciPartners need to register a series of basic information about product equipment on the [OpenHarmony compatibility platform](https://openatom.cn/atomavatar/#/login?redirect=%2Fauthorize%3Fresponse_type%3Dcode%26client_id%3D6bdacef0a8bd11ec938bd9550d2decfd%26redirect_uri%3Dhttps%3A%2F%2Fcompatibility.openharmony.cn%2Fconsole%26appName%3DOpenHarmony%E8%AE%A4%E8%AF%81%E5%B9%B3%E5%8F%B0%26scope%3D0,1,2,3%26state%3D%2Fpersonal), such as 公司简称(英文), 品牌英文名称, 设备型号, etc. 765bbf6e98Sopenharmony_ciIn the equipment certification processing process, the equipment certification module reads the equipment information and reports it to the foundation cloud, which verifies it. Therefore, partners are required to complete product information registration on the official website of the OpenHarmony compatibility platform in advance, including the following two steps: 775bbf6e98Sopenharmony_ci 785bbf6e98Sopenharmony_ci1)Partners complete device information registration on the official website of OpenHarmony compatibility platform. 795bbf6e98Sopenharmony_ci2)Partners write the device information registered on the official website of the OpenHarmony compatibility platform to the device. 805bbf6e98Sopenharmony_ci 815bbf6e98Sopenharmony_ci 825bbf6e98Sopenharmony_ci1. Partners complete information registration on the OpenHarmony compatibility platform 835bbf6e98Sopenharmony_ci 845bbf6e98Sopenharmony_ci Partners need to register relevant equipment certification data on the OpenHarmony compatibility platform, please follow the registration process on the official website. 855bbf6e98Sopenharmony_ci 865bbf6e98Sopenharmony_ci2. Partners writes the registered OS information to the device 875bbf6e98Sopenharmony_ci 885bbf6e98Sopenharmony_ci For the information registered by partners on the OpenHarmony compatibility platform, the version package provides relevant interfaces for partners to fill in. 895bbf6e98Sopenharmony_ci When calling the xts_device_attest function, the value filled in by the partner will be reported to the foundation cloud, which will compare and verify the information registered in the previous section with the information reported by the device. 905bbf6e98Sopenharmony_ci xts_device_attest module depends on some device information and needs to be adapted and modified by partners. 915bbf6e98Sopenharmony_ci Device information is located in the startup subsystem file: base/startup/init/services/etc/param/ohos_const/ohos.para.The device OS information is shown in the following table: 925bbf6e98Sopenharmony_ci 935bbf6e98Sopenharmony_ci**table 2** 945bbf6e98Sopenharmony_ci| Device information | ohos.para configuration parameter | Note | 955bbf6e98Sopenharmony_ci| --------------- | ------------------------------------------------------------ | ---------------------------- | 965bbf6e98Sopenharmony_ci| 发布类型 | const.ohos.releasetype=Beta | Use default | 975bbf6e98Sopenharmony_ci| api版本 | const.ohos.apiversion=6 | Use default | 985bbf6e98Sopenharmony_ci| 安全补丁标签 | const.ohos.version.security_patch=2021-09-01 | 2021-09-01 replace with real value | 995bbf6e98Sopenharmony_ci| 软件版本号 | const.ohos.fullname=OpenHarmony-1.0.1.0 | Use default | 1005bbf6e98Sopenharmony_ci 1015bbf6e98Sopenharmony_ciDevice product information is located in the vendor subsystem file: base/startup/init/services/etc/param/ohos.para. The device product information is shown in the following table: 1025bbf6e98Sopenharmony_ci 1035bbf6e98Sopenharmony_ci**table 3** 1045bbf6e98Sopenharmony_ci| Device information | vendor.para configuration parameter | Note | 1055bbf6e98Sopenharmony_ci| ---------------- | ------------------------------------------------- | ---------------------------- | 1065bbf6e98Sopenharmony_ci| 企业简称(英文) | const.product.manufacturer=**** | **** replace with real value | 1075bbf6e98Sopenharmony_ci| 品牌英文名 | const.product.brand=**** | **** replace with real value | 1085bbf6e98Sopenharmony_ci| 设备型号 | const.product.model=**** | **** replace with real value | 1095bbf6e98Sopenharmony_ci| 软件版本号 | \# const.product.software.version="OpenHarmony 1.0.1" const.product.software.version=OpenHarmony 3.3.3.3 | "OpenHarmony 1.0.1" replace with real value | 1105bbf6e98Sopenharmony_ci| 版本 id | | No partner operation is required, and the system automatically generates | 1115bbf6e98Sopenharmony_ci| 版本 Hash | const.ohos.buildroothash=default | 添加该数据 defaultreplace with real value| 1125bbf6e98Sopenharmony_ci 1135bbf6e98Sopenharmony_ciNote:版本 id needs to be obtained through equipment,Fill in the OpenHarmony compatibility platform,版本 id consists of: 1145bbf6e98Sopenharmony_ciVersionId = deviceType/manufacture/brand/productSeries/OSFullName/productModel/softwareModel/OHOS_SDK_API_VERSION/incrementalVersion/buildType 1155bbf6e98Sopenharmony_ci 1165bbf6e98Sopenharmony_ciGet 版本 id: 1175bbf6e98Sopenharmony_ci 1) OS information and product information writing device 1185bbf6e98Sopenharmony_ci 2) Release encrypted log(Modify the modification of PrintDevSysInfo in the following figure) 1195bbf6e98Sopenharmony_ci 3) Burn 1205bbf6e98Sopenharmony_ci 4) View 版本 ID through logs 1215bbf6e98Sopenharmony_ci 1225bbf6e98Sopenharmony_ci 1235bbf6e98Sopenharmony_ci 1245bbf6e98Sopenharmony_ciView 版本 ID through logs 1255bbf6e98Sopenharmony_ci 1265bbf6e98Sopenharmony_ci 1275bbf6e98Sopenharmony_ci 1285bbf6e98Sopenharmony_ci 1295bbf6e98Sopenharmony_ci### Dependent interface adaptation <a id="section503"></a> 1305bbf6e98Sopenharmony_ci 1315bbf6e98Sopenharmony_ciIn order to shield the differences in the underlying implementations of different modules, vendor defines token related APIs, which are implemented by partners through adaptation. The interface definitions are shown in the following table: 1325bbf6e98Sopenharmony_ci 1335bbf6e98Sopenharmony_ci**table 4** 1345bbf6e98Sopenharmony_ci| 1355bbf6e98Sopenharmony_ciFunction | Interface definition | Parameters definition | Return value | Belong to | 1365bbf6e98Sopenharmony_ci| ----------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------ | --------------------- | ------------------------- | 1375bbf6e98Sopenharmony_ci| Read manuKey | int32_t HalGetManufactureKey(char\* manuKey, uint32_t len) | acKey:Secret key storage memory len:memory length | 0:success -1:fail | ..\hal_token.h | 1385bbf6e98Sopenharmony_ci| Read ProductId | int32_t HalGetProdId(char\* productId, uint32_t len) | productId:Product model identification len:memory length | 0:success 1:fail | ..\hal_token.h | 1395bbf6e98Sopenharmony_ci| Read token | int32_t HalReadToken(char\* token, uint32_t len); | token:Token storage memory len:memory length | 0:success 1:fail | ..\hal_token.h | 1405bbf6e98Sopenharmony_ci| Write token | int32_t HalWriteToken(char\* token, uint32_t len); | token:Token storage memory len:memory length | 0:success 1:fail | ..\hal_token.h | 1415bbf6e98Sopenharmony_ci|Read ProductKey(Reserved interface) | int32_t HalGetProdKey(char\* productKey, uint32_t len) | productKey:Product (Unique) Secret Key len:memory length | 0:success 1:fail | ..\hal_token.h | 1425bbf6e98Sopenharmony_ci 1435bbf6e98Sopenharmony_ci 1445bbf6e98Sopenharmony_ci 1. HalGetManufactureKey 1455bbf6e98Sopenharmony_ci manuKey is a parameter used to generate AES secret key in combination with the token, which is downloaded from the OpenHarmony compatibility platform. 1465bbf6e98Sopenharmony_ci 1475bbf6e98Sopenharmony_ci 1485bbf6e98Sopenharmony_ci 1495bbf6e98Sopenharmony_ci Convert ASCII code to hexadecimal through tools. 1505bbf6e98Sopenharmony_ci 1515bbf6e98Sopenharmony_ci 1525bbf6e98Sopenharmony_ci 1535bbf6e98Sopenharmony_ci 1545bbf6e98Sopenharmony_ci 1555bbf6e98Sopenharmony_ci 1565bbf6e98Sopenharmony_ci Preset in the return value of HalGetManufactureKey interface. 1575bbf6e98Sopenharmony_ci 1585bbf6e98Sopenharmony_ci 1595bbf6e98Sopenharmony_ci 1605bbf6e98Sopenharmony_ci 2. HalGetProdId 1615bbf6e98Sopenharmony_ci ProductId is a parameter that is used to generate AES secret key together with the token, which can be viewed on the OpenHarmony platform. 1625bbf6e98Sopenharmony_ci 1635bbf6e98Sopenharmony_ci 1645bbf6e98Sopenharmony_ci 1655bbf6e98Sopenharmony_ci Preset in the return value of HalGetProductId interface 1665bbf6e98Sopenharmony_ci 1675bbf6e98Sopenharmony_ci 1685bbf6e98Sopenharmony_ci 1695bbf6e98Sopenharmony_ci 3. HalReadToken 和 HalWriteToken 1705bbf6e98Sopenharmony_ci The manufacturer needs to implement the token read and write interface, write the token in the security partition of the device, and the partition will not be erased when the device is restarted or initialized. 1715bbf6e98Sopenharmony_ci 1725bbf6e98Sopenharmony_ci 4. HalGetProdKey 1735bbf6e98Sopenharmony_ci Reserved interface, which does not need to be implemented temporarily. 1745bbf6e98Sopenharmony_ci 1755bbf6e98Sopenharmony_ci 1765bbf6e98Sopenharmony_ci### External interface<a id="section504"></a> 1775bbf6e98Sopenharmony_ci 1785bbf6e98Sopenharmony_cixts_device_attest module external interface,the following table: 1795bbf6e98Sopenharmony_ci 1805bbf6e98Sopenharmony_ci| **Interface Name** | **Description** | 1815bbf6e98Sopenharmony_ci| ------------------------------------------------------- | ------------ | 1825bbf6e98Sopenharmony_ci| int32_t GetAttestStatus(AttestResultInfo* attestResultInfo); | Get attest result | 1835bbf6e98Sopenharmony_ci 1845bbf6e98Sopenharmony_ciThe service of xts_device_attest starts automatically when device is started. After the network connection is successful, it will enter the process of xts_device_attest. By querying the GetAttestStatus interface, you can get the results of device attest. 1855bbf6e98Sopenharmony_ciCall to view sample example. 1865bbf6e98Sopenharmony_ci 1875bbf6e98Sopenharmony_ci### Compilation instruction<a id="section505"></a> 1885bbf6e98Sopenharmony_ci 1895bbf6e98Sopenharmony_ciTake rk3568 as an example 1905bbf6e98Sopenharmony_ci```c 1915bbf6e98Sopenharmony_ci./build.sh --product-name=rk3568 system_size=standard 1925bbf6e98Sopenharmony_ci``` 1935bbf6e98Sopenharmony_ci 1945bbf6e98Sopenharmony_ci## Repositories Involved<a id="section600"></a> 1955bbf6e98Sopenharmony_ci 1965bbf6e98Sopenharmony_ci**xts\_device\_attest** 1975bbf6e98Sopenharmony_ci 1985bbf6e98Sopenharmony_ci[xts\_device\_attest\_lite](https://gitee.com/openharmony-sig/xts_device_attest_lite/)