atuinsh / atuin

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

Can't sync with hosted server #434

Closed thallada closed 2 years ago

thallada commented 2 years ago

I setup the atuin server following the directions here and confirmed that it's running correctly by getting a terry pratchett quote when I query it:

xh https://<my-server>/
HTTP/2.0 200 OK
content-length: 202
content-type: text/plain; charset=utf-8
date: Fri, 03 Jun 2022 16:10:24 GMT
server: nginx/1.14.0 (Ubuntu)

"Through the fathomless deeps of space swims the star turtle Great A’Tuin, bearing on its back the four giant elephants who carry on their shoulders the mass of the Discworld."
        -- Sir Terry Pratchett
Error: encryption key is not a valid message pack encoding

Caused by:
   0: IO error while reading marker: failed to fill whole buffer
   1: failed to fill whole buffer

Location:
    atuin-client/src/encryption.rs:81:10

After setting sync_address to my server in ~/.config/atuin/config.toml. I was then able to register a user on it, confirmed that it was actually created by looking at the database and seeing the user:

=> select * from users;
 id | username |       email       |                                             password
----+----------+-------------------+---------------------------------------------------------------------------------------------------
  1 | thallada | <my-email> | <redacted>
(1 row)

However, now I'm trying to login and it's asking me for an encryption key? I never setup an encryption key (only specified username, email, and password with the register command) so I entered a blank entry. Now when I attempt to atuin sync I get this error:

atuin sync
Error: encryption key is not a valid message pack encoding

Caused by:
   0: IO error while reading marker: failed to fill whole buffer
   1: failed to fill whole buffer

Location:
    atuin-client/src/encryption.rs:81:10

I see there is an atuin key command, which supposedly prints the encryption key, but I get this error when I run that:

atuin key
Error: could not load encryption key

Caused by:
   0: encryption key is not a valid message pack encoding
   1: IO error while reading marker: failed to fill whole buffer
   2: failed to fill whole buffer

Location:
    atuin-client/src/encryption.rs:81:10

What am I missing here?

thallada commented 2 years ago

I think I figured it out. I logged out with atuin logout after running atuin register but I never ran atuin key before logging out so I never got the encryption key. I did this because I wanted to test logging in but I never knew there was an encryption key I needed to copy first.

I would recommend adding docs about how the encryption key is generated, and I think the register command should print it to the shell to prompt the user to save it with their password.

Without the encryption key, my user was now useless so I had to log into the DB shell and delete the user and re-register:

DELETE FROM users;
DELETE FROM sessions;
ellie commented 2 years ago

Hey! Thanks for the really detailed issue! Glad you got it figured out :)

I would recommend adding docs about how the encryption key is generated, and I think the register command should print it to the shell to prompt the user to save it with their password.

I agree, we definitely need to improve the story around encryption keys in general tbh. Eg #386

I'll try and get this documented soon, I'm currently reworking a bunch of docs anyway!