1e41f4b71Sopenharmony_ci# Development on Application Signature Verification 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## When to Use 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_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. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci- Application development: After developing an application and generating a package for installation, you must sign the installation package to prevent it from being tampered with after release. The OpenHarmony application signature verification module provides a signing tool hapsigner, specifications for generating a signing certificate, and a public key certificate for you to sign your application package. To facilitate your app experience, OpenHarmony is preset with the public key certificate and the private key for offline signing and signature verification. For commercial applications, you need to replace the public key certificate and private key. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci- 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 signature verification module uses the preset public key certificate to verify the signature. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## Signature Verification Process 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciAn unsigned HAP is in **.zip** format and consists of a file block, central directory, and end of central directory (EOCD). 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciAfter the HAP is signed, a signature block is added between the file block and the central directory. The integrated signature block consists of a profile signature block, HAP signature block, and signature header. The following figure shows the structure of a signed HAP. 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci **Figure 1** Structure of a signed HAP 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciThe signature verification process consists of three steps: HAP signature verification, profile signature verification, and profile content verification. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**HAP signature verification** 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ciThe HAP signature block is a signed data block in PKCS #7 format. The signature verification process includes PKSC7 signature verification, hash comparison, certificate chain verification, and matching between the certificate chain and the device's preset root certificate. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Profile signature verification** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ciThe profile signature block is a signed data block in PKCS #7 format. The profile content is stored in **contentinfo** of the PKCS #7 signature block. The signature verification process includes PKCS #7 signature verification, hash comparison, certificate chain verification, and profile certificate validity verification. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**Profile content verification** 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciThe signature verification module checks the validity of the profile content. If the profile is of the debug type, the module checks whether the UDID of the current device is contained in the UDID list in the profile. If yes, the module compares the certificate in the profile with the certificate used for HAP signature verification. If they are the same, the entire verification process is complete. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci## Available APIs 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ciThe following table lists the **innerkits** APIs provided by the signature verification component. These APIs are available only for system applications. 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci **Table 1** Signature verification APIs for the mini system 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci| API| Description| 45e41f4b71Sopenharmony_ci| -------- | -------- | 46e41f4b71Sopenharmony_ci| int APPVERI_AppVerify(const char \*filePath, VerifyResult \*verifyRst) | Verifies a signature based on the specified file path. This API returns the data obtained from the profile to the caller through **verifyRst**.| 47e41f4b71Sopenharmony_ci| int APPVERI_SetDebugMode(bool mode) | Sets the debugging mode. If **mode** is set to **true**, certificate chain verification based on the debugging root key is enabled; if **mode** is set to **false**, it is disabled.<br>Note: Currently, no certificate based on the existing debugging root key is available. You can replace the debugging root key and perform related verification as required.| 48e41f4b71Sopenharmony_ci| void APPVERI_FreeVerifyRst(VerifyResult \*verifyRst) | Releases the memory of **verifyRst**.| 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci **Table 2** Signature verification APIs for the standard system 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci| API| Description| 53e41f4b71Sopenharmony_ci| -------- | -------- | 54e41f4b71Sopenharmony_ci| int HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult) | Verifies the application integrity.| 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci## How to Develop 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci### Developing an OpenHarmony Self-signed Application 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ciFor details, see [Having Your App Automatically Signed](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-auto-configuring-signature-information-0000001271659465). 63