From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 17D3D7DD63 for ; Tue, 9 Nov 2021 17:20:25 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 15CBE106F6 for ; Tue, 9 Nov 2021 17:20:25 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id EDEA7106B4 for ; Tue, 9 Nov 2021 17:20:22 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8AAE342AB7 for ; Tue, 9 Nov 2021 17:20:22 +0100 (CET) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Tue, 9 Nov 2021 17:20:08 +0100 Message-Id: <20211109162009.3186-8-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109162009.3186-1-s.ivanov@proxmox.com> References: <20211109162009.3186-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.360 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [acme.pm, certificates.pm] Subject: [pmg-devel] [PATCH pmg-api 1/2] api: acme: set http_proxy if configured in pmg.conf X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 16:20:25 -0000 If a http_proxy is set in pmg.conf, use it for communicating with the (usually public) Acme provider. Signed-off-by: Stoiko Ivanov --- src/PMG/API2/ACME.pm | 21 +++++++++++++++++++++ src/PMG/API2/Certificates.pm | 13 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/PMG/API2/ACME.pm b/src/PMG/API2/ACME.pm index 42c9f4e..bb12177 100644 --- a/src/PMG/API2/ACME.pm +++ b/src/PMG/API2/ACME.pm @@ -14,6 +14,7 @@ use PVE::ACME::Challenge; use PMG::RESTEnvironment; use PMG::RS::Acme; use PMG::CertHelpers; +use PMG::Config; use PMG::API2::ACMEPlugin; @@ -159,6 +160,11 @@ __PACKAGE__->register_method ({ print "Registering new ACME account..\n"; my $acme = PMG::RS::Acme->new($directory); + my $pmg_cfg = PMG::Config->new(); + if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) { + $acme->set_proxy($http_proxy); + } + eval { $acme->new_account($account_file, defined($param->{tos_url}), $contact, undef); }; @@ -192,6 +198,11 @@ my $update_account = sub { if ! -e $account_file; my $acme = PMG::RS::Acme->load($account_file); + my $pmg_cfg = PMG::Config->new(); + if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) { + $acme->set_proxy($http_proxy); + } + eval { $acme->update_account(\%info); }; @@ -297,6 +308,11 @@ __PACKAGE__->register_method ({ if ! -e $account_file; my $acme = PMG::RS::Acme->load($account_file); + my $pmg_cfg = PMG::Config->new(); + if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) { + $acme->set_proxy($http_proxy); + } + my $data = $acme->account(); return { @@ -365,6 +381,11 @@ __PACKAGE__->register_method ({ my $directory = extract_param($param, 'directory') // $acme_default_directory_url; my $acme = PMG::RS::Acme->new($directory); + my $pmg_cfg = PMG::Config->new(); + if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) { + $acme->set_proxy($http_proxy); + } + my $meta = $acme->get_meta(); return $meta ? $meta->{termsOfService} : undef; diff --git a/src/PMG/API2/Certificates.pm b/src/PMG/API2/Certificates.pm index b52f010..6627328 100644 --- a/src/PMG/API2/Certificates.pm +++ b/src/PMG/API2/Certificates.pm @@ -9,6 +9,7 @@ use PVE::JSONSchema qw(get_standard_option); use PVE::Tools qw(extract_param file_get_contents file_set_contents); use PMG::CertHelpers; +use PMG::Config; use PMG::NodeConfig; use PMG::RS::Acme; use PMG::RS::CSR; @@ -535,6 +536,10 @@ __PACKAGE__->register_method ({ print "Loading ACME account details\n"; my $acme = PMG::RS::Acme->load($account_file); + my $pmg_cfg = PMG::Config->new(); + if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) { + $acme->set_proxy($http_proxy); + } my ($cert, $key) = $order_certificate->($acme, $acme_config); my $certificate = "$key\n$cert"; @@ -609,6 +614,10 @@ __PACKAGE__->register_method ({ print "Loading ACME account details\n"; my $acme = PMG::RS::Acme->load($account_file); + my $pmg_cfg = PMG::Config->new(); + if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) { + $acme->set_proxy($http_proxy); + } my ($cert, $key) = $order_certificate->($acme, $acme_config); my $certificate = "$key\n$cert"; @@ -676,6 +685,10 @@ __PACKAGE__->register_method ({ print "Loading ACME account details\n"; my $acme = PMG::RS::Acme->load($account_file); + my $pmg_cfg = PMG::Config->new(); + if (my $http_proxy = $pmg_cfg->get('admin', 'http_proxy')) { + $acme->set_proxy($http_proxy); + } print "Revoking old certificate\n"; eval { $acme->revoke_certificate($cert, undef) }; -- 2.30.2