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() {}
27 
~PkgVerifyUtil()28     ~PkgVerifyUtil() {}
29 
30     int32_t VerifyPackageSign(const Hpackage::PkgStreamPtr PkgStream, const std::string &path) const;
31     int32_t VerifySign(std::vector<uint8_t> &signData, std::vector<uint8_t> &digest) const;
32     int32_t VerifySourceDigest(std::vector<uint8_t> &signature, std::vector<uint8_t> &sourceDigest,
33         const std::string &keyPath) const;
34     int32_t VerifyAccPackageSign(const PkgStreamPtr pkgStream, const std::string &keyPath) const;
35     int32_t GetSignature(const PkgStreamPtr pkgStream, size_t &signatureSize,
36         std::vector<uint8_t> &signature, uint16_t &commentTotalLenAll) const;
37 #ifndef UPDATER_UT
38 private:
39 #else
40 public:
41 #endif
42 
43     int32_t ParsePackage(const PkgStreamPtr pkgStream, size_t &signatureStart,
44         size_t &signatureSize, uint16_t &commentTotalLenAll) const;
45 
46     int32_t Pkcs7verify(std::vector<uint8_t> &signature, std::vector<uint8_t> &hash) const;
47 
48     int32_t HashCheck(const PkgStreamPtr srcData, const size_t dataLen,
49         const std::vector<uint8_t> &hash, const std::string &path) const;
50 };
51 } // namespace Hpackage
52 #endif
53