• 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 #include "local_sign_provider.h"
16 #include "params.h"
17 #include "file_utils.h"
18 
19 namespace OHOS {
20 namespace SignatureTools {
GetCrl()21 std::optional<X509_CRL*> LocalSignProvider::GetCrl()
22 {
23     return std::optional<X509_CRL*>();
24 }
25 
CheckParams(Options * options)26 bool LocalSignProvider::CheckParams(Options* options)
27 {
28     if (!SignProvider::CheckParams(options)) {
29         SIGNATURE_TOOLS_LOGE("Parameter check failed !");
30         return false;
31     }
32     std::vector<std::string> paramFileds;
33     paramFileds.emplace_back(ParamConstants::PARAM_LOCAL_JKS_KEYSTORE);
34     paramFileds.emplace_back(ParamConstants::PARAM_LOCAL_JKS_KEYSTORE_CODE);
35     paramFileds.emplace_back(ParamConstants::PARAM_LOCAL_JKS_KEYALIAS_CODE);
36     std::unordered_set<std::string> paramSet = Params::InitParamField(paramFileds);
37     if (!this->SetSignParams(options, paramSet)) {
38         return false;
39     }
40     if (!CheckPublicKeyPath()) {
41         SIGNATURE_TOOLS_LOGE("appCertFile Parameter check error !");
42         return false;
43     }
44     return true;
45 }
46 
CheckPublicKeyPath()47 bool LocalSignProvider::CheckPublicKeyPath()
48 {
49     bool flag = false;
50     std::string publicCertsFile = signParams[ParamConstants::PARAM_LOCAL_PUBLIC_CERT];
51     flag = !FileUtils::IsValidFile(publicCertsFile);
52     if (flag) {
53         SIGNATURE_TOOLS_LOGE("%s", std::string(publicCertsFile + " is valid").c_str());
54         return false;
55     }
56     std::ifstream publicKeyFile(publicCertsFile);
57     flag = !publicKeyFile.is_open();
58     if (flag) {
59         PrintErrorNumberMsg("IO_ERROR", IO_ERROR, publicCertsFile + " open failed ");
60         return false;
61     }
62     publicKeyFile.close();
63     return true;
64 }
65 } // namespace SignatureTools
66 } // namespace OHOS