From: Folke Gleumes <f.gleumes@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH backup 3/8] acme: api: add eab options to api
Date: Tue, 14 Nov 2023 15:14:03 +0100 [thread overview]
Message-ID: <20231114141408.228705-5-f.gleumes@proxmox.com> (raw)
In-Reply-To: <20231114141408.228705-1-f.gleumes@proxmox.com>
Optionally allow for setting external account binding credentials at the
account registration endpoint.
Signed-off-by: Folke Gleumes <f.gleumes@proxmox.com>
---
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<String>,
rsa_bits: Option<u32>,
+ 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<String> {
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<String>,
directory: Option<String>,
+ eab_kid: Option<String>,
+ eab_hmac_key: Option<String>,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<String, Error> {
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<u32>,
+ 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
next prev parent reply other threads:[~2023-11-14 14:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 14:13 [pmg-devel] [PATCH acme-rs/backup/perl-rs/pmg-api 0/8] add external account binding to pmg and pbs Folke Gleumes
2023-11-14 14:14 ` [pmg-devel] [PATCH acme-rs 1/8] add external account binding Folke Gleumes
2023-11-14 14:14 ` [pmg-devel] [PATCH acme-rs 2/8] add meta fields returned by the directory Folke Gleumes
2023-12-04 10:56 ` [pmg-devel] applied: " Wolfgang Bumiller
2023-11-14 14:14 ` [pmg-devel] [PATCH] expand helper function by eab credentials Folke Gleumes
2023-12-04 10:57 ` [pmg-devel] applied: " Wolfgang Bumiller
2023-11-14 14:14 ` Folke Gleumes [this message]
2023-11-14 14:14 ` [pmg-devel] [PATCH backup 4/8] cli: acme: add possibility to set eab via the cli Folke Gleumes
2023-11-14 14:14 ` [pmg-devel] [PATCH perl-rs 5/8] acme: add eab fields for pmg Folke Gleumes
2023-12-06 11:37 ` [pmg-devel] applied: " Wolfgang Bumiller
2023-11-14 14:14 ` [pmg-devel] [PATCH pmg-api 6/8] api: acme: add eab parameters Folke Gleumes
2023-11-14 14:14 ` [pmg-devel] [PATCH pmg-api 7/8] api: acme: deprecate tos endpoint in favor of new meta endpoint Folke Gleumes
2023-11-14 14:14 ` [pmg-devel] [PATCH pmg-api 8/8] cli: acme: expose acme eab options on the cli Folke Gleumes
2023-12-06 11:41 ` [pmg-devel] applied: " Wolfgang Bumiller
2023-12-06 11:59 ` [pmg-devel] applied-series: [PATCH acme-rs/backup/perl-rs/pmg-api 0/8] add external account binding to pmg and pbs Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231114141408.228705-5-f.gleumes@proxmox.com \
--to=f.gleumes@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox