• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 HAP_CRL_MANAGER_H
16 #define HAP_CRL_MANAGER_H
17 
18 #include <mutex>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include "common/export_define.h"
24 #include "common/hap_byte_buffer.h"
25 #include "openssl/ossl_typ.h"
26 #include "util/pkcs7_context.h"
27 
28 namespace OHOS {
29 namespace Security {
30 namespace Verify {
31 using IssuerCrlMap = std::unordered_map<std::string, X509_CRL*>;
32 
33 class HapCrlManager {
34 public:
35     DLL_EXPORT static HapCrlManager& GetInstance();
36     DLL_EXPORT void Init();
37     DLL_EXPORT bool CrlCheck(X509* cert, X509_CRL* targetCrl, Pkcs7Context& pkcs7Context);
38     DLL_EXPORT void WriteCrlsToFile();
39 
40 private:
41     HapCrlManager();
42     ~HapCrlManager();
43 
44     /* Forbid external replication constructs and external replication */
45     HapCrlManager(const HapCrlManager& hapCrlManager) = delete;
46     HapCrlManager& operator = (const HapCrlManager& hapCrlManager) = delete;
47 
48     DLL_EXPORT X509_CRL* GetFinalCrl(X509_CRL* crlInPackage, Pkcs7Context& pkcs7Context);
49     DLL_EXPORT X509_CRL* GetCrlByIssuer(const std::string& issuer);
50     DLL_EXPORT void UpdateCrlByIssuer(const std::string& issuer, X509_CRL* crl);
51     DLL_EXPORT bool ReadCrls(HapByteBuffer& crlsBuffer);
52     DLL_EXPORT bool ParseCrls(HapByteBuffer& crlsBuffer);
53 
54 private:
55     DLL_EXPORT static const std::string HAP_CRL_FILE_PATH;
56     std::mutex crlMtx;
57     IssuerCrlMap crlsMap;
58     bool isInit;
59 };
60 } // namespace Verify
61 } // namespace Security
62 } // namespace OHOS
63 #endif // HAP_CRL_MANAGER_H
64