···11+## bitwarden-ruby
22+33+### Migrating to ActiveRecord
44+55+If you've used this application before it switched to using ActiveRecord, you
66+need to do the following steps to migrate the data and generate the new table
77+structures.
88+99+Even though the migration script will create a backup of your database, it is
1010+probably best to create a backup yourself.
1111+You can also copy the `db/production.sqlite3` to your local machine and do the
1212+migration there.
1313+1414+After a successful migration you'd have to copy the updated database file back
1515+to the production machine.
1616+1717+First make sure you have the latest code:
1818+1919+ git pull
2020+2121+Afterwards you need to run bundle to add some required libraries for the migration
2222+2323+ bundle --with migrate
2424+2525+Now you are ready to do the migration:
2626+2727+ bundle exec ruby tools/migrate_to_ar.rb -e production
2828+2929+The -e switch allows you to select the correct database environment from
3030+`db/config.yml`.
3131+The migration script will:
3232+3333+ - dump the contents of the database to a YAML file
3434+ - rename the original database file to `production.sqlite3.#{Time.now.to_i}`
3535+ - create the database using ActiveRecord migrations
3636+ - load the contents from the dump file
3737+ - remove the dump file
3838+3939+Now your data is completely migrated and the library will now use ActiveRecord
4040+to handle anything database related.
4141+4242+Note: The ActiveRecord migration also defaults to putting the production
4343+database files in `db/production/` instead of just `db/`, which allows for
4444+a separate user to be able to write to the SQLite file without writing to
4545+`db/config.yml` and `db/migrate/` files.
+27-54
README.md
···1414This means you can easily run the server locally and have your data never
1515leave your device, or run it on your own web server via Rack and some front-end
1616HTTP server with TLS to support syncing across multiple devices.
1717-Backing up your data is as easy as copying the `db/production.sqlite3` file
1818-somewhere.
1717+Backing up your data is as easy as copying the `db/production/production.sqlite3`
1818+file somewhere.
19192020All user data in the SQLite database is stored in an encrypted format the
2121[same way](https://help.bitwarden.com/crypto.html)
···37373838Run `bundle install` at least once.
39394040-In order to create the database and the required tables run:
4040+In order to create the initial environment, it is recommended to create a new,
4141+unprivileged user on your system dedicated to running bitwarden-ruby such as
4242+with `useradd`.
4343+This documentation will assume a user has been created named `_bitwarden`.
4444+4545+In order to create the initial database and the required tables run:
4646+4747+ mkdir db/production
4848+ sudo chown _bitwarden db/production
4949+ sudo -u _bitwarden env RACK_ENV=production bundle exec rake db:migrate
41504242- env RACK_ENV=production bundle exec rake db:migrate
5151+If you've previously used bitwarden-ruby before July 30, 2018, when it did not
5252+use ActiveRecord, you should instead
5353+[migrate](AR-MIGRATE.md)
5454+your existing database.
43554444-To run via Rack on port 4567:
5656+To run via Rack on port 4567, as user `_bitwarden`:
45574646- env RACK_ENV=production bundle exec rackup -p 4567 config.ru
5858+ sudo -u _bitwarden env RACK_ENV=production bundle exec rackup -p 4567 config.ru
47594860You'll probably want to run it once with signups enabled, to allow yourself
4961to create an account:
50625151- env RACK_ENV=production ALLOW_SIGNUPS=1 bundle exec rackup -p 4567 config.ru
6363+ sudo -u _bitwarden env RACK_ENV=production ALLOW_SIGNUPS=1 bundle exec rackup -p 4567 config.ru
52645365Once the server is running, the Bitwarden apps (such as the Firefox extension)
5466can be configured to use your own Bitwarden server before login.
···6476requires interacting with the plaintext password, which the web API will never
6577do).
66786767-```
6868-env RACK_ENV=production bundle exec ruby tools/change_master_password.rb -u you@example.com
6969-```
7070-7171-### Migrating to ActiveRecord
7272-7373-If you've used this library before it switched to using ActiveRecord, you need to do the following steps to migrate the data and generate the new table structures. Even though the migration script will create a backup of your database, it is probably best to create a backup yourself. You can also copy the ```db/production.sqlite3``` to your local machine and do the migration there. After a successful migration you'd have to copy the updated database file back to the production machine.
7474-7575-First make sure you have the latest code:
7676-7777- git pull
7878-7979-Afterwards you need to run bundle to add some required libraries for the migration
8080-8181- bundle --with migrate
8282-8383-Now you are ready to do the migration
8484-8585- ruby tools/migrate_to_ar.rb -e production
8686-8787-The -e switch allows you to select the correct database environment from db/config.yml. The migration script will:#
8888-8989- * dump the contents of the database to a YAML file
9090- * rename the original database file to ```production.sqlite3.#{Time.now.to_i}```
9191- * create the database using ActiveRecord migrations
9292- * load the contents from the dump file
9393- * remove the dump file
9494-9595-Now your data is completely migrated and the library will now use ActiveRecord to handle anything database related :-)
7979+ sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/change_master_password.rb -u you@example.com
96809781### 1Password Conversion
9882···10286Once you have created your initial user account through `bitwarden-ruby`, run
10387the conversion tool with your account e-mail address:
10488105105-```
106106-env RACK_ENV=production bundle exec ruby tools/1password_import.rb -f /path/to/data.1pif -u you@example.com
107107-```
8989+ sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/1password_import.rb -f /path/to/data.1pif -u you@example.com
1089010991It will prompt you for the master password you already created, and then
11092convert and import as many items as it can.
···124106Once you have created your initial user account through `bitwarden-ruby`, run
125107the conversion tool with your account e-mail address:
126108127127-```
128128-env RACK_ENV=production bundle exec ruby tools/lastpass_import.rb -f /path/to/data.csv -u you@example.com
129129-```
109109+ sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/lastpass_import.rb -f /path/to/data.csv -u you@example.com
130110131111It will prompt you for the master password you already created, and then
132112convert and import as many items as it can.
···145125Once you have created your initial user account through `bitwarden-ruby`, run
146126the conversion tool with your account e-mail address:
147127148148-```
149149-env RACK_ENV=production bundle exec ruby tools/bitwarden_import.rb -f /path/to/data.csv -u you@example.com
150150-```
128128+ sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/bitwarden_import.rb -f /path/to/data.csv -u you@example.com
151129152130It will prompt you for the master password you already created, and then
153131convert and import as many items as it can.
···165143Once you have created your initial user account through `bitwarden-ruby`, run
166144the conversion tool with your account e-mail address:
167145168168-```
169169-env RACK_ENV=production bundle exec ruby tools/keepass_import.rb -f /path/to/data.kdbx -u you@example.com
170170-```
146146+ sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/keepass_import.rb -f /path/to/data.kdbx -u you@example.com
171147172148If your Keepass-database is secured using a keyfile, you can pass it using the `-k` parameter:
173149174174-```
175175-env RACK_ENV=production bundle exec ruby tools/keepass_import.rb -f /path/to/data.kdbx -k /path/to/keyfile.key -u you@example.com
176176-```
150150+ sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/keepass_import.rb -f /path/to/data.kdbx -k /path/to/keyfile.key -u you@example.com
177151178152It will prompt you for the master password you already created, and then
179153convert and import as many items as it can.
···181155This tool operates on the SQLite database directly (not through its REST API)
182156so you can run it offline.
183157184184-185158### 2-Factor Authentication
186159187160The Bitwarden browser extensions and mobile apps support accounts that require
···190163signed up in the previous steps, run the `tools/activate_totp.rb` program on
191164the server:
192165193193- env RACK_ENV=production bundle exec ruby tools/activate_totp.rb -u you@example.com
166166+ sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/activate_totp.rb -u you@example.com
194167195168You'll be shown a `data:` URL that has a PNG-encoded QR code, which you must
196169copy and paste into a browser, then scan with your mobile TOTP authenticator
···204177205178### License
206179207207-Copyright (c) 2017 joshua stein `<jcs@jcs.org>`
180180+Copyright (c) 2017-2018 joshua stein `<jcs@jcs.org>`
208181209182Permission to use, copy, modify, and distribute this software for any
210183purpose with or without fee is hereby granted, provided that the above