OpenVPN 3 Core Library
Loading...
Searching...
No Matches
engine.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// Method to set up a particular OpenSSL engine type
13
14#ifndef OPENVPN_OPENSSL_UTIL_ENGINE_H
15#define OPENVPN_OPENSSL_UTIL_ENGINE_H
16
17#include <string>
18
19#include <openssl/opensslv.h>
20
21#if OPENSSL_VERSION_NUMBER >= 0x30000000L
22#define OPENSSL_NO_ENGINE
23#endif
24
25#ifndef OPENSSL_NO_ENGINE
26#include <openssl/engine.h>
27#endif
28
31
32namespace openvpn {
33
34OPENVPN_EXCEPTION(openssl_engine_error);
35
36inline void openssl_setup_engine(const std::string &engine)
37{
38#ifndef OPENSSL_NO_ENGINE
39 ENGINE_load_builtin_engines();
40
41 if (engine == "auto")
42 {
43 ENGINE_register_all_complete();
44 return;
45 }
46
47 ENGINE *e = ENGINE_by_id(engine.c_str());
48 if (!e)
49 throw openssl_engine_error();
50 if (!ENGINE_set_default(e, ENGINE_METHOD_ALL))
51 throw openssl_engine_error();
52#endif
53}
54
55} // namespace openvpn
56
57#endif // OPENVPN_OPENSSL_UTIL_ENGINE_H
#define OPENVPN_EXCEPTION(C)
Definition exception.hpp:99
void openssl_setup_engine(const std::string &engine)
Definition engine.hpp:36