Skip to content

Commit e776f78

Browse files
authored
[PM-6895] Add script to auto-populate crypto values in .env (#343)
* Add script to auto-populate crypto values in .env * convert generate-crypto script to ts * remove crypto values from .env.example * update README * add typechecking command * resolve strict typing issues
1 parent f1176d0 commit e776f78

File tree

8 files changed

+437
-11
lines changed

8 files changed

+437
-11
lines changed

.env.example

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,3 @@ BW_DB_PORT=3306
5454
BW_ENABLE_SSL="true"
5555
BW_SSL_CERT="ssl.crt"
5656
BW_SSL_KEY="ssl.key"
57-
58-
# Account creation
59-
# Pull the following values from https://bitwarden.com/crypto.html
60-
KDF_ITERATIONS=600000
61-
MASTER_PASSWORD_HASH=""
62-
PROTECTED_SYMMETRIC_KEY=""
63-
GENERATED_RSA_KEY_PAIR_PUBLIC_KEY=""
64-
GENERATED_RSA_KEY_PAIR_PROTECTED_PRIVATE_KEY=""

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ The aim of this project is to track and anticipate the compatibility of the Bitw
5858
- Create an `.env` file in the root directory with values pointing to the vault you want to test against (use `.env.example` as guidance) and populate it with your desired values
5959
- Run `npm run setup:install` to generate and add installation values to your dotfile
6060
- Alternatively, you can generate them at `https://bitwarden.com/host` and add them to your dotfile manually as `BW_INSTALLATION_ID` and `BW_INSTALLATION_KEY`
61+
- Run `npm run setup:crypto` to generate and add crypto values to your dotfile
62+
- Alternatively, you can create the required values manually with guidance from `https://bitwarden.com/help/bitwarden-security-white-paper/#hashing-key-derivation-and-encryption` and add them to your dotfile as `KDF_ITERATIONS`, `MASTER_PASSWORD_HASH`, `PROTECTED_SYMMETRIC_KEY`, `GENERATED_RSA_KEY_PAIR_PUBLIC_KEY`, and `GENERATED_RSA_KEY_PAIR_PROTECTED_PRIVATE_KEY`
6163
- Install node (with `nvm install` if `nvm` is installed)
6264
- Install Bitwarden CLI (with npm: `npm install -g @bitwarden/cli`)
6365
- Do a clean-install with `npm ci` (this will also fetch and set up the Bitwarden clients repo)

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"setup:ssl": "./scripts/generate-certs.sh",
5050
"setup:test-site": "rimraf test-site && ./scripts/setup-test-site.sh",
5151
"setup:vault": "npm run seed:vault:account && npm run seed:vault:ciphers",
52+
"setup:crypto": "ts-node ./scripts/generate-crypto.ts",
5253
"start:cli": "./scripts/cli-serve-helper.sh",
5354
"start:test-site": "./scripts/serve-test-site.sh",
5455
"stop:cli": "kill $(ps -e | grep 'bw serve' | grep -v 'vault-seeder' | awk '{print $1}')",
@@ -77,7 +78,8 @@
7778
"test:static:notification:ci": "npm run pretest && NODE_EXTRA_CA_CERTS=ssl.crt xvfb-run playwright test tests/static/notifications.spec.ts",
7879
"test:static:notification:headless": "npm run pretest && NODE_EXTRA_CA_CERTS=ssl.crt HEADLESS=true playwright test tests/static/notifications.spec.ts",
7980
"test:webserve": "cd clients/apps/web && npm run build:bit:watch",
80-
"test:webserve:bitwarden": "cd clients/apps/web && ENV=cloud npm run build:oss:watch"
81+
"test:webserve:bitwarden": "cd clients/apps/web && ENV=cloud npm run build:oss:watch",
82+
"typecheck": "npx tsc -p ./scripts/tsconfig.json && npx tsc -p ./tests/tsconfig.json"
8183
},
8284
"engines": {
8385
"node": "23.11.x",

scripts/create-account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async function createAccount() {
6262
typeof preCreationResponseData !== "string" &&
6363
preCreationResponseData.object === "error"
6464
) {
65-
const emailIsTaken = !!preCreationResponseData.message.match(
65+
const emailIsTaken = !!preCreationResponseData.message?.match(
6666
/^Email .+@.+ is already taken$/g,
6767
)?.length;
6868

scripts/first-time-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ npx playwright install --with-deps chromium
99
npm run setup:extension
1010
npm run build:extension
1111
npm run setup:install
12+
npm run setup:crypto
1213
docker compose up -d --build --remove-orphans --wait --wait-timeout 60
1314
npm run seed:vault:account
1415
npm run start:cli

0 commit comments

Comments
 (0)