• 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 #ifndef PKG_VERIFY_UTIL_H
17 #define PKG_VERIFY_UTIL_H
18 
19 #include <vector>
20 #include "pkcs7_signed_data.h"
21 #include "pkg_stream.h"
22 
23 namespace Hpackage {
24 class PkgVerifyUtil {
25 public:
PkgVerifyUtil()26     PkgVerifyUtil() {}
PkgVerifyUtil(bool isOldSigSupport)27     explicit PkgVerifyUtil(bool isOldSigSupport) : isOldSigSupport_(isOldSigSupport) {}
28 
~PkgVerifyUtil()29     ~PkgVerifyUtil() {}
30 
31     int32_t VerifyPackageSign(const Hpackage::PkgStreamPtr PkgStream, const std::string &path) const;
32     int32_t VerifySign(std::vector<uint8_t> &signData, std::vector<uint8_t> &digest) const;
33     int32_t VerifySourceDigest(std::vector<uint8_t> &signature, std::vector<uint8_t> &sourceDigest,
34         const std::string &keyPath) const;
35     int32_t VerifyAccPackageSign(const PkgStreamPtr pkgStream, const std::string &keyPath) const;
36     int32_t GetSignature(const PkgStreamPtr pkgStream, size_t &signatureSize,
37         std::vector<uint8_t> &signature, uint16_t &commentTotalLenAll) const;
38 #ifndef UPDATER_UT
39 private:
40 #else
41 public:
42 #endif
43 
44     int32_t ParsePackage(const PkgStreamPtr pkgStream, size_t &signatureStart,
45         size_t &signatureSize, uint16_t &commentTotalLenAll) const;
46 
47     int32_t Pkcs7verify(std::vector<uint8_t> &signature, std::vector<uint8_t> &hash) const;
48 
49     int32_t HashCheck(const PkgStreamPtr srcData, const size_t dataLen,
50         const std::vector<uint8_t> &hash, const std::string &path) const;
51 
52     std::string GetPkgTime(const std::string &pkgPath) const;
53 
54     void WriteHash(std::vector<uint8_t> &hash, const std::string &pkgPath) const;
55 private:
56     bool isOldSigSupport_ {true};
57 };
58 } // namespace Hpackage
59 #endif
60