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_RESULT_H 16 #define HAP_VERIFY_RESULT_H 17 18 #include <string> 19 #include <vector> 20 21 #include "common/export_define.h" 22 #include "common/hap_byte_buffer.h" 23 #include "provision/provision_info.h" 24 25 namespace OHOS { 26 namespace Security { 27 namespace Verify { 28 enum class DevMode { 29 DEFAULT = 0, 30 DEV, 31 NON_DEV, 32 }; 33 34 enum HapVerifyResultCode { 35 VERIFY_SUCCESS = 0, 36 FILE_PATH_INVALID = -1, 37 OPEN_FILE_ERROR = -2, 38 SIGNATURE_NOT_FOUND = -3, 39 VERIFY_APP_PKCS7_FAIL = -4, 40 PROFILE_PARSE_FAIL = -5, 41 APP_SOURCE_NOT_TRUSTED = -6, 42 GET_DIGEST_FAIL = -7, 43 VERIFY_INTEGRITY_FAIL = -8, 44 FILE_SIZE_TOO_LARGE = -9, 45 GET_PUBLICKEY_FAIL = -10, 46 GET_SIGNATURE_FAIL = -11, 47 NO_PROFILE_BLOCK_FAIL = -12, 48 VERIFY_SIGNATURE_FAIL = -13, 49 VERIFY_SOURCE_INIT_FAIL = -14, 50 }; 51 52 enum GetOptionalBlockResultCode { 53 GET_SUCCESS = 0, 54 NO_THIS_BLOCK_IN_PACKAGE = 1, 55 }; 56 57 struct OptionalBlock { 58 int32_t optionalType = 0; 59 HapByteBuffer optionalBlockValue; 60 }; 61 62 class HapVerifyResult { 63 public: 64 DLL_EXPORT HapVerifyResult(); 65 DLL_EXPORT ~HapVerifyResult(); 66 DLL_EXPORT int32_t GetVersion() const; 67 DLL_EXPORT void SetVersion(int32_t signatureVersion); 68 DLL_EXPORT void SetPkcs7SignBlock(const HapByteBuffer& pkcs7); 69 DLL_EXPORT void SetPkcs7ProfileBlock(const HapByteBuffer& pkcs7); 70 DLL_EXPORT void SetOptionalBlocks(const std::vector<OptionalBlock>& option); 71 DLL_EXPORT void SetProvisionInfo(const ProvisionInfo& info); 72 DLL_EXPORT int32_t GetProperty(std::string& property) const; 73 DLL_EXPORT ProvisionInfo GetProvisionInfo() const; 74 DLL_EXPORT std::vector<std::string> GetPublicKey() const; 75 DLL_EXPORT std::vector<std::string> GetSignature() const; 76 void SetPublicKey(const std::vector<std::string>& inputPubkeys); 77 void SetSignature(const std::vector<std::string>& inputSignatures); 78 79 private: 80 DLL_EXPORT int32_t GetBlockFromOptionalBlocks(int32_t blockType, std::string& block) const; 81 82 private: 83 int32_t version = 0; 84 std::vector<std::string> publicKeys; 85 std::vector<std::string> signatures; 86 HapByteBuffer pkcs7SignBlock; 87 HapByteBuffer pkcs7ProfileBlock; 88 std::vector<OptionalBlock> optionalBlocks; 89 ProvisionInfo provisionInfo; 90 }; 91 } // namespace Verify 92 } // namespace Security 93 } // namespace OHOS 94 #endif // HAP_VERIFY_RESULT_H 95