Skip to content

Commit

Permalink
feat: don't stop with invalid key (#1612)
Browse files Browse the repository at this point in the history
An issue with the old sync was that if there was _one_ record encrypted
with a different key, sync would stop. You'd need to delete your account
and start from scratch. This sucked.

This change means we will carry on, and try to encrypt and build with as
much of the history as we are able to decrypt.

This is possible because we can quite happily store data on disk that we
cannot decrypt. The old store couldn't do this.

In future, we might consider a keyring containing multiple keys.
  • Loading branch information
ellie committed Jan 22, 2024
1 parent 6af6c90 commit d84f5b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion atuin-client/src/history/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,16 @@ impl HistoryStore {
for record in records.into_iter() {
let hist = match record.version.as_str() {
HISTORY_VERSION => {
let decrypted = record.decrypt::<PASETO_V4>(&self.encryption_key)?;
let decrypted = record.decrypt::<PASETO_V4>(&self.encryption_key);

let decrypted = match decrypted {
Ok(d) => d,
Err(e) => {
println!("failed to decrypt history: {e}");
continue;
}
};

HistoryRecord::deserialize(&decrypted.data, HISTORY_VERSION)
}
version => bail!("unknown history version {version:?}"),
Expand Down
1 change: 1 addition & 0 deletions atuin-client/src/record/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl PASETO_V4 {
// For now though we will only support the one key and key rotation will
// have to be a hard reset
let current_kid = wrapping_key.to_id();

ensure!(
current_kid == kid,
"attempting to decrypt with incorrect key. currently using {current_kid}, expecting {kid}"
Expand Down

0 comments on commit d84f5b2

Please sign in to comment.