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_VERIFY_SIGN_TOOL_H 16 #define OHOS_GLOBAL_I18N_VERIFY_SIGN_TOOL_H 17 18 #include <openssl/rsa.h> 19 #include <string> 20 #include <vector> 21 22 namespace OHOS { 23 namespace Global { 24 namespace I18n { 25 enum VerifyStatus { 26 VERIFY_FAILED = 0, 27 VERIFY_START = 1, 28 VERIFY_SUCCESS = 2 29 }; 30 31 class SignatureVerifier { 32 public: 33 static bool VerifyCertFile(const std::string& certPath, 34 const std::string& verifyPath, const std::string& pubkeyPath, const std::string& manifestPath); 35 static bool VerifyParamFile(const std::string& filePath, 36 const std::string& manifestPath, const std::string& absFilePath); 37 static std::string LoadFileVersion(const std::string& versionPath); 38 static int CompareVersion(std::string& preVersion, std::string& curVersion); 39 40 private: 41 static bool VerifyRsa(RSA* pubkey, const std::string& digest, const std::string& sign); 42 static std::string CalcFileSha256Digest(const std::string& path); 43 static void CalcBase64(uint8_t* input, uint32_t inputLen, std::string& encodedStr); 44 static int CalcFileShaOriginal(const std::string& filePath, unsigned char* hash); 45 static bool VerifyFileSign(const std::string& pubkeyPath, const std::string& signPath, 46 const std::string& digestPath); 47 static std::string GetFileStream(const std::string& filePath); 48 static const int HASH_BUFFER_SIZE; 49 static const int MIN_SIZE; 50 static const int VERSION_SIZE; 51 }; 52 53 } // namespace I18n 54 } // namespace Global 55 } // namespace OHOS 56 #endif