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 DEVICE_UNAUTHORIZED = -15, 51 }; 52 53 enum GetOptionalBlockResultCode { 54 GET_SUCCESS = 0, 55 NO_THIS_BLOCK_IN_PACKAGE = 1, 56 }; 57 58 struct OptionalBlock { 59 int32_t optionalType = 0; 60 HapByteBuffer optionalBlockValue; 61 }; 62 63 class HapVerifyResult { 64 public: 65 DLL_EXPORT HapVerifyResult(); 66 DLL_EXPORT ~HapVerifyResult(); 67 DLL_EXPORT int32_t GetVersion() const; 68 DLL_EXPORT void SetVersion(int32_t signatureVersion); 69 DLL_EXPORT void SetPkcs7SignBlock(const HapByteBuffer& pkcs7); 70 DLL_EXPORT void SetPkcs7ProfileBlock(const HapByteBuffer& pkcs7); 71 DLL_EXPORT void SetOptionalBlocks(const std::vector<OptionalBlock>& option); 72 DLL_EXPORT void SetProvisionInfo(const ProvisionInfo& info); 73 DLL_EXPORT int32_t GetProperty(std::string& property) const; 74 DLL_EXPORT ProvisionInfo GetProvisionInfo() const; 75 DLL_EXPORT std::vector<std::string> GetPublicKey() const; 76 DLL_EXPORT std::vector<std::string> GetSignature() const; 77 void SetPublicKey(const std::vector<std::string>& inputPubkeys); 78 void SetSignature(const std::vector<std::string>& inputSignatures); 79 80 private: 81 DLL_EXPORT int32_t GetBlockFromOptionalBlocks(int32_t blockType, std::string& block) const; 82 83 private: 84 int32_t version = 0; 85 std::vector<std::string> publicKeys; 86 std::vector<std::string> signatures; 87 HapByteBuffer pkcs7SignBlock; 88 HapByteBuffer pkcs7ProfileBlock; 89 std::vector<OptionalBlock> optionalBlocks; 90 ProvisionInfo provisionInfo; 91 }; 92 } // namespace Verify 93 } // namespace Security 94 } // namespace OHOS 95 #endif // HAP_VERIFY_RESULT_H 96