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 0448C7B163 for ; Tue, 11 May 2021 15:54:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D34FA22CAA for ; Tue, 11 May 2021 15:54:06 +0200 (CEST) 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 E666F22C6C for ; Tue, 11 May 2021 15:54:04 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B8F1842F21 for ; Tue, 11 May 2021 15:54:04 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Tue, 11 May 2021 15:53:57 +0200 Message-Id: <20210511135400.32406-5-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210511135400.32406-1-w.bumiller@proxmox.com> References: <20210511135400.32406-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.133 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_2 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_4 0.1 random spam to be learned in bayes 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. [proxmox-backup-proxy.rs] Subject: [pbs-devel] [PATCH backup 4/7] proxy: factor out tls acceptor creation X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2021 13:54:07 -0000 Signed-off-by: Wolfgang Bumiller --- src/bin/proxmox-backup-proxy.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 0b4b5586..c05bcd20 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -113,15 +113,11 @@ async fn run() -> Result<(), Error> { let rest_server = RestServer::new(config); //openssl req -x509 -newkey rsa:4096 -keyout /etc/proxmox-backup/proxy.key -out /etc/proxmox-backup/proxy.pem -nodes - let key_path = configdir!("/proxy.key"); - let cert_path = configdir!("/proxy.pem"); - let mut acceptor = SslAcceptor::mozilla_intermediate_v5(SslMethod::tls()).unwrap(); - acceptor.set_private_key_file(key_path, SslFiletype::PEM) - .map_err(|err| format_err!("unable to read proxy key {} - {}", key_path, err))?; - acceptor.set_certificate_chain_file(cert_path) - .map_err(|err| format_err!("unable to read proxy cert {} - {}", cert_path, err))?; - acceptor.check_private_key().unwrap(); + // we build the initial acceptor here as we cannot start if this fails - certificate reloads + // will be handled inside the accept loop and simply log an error if we cannot load the new + // certificate! + let acceptor = make_tls_acceptor()?; let acceptor = Arc::new(acceptor.build()); @@ -170,6 +166,20 @@ async fn run() -> Result<(), Error> { Ok(()) } +fn make_tls_acceptor() -> Result, Error> { + let key_path = configdir!("/proxy.key"); + let cert_path = configdir!("/proxy.pem"); + + let mut acceptor = SslAcceptor::mozilla_intermediate_v5(SslMethod::tls()).unwrap(); + acceptor.set_private_key_file(key_path, SslFiletype::PEM) + .map_err(|err| format_err!("unable to read proxy key {} - {}", key_path, err))?; + acceptor.set_certificate_chain_file(cert_path) + .map_err(|err| format_err!("unable to read proxy cert {} - {}", cert_path, err))?; + acceptor.check_private_key().unwrap(); + + Ok(Arc::new(acceptor.build())) +} + type ClientStreamResult = Result>>, Error>; const MAX_PENDING_ACCEPTS: usize = 1024; -- 2.20.1