• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 HapVerifyResultCode {
29     VERIFY_SUCCESS = 0,
30     FILE_PATH_INVALID = -1,
31     OPEN_FILE_ERROR = -2,
32     SIGNATURE_NOT_FOUND = -3,
33     VERIFY_APP_PKCS7_FAIL = -4,
34     PROFILE_PARSE_FAIL = -5,
35     APP_SOURCE_NOT_TRUSTED = -6,
36     GET_DIGEST_FAIL = -7,
37     VERIFY_INTEGRITY_FAIL = -8,
38     FILE_SIZE_TOO_LARGE = -9,
39     GET_PUBLICKEY_FAIL = -10,
40     GET_SIGNATURE_FAIL = -11,
41     NO_PROFILE_BLOCK_FAIL = -12,
42     VERIFY_SIGNATURE_FAIL = -13,
43     VERIFY_SOURCE_INIT_FAIL = -14,
44 };
45 
46 enum GetOptionalBlockResultCode {
47     GET_SUCCESS = 0,
48     NO_THIS_BLOCK_IN_PACKAGE = 1,
49 };
50 
51 struct OptionalBlock {
52     int optionalType;
53     HapByteBuffer optionalBlockValue;
54 };
55 
56 class HapVerifyResult {
57 public:
58     DLL_EXPORT HapVerifyResult();
59     DLL_EXPORT ~HapVerifyResult();
60     DLL_EXPORT int GetVersion() const;
61     DLL_EXPORT void SetVersion(int signatureVersion);
62     DLL_EXPORT void SetPkcs7SignBlock(const HapByteBuffer& pkcs7);
63     DLL_EXPORT void SetPkcs7ProfileBlock(const HapByteBuffer& pkcs7);
64     DLL_EXPORT void SetOptionalBlocks(const std::vector<OptionalBlock>& option);
65     DLL_EXPORT void SetProvisionInfo(const ProvisionInfo& info);
66     DLL_EXPORT int GetProperty(std::string& property) const;
67     DLL_EXPORT ProvisionInfo GetProvisionInfo() const;
68     DLL_EXPORT std::vector<std::string> GetPublicKey() const;
69     DLL_EXPORT std::vector<std::string> GetSignature() const;
70     void SetPublicKey(const std::vector<std::string>& inputPubkeys);
71     void SetSignature(const std::vector<std::string>& inputSignatures);
72 
73 private:
74     DLL_EXPORT int GetBlockFromOptionalBlocks(int blockType, std::string& block) const;
75 
76 private:
77     int version;
78     std::vector<std::string> publicKeys;
79     std::vector<std::string> signatures;
80     HapByteBuffer pkcs7SignBlock;
81     HapByteBuffer pkcs7ProfileBlock;
82     std::vector<OptionalBlock> optionalBlocks;
83     ProvisionInfo provisionInfo;
84 };
85 } // namespace Verify
86 } // namespace Security
87 } // namespace OHOS
88 #endif // HAP_VERIFY_RESULT_H
89