• 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_PKCS7_CONTEXT_H
16 #define HAP_PKCS7_CONTEXT_H
17 
18 #include <vector>
19 #include <string>
20 
21 #include "openssl/pkcs7.h"
22 #include "openssl/x509.h"
23 
24 #include "common/hap_byte_buffer.h"
25 #include "init/matching_result.h"
26 
27 namespace OHOS {
28 namespace Security {
29 namespace Verify {
30 using CertChain = std::vector<X509*>;
31 using Pkcs7CertChains = std::vector<CertChain>;
32 
33 struct Pkcs7Context {
34     bool needWriteCrl;
35     int32_t digestAlgorithm;
36     MatchingResult matchResult;
37     std::string certIssuer;
38     PKCS7* p7;
39     Pkcs7CertChains certChains;
40     HapByteBuffer content;
41 
Pkcs7ContextPkcs7Context42     Pkcs7Context()
43         : needWriteCrl(false), digestAlgorithm(0), matchResult(), certIssuer(),
44           p7(nullptr), certChains(), content()
45     {
46     }
47 
~Pkcs7ContextPkcs7Context48     ~Pkcs7Context()
49     {
50         if (p7 != nullptr) {
51             PKCS7_free(p7);
52             p7 = nullptr;
53         }
54         for (auto certChain : certChains) {
55             for (auto cert : certChain) {
56                 X509_free(cert);
57             }
58         }
59         certChains.clear();
60     }
61 };
62 } // namespace Verify
63 } // namespace Security
64 } // namespace OHOS
65 #endif // HAP_PKCS7_CONTEXT_H
66