mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-04-30 21:50:42 +00:00
pbs-config: move secret generation into token_shadow
so we have only one place where we generate secrets. Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
This commit is contained in:
parent
d977da6411
commit
17f183c40b
@ -24,6 +24,7 @@ proxmox-section-config.workspace = true
|
|||||||
proxmox-shared-memory.workspace = true
|
proxmox-shared-memory.workspace = true
|
||||||
proxmox-sys = { workspace = true, features = [ "acl", "crypt", "timer" ] }
|
proxmox-sys = { workspace = true, features = [ "acl", "crypt", "timer" ] }
|
||||||
proxmox-time.workspace = true
|
proxmox-time.workspace = true
|
||||||
|
proxmox-uuid.workspace = true
|
||||||
|
|
||||||
pbs-api-types.workspace = true
|
pbs-api-types.workspace = true
|
||||||
pbs-buildcfg.workspace = true
|
pbs-buildcfg.workspace = true
|
||||||
|
@ -61,8 +61,16 @@ pub fn verify_secret(tokenid: &Authid, secret: &str) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates a new secret for the given tokenid / API token, sets it then returns it.
|
||||||
|
/// The secret is stored as salted hash.
|
||||||
|
pub fn generate_and_set_secret(tokenid: &Authid) -> Result<String, Error> {
|
||||||
|
let secret = format!("{:x}", proxmox_uuid::Uuid::generate());
|
||||||
|
set_secret(tokenid, &secret)?;
|
||||||
|
Ok(secret)
|
||||||
|
}
|
||||||
|
|
||||||
/// Adds a new entry for the given tokenid / API token secret. The secret is stored as salted hash.
|
/// Adds a new entry for the given tokenid / API token secret. The secret is stored as salted hash.
|
||||||
pub fn set_secret(tokenid: &Authid, secret: &str) -> Result<(), Error> {
|
fn set_secret(tokenid: &Authid, secret: &str) -> Result<(), Error> {
|
||||||
if !tokenid.is_token() {
|
if !tokenid.is_token() {
|
||||||
bail!("not an API token ID");
|
bail!("not an API token ID");
|
||||||
}
|
}
|
||||||
|
@ -495,8 +495,7 @@ pub fn generate_token(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let secret = format!("{:x}", proxmox_uuid::Uuid::generate());
|
let secret = token_shadow::generate_and_set_secret(&tokenid)?;
|
||||||
token_shadow::set_secret(&tokenid, &secret)?;
|
|
||||||
|
|
||||||
let token = ApiToken {
|
let token = ApiToken {
|
||||||
tokenid,
|
tokenid,
|
||||||
|
Loading…
Reference in New Issue
Block a user