···11-## bitwarden-ruby
11+## Rubywarden
2233-### Migrating to ActiveRecord
33+### Migrating From `bitwarden-ruby` to Rubywarden and ActiveRecord
4455-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.
55+If you've used this application before it switched to using ActiveRecord
66+(when it was called `bitwarden-ruby`),
77+you need to do the following steps to migrate the data and generate the new
88+table structures.
89910Even though the migration script will create a backup of your database, it is
1011probably best to create a backup yourself.
+34-34
README.md
···22[Bitwarden](https://bitwarden.com/)
33project nor 8bit Solutions LLC.)*
4455-## bitwarden-ruby
55+## Rubywarden
6677A small, self-contained API server written in Ruby and Sinatra to provide a
88private backend for the open-source
···2222it is in the official Bitwarden backend, where the master password is never
2323known by the server.
2424For details on the format, consult the
2525-[documentation](https://github.com/jcs/bitwarden-ruby/blob/master/API.md).
2525+[documentation](https://github.com/jcs/rubywarden/blob/master/API.md).
26262727### API Documentation
28282929This project also contains independent
3030-[documentation for Bitwarden's API](https://github.com/jcs/bitwarden-ruby/blob/master/API.md)
3030+[documentation for Bitwarden's API](https://github.com/jcs/rubywarden/blob/master/API.md)
3131written as I work on this server, since there doesn't seem to be any
3232documentation available other than the
3333[.NET Bitwarden code](https://github.com/bitwarden/core)
···3838Run `bundle install` at least once.
39394040In 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
4141+unprivileged user on your system dedicated to running Rubywarden such as
4242with `useradd`.
4343-This documentation will assume a user has been created named `_bitwarden`.
4343+This documentation will assume a user has been created named `_rubywarden`.
44444545In order to create the initial database and the required tables run:
46464747 mkdir db/production
4848- sudo chown _bitwarden db/production
4949- sudo -u _bitwarden env RACK_ENV=production bundle exec rake db:migrate
4848+ sudo chown _rubywarden db/production
4949+ sudo -u _rubywarden env RACK_ENV=production bundle exec rake db:migrate
50505151-If you've previously used bitwarden-ruby before July 30, 2018, when it did not
5252-use ActiveRecord, you should instead
5151+If you've previously used Rubywarden before July 30, 2018 when it was called
5252+`bitwarden-ruby`, when it did not use ActiveRecord, you should instead
5353[migrate](AR-MIGRATE.md)
5454your existing database.
55555656-To run via Rack on port 4567, as user `_bitwarden`:
5656+To run via Rack on port 4567, as user `_rubywarden`:
57575858- sudo -u _bitwarden env RACK_ENV=production bundle exec rackup -p 4567 config.ru
5858+ sudo -u _rubywarden env RACK_ENV=production bundle exec rackup -p 4567 config.ru
59596060You'll probably want to run it once with signups enabled, to allow yourself
6161to create an account:
62626363- sudo -u _bitwarden env RACK_ENV=production ALLOW_SIGNUPS=1 bundle exec rackup -p 4567 config.ru
6363+ sudo -u _rubywarden env RACK_ENV=production ALLOW_SIGNUPS=1 bundle exec rackup -p 4567 config.ru
64646565Once the server is running, the Bitwarden apps (such as the Firefox extension)
6666can be configured to use your own Bitwarden server before login.
···7676requires interacting with the plaintext password, which the web API will never
7777do).
78787979- sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/change_master_password.rb -u you@example.com
7979+ sudo -u _rubywarden env RACK_ENV=production bundle exec ruby tools/change_master_password.rb -u you@example.com
80808181### 2-Factor Authentication
8282···8686signed up in the previous steps, run the `tools/activate_totp.rb` program on
8787the server:
88888989- sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/activate_totp.rb -u you@example.com
8989+ sudo -u _rubywarden env RACK_ENV=production bundle exec ruby tools/activate_totp.rb -u you@example.com
90909191You'll be shown a `data:` URL that has a PNG-encoded QR code, which you must
9292copy and paste into a browser, then scan with your mobile TOTP authenticator
···108108Export everything from 1Password in its "1Password Interchange Format".
109109It should create a directory with a `data.1pif` file (which is unencrypted, so
110110be careful with it).
111111-Once you have created your initial user account through `bitwarden-ruby`, run
112112-the conversion tool with your account e-mail address:
111111+Once you have created your initial user account through Rubywarden, run the
112112+conversion tool with your account e-mail address:
113113114114- sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/1password_import.rb -f /path/to/data.1pif -u you@example.com
114114+ sudo -u _rubywarden env RACK_ENV=production bundle exec ruby tools/1password_import.rb -f /path/to/data.1pif -u you@example.com
115115116116It will prompt you for the master password you already created, and then
117117convert and import as many items as it can.
···127127and any custom fields will lose their type (text, hidden, or boolean) and be
128128simply exported as text.
129129130130-Once you have created your initial user account through `bitwarden-ruby`, run
131131-the conversion tool with your account e-mail address:
130130+Once you have created your initial user account through Rubywarden, run the
131131+conversion tool with your account e-mail address:
132132133133- sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/bitwarden_import.rb -f /path/to/data.csv -u you@example.com
133133+ sudo -u _rubywarden env RACK_ENV=production bundle exec ruby tools/bitwarden_import.rb -f /path/to/data.csv -u you@example.com
134134135135It will prompt you for the master password you already created, and then
136136convert and import as many items as it can.
···138138This tool operates on the SQLite database directly (not through its REST API)
139139so you can run it offline.
140140141141-### Keepass
141141+#### Keepass
142142143143In order to use the Keepass converter, you will need to install the necessary
144144dependency, using `bundle install --with keepass`.
145145146146There is no need to export your Keepass-database - you can use it as is.
147147148148-Once you have created your initial user account through `bitwarden-ruby`, run
149149-the conversion tool with your account e-mail address:
148148+Once you have created your initial user account through Rubywarden, run the
149149+conversion tool with your account e-mail address:
150150151151- sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/keepass_import.rb -f /path/to/data.kdbx -u you@example.com
151151+ sudo -u _rubywarden env RACK_ENV=production bundle exec ruby tools/keepass_import.rb -f /path/to/data.kdbx -u you@example.com
152152153153If your Keepass-database is secured using a keyfile, you can pass it using the `-k` parameter:
154154155155- 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
155155+ sudo -u _rubywarden 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
156156157157It will prompt you for the master password you already created, and then
158158convert and import as many items as it can.
···163163#### Lastpass
164164165165Export everything from LastPass by going to your vault, "More Options",
166166-"Advanced" and then "Export". It will then export your details in a new browser
167167-window in CSV format, copy and paste this data into a file accessible from your
168168-bitwarden-ruby installation. Unfortunately due to limitations in LastPass
169169-export the "extra fields" and "attachments" data in the LastPass vault will not
170170-be converted.
166166+"Advanced" and then "Export".
167167+It will then export your details in a new browser window in CSV format, copy
168168+and paste this data into a file accessible from your Rubywarden installation.
169169+Unfortunately due to limitations in LastPass export the "extra fields" and
170170+"attachments" data in the LastPass vault will not be converted.
171171172172-Once you have created your initial user account through `bitwarden-ruby`, run
173173-the conversion tool with your account e-mail address:
172172+Once you have created your initial user account through Rubywarden, run the
173173+conversion tool with your account e-mail address:
174174175175- sudo -u _bitwarden env RACK_ENV=production bundle exec ruby tools/lastpass_import.rb -f /path/to/data.csv -u you@example.com
175175+ sudo -u _rubywarden env RACK_ENV=production bundle exec ruby tools/lastpass_import.rb -f /path/to/data.csv -u you@example.com
176176177177It will prompt you for the master password you already created, and then
178178convert and import as many items as it can.
···180180This tool operates on the SQLite database directly (not through its REST API)
181181so you can run it offline.
182182183183-### License
183183+### Rubywarden License
184184185185Copyright (c) 2017-2018 joshua stein `<jcs@jcs.org>`
186186
+2-2
config.ru
···1414# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515#
16161717-require File.dirname(__FILE__) + "/lib/bitwarden_ruby.rb"
1717+require File.dirname(__FILE__) + "/lib/rubywarden.rb"
1818require "#{APP_ROOT}/lib/app.rb"
19192020-run BitwardenRuby::App
2020+run Rubywarden::App
+5-5
lib/app.rb
···2323require_relative 'routes/icons'
2424require_relative 'routes/identity'
25252626-module BitwardenRuby
2626+module Rubywarden
2727 class App < Sinatra::Base
2828 register Sinatra::Namespace
2929 register Sinatra::ActiveRecordExtension
···3535 enable :logging
3636 end
37373838- helpers BitwardenRuby::RequestHelpers
3838+ helpers Rubywarden::RequestHelpers
39394040 before do
4141 if request.content_type.to_s.match(/\Aapplication\/json(;|\z)/)
···5555 content_type :json
5656 end
57575858- register BitwardenRuby::Routing::Api
5959- register BitwardenRuby::Routing::Icons
6060- register BitwardenRuby::Routing::Identity
5858+ register Rubywarden::Routing::Api
5959+ register Rubywarden::Routing::Icons
6060+ register Rubywarden::Routing::Identity
6161 end
6262end
+4-1
lib/bitwarden.rb
···170170171171 class Token
172172 class << self
173173- KEY = "#{APP_ROOT}/db/production/jwt-rsa.key"
173173+ KEY = "#{APP_ROOT}/db/#{RACK_ENV}/jwt-rsa.key"
174174175175 attr_reader :rsa
176176···181181 else
182182 @rsa = OpenSSL::PKey::RSA.generate 2048
183183184184+ if !Dir.exists?(File.dirname(KEY))
185185+ Dir.mkdir(File.dirname(KEY))
186186+ end
184187 f = File.new(KEY, File::CREAT|File::TRUNC|File::RDWR, 0600)
185188 f.write @rsa.to_pem
186189 f.write @rsa.public_key.to_pem
lib/bitwarden_ruby.rb
lib/rubywarden.rb
+2-2
lib/helpers/request_helpers.rb
···1414# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515#
16161717-module BitwardenRuby
1717+module Rubywarden
1818 module RequestHelpers
1919 def device_from_bearer
2020 if m = request.env["HTTP_AUTHORIZATION"].to_s.match(/^Bearer (.+)/)
···4646 }.to_json ]
4747 end
4848 end
4949-end4949+end
+2-2
lib/routes/api.rb
···1414# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515#
16161717-module BitwardenRuby
1717+module Rubywarden
1818 module Routing
1919 module Api
2020 def self.registered(app)
···323323 end
324324 end
325325 end
326326-end326326+end
+2-2
lib/routes/icons.rb
···1414# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515#
16161717-module BitwardenRuby
1717+module Rubywarden
1818 module Routing
1919 module Icons
2020 def self.registered(app)
···2828 end
2929 end
3030 end
3131-end3131+end
+2-2
lib/routes/identity.rb
···1414# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515#
16161717-module BitwardenRuby
1717+module Rubywarden
1818 module Routing
1919 module Identity
2020 def self.registered(app)
···118118 end
119119 end
120120 end
121121-end121121+end
+2-2
spec/spec_helper.rb
···1111# most tests require this to be on
1212ALLOW_SIGNUPS = true
13131414-require File.realpath(File.dirname(__FILE__) + "/../lib/bitwarden_ruby.rb")
1414+require File.realpath(File.dirname(__FILE__) + "/../lib/rubywarden.rb")
1515require "#{APP_ROOT}/lib/app.rb"
16161717#load 'db/schema.rb'
···4747end
48484949def app
5050- BitwardenRuby::App
5050+ Rubywarden::App
5151end