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 16 #ifndef SIGNATRUETOOLS_LOCALIIZATION_ADAPTER_H 17 #define SIGNATRUETOOLS_LOCALIIZATION_ADAPTER_H 18 19 #include <memory> 20 #include <string> 21 22 #include "openssl/ssl.h" 23 #include "openssl/pem.h" 24 #include "openssl/err.h" 25 #include "options.h" 26 #include "key_store_helper.h" 27 #include "cert_dn_utils.h" 28 #include "signature_tools_log.h" 29 #include "digest_common.h" 30 namespace OHOS { 31 namespace SignatureTools { 32 class LocalizationAdapter { 33 public: 34 LocalizationAdapter() = default; 35 LocalizationAdapter(Options* options); 36 ~LocalizationAdapter() = default; 37 38 int IsAliasExist(const std::string& alias); 39 int GetKeyPair(bool autoCreate, EVP_PKEY** keyPair); 40 int IssuerKeyStoreFile(EVP_PKEY** keyPair, bool autoCreate); 41 int KeyStoreFile(EVP_PKEY** keyPair, bool autoCreate); 42 43 void ResetPwd(); 44 void SetIssuerKeyStoreFile(bool issuerKeyStoreFile); 45 void AppAndProfileAssetsRealse(std::initializer_list<EVP_PKEY*> keys, 46 std::initializer_list<X509_REQ*> reqs, 47 std::initializer_list<X509*> certs); 48 49 bool IsOutFormChain(); 50 bool IsRemoteSigner(); 51 52 const std::string GetSignAlg() const; 53 const std::string GetOutFile(); 54 const std::string GetInFile(); 55 56 Options* GetOptions(); 57 EVP_PKEY* GetAliasKey(bool autoCreate); 58 EVP_PKEY* GetIssuerKeyByAlias(); 59 X509* GetSubCaCertFile(); 60 X509* GetCaCertFile(); 61 STACK_OF(X509)* GetSignCertChain(); 62 std::vector<X509*> GetCertsFromFile(std::string& certPath, const std::string& logTitle); 63 64 private: 65 void ResetChars(char* chars); 66 67 public: 68 Options* options; 69 std::unique_ptr<KeyStoreHelper> keyStoreHelper; 70 71 private: 72 static constexpr int MIN_CERT_CHAIN_SIZE = 2; 73 static constexpr int MAX_CERT_CHAIN_SIZE = 3; 74 bool isIssuerKeyStoreFile; 75 }; 76 } // namespace SignatureTools 77 } // namespace OHOS 78 #endif // SIGNATRUETOOLS_LOCALIIZATION_ADAPTER_H 79