• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "pkg_verify.h"
17 
18 #include "log/log.h"
19 #include "package/cert_verify.h"
20 #include "package/pkg_manager.h"
21 #include "utils.h"
22 
23 namespace OHOS {
24 namespace SysInstaller {
25 using namespace Updater;
26 using namespace Hpackage;
27 
28 constexpr const char *CERT_NAME = "/updater/certificate/signing_cert.crt";
29 
Init()30 void PkgVerify::Init()
31 {
32     CertVerify::GetInstance().RegisterCertHelper(std::make_unique<SingleCertHelper>());
33 }
34 
UpdatePreCheck(const std::string & pkgPath)35 int PkgVerify::UpdatePreCheck(const std::string &pkgPath)
36 {
37     if (statusManager_ == nullptr) {
38         LOG(ERROR) << "statusManager_ nullptr";
39         return -1;
40     }
41 
42     if (!verifyInit_) {
43         Init();
44         verifyInit_ = true;
45     }
46 
47     statusManager_->UpdateCallback(UPDATE_STATE_ONGOING, 1); // 1 : 1%
48     int ret = VerifyPackage(pkgPath.c_str(), CERT_NAME, "", nullptr, 0);
49     if (ret != 0) {
50         LOG(ERROR) << "VerifyPackage failed:" << ret;
51         statusManager_->UpdateCallback(UPDATE_STATE_ONGOING, 1); // 1 : 1%
52         return -1;
53     }
54 
55     statusManager_->UpdateCallback(UPDATE_STATE_ONGOING, 5); // 5 : %5
56     LOG(INFO) << "UpdatePreCheck successful";
57     return 0;
58 }
59 } // namespace SysInstaller
60 } // namespace OHOS
61