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 C05659A01E for ; Tue, 14 Nov 2023 15:08:16 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A2F451C6CE for ; Tue, 14 Nov 2023 15:07:46 +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 for ; Tue, 14 Nov 2023 15:07:45 +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 9ABE842A84 for ; Tue, 14 Nov 2023 15:07:45 +0100 (CET) From: Folke Gleumes To: pve-devel@lists.proxmox.com Date: Tue, 14 Nov 2023 15:07:14 +0100 Message-Id: <20231114140719.225971-5-f.gleumes@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231114140719.225971-1-f.gleumes@proxmox.com> References: <20231114140719.225971-1-f.gleumes@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.021 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH backup 3/8] acme: api: add eab options to api X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Nov 2023 14:08:16 -0000 Optionally allow for setting external account binding credentials at the account registration endpoint. Signed-off-by: Folke Gleumes --- src/acme/client.rs | 7 +++++- src/api2/config/acme.rs | 35 +++++++++++++++++++++++--- src/bin/proxmox_backup_manager/acme.rs | 12 ++++++--- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/acme/client.rs b/src/acme/client.rs index 46566210..1396eb2c 100644 --- a/src/acme/client.rs +++ b/src/acme/client.rs @@ -116,6 +116,7 @@ impl AcmeClient { tos_agreed: bool, contact: Vec, rsa_bits: Option, + eab_creds: Option<(String, String)>, ) -> Result<&'a Account, anyhow::Error> { self.tos = if tos_agreed { self.terms_of_service_url().await?.map(str::to_owned) @@ -123,10 +124,14 @@ impl AcmeClient { None }; - let account = Account::creator() + let mut account = Account::creator() .set_contacts(contact) .agree_to_tos(tos_agreed); + if let Some((eab_kid, eab_hmac_key)) = eab_creds { + account = account.set_eab_credentials(eab_kid, eab_hmac_key)?; + } + let account = if let Some(bits) = rsa_bits { account.generate_rsa_key(bits)? } else { diff --git a/src/api2/config/acme.rs b/src/api2/config/acme.rs index 1954318b..8f010027 100644 --- a/src/api2/config/acme.rs +++ b/src/api2/config/acme.rs @@ -182,6 +182,16 @@ fn account_contact_from_string(s: &str) -> Vec { description: "The ACME Directory.", optional: true, }, + eab_kid: { + type: String, + description: "Key Identifier for External Account Binding.", + optional: true, + }, + eab_hmac_key: { + type: String, + description: "HMAC Key for External Account Binding.", + optional: true, + } }, }, access: { @@ -196,6 +206,8 @@ fn register_account( contact: String, tos_url: Option, directory: Option, + eab_kid: Option, + eab_hmac_key: Option, rpcenv: &mut dyn RpcEnvironment, ) -> Result { let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; @@ -204,6 +216,15 @@ fn register_account( AcmeAccountName::from_string_unchecked("default".to_string()) }); + // TODO: this should be done via the api definition, but + // the api macro currently lacks this ability (2023-11-06) + if eab_kid.is_some() ^ eab_hmac_key.is_some() { + http_bail!( + BAD_REQUEST, + "either both or none of 'eab_kid' and 'eab_hmac_key' have to be set." + ); + } + if Path::new(&crate::config::acme::account_path(&name)).exists() { http_bail!(BAD_REQUEST, "account {} already exists", name); } @@ -224,8 +245,15 @@ fn register_account( task_log!(worker, "Registering ACME account '{}'...", &name); - let account = - do_register_account(&mut client, &name, tos_url.is_some(), contact, None).await?; + let account = do_register_account( + &mut client, + &name, + tos_url.is_some(), + contact, + None, + eab_kid.zip(eab_hmac_key), + ) + .await?; task_log!( worker, @@ -244,10 +272,11 @@ pub async fn do_register_account<'a>( agree_to_tos: bool, contact: String, rsa_bits: Option, + eab_creds: Option<(String, String)>, ) -> Result<&'a Account, Error> { let contact = account_contact_from_string(&contact); client - .new_account(name, agree_to_tos, contact, rsa_bits) + .new_account(name, agree_to_tos, contact, rsa_bits, eab_creds) .await } diff --git a/src/bin/proxmox_backup_manager/acme.rs b/src/bin/proxmox_backup_manager/acme.rs index de48a420..17ca5958 100644 --- a/src/bin/proxmox_backup_manager/acme.rs +++ b/src/bin/proxmox_backup_manager/acme.rs @@ -156,9 +156,15 @@ async fn register_account( println!("Attempting to register account with {:?}...", directory); - let account = - api2::config::acme::do_register_account(&mut client, &name, tos_agreed, contact, None) - .await?; + let account = api2::config::acme::do_register_account( + &mut client, + &name, + tos_agreed, + contact, + None, + None, + ) + .await?; println!("Registration successful, account URL: {}", account.location); -- 2.39.2