diff --git a/bundle.json b/bundle.json index fccf599735548c22daa1a8ca936af4d236a20033..590f64fe56eff6e3a7eda95b2d2f23f3bed68ebb 100644 --- a/bundle.json +++ b/bundle.json @@ -49,7 +49,8 @@ "interfaces/hap_verify.h", "common/hap_byte_buffer.h", "common/export_define.h", - "provision/provision_info.h" + "provision/provision_info.h", + "util/signature_info.h" ] }, "name": "//base/security/appverify/interfaces/innerkits/appverify:libhapverify" @@ -70,4 +71,4 @@ } } } - \ No newline at end of file + diff --git a/interfaces/innerkits/appverify/include/interfaces/hap_verify.h b/interfaces/innerkits/appverify/include/interfaces/hap_verify.h index ab11015a8aeddf7942af7dbf54e954ecaf8f6962..4cc94611bbe34caceef768a0850386b78dfa3eaf 100644 --- a/interfaces/innerkits/appverify/include/interfaces/hap_verify.h +++ b/interfaces/innerkits/appverify/include/interfaces/hap_verify.h @@ -19,6 +19,7 @@ #include "common/export_define.h" #include "interfaces/hap_verify_result.h" +#include "util/signature_info.h" namespace OHOS { namespace Security { @@ -27,6 +28,7 @@ DLL_EXPORT bool EnableDebugMode(); DLL_EXPORT void DisableDebugMode(); DLL_EXPORT int32_t HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult); DLL_EXPORT int32_t ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); +DLL_EXPORT int32_t ParseHapSignatureInfo(const std::string& filePath, SignatureInfo &hapSignInfo); DLL_EXPORT void SetDevMode(DevMode devMode); } // namespace Verify } // namespace Security diff --git a/interfaces/innerkits/appverify/include/verify/hap_verify_v2.h b/interfaces/innerkits/appverify/include/verify/hap_verify_v2.h index 74fa3a69586a86759ac3da39d8f5c95f3f7a5ddd..620c8514bd194530512a8b05f38c19c906cda25f 100644 --- a/interfaces/innerkits/appverify/include/verify/hap_verify_v2.h +++ b/interfaces/innerkits/appverify/include/verify/hap_verify_v2.h @@ -22,6 +22,7 @@ #include "interfaces/hap_verify_result.h" #include "provision/provision_verify.h" #include "util/hap_verify_openssl_utils.h" +#include "util/signature_info.h" namespace OHOS { namespace Security { @@ -30,6 +31,7 @@ class HapVerifyV2 { public: int32_t Verify(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); int32_t ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); + int32_t ParseHapSignatureInfo(const std::string& filePath, SignatureInfo &hapSignInfo); private: int32_t Verify(RandomAccessFile& hapFile, HapVerifyResult& hapVerifyV1Result); diff --git a/interfaces/innerkits/appverify/src/interfaces/hap_verify.cpp b/interfaces/innerkits/appverify/src/interfaces/hap_verify.cpp index 55c9e92f9fd260d685367f4e946fb4b5dc02cf8c..316cfc53764dbb42c37df945fb4f503788a7a19d 100644 --- a/interfaces/innerkits/appverify/src/interfaces/hap_verify.cpp +++ b/interfaces/innerkits/appverify/src/interfaces/hap_verify.cpp @@ -97,6 +97,13 @@ int32_t ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV HapVerifyV2 hapVerifyV2; return hapVerifyV2.ParseHapProfile(filePath, hapVerifyV1Result); } + +int32_t ParseHapSignatureInfo(const std::string& filePath, SignatureInfo &hapSignInfo) +{ + HapVerifyV2 hapVerifyV2; + return hapVerifyV2.ParseHapSignatureInfo(filePath, hapSignInfo); +} + } // namespace Verify } // namespace Security } // namespace OHOS diff --git a/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp b/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp index 6379eb2ca82cfdd0da52f5d4086a42a13d84f9c3..bab73c94135a255f0f1fe638716ef3ee04a8beec 100644 --- a/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp +++ b/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp @@ -425,6 +425,26 @@ int32_t HapVerifyV2::ParseHapProfile(const std::string& filePath, HapVerifyResul hapVerifyV1Result.SetProvisionInfo(info); return VERIFY_SUCCESS; } + +int32_t HapVerifyV2::ParseHapSignatureInfo(const std::string& filePath, SignatureInfo &hapSignInfo) +{ + std::string standardFilePath; + if (!CheckFilePath(filePath, standardFilePath)) { + return FILE_PATH_INVALID; + } + + RandomAccessFile hapFile; + if (!hapFile.Init(standardFilePath)) { + HAPVERIFY_LOG_ERROR(LABEL, "open standard file failed"); + return OPEN_FILE_ERROR; + } + + if (!HapSigningBlockUtils::FindHapSignature(hapFile, hapSignInfo)) { + return SIGNATURE_NOT_FOUND; + } + return VERIFY_SUCCESS; +} + } // namespace Verify } // namespace Security } // namespace OHOS