1f2d4f7b0Sopenharmony_ci# appverify<a name="EN-US_TOPIC_0000001096592945"></a> 2f2d4f7b0Sopenharmony_ci 3f2d4f7b0Sopenharmony_ci- [Introduction](#section11660541593) 4f2d4f7b0Sopenharmony_ci- [Architecture](#section9498162413412) 5f2d4f7b0Sopenharmony_ci- [Directory Structure](#section161941989596) 6f2d4f7b0Sopenharmony_ci- [Constraints](#section119744591305) 7f2d4f7b0Sopenharmony_ci- [Usage](#section1312121216216) 8f2d4f7b0Sopenharmony_ci - [Available APIs](#section1551164914237) 9f2d4f7b0Sopenharmony_ci - [Usage Guidelines](#section129654513264) 10f2d4f7b0Sopenharmony_ci 11f2d4f7b0Sopenharmony_ci- [Repositories Involved](#section1371113476307) 12f2d4f7b0Sopenharmony_ci 13f2d4f7b0Sopenharmony_ci## Introduction<a name="section11660541593"></a> 14f2d4f7b0Sopenharmony_ci 15f2d4f7b0Sopenharmony_ciTo ensure the integrity and trustworthiness of the applications to be installed in OpenHarmony, the applications must be signed and their signatures must be verified. 16f2d4f7b0Sopenharmony_ci 17f2d4f7b0Sopenharmony_ci- **In application development**: After developing an application, you need to sign its installation package to ensure that the installation package is not tampered with when it is released on devices. To sign the application package, you can use the signature tools and the public key certificates and follow the signing certificate generation specifications provided by the application integrity verification module. For your convenience, a public key certificate and a corresponding private key are preset in OpenHarmony. You need to replace the public key certificate and private key in your commercial version of OpenHarmony. 18f2d4f7b0Sopenharmony_ci 19f2d4f7b0Sopenharmony_ci- **In application installation**: The Application Framework subsystem of OpenHarmony installs applications. Upon receiving an application installation package, the Application Framework subsystem parses the signature of the installation package, and verifies the signature using the application integrity verification APIs. The application can be installed only after the verification succeeds. During the verification, the application integrity verification module uses the preset public key certificate to verify the signature. 20f2d4f7b0Sopenharmony_ci 21f2d4f7b0Sopenharmony_ci## Architecture<a name="section9498162413412"></a> 22f2d4f7b0Sopenharmony_ci 23f2d4f7b0Sopenharmony_ci**Figure 1** Application integrity verification architecture<a name="fig78941174427"></a> 24f2d4f7b0Sopenharmony_ci 25f2d4f7b0Sopenharmony_ci 26f2d4f7b0Sopenharmony_ci- **APIs between subsystems**: APIs provided by the application integrity verification module for other modules 27f2d4f7b0Sopenharmony_ci 28f2d4f7b0Sopenharmony_ci- **Integrity verification**: ensures the integrity of application bundles and prevents tampering through signature verification. 29f2d4f7b0Sopenharmony_ci 30f2d4f7b0Sopenharmony_ci- **Application source identification**: identifies the application source by matching the signature certificate chain with the trusted source list. 31f2d4f7b0Sopenharmony_ci 32f2d4f7b0Sopenharmony_ci## Directory Structure<a name="section161941989596"></a> 33f2d4f7b0Sopenharmony_ci 34f2d4f7b0Sopenharmony_ci``` 35f2d4f7b0Sopenharmony_ci/base/security/appverify 36f2d4f7b0Sopenharmony_ci├── interfaces/innerkits/appverify # Application integrity verification module 37f2d4f7b0Sopenharmony_ci│ ├── config # Application signature root certificates and configuration files for the trusted source list 38f2d4f7b0Sopenharmony_ci│ ├── include # Header files 39f2d4f7b0Sopenharmony_ci│ ├── src # Source code 40f2d4f7b0Sopenharmony_ci│ ├── test # Automated test cases 41f2d4f7b0Sopenharmony_ci├── test/resource # Test resources 42f2d4f7b0Sopenharmony_ci``` 43f2d4f7b0Sopenharmony_ci 44f2d4f7b0Sopenharmony_ci## Constraints<a name="section119744591305"></a> 45f2d4f7b0Sopenharmony_ci 46f2d4f7b0Sopenharmony_ciThe certificates used for application integrity verification are specific to OpenHarmony. The corresponding public key certificates and private keys are preset in the open-source code repositories of OpenHarmony to provide offline signing and verification capabilities for the open-source community. The public key certificates and the corresponding private keys need to be replaced in commercial versions that are based on OpenHarmony. 47f2d4f7b0Sopenharmony_ci 48f2d4f7b0Sopenharmony_ci## Usage<a name="section1312121216216"></a> 49f2d4f7b0Sopenharmony_ci 50f2d4f7b0Sopenharmony_ciThe application integrity verification module provides an inter-subsystem API, which is called by the Bundle Manager Service \(BMS\) during application installation. 51f2d4f7b0Sopenharmony_ci 52f2d4f7b0Sopenharmony_ci### Available APIs<a name="section1551164914237"></a> 53f2d4f7b0Sopenharmony_ci 54f2d4f7b0Sopenharmony_ci<a name="table775715438253"></a> 55f2d4f7b0Sopenharmony_ci<table><thead align="left"><tr id="row12757154342519"><th class="cellrowborder" valign="top" width="50.22%" id="mcps1.1.3.1.1"><p id="p1075794372512"><a name="p1075794372512"></a><a name="p1075794372512"></a>API</p> 56f2d4f7b0Sopenharmony_ci</th> 57f2d4f7b0Sopenharmony_ci<th class="cellrowborder" valign="top" width="49.78%" id="mcps1.1.3.1.2"><p id="p375844342518"><a name="p375844342518"></a><a name="p375844342518"></a>Description</p> 58f2d4f7b0Sopenharmony_ci</th> 59f2d4f7b0Sopenharmony_ci</tr> 60f2d4f7b0Sopenharmony_ci</thead> 61f2d4f7b0Sopenharmony_ci<tbody><tr id="row1348165765318"><td class="cellrowborder" valign="top" width="50.22%" headers="mcps1.1.3.1.1 "><p id="p154855755315"><a name="p154855755315"></a><a name="p154855755315"></a>int32_t HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult)</p> 62f2d4f7b0Sopenharmony_ci</td> 63f2d4f7b0Sopenharmony_ci<td class="cellrowborder" valign="top" width="49.78%" headers="mcps1.1.3.1.2 "><p id="p64845775315"><a name="p64845775315"></a><a name="p64845775315"></a>Verifies application integrity and identifies the application source.</p> 64f2d4f7b0Sopenharmony_ci</td> 65f2d4f7b0Sopenharmony_ci</tr> 66f2d4f7b0Sopenharmony_ci</tbody> 67f2d4f7b0Sopenharmony_ci</table> 68f2d4f7b0Sopenharmony_ci 69f2d4f7b0Sopenharmony_ci### Usage Guidelines<a name="section129654513264"></a> 70f2d4f7b0Sopenharmony_ci 71f2d4f7b0Sopenharmony_ciThe **HapVerify\(\)** API provided by the application integrity verification module is an inter-subsystem API. This API can be called with the HAP file path passed to verify the integrity of an application, and the verification result can be obtained from the return value. The signature of the application can be obtained from the input parameter **hapVerifyResult**. 72f2d4f7b0Sopenharmony_ci 73f2d4f7b0Sopenharmony_ci``` 74f2d4f7b0Sopenharmony_ciSecurity::Verify::HapVerifyResult verifyResult; 75f2d4f7b0Sopenharmony_ciint32_t res = Security::Verify::HapVerify(hapPath, verifyResult); 76f2d4f7b0Sopenharmony_ciif (res != Security::Verify::HapVerifyResultCode::VERIFY_SUCCESS) { 77f2d4f7b0Sopenharmony_ci // processing error 78f2d4f7b0Sopenharmony_ci} 79f2d4f7b0Sopenharmony_ci``` 80f2d4f7b0Sopenharmony_ci 81f2d4f7b0Sopenharmony_ci## Repositories Involved<a name="section1371113476307"></a> 82f2d4f7b0Sopenharmony_ci 83f2d4f7b0Sopenharmony_ciSecurity subsystem 84f2d4f7b0Sopenharmony_ci 85f2d4f7b0Sopenharmony_cihmf/security/appverify 86f2d4f7b0Sopenharmony_ci 87