OpenVPN 3 Core Library
Loading...
Searching...
No Matches
awshttp.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// Build HTTPS context for AWS queries
13
14#ifndef OPENVPN_AWS_AWSHTTP_H
15#define OPENVPN_AWS_AWSHTTP_H
16
17#include <string>
18#include <utility>
19
23#include <openvpn/aws/awsca.hpp>
25
26namespace openvpn::AWS {
28{
29 public:
31 const int debug_level)
33 digest_factory_(new CryptoDigestFactory<SSLLib::CryptoAPI>()),
34 rng_(std::move(rng)),
36 {
38 }
39
40#ifdef VPN_BINDING_PROFILES
42 const int debug_level,
43 const OptionList &opt) // for VPN binding profile
45 {
47 }
48#endif
49
51 {
53 ts->host.host = std::move(host);
54 ts->host.port = "443";
55#ifdef VPN_BINDING_PROFILES
56 ts->host.via_vpn = via_vpn_;
57#endif
58 ts->http_config = http_config_;
59 ts->max_retries = 10;
60 ts->retry_on_http_4xx = true;
61 ts->retry_duration = Time::Duration::seconds(1);
62 ts->debug_level = debug_level_;
63 return ts;
64 }
65
66 int debug_level() const
67 {
68 return debug_level_;
69 }
70
72 {
73 return *digest_factory_;
74 }
75
77 {
78 return rng_.get();
79 }
80
81 private:
83 {
84 // SSL flags
85 unsigned int ssl_flags = 0;
86 if (debug_level_ >= 2)
87 ssl_flags |= SSLConst::LOG_VERIFY_STATUS;
88
89 // make SSL context using awspc_web_cert() as our CA bundle
90 SSLLib::SSLAPI::Config::Ptr ssl(new SSLLib::SSLAPI::Config);
91 ssl->set_mode(Mode(Mode::CLIENT));
92 ssl->load_ca(api_ca(), false);
93 ssl->set_local_cert_enabled(false);
94 ssl->set_tls_version_min(TLSVersion::Type::V1_2);
95 ssl->set_remote_cert_tls(KUParse::TLS_WEB_SERVER);
96 ssl->set_flags(ssl_flags);
97 ssl->set_frame(frame_);
98 ssl->set_rng(rng_);
99
100 // make HTTP context
102 hc->frame = frame_;
103 hc->ssl_factory = ssl->new_factory();
104 hc->user_agent = "OpenVPN-PG";
105 hc->connect_timeout = 30;
106 hc->general_timeout = 60;
107 return hc;
108 }
109
114#ifdef VPN_BINDING_PROFILES
115 WS::ViaVPN::Ptr via_vpn_;
116#endif
118};
119} // namespace openvpn::AWS
120
121#endif
HTTPContext(StrongRandomAPI::Ptr rng, const int debug_level)
Definition awshttp.hpp:30
WS::ClientSet::TransactionSet::Ptr transaction_set(std::string host) const
Definition awshttp.hpp:50
WS::Client::Config::Ptr http_config() const
Definition awshttp.hpp:82
WS::Client::Config::Ptr http_config_
Definition awshttp.hpp:113
StrongRandomAPI::Ptr rng_
Definition awshttp.hpp:112
StrongRandomAPI * rng() const
Definition awshttp.hpp:76
DigestFactory & digest_factory() const
Definition awshttp.hpp:71
DigestFactory::Ptr digest_factory_
Definition awshttp.hpp:111
T * get() const noexcept
Returns the raw pointer to the object T, or nullptr.
Definition rc.hpp:321
Abstract base class for cryptographically strong random number generators.
Definition randapi.hpp:228
static ViaVPN::Ptr client_new_if_enabled(const OptionList &opt)
Definition httpvpn.hpp:55
std::string api_ca()
Definition awsca.hpp:21
Frame::Ptr frame_init_simple(const size_t payload)
proxy_host_port host