19596a2c1Sopenharmony_ci/*
29596a2c1Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
39596a2c1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
49596a2c1Sopenharmony_ci * you may not use this file except", "in compliance with the License.
59596a2c1Sopenharmony_ci * You may obtain a copy of the License at
69596a2c1Sopenharmony_ci *
79596a2c1Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
89596a2c1Sopenharmony_ci *
99596a2c1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
109596a2c1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
119596a2c1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
129596a2c1Sopenharmony_ci * See the License for the specific language governing permissions and
139596a2c1Sopenharmony_ci * limitations under the License.
149596a2c1Sopenharmony_ci */
159596a2c1Sopenharmony_ci#ifndef OHOS_GLOBAL_I18N_VERIFY_SIGN_TOOL_H
169596a2c1Sopenharmony_ci#define OHOS_GLOBAL_I18N_VERIFY_SIGN_TOOL_H
179596a2c1Sopenharmony_ci
189596a2c1Sopenharmony_ci#include <openssl/rsa.h>
199596a2c1Sopenharmony_ci#include <string>
209596a2c1Sopenharmony_ci#include <vector>
219596a2c1Sopenharmony_ci
229596a2c1Sopenharmony_cinamespace OHOS {
239596a2c1Sopenharmony_cinamespace Global {
249596a2c1Sopenharmony_cinamespace I18n {
259596a2c1Sopenharmony_cienum VerifyStatus {
269596a2c1Sopenharmony_ci    VERIFY_FAILED = 0,
279596a2c1Sopenharmony_ci    VERIFY_START = 1,
289596a2c1Sopenharmony_ci    VERIFY_SUCCESS = 2
299596a2c1Sopenharmony_ci};
309596a2c1Sopenharmony_ci
319596a2c1Sopenharmony_ciclass SignatureVerifier {
329596a2c1Sopenharmony_cipublic:
339596a2c1Sopenharmony_ci    static bool VerifyCertFile(const std::string& certPath,
349596a2c1Sopenharmony_ci        const std::string& verifyPath, const std::string& pubkeyPath, const std::string& manifestPath);
359596a2c1Sopenharmony_ci    static bool VerifyParamFile(const std::string& filePath,
369596a2c1Sopenharmony_ci        const std::string& manifestPath, const std::string& absFilePath);
379596a2c1Sopenharmony_ci    static std::string LoadFileVersion(const std::string& versionPath);
389596a2c1Sopenharmony_ci    static int CompareVersion(std::string& preVersion, std::string& curVersion);
399596a2c1Sopenharmony_ci
409596a2c1Sopenharmony_ciprivate:
419596a2c1Sopenharmony_ci    static bool VerifyRsa(RSA* pubkey, const std::string& digest, const std::string& sign);
429596a2c1Sopenharmony_ci    static std::string CalcFileSha256Digest(const std::string& path);
439596a2c1Sopenharmony_ci    static void CalcBase64(uint8_t* input, uint32_t inputLen, std::string& encodedStr);
449596a2c1Sopenharmony_ci    static int CalcFileShaOriginal(const std::string& filePath, unsigned char* hash);
459596a2c1Sopenharmony_ci    static bool VerifyFileSign(const std::string& pubkeyPath, const std::string& signPath,
469596a2c1Sopenharmony_ci        const std::string& digestPath);
479596a2c1Sopenharmony_ci    static std::string GetFileStream(const std::string& filePath);
489596a2c1Sopenharmony_ci    static const int HASH_BUFFER_SIZE;
499596a2c1Sopenharmony_ci    static const int MIN_SIZE;
509596a2c1Sopenharmony_ci    static const int VERSION_SIZE;
519596a2c1Sopenharmony_ci};
529596a2c1Sopenharmony_ci
539596a2c1Sopenharmony_ci} // namespace I18n
549596a2c1Sopenharmony_ci} // namespace Global
559596a2c1Sopenharmony_ci} // namespace OHOS
569596a2c1Sopenharmony_ci#endif