1 /* 2 * Copyright (c) 2024-2024 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 SIGNATRUETOOLS_BC_SIGNEDDATA_GENERATOR_H 16 #define SIGNATRUETOOLS_BC_SIGNEDDATA_GENERATOR_H 17 18 #include <string> 19 #include <vector> 20 #include <memory> 21 22 #include "openssl/x509.h" 23 #include "signeddata_generator.h" 24 #include "pkcs7_data.h" 25 #include "signer_config.h" 26 #include "signer.h" 27 28 namespace OHOS { 29 namespace SignatureTools { 30 31 class BCSignedDataGenerator : public SignedDataGenerator { 32 public: 33 /** 34 * Generate signature data with specific content and sign configuration. 35 * 36 * @param content unsigned file digest content. 37 * @param signerConfig sign configurations. 38 * @ret signed data. 39 * @return 0:success <0:error 40 */ 41 static int GetSigAlg(SignerConfig* signerConfig, std::string& sigAlg); 42 int GenerateSignedData(const std::string& content, SignerConfig* signerConfig, std::string& ret)override; 43 void SetOwnerId(const std::string& ownerID); 44 45 private: 46 // @return 0(NID_undef) >0: success(new NID) 47 static int CreateNIDFromOID(const std::string& oid, const std::string& shortName, 48 const std::string& longName); 49 int PackageSignedData(const std::string& content, const std::shared_ptr<Signer>& signer, 50 const std::string& sigAlg, std::string& ret); 51 // @return 0:success <0 :error 52 int AddOwnerID(std::vector<PKCS7Attr>& attrs, const std::string& ownerID); 53 54 private: 55 std::string m_ownerID; 56 }; 57 } // namespace SignatureTools 58 } // namespace OHOS 59 #endif // SIGNATRUETOOLS_BC_SIGNEDDATA_GENERATOR_H