make keychain records append-only
This commit is contained in:
parent
8780350d41
commit
9e5871d02a
3 changed files with 95 additions and 14 deletions
|
|
@ -9524,19 +9524,48 @@ fn import_verified_sigchain(
|
|||
}
|
||||
let existing_ops = load_keychain_ops(store)?
|
||||
.into_iter()
|
||||
.map(|op| op.id)
|
||||
.collect::<BTreeSet<_>>();
|
||||
.map(|op| (op.id.clone(), op))
|
||||
.collect::<BTreeMap<_, _>>();
|
||||
let existing_signatures = load_keychain_signatures(store)?
|
||||
.into_iter()
|
||||
.map(|signature| {
|
||||
(
|
||||
signature.op_id,
|
||||
signature.signer,
|
||||
signature.namespace,
|
||||
signature.signature,
|
||||
(
|
||||
signature.op_id.clone(),
|
||||
signature.signer.clone(),
|
||||
signature.namespace.clone(),
|
||||
),
|
||||
signature,
|
||||
)
|
||||
})
|
||||
.collect::<BTreeSet<_>>();
|
||||
.collect::<BTreeMap<_, _>>();
|
||||
for op in ops {
|
||||
if existing_ops
|
||||
.get(&op.id)
|
||||
.is_some_and(|existing| existing != op)
|
||||
{
|
||||
return Err(NodeError::Unauthorized(format!(
|
||||
"refusing keychain operation {} because that ID already names different immutable content",
|
||||
op.id
|
||||
)));
|
||||
}
|
||||
}
|
||||
for signature in signatures {
|
||||
let identity = (
|
||||
signature.op_id.clone(),
|
||||
signature.signer.clone(),
|
||||
signature.namespace.clone(),
|
||||
);
|
||||
if existing_signatures
|
||||
.get(&identity)
|
||||
.is_some_and(|existing| existing != signature)
|
||||
{
|
||||
return Err(NodeError::Unauthorized(format!(
|
||||
"refusing keychain signature for {} because its signer and namespace already name different immutable content",
|
||||
signature.op_id
|
||||
)));
|
||||
}
|
||||
}
|
||||
let mut signatures_imported = 0;
|
||||
let mut ops_imported = 0;
|
||||
for op in ops {
|
||||
|
|
@ -9547,7 +9576,7 @@ fn import_verified_sigchain(
|
|||
.collect::<Vec<_>>();
|
||||
store
|
||||
.insert_keychain_op_with_signatures(&stored_keychain_op_from_op(op)?, &op_signatures)?;
|
||||
if !existing_ops.contains(&op.id) {
|
||||
if !existing_ops.contains_key(&op.id) {
|
||||
ops_imported += 1;
|
||||
}
|
||||
for signature in signatures
|
||||
|
|
@ -9558,9 +9587,8 @@ fn import_verified_sigchain(
|
|||
signature.op_id.clone(),
|
||||
signature.signer.clone(),
|
||||
signature.namespace.clone(),
|
||||
signature.signature.clone(),
|
||||
);
|
||||
signatures_imported += usize::from(!existing_signatures.contains(&key));
|
||||
signatures_imported += usize::from(!existing_signatures.contains_key(&key));
|
||||
}
|
||||
}
|
||||
Ok(geth_control::KeychainFetchImportReport {
|
||||
|
|
|
|||
Loading…
Reference in a new issue