Use the password cache when unlocking keys managed by the key store.

- Change `Sq::get_signer` to also consider the password cache when
    unlocking a key managed by the key store.
This commit is contained in:
Neal H. Walfield 2024-06-03 15:31:57 +02:00
parent a2c482e4f3
commit 256679bce3
No known key found for this signature in database
GPG Key ID: 6863C9AD5B4D22D3

View File

@ -1099,28 +1099,34 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
'key: for mut key in remote_keys.into_iter() {
let password = if let Protection::Password(hint) = key.locked()? {
if let Some(hint) = hint {
eprintln!("{}", hint);
}
loop {
let p = password::prompt_to_unlock(&format!(
"Please enter the password to decrypt \
the key {}/{}, {}",
ka.cert().keyid(), ka.keyid(), uid))?;
if p == "".into() {
eprintln!("Giving up.");
continue 'key;
if let Some(password) = self.cached_passwords().find(|password| {
key.unlock(password.clone()).is_ok()
}) {
Some(password)
} else {
if let Some(hint) = hint {
eprintln!("{}", hint);
}
match key.unlock(p.clone()) {
Ok(()) => {
self.cache_password(p.clone());
break Some(p)
loop {
let p = password::prompt_to_unlock(&format!(
"Please enter the password to decrypt \
the key {}/{}, {}",
ka.cert().keyid(), ka.keyid(), uid))?;
if p == "".into() {
eprintln!("Giving up.");
continue 'key;
}
Err(err) => {
eprintln!("Failed to unlock key: {}", err);
match key.unlock(p.clone()) {
Ok(()) => {
self.cache_password(p.clone());
break Some(p)
}
Err(err) => {
eprintln!("Failed to unlock key: {}", err);
}
}
}
}