1# Development on Application Signature Verification 2 3 4## When to Use 5 6To ensure the integrity and trustworthiness of the applications to be installed in OpenHarmony, the applications must be signed and their signatures must be verified. 7 8- 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. 9 10- 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. 11 12 13## Signature Verification Process 14 15An unsigned HAP is in **.zip** format and consists of a file block, central directory, and end of central directory (EOCD). 16 17After 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. 18 19 **Figure 1** Structure of a signed HAP 20 21 22 23The signature verification process consists of three steps: HAP signature verification, profile signature verification, and profile content verification. 24 25**HAP signature verification** 26 27The 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. 28 29**Profile signature verification** 30 31The 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. 32 33**Profile content verification** 34 35The 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. 36 37 38## Available APIs 39 40The following table lists the **innerkits** APIs provided by the signature verification component. These APIs are available only for system applications. 41 42 **Table 1** Signature verification APIs for the mini system 43 44| API| Description| 45| -------- | -------- | 46| 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**.| 47| 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.| 48| void APPVERI_FreeVerifyRst(VerifyResult \*verifyRst) | Releases the memory of **verifyRst**.| 49 50 **Table 2** Signature verification APIs for the standard system 51 52| API| Description| 53| -------- | -------- | 54| int HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult) | Verifies the application integrity.| 55 56 57## How to Develop 58 59 60### Developing an OpenHarmony Self-signed Application 61 62For details, see [Having Your App Automatically Signed](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-auto-configuring-signature-information-0000001271659465). 63