1 /*
2  * Copyright (c) 2023-2023 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 LOG_SIGN_TOOLS_H
17 #define LOG_SIGN_TOOLS_H
18 
19 #include <fstream>
20 #include <functional>
21 #include <iomanip>
22 #include <memory>
23 #include <openssl/bio.h>
24 #include <openssl/evp.h>
25 #include <openssl/md5.h>
26 #include <openssl/pem.h>
27 #include <openssl/rsa.h>
28 #include <openssl/sha.h>
29 #include <string>
30 #include <sstream>
31 #include <unistd.h>
32 
33 #include "param_const_common.h"
34 
35 namespace OHOS {
36 namespace HiviewDFX {
37 class LogSignTools {
38 public:
39     static bool VerifyFileSign(const std::string &pubKeyPath, const std::string &signPath,
40         const std::string &digestPath);
41     static std::string CalcFileSha256Digest(const std::string &fpath);
42 
43 private:
44     static int CalcFileSha(const std::string& path, unsigned char *hash, size_t outLen);
45     static void CalcBase64(uint8_t *input, uint32_t inputLen, std::string &encodedStr);
46     static bool VerifyRsa(RSA *rsa, const std::string &digest, const std::string &sign);
47 };
48 } // namespace HiviewDFX
49 } // namespace OHOS
50 
51 #endif // LOG_SIGN_TOOLS_H
52