1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef HAP_VERIFY_HAP_V2_H 16 #define HAP_VERIFY_HAP_V2_H 17 18 #include <string> 19 20 #include "common/hap_byte_buffer.h" 21 #include "common/random_access_file.h" 22 #include "interfaces/hap_verify_result.h" 23 #include "provision/provision_verify.h" 24 #include "util/hap_verify_openssl_utils.h" 25 26 namespace OHOS { 27 namespace Security { 28 namespace Verify { 29 class HapVerifyV2 { 30 public: 31 int Verify(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); 32 int ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); 33 34 private: 35 int Verify(RandomAccessFile& hapFile, HapVerifyResult& hapVerifyV1Result); 36 bool VerifyAppPkc7AndParseProfile(Pkcs7Context& pkcs7Context, HapByteBuffer& hapProfileBlock, 37 HapVerifyResult& hapVerifyV1Result); 38 bool VerifyAppSourceAndParseProfile(Pkcs7Context& pkcs7Context, const HapByteBuffer& hapProfileBlock, 39 HapVerifyResult& hapVerifyV1Result, bool& profileNeadWriteCrl); 40 bool VerifyAppPkcs7(Pkcs7Context& pkcs7Context, const HapByteBuffer& hapSignatureBlock); 41 bool VerifyAppSource(Pkcs7Context& pkcs7Context, Pkcs7Context& profileContext); 42 DLL_EXPORT bool GetDigestAndAlgorithm(Pkcs7Context& digest); 43 DLL_EXPORT bool CheckFilePath(const std::string& filePath, std::string& standardFilePath); 44 void WriteCrlIfNeed(const Pkcs7Context& pkcs7Context, const bool& profileNeedWriteCrl); 45 DLL_EXPORT bool ParseAndVerifyProfileIfNeed(const std::string& profile, ProvisionInfo& provisionInfo, 46 bool isCallParseAndVerify); 47 bool IsAppDistributedTypeAllowInstall(const AppDistType& type, const ProvisionInfo& provisionInfo) const; 48 DLL_EXPORT bool VerifyProfileInfo(const Pkcs7Context& pkcs7Context, const Pkcs7Context& profileContext, 49 ProvisionInfo& provisionInfo); 50 bool CheckProfileSignatureIsRight(const MatchingStates& matchState, const ProvisionType& type); 51 DLL_EXPORT bool GenerateAppId(ProvisionInfo& provisionInfo); 52 DLL_EXPORT bool GenerateFingerprint(ProvisionInfo& provisionInfo); 53 bool VerifyProfileSignature(const Pkcs7Context& pkcs7Context, Pkcs7Context& profileContext); 54 55 private: 56 static const int HEX_PRINT_LENGTH; 57 static const int DIGEST_BLOCK_LEN_OFFSET; 58 static const int DIGEST_ALGORITHM_OFFSET; 59 static const int DIGEST_LEN_OFFSET; 60 static const int DIGEST_OFFSET_IN_CONTENT; 61 static const std::string HAP_APP_PATTERN; 62 static const std::string HQF_APP_PATTERN; 63 static const std::string HSP_APP_PATTERN; 64 }; 65 } // namespace Verify 66 } // namespace Security 67 } // namespace OHOS 68 #endif // HAP_VERIFY_HAP_V2_H 69