• 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 #ifndef SIGNATURETOOLS_CODE_SIGNING_H
16 #define SIGNATURETOOLS_CODE_SIGNING_H
17 
18 #include <vector>
19 #include <string>
20 #include <mutex>
21 
22 #include "securec.h"
23 #include "thread_pool.h"
24 #include "file_utils.h"
25 #include "local_signer.h"
26 #include "signer_config.h"
27 #include "signature_tools_log.h"
28 #include "fs_verity_generator.h"
29 #include "bc_signeddata_generator.h"
30 
31 namespace OHOS {
32 namespace SignatureTools {
33 class CodeSigning {
34 public:
35     CodeSigning(SignerConfig* signConfig, bool selfSign);
36     CodeSigning();
37 
38     bool GetElfCodeSignBlock(const std::string &input, uint64_t& csOffset, std::vector<int8_t> &codesignData);
39 
40 public:
41     bool GenerateSignature(const std::vector<int8_t>& signedData, const std::string& ownerID,
42                            std::vector<int8_t>& ret);
43     bool GetOwnerIdFromCert(std::string& ownerID);
44     SignerConfig* m_signConfig;
45     bool m_selfSign;
46 
47 private:
48     static constexpr int MIN_CERT_CHAIN_SIZE = 2;
49     static constexpr int MAX_CERT_CHAIN_SIZE = 3;
50 };
51 } // namespace SignatureTools
52 } // namespace OHOS
53 #endif // SIGNATURETOOLS_CODE_SIGNING_H