• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 CODE_SIGN_SIGNER_INFO_H
17 #define CODE_SIGN_SIGNER_INFO_H
18 
19 #include <vector>
20 
21 #include "byte_buffer.h"
22 #include "openssl/evp.h"
23 #include "openssl/pkcs7.h"
24 #include "openssl/x509.h"
25 
26 namespace OHOS {
27 namespace Security {
28 namespace CodeSign {
29 class SignerInfo {
30 public:
31     bool InitSignerInfo(X509 *cert, const EVP_MD *md, const ByteBuffer &contentData, bool carrySigningTime = false);
32     bool AddSignatureInSignerInfo(const ByteBuffer &signature);
33     uint8_t *GetDataToSign(uint32_t &len);
34     PKCS7_SIGNER_INFO *GetSignerInfo();
35 private:
36     bool AddAttrsToSignerInfo(const ByteBuffer &contentData);
37     bool ComputeDigest(const ByteBuffer &data, ByteBuffer &digest);
38     int GetSignAlgorithmID(const X509 *cert);
39 
40     PKCS7_SIGNER_INFO *p7info_ = nullptr;
41     const EVP_MD *md_ = nullptr;
42     bool carrySigningTime_ = false;
43     std::unique_ptr<ByteBuffer> unsignedData_ = nullptr;
44 };
45 }
46 }
47 }
48 #endif