OpenVPN 3 Core Library
Loading...
Searching...
No Matches
x509store.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12// Wrap an OpenSSL X509Store object
13
14#pragma once
15
22
23namespace openvpn::OpenSSLPKI {
24
26{
27 public:
28 OPENVPN_EXCEPTION(x509_store_error);
29
31
33 : x509_store_(nullptr)
34 {
35 }
36
37 explicit X509Store(const CertCRLList &cc)
38 {
39 init();
40
41 // Load cert list
42 {
43 for (const auto &e : cc.certs)
44 {
45 if (!::X509_STORE_add_cert(x509_store_, e.obj()))
46 throw x509_store_error("X509_STORE_add_cert(");
47 }
48 }
49
50 // Load CRL list
51 {
52 if (cc.crls.defined())
53 {
54 ::X509_STORE_set_flags(x509_store_, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL);
55 for (const auto &e : cc.crls)
56 {
57 if (!::X509_STORE_add_crl(x509_store_, e.obj()))
58 throw x509_store_error("X509_STORE_add_crl");
59 }
60 }
61 }
62 }
63
64 X509_STORE *obj() const
65 {
66 return x509_store_;
67 }
68
69 X509_STORE *release()
70 {
71 X509_STORE *ret = x509_store_;
72 x509_store_ = nullptr;
73 return ret;
74 }
75
77 {
78 if (x509_store_)
79 ::X509_STORE_free(x509_store_);
80 }
81
82 private:
83 void init()
84 {
85 x509_store_ = ::X509_STORE_new();
86 if (!x509_store_)
87 throw x509_store_error("X509_STORE_new");
88 }
89
90 ::X509_STORE *x509_store_;
91};
92} // namespace openvpn::OpenSSLPKI
CertCRLListTemplate< X509List, CRLList > CertCRLList
Definition x509store.hpp:30
X509_STORE * obj() const
Definition x509store.hpp:64
X509Store(const CertCRLList &cc)
Definition x509store.hpp:37
OPENVPN_EXCEPTION(x509_store_error)
std::string ret