From 6566efec4ae56150f4e8569cd37a63ae8ce2a0ac Mon Sep 17 00:00:00 2001 From: zhushengle Date: Tue, 31 Oct 2023 13:58:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=90=E4=BE=9B=E5=AF=B9=E5=A4=96?= =?UTF-8?q?=E8=8E=B7=E5=8F=96signatureinfo=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushengle Change-Id: I6ad3711713c12feac900b4862849bfa6794e6885 --- bundle.json | 5 +++-- .../appverify/include/interfaces/hap_verify.h | 2 ++ .../appverify/include/verify/hap_verify_v2.h | 2 ++ .../appverify/src/interfaces/hap_verify.cpp | 7 +++++++ .../appverify/src/verify/hap_verify_v2.cpp | 20 +++++++++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/bundle.json b/bundle.json index fccf599..590f64f 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 ab11015..4cc9461 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 74fa3a6..620c851 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 55c9e92..316cfc5 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 6379eb2..bab73c9 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 -- Gitee