• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025-2025 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 
16 #ifndef SIGNATRUETOOLS_VERIFY_ELF_H
17 #define SIGNATRUETOOLS_VERIFY_ELF_H
18 
19 #include <string>
20 #include <vector>
21 #include <elfio.hpp>
22 #include <openssl/x509.h>
23 #include "pkcs7_data.h"
24 #include "options.h"
25 #include "signature_tools_log.h"
26 
27 namespace OHOS {
28 namespace SignatureTools {
29 
30 struct ElfSignInfo {
31     uint32_t type;
32     uint32_t length;
33     uint8_t  version;
34     uint8_t  hashAlgorithm;
35     uint8_t  logBlockSize;
36     uint8_t  saltSize;
37     uint32_t signSize;
38     uint64_t dataSize;
39     uint8_t  rootHash[64];
40     uint8_t  salt[32];
41     uint32_t flags;
42     uint8_t  reserved_1[12];
43     uint8_t  reserved_2[127];
44     uint8_t  csVersion;
45     uint8_t  signature[0];
46 };
47 
48 class VerifyElf {
49 public:
50     static constexpr int PAGE_SIZE = 4096;
51     static const std::string profileSec;
52     static const std::string permissionSec;
53     static const std::string codesignSec;
54 
55 public:
56     bool Verify(Options* options);
57     static bool CheckParams(Options* options);
58 
59 private:
60     static bool ParseSignBlock(const ELFIO::elfio& elfReader);
61     static bool PrintCertChainToCmd(std::vector<X509*>& certChain);
62 };
63 } // namespace SignatureTools
64 } // namespace OHOS
65 #endif