OpenVPN 3 Core Library
Loading...
Searching...
No Matches
acc_certcheck.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#pragma once
13
14#include <string>
15#include <memory>
16#include <optional>
17#include <stdexcept>
18
22
23namespace openvpn {
24
37{
42 SslApiBuilder(SSLLib::SSLAPI::Config::Ptr cfg)
43 : mConfig(std::move(cfg)),
44 mFactory(mConfig->new_factory()),
45 mServer(mFactory->ssl()) {};
46
47 SslApiBuilder(const SslApiBuilder &) = delete;
48 SslApiBuilder(SslApiBuilder &&) noexcept = delete;
49 SslApiBuilder &operator=(const SslApiBuilder &) = delete;
50 SslApiBuilder &operator=(SslApiBuilder &&) = delete;
51
52 public: // API
58 {
59 return *mServer;
60 }
61
62 private: // Data
63 SSLLib::SSLAPI::Config::Ptr mConfig;
66};
87{
88 using MsgT = std::optional<std::string>;
89 AccHandshaker() = default;
90 AccHandshaker(SSLLib::SSLAPI::Config::Ptr cfg);
91 MsgT process_msg(const MsgT &msg);
92 std::string details();
93 void reset(SSLLib::SSLAPI::Config::Ptr cfg);
94
95 private:
96 std::unique_ptr<SslApiBuilder> mSslApi;
97};
102inline AccHandshaker::AccHandshaker(SSLLib::SSLAPI::Config::Ptr cfg)
103 : mSslApi(new SslApiBuilder(std::move(cfg)))
104{
105 mSslApi->get().start_handshake();
106}
117{
118 if (!mSslApi)
119 throw std::runtime_error("AccHandshaker::process_msg: not configured");
120
121 MsgT ret = std::nullopt;
122 auto &api = mSslApi->get();
123 if (msg)
124 {
125 api.write_ciphertext(BufferAllocatedRc::Create(reinterpret_cast<const unsigned char *>(msg->c_str()),
126 msg->size(),
128
129 // Won't handshake without this even though there is no data available.
130 uint8_t cleartext[8];
131 api.read_cleartext(cleartext, sizeof(cleartext));
132 }
133
134 if (api.read_ciphertext_ready())
135 {
136 auto reply = api.read_ciphertext();
137 ret = {reinterpret_cast<const char *>(reply->c_data()),
138 reinterpret_cast<const char *>(reply->c_data_end())};
139 }
140
141 return ret;
142}
148inline std::string AccHandshaker::details()
149{
150 if (!mSslApi)
151 throw std::runtime_error("AccHandshaker::details: not configured");
152
153 return mSslApi->get().ssl_handshake_details();
154}
163inline void AccHandshaker::reset(SSLLib::SSLAPI::Config::Ptr cfg)
164{
165 mSslApi.reset(new SslApiBuilder(std::move(cfg)));
166 mSslApi->get().start_handshake();
167}
168
169} // namespace openvpn
static Ptr Create(ArgsT &&...args)
Creates a new instance of RcEnable with the given arguments.
Definition make_rc.hpp:43
constexpr BufferFlags NO_FLAGS(0u)
no flags set
defines a class that handles SSL/TLS handshaking
std::string details()
returns ssl_handshake_details() if the SSLAPI is available
std::unique_ptr< SslApiBuilder > mSslApi
std::optional< std::string > MsgT
MsgT process_msg(const MsgT &msg)
Incrementally process the CLIENT HELLO / SERVER HELLO exchange.
void reset(SSLLib::SSLAPI::Config::Ptr cfg)
Re-init the handshaker.
The SslApiBuilder struct is used to initialize and configure an SSL/TLS API in OpenVPN.
SslApiBuilder(const SslApiBuilder &)=delete
SSLLib::SSLAPI::Config::Ptr mConfig
Configuration for this SSL server.
openvpn::SSLAPI & get()
get a reference to the encapsulated ssl object
SslApiBuilder(SslApiBuilder &&) noexcept=delete
SslApiBuilder(SSLLib::SSLAPI::Config::Ptr cfg)
Construct a new SslApiBuilder object.
openvpn::SSLAPI::Ptr mServer
Server created from the factory - depends on mConfig and mFactory.
openvpn::SSLFactoryAPI::Ptr mFactory
Factory from the SSL configuration.
std::string ret
#define msg(flags,...)