154aa6d63Sopenharmony_ci/* 254aa6d63Sopenharmony_ci * Copyright (c) 2024-2024 Huawei Device Co., Ltd. 354aa6d63Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 454aa6d63Sopenharmony_ci * you may not use this file except in compliance with the License. 554aa6d63Sopenharmony_ci * You may obtain a copy of the License at 654aa6d63Sopenharmony_ci * 754aa6d63Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 854aa6d63Sopenharmony_ci * 954aa6d63Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1054aa6d63Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1154aa6d63Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1254aa6d63Sopenharmony_ci * See the License for the specific language governing permissions and 1354aa6d63Sopenharmony_ci * limitations under the License. 1454aa6d63Sopenharmony_ci */ 1554aa6d63Sopenharmony_ci#ifndef SIGNATRUETOOLS_VERIFY_HAP_V2_H 1654aa6d63Sopenharmony_ci#define SIGNATRUETOOLS_VERIFY_HAP_V2_H 1754aa6d63Sopenharmony_ci#include <string> 1854aa6d63Sopenharmony_ci 1954aa6d63Sopenharmony_ci#include "byte_buffer.h" 2054aa6d63Sopenharmony_ci#include "random_access_file.h" 2154aa6d63Sopenharmony_ci#include "profile_verify.h" 2254aa6d63Sopenharmony_ci#include "verify_hap_openssl_utils.h" 2354aa6d63Sopenharmony_ci#include "signature_info.h" 2454aa6d63Sopenharmony_ci#include "options.h" 2554aa6d63Sopenharmony_ci#include "file_utils.h" 2654aa6d63Sopenharmony_ci 2754aa6d63Sopenharmony_cinamespace OHOS { 2854aa6d63Sopenharmony_cinamespace SignatureTools { 2954aa6d63Sopenharmony_ciclass VerifyHap { 3054aa6d63Sopenharmony_cipublic: 3154aa6d63Sopenharmony_ci static const int32_t HEX_PRINT_LENGTH; 3254aa6d63Sopenharmony_ci static const int32_t DIGEST_BLOCK_LEN_OFFSET; 3354aa6d63Sopenharmony_ci static const int32_t DIGEST_ALGORITHM_OFFSET; 3454aa6d63Sopenharmony_ci static const int32_t DIGEST_LEN_OFFSET; 3554aa6d63Sopenharmony_ci static const int32_t DIGEST_OFFSET_IN_CONTENT; 3654aa6d63Sopenharmony_ci static const std::string HAP_APP_PATTERN; 3754aa6d63Sopenharmony_ci static const std::string HQF_APP_PATTERN; 3854aa6d63Sopenharmony_ci static const std::string HSP_APP_PATTERN; 3954aa6d63Sopenharmony_ci static const std::string APP_APP_PATTERN; 4054aa6d63Sopenharmony_ci static const int OFFSET_ZERO = 0; 4154aa6d63Sopenharmony_ci static const int OFFSET_FOUR = 4; 4254aa6d63Sopenharmony_ci static const int OFFSET_EIGHT = 8; 4354aa6d63Sopenharmony_ci 4454aa6d63Sopenharmony_ci VerifyHap(); 4554aa6d63Sopenharmony_ci VerifyHap(bool isPrintCert); 4654aa6d63Sopenharmony_ci void setIsPrintCert(bool printCert); 4754aa6d63Sopenharmony_ci 4854aa6d63Sopenharmony_ci bool HapOutPutPkcs7(PKCS7* p7, const std::string& outPutPath); 4954aa6d63Sopenharmony_ci 5054aa6d63Sopenharmony_ci DLL_EXPORT bool CheckFilePath(const std::string& filePath, std::string& standardFilePath); 5154aa6d63Sopenharmony_ci 5254aa6d63Sopenharmony_ci bool outputOptionalBlocks(const std::string& outputProfileFile, const std::string& outputProofFile, 5354aa6d63Sopenharmony_ci const std::string& outputPropertyFile, 5454aa6d63Sopenharmony_ci const std::vector<OptionalBlock>& optionBlocks); 5554aa6d63Sopenharmony_ci bool writeOptionalBytesToFile(const OptionalBlock& optionalBlock, const std::string& path); 5654aa6d63Sopenharmony_ci 5754aa6d63Sopenharmony_ci bool HapOutPutCertChain(std::vector<X509*>& certs, const std::string& outPutPath); 5854aa6d63Sopenharmony_ci 5954aa6d63Sopenharmony_ci int32_t Verify(const std::string& filePath, Options* options); 6054aa6d63Sopenharmony_ci 6154aa6d63Sopenharmony_ci int32_t WriteVerifyOutput(Pkcs7Context& pkcs7Context, std::vector<int8_t>& profile, Options* options); 6254aa6d63Sopenharmony_ci 6354aa6d63Sopenharmony_ci int32_t Verify(RandomAccessFile& hapFile, Options* options, const std::string& filePath); 6454aa6d63Sopenharmony_ci 6554aa6d63Sopenharmony_ci bool CheckCodeSign(const std::string& hapFilePath, const std::vector<OptionalBlock>& optionalBlocks)const; 6654aa6d63Sopenharmony_ci static int GetProfileContent(const std::string profile, std::string& ret); 6754aa6d63Sopenharmony_ci 6854aa6d63Sopenharmony_ci bool VerifyAppPkcs7(Pkcs7Context& pkcs7Context, const ByteBuffer& hapSignatureBlock); 6954aa6d63Sopenharmony_ci DLL_EXPORT bool GetDigestAndAlgorithm(Pkcs7Context& digest); 7054aa6d63Sopenharmony_ci static bool PrintCertChainToCmd(std::vector<X509*>& certChain); 7154aa6d63Sopenharmony_ci 7254aa6d63Sopenharmony_ciprivate: 7354aa6d63Sopenharmony_ci bool isPrintCert; 7454aa6d63Sopenharmony_ci}; 7554aa6d63Sopenharmony_ci} // namespace SignatureTools 7654aa6d63Sopenharmony_ci} // namespace OHOS 7754aa6d63Sopenharmony_ci#endif // SIGNATRUETOOLS_VERIFY_HAP_V2_H