add "password hint" to KeyConfig
This commit is contained in:
@ -26,6 +26,7 @@ use crate::{
|
||||
api2::types::{
|
||||
TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
|
||||
PROXMOX_CONFIG_DIGEST_SCHEMA,
|
||||
PASSWORD_HINT_SCHEMA,
|
||||
TapeKeyMetadata,
|
||||
},
|
||||
backup::{
|
||||
@ -57,7 +58,7 @@ pub fn list_keys(
|
||||
|
||||
for (fingerprint, item) in key_map {
|
||||
list.push(TapeKeyMetadata {
|
||||
hint: item.hint,
|
||||
hint: item.hint.unwrap_or(String::new()),
|
||||
fingerprint: as_fingerprint(fingerprint.bytes()),
|
||||
});
|
||||
}
|
||||
@ -75,9 +76,7 @@ pub fn list_keys(
|
||||
min_length: 5,
|
||||
},
|
||||
hint: {
|
||||
description: "Password restore hint.",
|
||||
min_length: 1,
|
||||
max_length: 32,
|
||||
schema: PASSWORD_HINT_SCHEMA,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -92,11 +91,12 @@ pub fn create_key(
|
||||
_rpcenv: &mut dyn RpcEnvironment
|
||||
) -> Result<Fingerprint, Error> {
|
||||
|
||||
let (key, key_config) = generate_tape_encryption_key(password.as_bytes())?;
|
||||
let (key, mut key_config) = generate_tape_encryption_key(password.as_bytes())?;
|
||||
key_config.hint = Some(hint);
|
||||
|
||||
let fingerprint = key_config.fingerprint.clone().unwrap();
|
||||
|
||||
insert_key(key, key_config, hint)?;
|
||||
insert_key(key, key_config)?;
|
||||
|
||||
Ok(fingerprint)
|
||||
}
|
||||
|
@ -484,11 +484,21 @@ pub async fn restore_key(
|
||||
let (_media_id, key_config) = drive.read_label()?;
|
||||
|
||||
if let Some(key_config) = key_config {
|
||||
let hint = String::from("fixme: add hint");
|
||||
// fixme: howto show restore hint
|
||||
let password_fn = || { Ok(password.as_bytes().to_vec()) };
|
||||
let (key, ..) = decrypt_key_config(&key_config, &password_fn)?;
|
||||
config::tape_encryption_keys::insert_key(key, key_config, hint)?;
|
||||
let key = match decrypt_key_config(&key_config, &password_fn) {
|
||||
Ok((key, ..)) => key,
|
||||
Err(_) => {
|
||||
match key_config.hint {
|
||||
Some(hint) => {
|
||||
bail!("decrypt key failed (password hint: {})", hint);
|
||||
}
|
||||
None => {
|
||||
bail!("decrypt key failed (wrong password)");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
config::tape_encryption_keys::insert_key(key, key_config)?;
|
||||
} else {
|
||||
bail!("media does not contain any encryption key configuration");
|
||||
}
|
||||
|
@ -1249,3 +1249,10 @@ pub const DATASTORE_NOTIFY_STRING_SCHEMA: Schema = StringSchema::new(
|
||||
"Datastore notification setting")
|
||||
.format(&ApiStringFormat::PropertyString(&DatastoreNotify::API_SCHEMA))
|
||||
.schema();
|
||||
|
||||
|
||||
pub const PASSWORD_HINT_SCHEMA: Schema = StringSchema::new("Password hint.")
|
||||
.format(&SINGLE_LINE_COMMENT_FORMAT)
|
||||
.min_length(1)
|
||||
.max_length(64)
|
||||
.schema();
|
||||
|
Reference in New Issue
Block a user