Starting from 6.1.1(24), the file code signature information query API is supported, allowing you to obtain the signature information of signed files on a device.
The signature information includes the app ID, issuing organization certificate chain, signature digest, signature timestamp, and the hash algorithm used for the signing. Through the HMS_SecurityAudit_AcquireCodeSign API, apps can obtain code signature information to help assess the integrity and security of the code being executed. This helps prevent the execution of malicious software and enhances the device's security capabilities.

Process description:
The following table lists the APIs. For details about the APIs, please refer to API Reference.
| API | Description |
|---|---|
| int32_t HMS_SecurityAudit_AcquireCodeSign(char* path, char** outOwnedResult) | Obtains the code signature information of the file specified by the input file path. |
When preparing for the development, you need to apply for the ohos.permission.QUERY_AUDIT_EVENT permission. Only enterprise apps in the trustlist can apply for this permission. For details about how to apply for this permission, please refer to Permissions for Enterprise Applications.
Import and link the security audit shared library in CMakeLists.txt.
find_library(dsm-lib libsecurityaudit_ndk.z.so)
target_link_libraries(entry PUBLIC libace_napi.z.so ${dsm-lib}) Import the security audit header file.
#include <cstdio> #include "DeviceSecurityKit/security_audit.h"
Call the HMS_SecurityAudit_AcquireCodeSign API to obtain the code signature information of the input file. After the returned code signature information is processed, release the memory allocated for the input and output parameters.
char *result = nullptr;
const char *path = "test";
// ...
int32_t ret = HMS_SecurityAudit_AcquireCodeSign(const_cast<char*>(path), &result);
if (ret == 0 && result != nullptr) {
printf("HMS_SecurityAudit_AcquireCodeSign result: %s\n", result);
} else {
printf("HMS_SecurityAudit_AcquireCodeSign failed with error: %d\n", ret);
}
// ...
if (result != nullptr) {
delete[] result;
result = nullptr;
}