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
16
#include <
openvpn/common/size.hpp
>
17
#include <
openvpn/common/exception.hpp
>
18
#include <
openvpn/pki/cclist.hpp
>
19
#include <
openvpn/openssl/util/error.hpp
>
20
#include <
openvpn/openssl/pki/x509.hpp
>
21
#include <
openvpn/openssl/pki/crl.hpp
>
22
23
namespace
openvpn::OpenSSLPKI
{
24
25
class
X509Store
26
{
27
public
:
28
OPENVPN_EXCEPTION
(x509_store_error);
29
30
typedef
CertCRLListTemplate<X509List, CRLList>
CertCRLList
;
31
32
X509Store
()
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
76
~X509Store
()
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
cclist.hpp
openvpn::CertCRLListTemplate
Definition
cclist.hpp:31
openvpn::CertCRLListTemplate::certs
CertList certs
Definition
cclist.hpp:149
openvpn::CertCRLListTemplate::crls
CRLList crls
Definition
cclist.hpp:150
openvpn::OpenSSLPKI::X509Store
Definition
x509store.hpp:26
openvpn::OpenSSLPKI::X509Store::~X509Store
~X509Store()
Definition
x509store.hpp:76
openvpn::OpenSSLPKI::X509Store::X509Store
X509Store()
Definition
x509store.hpp:32
openvpn::OpenSSLPKI::X509Store::CertCRLList
CertCRLListTemplate< X509List, CRLList > CertCRLList
Definition
x509store.hpp:30
openvpn::OpenSSLPKI::X509Store::init
void init()
Definition
x509store.hpp:83
openvpn::OpenSSLPKI::X509Store::x509_store_
::X509_STORE * x509_store_
Definition
x509store.hpp:90
openvpn::OpenSSLPKI::X509Store::obj
X509_STORE * obj() const
Definition
x509store.hpp:64
openvpn::OpenSSLPKI::X509Store::X509Store
X509Store(const CertCRLList &cc)
Definition
x509store.hpp:37
openvpn::OpenSSLPKI::X509Store::release
X509_STORE * release()
Definition
x509store.hpp:69
openvpn::OpenSSLPKI::X509Store::OPENVPN_EXCEPTION
OPENVPN_EXCEPTION(x509_store_error)
crl.hpp
exception.hpp
openvpn::OpenSSLPKI
Definition
crl.hpp:26
error.hpp
size.hpp
ret
std::string ret
Definition
test_capture.cpp:268
x509.hpp
openvpn
openssl
pki
x509store.hpp
Generated by
1.9.8