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 6A9ED68AEA for ; Tue, 9 Mar 2021 15:14:42 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E8E37B258 for ; Tue, 9 Mar 2021 15:14:22 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 02F75B0E6 for ; Tue, 9 Mar 2021 15:14:11 +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 C13A146011 for ; Tue, 9 Mar 2021 15:14:10 +0100 (CET) From: Wolfgang Bumiller To: pmg-devel@lists.proxmox.com Date: Tue, 9 Mar 2021 15:13:50 +0100 Message-Id: <20210309141401.19237-7-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210309141401.19237-1-w.bumiller@proxmox.com> References: <20210309141401.19237-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.039 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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. [acmeplugin.pm, api2.pm, certificates.pm, acme.pm, action.pm, nodes.pm, what.pm, when.pm] Subject: [pmg-devel] [PATCH api 6/8] add certificates api endpoint 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 Mar 2021 14:14:42 -0000 This adds /nodes/{nodename}/certificates endpoint containing: /custom/{type} - update smtp or api certificates manually /acme/{type} - update via acme Signed-off-by: Wolfgang Bumiller --- src/Makefile | 1 + src/PMG/API2/Certificates.pm | 690 +++++++++++++++++++++++++++++++++++ src/PMG/API2/Nodes.pm | 7 + 3 files changed, 698 insertions(+) create mode 100644 src/PMG/API2/Certificates.pm diff --git a/src/Makefile b/src/Makefile index ebc6bd8..e0629b2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -155,6 +155,7 @@ LIBSOURCES = \ PMG/API2/When.pm \ PMG/API2/What.pm \ PMG/API2/Action.pm \ + PMG/API2/Certificates.pm \ PMG/API2/ACME.pm \ PMG/API2/ACMEPlugin.pm \ PMG/API2.pm \ diff --git a/src/PMG/API2/Certificates.pm b/src/PMG/API2/Certificates.pm new file mode 100644 index 0000000..d196af6 --- /dev/null +++ b/src/PMG/API2/Certificates.pm @@ -0,0 +1,690 @@ +package PMG::API2::Certificates; + +use strict; +use warnings; + +use PVE::Certificate; +use PVE::Exception qw(raise raise_param_exc); +use PVE::JSONSchema qw(get_standard_option); +use PVE::Tools qw(extract_param file_get_contents file_set_contents); + +use PMG::CertHelpers; +use PMG::NodeConfig; +use PMG::RS::CSR; + +use PMG::API2::ACMEPlugin; + +use base qw(PVE::RESTHandler); + +my $acme_account_dir = PMG::CertHelpers::acme_account_dir(); + +sub first_typed_pem_entry : prototype($$) { + my ($label, $data) = @_; + + if ($data =~ /^(-----BEGIN (?