atuinsh / atuin

✨ Magical shell history
https://atuin.sh
MIT License
18.54k stars 520 forks source link

[Bug]: Failed to sync; attempting to decrypt with incorrect key #2197

Closed PerynFr closed 3 days ago

PerynFr commented 3 days ago

What did you expect to happen?

I was expecting synchronization, the password was created, login was successful, but an error occurred during synchronization

╰─❯ atuin sync ─╯ Uploading 8 records to 01904e75bcbb752da18f46d5eb1400e8/history [00:00:00] [##################################################################################################################] 8/8 (0.0s)9/0 up/down to record store 1133 in history index, but 38 in history store Running automatic history store init... Error: attempting to decrypt with incorrect key. currently using k4.lid.EYc1sfVm3F-SXpQncjfurYvsz64edSmVFtJqKdP5SJZp, expecting k4.lid.fIFwT73H69QOlY2ySGY92P_AsWptPibhNrPqHnGcMZeA

Location: crates/atuin-client/src/record/encryption.rs:132:9

What happened?

What can I do? it didn't help me: https://forum.atuin.sh/t/sync-v2-testing/124/29?u=ellie

my problem:

Local store purge completed OK
╭─     ~/.local/share/atuin                                                                                                  15:57:47 ─╮
╰─❯ atuin store purge                                                                                                                    ─╯
Purging local records that cannot be decrypted
Local store purge completed OK
╭─     ~/.local/share/atuin                                                                                                  15:57:52 ─╮
╰─❯ atuin store verify                                                                                                                   ─╯
Verifying local store can be decrypted with the current key
Local store encryption verified OK
╭─     ~/.local/share/atuin                                                                                                  15:57:59 ─╮
╰─❯ atuin store push                                                                                                                     ─╯
Uploading 10 records to 01904e75bcbb752da18f46d5eb1400e8/history
  [00:00:00] [################################################################################################################] 10/10 (0.0s)Uploaded 11 records
╭─     ~/.local/share/atuin                                                                                                  15:58:07 ─╮
╰─❯ atuin store pull                                                                                                                     ─╯
Downloading 16 records from 01904f2f9c507d2caa56728715de2778/history
  [00:00:00] [################################################################################################################] 16/16 (0.0s)Downloaded 17 records
Error: attempting to decrypt with incorrect key. currently using k4.lid.3gH7OFUMKdteVMvqAtOye6KWsSKZkUM_vwMRRiYXS6v5, expecting k4.lid.fIFwT73H69QOlY2ySGY92P_AsWptPibhNrPqHnGcMZeA

Location:
    crates/atuin-client/src/record/encryption.rs:132:9
╭─     ~/.local/share/atuin    

Atuin doctor output

╰─❯ atuin doctor                                                                                                                         ─╯
Atuin Doctor
Checking for diagnostics

Please include the output below with any bug reports or issues

{
  "atuin": {
    "version": "18.3.0",
    "sync": {
      "cloud": true,
      "records": true,
      "auto_sync": true,
      "last_sync": "2024-06-25 14:00:10.187958426 +00:00:00"
    },
    "sqlite_version": "3.44.0"
  },
  "shell": {
    "name": "zsh",
    "default": "zsh",
    "plugins": [
      "atuin"
    ],
    "preexec": "built-in"
  },
  "system": {
    "os": "Debian GNU/Linux",
    "arch": "x86_64",
    "version": "12",
    "disks": [
      {
        "name": "/dev/nvme0n1p2",
        "filesystem": "ext4"
      },
      {
        "name": "/dev/nvme0n1p1",
        "filesystem": "vfat"
      },
      {
        "name": "/dev/sda2",
        "filesystem": "ext4"
      },
      {
        "name": "/dev/sda1",
        "filesystem": "ext4"
      }
    ]
  }
}

Code of Conduct

ellie commented 3 days ago

Could you try following those instructions on the forum again please?

the --force args are required

ellie commented 3 days ago

Otherwise, dupe of

2007, #2096, #1895, etc

PerynFr commented 3 days ago

it's very good!

atuin store purge
atuin store verify
atuin store push --force
atuin store pull --force
atuin store rebuild history

after on 1 host and 2 another host

atuin sync -f

only after that I saw the same global history on both hosts, of course the key should be the same on both, write it into the file manually, it won’t work any other way. good luck everyone, and I hope this helps someone. the product is excellent!

ellie commented 3 days ago

write it into the file manually, it won’t work any other way.

I think this is the real issue - you should not need to do this manually. What lead you to having different keys on different hosts?

PerynFr commented 3 days ago

I don’t understand the algorithm for how to make them create the same, I tried all the logical methods, and only achieved this with my hands. need a clear manual

ellie commented 3 days ago

What do you mean? There's no algorithm to follow.

Did you use atuin login?

Sync setup docs: https://docs.atuin.sh/guide/sync/#login

It handles the case where keys differ, so you shouldn't need to do the above

PerynFr commented 3 days ago

Then, install Atuin on a new machine. Once installed, login with

atuin login -u

You will be prompted for your password, and for your key.

Syncing will happen automatically in the background, but you may wish to run it manually with.

This point is unclear, if I do not enter the key, another one will be created, although I will enter the same login and password, in what format should I enter the key so that there is no error? in words(atuin key) format? or from the key file?

ellie commented 3 days ago

If you read the entire "setting up sync" page, that should be covered for you

After registration, Atuin will generate an encryption key for you and store it locally. This is needed for logging in to other machines, and can be seen with

atuin key

Please never share this key with anyone! The Atuin developers will never ask you for your key, your password, or the contents of your Atuin directory.

If you lose your key, we can do nothing to help you. We recommend you store this somewhere safe, such as in a password manager.

PerynFr commented 3 days ago

if you run it on a new machine first (atuin sync), there will be an error, the sequence in the instructions is broken, first atuin sync -f (first time)

 atuin sync
Uploading 1 records to 0190535eb0d27dc0a9bea7f6d20918c4/history
2024-06-26T07:10:45.073663Z ERROR atuin_client::record::sync: failed to post records: error sending request for url (https://api.atuin.sh/api/v0/record): error trying to connect: operation timed out

Further: The instructions say that you can take the key from a file, and also get it using the command (atuin key), but it returns the key in 24 word format. Question: What algorithm can I use to convert a 24 word key into a key format in a file?

ellie commented 3 days ago

No, please do not run sync before logging in, you won't be authenticated and it won't work. Unless you're copying files between machines, in which case you'll have broken other things too. Please also don't go messing around with internal files unless you understand what's going on.

Please do exactly what the docs say.

The instructions say that you can take the key from a file

Nowhere in the docs do we say this. We say to use atuin key. The login prompt will use a file if it's already there, which would be the case if you run atuin logout, and then atuin login again.

The login command handles re-encrypting data so you do not end up opening an issue like this and needing to purge things. Use it

Question: What algorithm can I use to convert a 24 word key into a key format in a file?

Don't. Please. You'll break things. I'll re-iterate to make sure it's clear, but please do not mess around with internal files because you'll break things and I won't be able to support you.

PerynFr commented 3 days ago

thank you for the information, it helped me better understand how your very useful software works

ellie commented 3 days ago

You're welcome!