18e920a95Sopenharmony_ci/*
28e920a95Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
38e920a95Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48e920a95Sopenharmony_ci * you may not use this file except in compliance with the License.
58e920a95Sopenharmony_ci * You may obtain a copy of the License at
68e920a95Sopenharmony_ci *
78e920a95Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88e920a95Sopenharmony_ci *
98e920a95Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108e920a95Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118e920a95Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128e920a95Sopenharmony_ci * See the License for the specific language governing permissions and
138e920a95Sopenharmony_ci * limitations under the License.
148e920a95Sopenharmony_ci */
158e920a95Sopenharmony_ci
168e920a95Sopenharmony_ci#ifndef CODE_SIGN_SIGNER_INFO_H
178e920a95Sopenharmony_ci#define CODE_SIGN_SIGNER_INFO_H
188e920a95Sopenharmony_ci
198e920a95Sopenharmony_ci#include <vector>
208e920a95Sopenharmony_ci#include <string>
218e920a95Sopenharmony_ci#include <openssl/evp.h>
228e920a95Sopenharmony_ci#include <openssl/pkcs7.h>
238e920a95Sopenharmony_ci#include <openssl/x509.h>
248e920a95Sopenharmony_ci
258e920a95Sopenharmony_ci#include "byte_buffer.h"
268e920a95Sopenharmony_ci
278e920a95Sopenharmony_cinamespace OHOS {
288e920a95Sopenharmony_cinamespace Security {
298e920a95Sopenharmony_cinamespace CodeSign {
308e920a95Sopenharmony_ciclass SignerInfo {
318e920a95Sopenharmony_cipublic:
328e920a95Sopenharmony_ci    static const std::string OWNERID_OID;
338e920a95Sopenharmony_ci    static const std::string OWNERID_OID_SHORT_NAME;
348e920a95Sopenharmony_ci    static const std::string OWNERID_OID_LONG_NAME;
358e920a95Sopenharmony_ci
368e920a95Sopenharmony_ci    static int ParseOwnerIdFromSignature(const ByteBuffer &sigbuffer, std::string &ownerID);
378e920a95Sopenharmony_ci    bool InitSignerInfo(const std::string &ownerID, X509 *cert, const EVP_MD *md, const ByteBuffer &contentData,
388e920a95Sopenharmony_ci                        bool carrySigningTime = false);
398e920a95Sopenharmony_ci    bool AddSignatureInSignerInfo(const ByteBuffer &signature);
408e920a95Sopenharmony_ci    uint8_t *GetDataToSign(uint32_t &len);
418e920a95Sopenharmony_ci    PKCS7_SIGNER_INFO *GetSignerInfo();
428e920a95Sopenharmony_ci    int AddOwnerID(const std::string &ownerID);
438e920a95Sopenharmony_ci
448e920a95Sopenharmony_ciprivate:
458e920a95Sopenharmony_ci    bool AddAttrsToSignerInfo(const std::string &ownerID, const ByteBuffer &contentData);
468e920a95Sopenharmony_ci    bool ComputeDigest(const ByteBuffer &data, ByteBuffer &digest);
478e920a95Sopenharmony_ci    int GetSignAlgorithmID(const X509 *cert);
488e920a95Sopenharmony_ci
498e920a95Sopenharmony_ci    PKCS7_SIGNER_INFO *p7info_ = nullptr;
508e920a95Sopenharmony_ci    const EVP_MD *md_ = nullptr;
518e920a95Sopenharmony_ci    bool carrySigningTime_ = false;
528e920a95Sopenharmony_ci    std::unique_ptr<ByteBuffer> unsignedData_ = nullptr;
538e920a95Sopenharmony_ci};
548e920a95Sopenharmony_ci}
558e920a95Sopenharmony_ci}
568e920a95Sopenharmony_ci}
578e920a95Sopenharmony_ci#endif