2020-01-29 14:02:41 +01:00
|
|
|
// OpenVPN -- An application to securely tunnel IP networks
|
|
|
|
// over a single port, with support for SSL/TLS-based
|
|
|
|
// session authentication and key exchange,
|
|
|
|
// packet encryption, packet authentication, and
|
|
|
|
// packet compression.
|
2016-11-09 19:24:58 +01:00
|
|
|
//
|
2022-09-29 11:41:13 +02:00
|
|
|
// Copyright (C) 2012-2022 OpenVPN Inc.
|
2016-11-09 19:24:58 +01:00
|
|
|
//
|
2020-01-29 14:02:41 +01:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License Version 3
|
|
|
|
// as published by the Free Software Foundation.
|
2016-11-09 19:24:58 +01:00
|
|
|
//
|
2020-01-29 14:02:41 +01:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program in the COPYING file.
|
|
|
|
// If not, see <http://www.gnu.org/licenses/>.
|
2016-11-09 19:24:58 +01:00
|
|
|
|
|
|
|
// Build HTTPS context for AWS queries
|
|
|
|
|
|
|
|
#ifndef OPENVPN_AWS_AWSHTTP_H
|
|
|
|
#define OPENVPN_AWS_AWSHTTP_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include <openvpn/frame/frame_init.hpp>
|
|
|
|
#include <openvpn/crypto/digestapi.hpp>
|
|
|
|
#include <openvpn/ws/httpcliset.hpp>
|
|
|
|
#include <openvpn/aws/awsca.hpp>
|
|
|
|
#include <openvpn/ssl/sslchoose.hpp>
|
|
|
|
|
|
|
|
namespace openvpn {
|
|
|
|
namespace AWS {
|
|
|
|
class HTTPContext
|
2023-01-11 20:43:22 +01:00
|
|
|
{
|
|
|
|
public:
|
2023-11-14 04:30:58 +01:00
|
|
|
HTTPContext(StrongRandomAPI::Ptr rng,
|
2016-11-09 19:24:58 +01:00
|
|
|
const int debug_level)
|
2018-08-20 07:49:58 +02:00
|
|
|
: frame_(frame_init_simple(2048)),
|
2016-11-09 19:24:58 +01:00
|
|
|
digest_factory_(new CryptoDigestFactory<SSLLib::CryptoAPI>()),
|
|
|
|
rng_(std::move(rng)),
|
|
|
|
debug_level_(debug_level)
|
|
|
|
{
|
2018-09-22 00:39:53 +02:00
|
|
|
http_config_ = http_config();
|
2016-11-09 19:24:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-07 07:03:41 +02:00
|
|
|
#ifdef VPN_BINDING_PROFILES
|
2023-11-14 04:30:58 +01:00
|
|
|
HTTPContext(StrongRandomAPI::Ptr rng,
|
2022-05-13 19:52:33 +02:00
|
|
|
const int debug_level,
|
2022-06-07 07:03:41 +02:00
|
|
|
const OptionList &opt) // for VPN binding profile
|
2022-05-13 19:52:33 +02:00
|
|
|
: HTTPContext(rng, debug_level)
|
|
|
|
{
|
|
|
|
via_vpn_ = WS::ViaVPN::client_new_if_enabled(opt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-09 19:24:58 +01:00
|
|
|
WS::ClientSet::TransactionSet::Ptr transaction_set(std::string host) const
|
|
|
|
{
|
|
|
|
WS::ClientSet::TransactionSet::Ptr ts = new WS::ClientSet::TransactionSet;
|
|
|
|
ts->host.host = std::move(host);
|
|
|
|
ts->host.port = "443";
|
2022-06-07 07:03:41 +02:00
|
|
|
#ifdef VPN_BINDING_PROFILES
|
2022-05-13 19:52:33 +02:00
|
|
|
ts->host.via_vpn = via_vpn_;
|
|
|
|
#endif
|
2018-09-22 00:39:53 +02:00
|
|
|
ts->http_config = http_config_;
|
2018-08-25 07:22:55 +02:00
|
|
|
ts->max_retries = 10;
|
2022-06-09 09:02:28 +02:00
|
|
|
ts->retry_on_http_4xx = true;
|
2018-08-25 07:22:55 +02:00
|
|
|
ts->retry_duration = Time::Duration::seconds(1);
|
2016-11-09 19:24:58 +01:00
|
|
|
ts->debug_level = debug_level_;
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
int debug_level() const
|
|
|
|
{
|
|
|
|
return debug_level_;
|
|
|
|
}
|
|
|
|
|
|
|
|
DigestFactory &digest_factory() const
|
|
|
|
{
|
|
|
|
return *digest_factory_;
|
|
|
|
}
|
|
|
|
|
2023-11-14 04:30:58 +01:00
|
|
|
StrongRandomAPI *rng() const
|
2016-11-09 19:24:58 +01:00
|
|
|
{
|
|
|
|
return rng_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
WS::Client::Config::Ptr http_config() const
|
|
|
|
{
|
|
|
|
// SSL flags
|
|
|
|
unsigned int ssl_flags = 0;
|
2018-08-20 07:51:11 +02:00
|
|
|
if (debug_level_ >= 2)
|
2016-11-09 19:24:58 +01:00
|
|
|
ssl_flags |= SSLConst::LOG_VERIFY_STATUS;
|
|
|
|
|
|
|
|
// make SSL context using awspc_web_cert() as our CA bundle
|
|
|
|
SSLLib::SSLAPI::Config::Ptr ssl(new SSLLib::SSLAPI::Config);
|
|
|
|
ssl->set_mode(Mode(Mode::CLIENT));
|
|
|
|
ssl->load_ca(api_ca(), false);
|
|
|
|
ssl->set_local_cert_enabled(false);
|
2023-03-11 13:56:40 +01:00
|
|
|
ssl->set_tls_version_min(TLSVersion::Type::V1_2);
|
2016-11-09 19:24:58 +01:00
|
|
|
ssl->set_remote_cert_tls(KUParse::TLS_WEB_SERVER);
|
|
|
|
ssl->set_flags(ssl_flags);
|
|
|
|
ssl->set_frame(frame_);
|
|
|
|
ssl->set_rng(rng_);
|
|
|
|
|
|
|
|
// make HTTP context
|
|
|
|
WS::Client::Config::Ptr hc(new WS::Client::Config());
|
|
|
|
hc->frame = frame_;
|
|
|
|
hc->ssl_factory = ssl->new_factory();
|
|
|
|
hc->user_agent = "OpenVPN-PG";
|
|
|
|
hc->connect_timeout = 30;
|
|
|
|
hc->general_timeout = 60;
|
|
|
|
return hc;
|
|
|
|
}
|
|
|
|
|
|
|
|
Frame::Ptr frame_;
|
|
|
|
DigestFactory::Ptr digest_factory_;
|
2023-11-14 04:30:58 +01:00
|
|
|
StrongRandomAPI::Ptr rng_;
|
2018-09-22 00:39:53 +02:00
|
|
|
WS::Client::Config::Ptr http_config_;
|
2022-06-07 07:03:41 +02:00
|
|
|
#ifdef VPN_BINDING_PROFILES
|
2022-05-13 19:52:33 +02:00
|
|
|
WS::ViaVPN::Ptr via_vpn_;
|
|
|
|
#endif
|
2016-11-09 19:24:58 +01:00
|
|
|
int debug_level_;
|
|
|
|
};
|
|
|
|
} // namespace AWS
|
|
|
|
} // namespace openvpn
|
|
|
|
|
|
|
|
#endif
|