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