jcs / rubywarden

An unofficial, mostly Bitwarden-compatible API server written in Ruby (Sinatra and ActiveRecord)
ISC License
592 stars 49 forks source link

Invalid mac when importing csv #79

Closed phischmi closed 6 years ago

phischmi commented 6 years ago

Hi, just did a fresh install of rubywarden. When trying to import my CSV i get the following error: sudo -u _rubywarden env RUBYWARDEN_ENV=production bundle exec ruby tools/bitwarden_import.rb -f /home/XXX/bitwarden_export_20180924223701.csv -u XXX

/home/_rubywarden is not a directory. Bundler will use /tmp/bundler/home/XXX' as your home directory temporarily. master password for XXX: converting 1&1 FTP... /var/www/rubywarden/lib/bitwarden.rb:150:indecrypt': invalid mac "V[\xE5\xDAXQ\xB4t(vK\xA4\xD2\xD0\xCEr\xC1\x03\xF6\xE46Pp\xA7T\x8E\xAA\aXF\x8D\xB3" != "\n:\xF0\xCC/\x1E\x9Dv\xAA\xB9\xEEA,\x06\xC6\xF1\x13\xB4\xFBI@\nX\x18\xC1ue\xED\xB2\x91a\xE4" (RuntimeError) from /var/www/rubywarden/lib/user.rb:44:in encrypt_data_with_master_password_key' from tools/bitwarden_import.rb:38:inencrypt' from tools/bitwarden_import.rb:126:in block in <main>' from /usr/lib/ruby/2.3.0/csv.rb:1748:ineach' from /usr/lib/ruby/2.3.0/csv.rb:1131:in block in foreach' from /usr/lib/ruby/2.3.0/csv.rb:1282:inopen' from /usr/lib/ruby/2.3.0/csv.rb:1130:in foreach' from tools/bitwarden_import.rb:103:in

'

Joshndroid commented 6 years ago

@jcs i am also receiving this error when importing a bitwarden exported csv but im not using _rubywarden user

converting 3D Mark...
Traceback (most recent call last):
    8: from tools/bitwarden_import.rb:103:in `<main>'
    7: from /usr/lib/ruby/2.5.0/csv.rb:1141:in `foreach'
    6: from /usr/lib/ruby/2.5.0/csv.rb:1289:in `open'
    5: from /usr/lib/ruby/2.5.0/csv.rb:1142:in `block in foreach'
    4: from /usr/lib/ruby/2.5.0/csv.rb:1764:in `each'
    3: from tools/bitwarden_import.rb:126:in `block in <main>'
    2: from tools/bitwarden_import.rb:38:in `encrypt'
    1: from /home/file/rubywarden/lib/user.rb:44:in `encrypt_data_with_master_password_key'
/home/file/rubywarden/lib/bitwarden.rb:150:in `decrypt': invalid mac "|;\x9ERA1\r\x92\x95V\xBF'\\\x13\xA7={\x80\x9F\x12\\\x93\x89N\xDD\xCD\x8BMmo\x86\xF4" != "\xA3eb$K\xB9\xD6w\x90o\xF9\xCE\x97\xBER\xE3\xDA\xA1\xCBQ\x878\x1F\xA3\x92\x8BH\xD3\xB7\xE1Y\xD2" (RuntimeError)
phischmi commented 6 years ago

I now tried several older commits going back to e6f7e9e, which was the last commit i successfully deployed on Raspbian Stretch. Now i'm on Armbian Stretch receiving the above error with each commit i tested :/

phischmi commented 6 years ago

Also just tried the same on my Mac using rbenv. Same error. So it's obviously not an OS issue...

bahamas10 commented 6 years ago

Just ran into this error using the keepass importer.

jcs commented 6 years ago

I think this is related to HKDF key stretching which upstream is now using by default, so when setting up a new user from upstream apps, your key is set to a 2. version instead of 0. like older ones.

bahamas10 commented 6 years ago

Verified the user I created has a key starting with 2.:

$ echo 'select key from users;' | sudo -u rubywarden sqlite3 db/production/production.sqlite3 
2.<snipped>
jcs commented 6 years ago

This should be fixed in d6f13b8 if you folks want to try importing again.

phischmi commented 6 years ago

Works! Thanks!

bahamas10 commented 6 years ago

works for me as well, thanks!