OpenVPN 3 Core Library
Loading...
Searching...
No Matches
crl.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 X509_CRL object
13
14
#pragma once
15
16
#include <string>
17
#include <vector>
18
19
#include <openssl/ssl.h>
20
#include <openssl/bio.h>
21
22
#include <
openvpn/common/size.hpp
>
23
#include <
openvpn/common/exception.hpp
>
24
#include <
openvpn/openssl/util/error.hpp
>
25
26
namespace
openvpn::OpenSSLPKI
{
27
28
class
CRL
29
{
30
public
:
31
CRL
()
32
:
crl_
(nullptr)
33
{
34
}
35
36
explicit
CRL
(
const
std::string &crl_txt)
37
:
crl_
(nullptr)
38
{
39
parse_pem
(crl_txt);
40
}
41
42
CRL
(
const
CRL
&other)
43
:
crl_
(
dup
(other.
crl_
))
44
{
45
}
46
47
CRL
(
CRL
&&other) noexcept
48
:
crl_
(other.crl_)
49
{
50
other.crl_ =
nullptr
;
51
}
52
53
CRL
&
operator=
(
const
CRL
&other)
54
{
55
if
(
this
!= &other)
56
{
57
erase
();
58
crl_
=
dup
(other.
crl_
);
59
}
60
return
*
this
;
61
}
62
63
CRL
&
operator=
(
CRL
&&other)
noexcept
64
{
65
if
(
this
!= &other)
66
{
67
erase
();
68
crl_
= other.crl_;
69
other.crl_ =
nullptr
;
70
}
71
return
*
this
;
72
}
73
74
bool
defined
()
const
75
{
76
return
crl_
!=
nullptr
;
77
}
78
::X509_CRL *
obj
()
const
79
{
80
return
crl_
;
81
}
82
83
void
parse_pem
(
const
std::string &crl_txt)
84
{
85
BIO *bio = ::BIO_new_mem_buf(
const_cast<
char
*
>
(crl_txt.c_str()), numeric_cast<int>(crl_txt.length()));
86
if
(!bio)
87
throw
OpenSSLException
();
88
89
::X509_CRL *crl = ::PEM_read_bio_X509_CRL(bio,
nullptr
,
nullptr
,
nullptr
);
90
::BIO_free(bio);
91
if
(!crl)
92
throw
OpenSSLException
(
"CRL::parse_pem"
);
93
94
erase
();
95
crl_
= crl;
96
}
97
98
std::string
render_pem
()
const
99
{
100
if
(
crl_
)
101
{
102
BIO *bio = ::BIO_new(BIO_s_mem());
103
const
int
ret
= ::PEM_write_bio_X509_CRL(bio,
crl_
);
104
if
(
ret
== 0)
105
{
106
::BIO_free(bio);
107
throw
OpenSSLException
(
"CRL::render_pem"
);
108
}
109
110
{
111
char
*temp;
112
const
auto
buf_len = ::BIO_get_mem_data(bio, &temp);
113
std::string
ret
= std::string(temp, buf_len);
114
::BIO_free(bio);
115
return
ret
;
116
}
117
}
118
else
119
return
""
;
120
}
121
122
~CRL
()
123
{
124
erase
();
125
}
126
127
private
:
128
void
erase
()
129
{
130
if
(
crl_
)
131
::X509_CRL_free(
crl_
);
132
}
133
134
static
X509_CRL *
dup
(
const
X509_CRL *crl)
135
{
136
if
(crl)
137
return ::X509_CRL_dup(
const_cast<
X509_CRL *
>
(crl));
138
else
139
return
nullptr
;
140
}
141
142
::X509_CRL *
crl_
;
143
};
144
145
class
CRLList
:
public
std::vector<CRL>
146
{
147
public
:
148
typedef
X509
CRL
;
149
150
bool
defined
()
const
151
{
152
return
!empty();
153
}
154
155
std::string
render_pem
()
const
156
{
157
std::string
ret
;
158
for
(
const
auto
&e : *
this
)
159
ret
+= e.render_pem();
160
return
ret
;
161
}
162
};
163
}
// namespace openvpn::OpenSSLPKI
openvpn::OpenSSLException
Definition
error.hpp:30
openvpn::OpenSSLPKI::CRLList
Definition
crl.hpp:146
openvpn::OpenSSLPKI::CRLList::CRL
X509 CRL
Definition
crl.hpp:148
openvpn::OpenSSLPKI::CRLList::defined
bool defined() const
Definition
crl.hpp:150
openvpn::OpenSSLPKI::CRLList::render_pem
std::string render_pem() const
Definition
crl.hpp:155
openvpn::OpenSSLPKI::CRL
Definition
crl.hpp:29
openvpn::OpenSSLPKI::CRL::obj
::X509_CRL * obj() const
Definition
crl.hpp:78
openvpn::OpenSSLPKI::CRL::CRL
CRL(CRL &&other) noexcept
Definition
crl.hpp:47
openvpn::OpenSSLPKI::CRL::erase
void erase()
Definition
crl.hpp:128
openvpn::OpenSSLPKI::CRL::operator=
CRL & operator=(CRL &&other) noexcept
Definition
crl.hpp:63
openvpn::OpenSSLPKI::CRL::crl_
::X509_CRL * crl_
Definition
crl.hpp:142
openvpn::OpenSSLPKI::CRL::parse_pem
void parse_pem(const std::string &crl_txt)
Definition
crl.hpp:83
openvpn::OpenSSLPKI::CRL::CRL
CRL(const std::string &crl_txt)
Definition
crl.hpp:36
openvpn::OpenSSLPKI::CRL::dup
static X509_CRL * dup(const X509_CRL *crl)
Definition
crl.hpp:134
openvpn::OpenSSLPKI::CRL::defined
bool defined() const
Definition
crl.hpp:74
openvpn::OpenSSLPKI::CRL::operator=
CRL & operator=(const CRL &other)
Definition
crl.hpp:53
openvpn::OpenSSLPKI::CRL::CRL
CRL()
Definition
crl.hpp:31
openvpn::OpenSSLPKI::CRL::render_pem
std::string render_pem() const
Definition
crl.hpp:98
openvpn::OpenSSLPKI::CRL::~CRL
~CRL()
Definition
crl.hpp:122
openvpn::OpenSSLPKI::CRL::CRL
CRL(const CRL &other)
Definition
crl.hpp:42
openvpn::OpenSSLPKI::X509
Definition
x509.hpp:30
exception.hpp
openvpn::OpenSSLPKI
Definition
crl.hpp:26
error.hpp
size.hpp
ret
std::string ret
Definition
test_capture.cpp:268
openvpn
openssl
pki
crl.hpp
Generated by
1.9.8