• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef OHOS_GLOBAL_I18N_SIGNATURE_VERIFIER_H
16 #define OHOS_GLOBAL_I18N_SIGNATURE_VERIFIER_H
17 
18 #include <openssl/rsa.h>
19 #include <string>
20 #include <vector>
21 
22 namespace OHOS {
23 namespace Global {
24 namespace I18n {
25 class SignatureVerifier {
26 public:
27     static bool VerifyCertFile(const std::string& certPath, const std::string& verifyPath,
28         const std::string& pubkeyPath, const std::string& manifestPath);
29     static bool VerifyUpdateFile(const std::string& filePath, const std::string& manifestPath,
30         std::vector<std::string>& filesList);
31     static const size_t MIN_SIZE;
32 
33 private:
34     static bool VerifyRsa(RSA* pubkey, const std::string& digest, const std::string& sign);
35     static std::string CalcFileSha256Digest(const std::string& path);
36     static void CalcBase64(uint8_t* input, uint32_t inputLen, std::string& encodedStr);
37     static bool CalcFileShaOriginal(const std::string& filePath, unsigned char* hash);
38     static bool VerifyFileSign(const std::string& pubkeyPath, const std::string& signPath,
39         const std::string& digestPath);
40     static std::string GetFileStream(const std::string& filePath);
41     static const int32_t BASE64_ENCODE_PACKET_LEN;
42     static const int32_t BASE64_ENCODE_LEN_OF_EACH_GROUP_DATA;
43     static const size_t HASH_BUFFER_SIZE;
44     static const std::string PREFIX_NAME;
45 };
46 } // namespace I18n
47 } // namespace Global
48 } // namespace OHOS
49 #endif