mirror of
https://github.com/dani-garcia/vaultwarden.wiki.git
synced 2026-11-02 21:26:48 +02:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86546a76a7 | ||
|
|
57acc1a926 | ||
|
|
22b306bdde | ||
|
|
a560a92e2f | ||
|
|
3b0ac56c15 | ||
|
|
6f4cdb86f7 | ||
|
|
815c35ca25 | ||
|
|
592f9ea0fc |
No files matched your search
@@ -410,6 +410,12 @@
|
|||||||
## - "biometrics-sdk-ipc": Enable biometric unlock over the SDK IPC framework (Desktop >= 2026.9.0, Browser >= 2026.9.0)
|
## - "biometrics-sdk-ipc": Enable biometric unlock over the SDK IPC framework (Desktop >= 2026.9.0, Browser >= 2026.9.0)
|
||||||
## - "windows-native-credential-sync": Register the desktop app as a passkey provider in Windows, so passkeys in the vault can be used by other apps and browsers.
|
## - "windows-native-credential-sync": Register the desktop app as a passkey provider in Windows, so passkeys in the vault can be used by other apps and browsers.
|
||||||
## Requires the Microsoft Store (appx) build of the desktop app. Stable releases up to and including 2026.9.1 lack the required plugin registration, so it has no effect there yet.
|
## Requires the Microsoft Store (appx) build of the desktop app. Stable releases up to and including 2026.9.1 lack the required plugin registration, so it has no effect there yet.
|
||||||
|
## - "pm-27278-v2-password-registration": Register new accounts with v2 encryption. (Web >= 2026.6.4, Desktop/Browser/CLI >= 2026.7.0, Android >= 2026.4.1, iOS >= 2026.5.1)
|
||||||
|
## - "enable-account-encryption-v2-jit-password-registration": Give SSO users who set their master password on their first login v2 encryption. (Web >= 2026.1.1, Desktop/Browser/CLI >= 2026.1.0, Android >= 2026.4.1, iOS >= 2026.6.0)
|
||||||
|
## - "force-upgrade-v2-encryption": Upgrade every v1 account to v2 encryption the next time it's unlocked in a web, desktop, browser or CLI client. (Web >= 2026.6.4, Desktop/Browser/CLI >= 2026.7.0)
|
||||||
|
## These three flags can't be undone: a v2 account stays v2, and it can only log in from clients that are 2025.11.0 or newer and send their version, which rules out some older and third-party clients.
|
||||||
|
## - "pm-30144-sdk-key-rotation": Only for clients up to 2026.10.0 (Desktop up to 2026.10.1): together with "force-upgrade-v2-encryption", a manual key rotation also upgrades a v1 account to v2.
|
||||||
|
## - "pm-31050-no-logout-key-upgrade-rotation": Only for clients 2026.6.0 to 2026.10.0 (Desktop up to 2026.10.1): sync instead of logging out after the upgrade to v2. Newer clients always do.
|
||||||
# EXPERIMENTAL_CLIENT_FEATURE_FLAGS=
|
# EXPERIMENTAL_CLIENT_FEATURE_FLAGS=
|
||||||
|
|
||||||
## Require new device emails. When a user logs in an email is required to be sent.
|
## Require new device emails. When a user logs in an email is required to be sent.
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
name: SDK live tests
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
# Runs the live-server integration tests of bitwarden/sdk-internal against this branch.
|
||||||
|
# Only started by hand: it builds the SDK too, and the tests aren't in a released SDK yet.
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
sdk_ref:
|
||||||
|
description: "Branch, tag or commit of bitwarden/sdk-internal to test with"
|
||||||
|
required: true
|
||||||
|
default: "km/live-server-integration-tests"
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sdk-live-tests:
|
||||||
|
name: SDK live tests
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
timeout-minutes: 90
|
||||||
|
steps:
|
||||||
|
- name: "Install dependencies Ubuntu"
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends build-essential libssl-dev pkg-config
|
||||||
|
|
||||||
|
- name: "Checkout"
|
||||||
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: "Checkout sdk-internal"
|
||||||
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
repository: bitwarden/sdk-internal
|
||||||
|
ref: ${{ inputs.sdk_ref }}
|
||||||
|
path: sdk-internal
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
# Each checkout pins its own toolchain in rust-toolchain.toml
|
||||||
|
- name: "Install toolchains"
|
||||||
|
run: |
|
||||||
|
rustup toolchain install
|
||||||
|
cd sdk-internal
|
||||||
|
rustup toolchain install
|
||||||
|
rustup target add wasm32-unknown-unknown
|
||||||
|
rustup component add rust-src
|
||||||
|
|
||||||
|
- name: "Setup Node"
|
||||||
|
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
|
||||||
|
- name: "Install binaryen"
|
||||||
|
run: npm i -g binaryen@132.0.0
|
||||||
|
|
||||||
|
- name: "Run the SDK live tests"
|
||||||
|
run: tools/sdk-live-tests/run.sh --sdk-dir sdk-internal
|
||||||
|
|
||||||
|
- name: "Upload logs"
|
||||||
|
if: ${{ failure() }}
|
||||||
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||||
|
with:
|
||||||
|
name: sdk-live-tests-logs
|
||||||
|
path: target/sdk-live-tests/**/*.log
|
||||||
+2
-3
@@ -14,9 +14,8 @@ extend-ignore-re = [
|
|||||||
# In SMTP it's called HELO, so ignore it
|
# In SMTP it's called HELO, so ignore it
|
||||||
"(?i)helo_name",
|
"(?i)helo_name",
|
||||||
"Server name sent during.+HELO",
|
"Server name sent during.+HELO",
|
||||||
# COSE Is short for CBOR Object Signing and Encryption, ignore these specific items
|
# COSE Is short for CBOR Object Signing and Encryption
|
||||||
"COSEKey",
|
"(?i)cose",
|
||||||
"COSEAlgorithm",
|
|
||||||
# Ignore this specific string as it's valid
|
# Ignore this specific string as it's valid
|
||||||
"Ensure they are valid OTPs",
|
"Ensure they are valid OTPs",
|
||||||
# This word is misspelled upstream
|
# This word is misspelled upstream
|
||||||
|
|||||||
+1
-1
@@ -107,7 +107,7 @@ serde = { version = "1.0.229", features = ["derive"] }
|
|||||||
serde_json = "1.0.154"
|
serde_json = "1.0.154"
|
||||||
|
|
||||||
# A safe, extensible ORM and Query builder
|
# A safe, extensible ORM and Query builder
|
||||||
diesel = { version = "2.3.14", features = ["chrono", "r2d2", "numeric"] }
|
diesel = { version = "2.3.14", features = ["chrono", "r2d2", "numeric", "64-column-tables"] }
|
||||||
diesel_migrations = "2.3.2"
|
diesel_migrations = "2.3.2"
|
||||||
|
|
||||||
derive_more = { version = "2.1.1", features = [
|
derive_more = { version = "2.1.1", features = [
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
DROP TABLE IF EXISTS user_signature_key_pairs;
|
||||||
|
|
||||||
|
ALTER TABLE users DROP COLUMN signed_public_key;
|
||||||
|
ALTER TABLE users DROP COLUMN security_state;
|
||||||
|
ALTER TABLE users DROP COLUMN security_version;
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
ALTER TABLE users ADD COLUMN signed_public_key TEXT;
|
||||||
|
ALTER TABLE users ADD COLUMN security_state TEXT;
|
||||||
|
ALTER TABLE users ADD COLUMN security_version INTEGER;
|
||||||
|
|
||||||
|
CREATE TABLE user_signature_key_pairs (
|
||||||
|
uuid CHAR(36) NOT NULL PRIMARY KEY,
|
||||||
|
user_uuid CHAR(36) NOT NULL UNIQUE,
|
||||||
|
signature_algorithm INTEGER NOT NULL, -- 0 = ed25519, 1 = mldsa44
|
||||||
|
signing_key TEXT NOT NULL,
|
||||||
|
verifying_key TEXT NOT NULL,
|
||||||
|
created_at DATETIME NOT NULL,
|
||||||
|
updated_at DATETIME NOT NULL,
|
||||||
|
FOREIGN KEY (user_uuid) REFERENCES users (uuid) ON DELETE CASCADE
|
||||||
|
);
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE users DROP COLUMN v2_upgrade_token;
|
||||||
|
ALTER TABLE users_organizations DROP COLUMN v2_upgrade_token;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE users ADD COLUMN v2_upgrade_token TEXT;
|
||||||
|
ALTER TABLE users_organizations ADD COLUMN v2_upgrade_token TEXT;
|
||||||
Whitespace-only changes.
@@ -0,0 +1,4 @@
|
|||||||
|
-- Key rotations before this kept the id of the old user key, so every new
|
||||||
|
-- cipher was refused from then on. Stale ids can't be told apart, so clear
|
||||||
|
-- all of them; clients record their current key's id again when it's empty.
|
||||||
|
UPDATE users SET key_id = NULL;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
DROP TABLE IF EXISTS user_signature_key_pairs;
|
||||||
|
|
||||||
|
ALTER TABLE users DROP COLUMN signed_public_key;
|
||||||
|
ALTER TABLE users DROP COLUMN security_state;
|
||||||
|
ALTER TABLE users DROP COLUMN security_version;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
ALTER TABLE users ADD COLUMN signed_public_key TEXT;
|
||||||
|
ALTER TABLE users ADD COLUMN security_state TEXT;
|
||||||
|
ALTER TABLE users ADD COLUMN security_version INTEGER;
|
||||||
|
|
||||||
|
CREATE TABLE user_signature_key_pairs (
|
||||||
|
uuid CHAR(36) NOT NULL PRIMARY KEY,
|
||||||
|
user_uuid CHAR(36) NOT NULL UNIQUE REFERENCES users (uuid) ON DELETE CASCADE,
|
||||||
|
signature_algorithm INTEGER NOT NULL, -- 0 = ed25519, 1 = mldsa44
|
||||||
|
signing_key TEXT NOT NULL,
|
||||||
|
verifying_key TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL,
|
||||||
|
updated_at TIMESTAMP NOT NULL
|
||||||
|
);
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE users DROP COLUMN v2_upgrade_token;
|
||||||
|
ALTER TABLE users_organizations DROP COLUMN v2_upgrade_token;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE users ADD COLUMN v2_upgrade_token TEXT;
|
||||||
|
ALTER TABLE users_organizations ADD COLUMN v2_upgrade_token TEXT;
|
||||||
Whitespace-only changes.
@@ -0,0 +1,4 @@
|
|||||||
|
-- Key rotations before this kept the id of the old user key, so every new
|
||||||
|
-- cipher was refused from then on. Stale ids can't be told apart, so clear
|
||||||
|
-- all of them; clients record their current key's id again when it's empty.
|
||||||
|
UPDATE users SET key_id = NULL;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
DROP TABLE IF EXISTS user_signature_key_pairs;
|
||||||
|
|
||||||
|
ALTER TABLE users DROP COLUMN signed_public_key;
|
||||||
|
ALTER TABLE users DROP COLUMN security_state;
|
||||||
|
ALTER TABLE users DROP COLUMN security_version;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
ALTER TABLE users ADD COLUMN signed_public_key TEXT;
|
||||||
|
ALTER TABLE users ADD COLUMN security_state TEXT;
|
||||||
|
ALTER TABLE users ADD COLUMN security_version INTEGER;
|
||||||
|
|
||||||
|
CREATE TABLE user_signature_key_pairs (
|
||||||
|
uuid TEXT NOT NULL PRIMARY KEY,
|
||||||
|
user_uuid TEXT NOT NULL UNIQUE REFERENCES users (uuid) ON DELETE CASCADE,
|
||||||
|
signature_algorithm INTEGER NOT NULL, -- 0 = ed25519, 1 = mldsa44
|
||||||
|
signing_key TEXT NOT NULL,
|
||||||
|
verifying_key TEXT NOT NULL,
|
||||||
|
created_at DATETIME NOT NULL,
|
||||||
|
updated_at DATETIME NOT NULL
|
||||||
|
);
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE users DROP COLUMN v2_upgrade_token;
|
||||||
|
ALTER TABLE users_organizations DROP COLUMN v2_upgrade_token;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE users ADD COLUMN v2_upgrade_token TEXT;
|
||||||
|
ALTER TABLE users_organizations ADD COLUMN v2_upgrade_token TEXT;
|
||||||
Whitespace-only changes.
@@ -0,0 +1,4 @@
|
|||||||
|
-- Key rotations before this kept the id of the old user key, so every new
|
||||||
|
-- cipher was refused from then on. Stale ids can't be told apart, so clear
|
||||||
|
-- all of them; clients record their current key's id again when it's empty.
|
||||||
|
UPDATE users SET key_id = NULL;
|
||||||
+1
-1
@@ -430,7 +430,7 @@ async fn delete_user(user_id: UserId, token: AdminToken, conn: DbConn, nt: Notif
|
|||||||
if res.is_ok() {
|
if res.is_ok() {
|
||||||
nt.send_logout(&user, None, &conn).await;
|
nt.send_logout(&user, None, &conn).await;
|
||||||
if has_push_device {
|
if has_push_device {
|
||||||
push_logout_to_relay(&user, None);
|
push_logout_to_relay(&user, None, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+931
-167
File diff suppressed because it is too large.
Load diff
+38
-3
@@ -190,7 +190,7 @@ async fn sync(data: SyncData, headers: Headers, client_version: Option<ClientVer
|
|||||||
// https://github.com/bitwarden/android/blob/release/2025.12-rc41/network/src/main/kotlin/com/bitwarden/network/model/MasterPasswordUnlockDataJson.kt#L22-L26
|
// https://github.com/bitwarden/android/blob/release/2025.12-rc41/network/src/main/kotlin/com/bitwarden/network/model/MasterPasswordUnlockDataJson.kt#L22-L26
|
||||||
"masterKeyEncryptedUserKey": headers.user.akey,
|
"masterKeyEncryptedUserKey": headers.user.akey,
|
||||||
"masterKeyWrappedUserKey": headers.user.akey,
|
"masterKeyWrappedUserKey": headers.user.akey,
|
||||||
"salt": headers.user.email,
|
"salt": headers.user.master_password_salt(),
|
||||||
"containedKeyId": headers.user.key_id,
|
"containedKeyId": headers.user.key_id,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -202,6 +202,9 @@ async fn sync(data: SyncData, headers: Headers, client_version: Option<ClientVer
|
|||||||
if let Some(key_id) = &headers.user.key_id {
|
if let Some(key_id) = &headers.user.key_id {
|
||||||
user_decryption["userKeyId"] = json!(key_id);
|
user_decryption["userKeyId"] = json!(key_id);
|
||||||
}
|
}
|
||||||
|
if let Some(v2_upgrade_token) = headers.user.v2_upgrade_token_json() {
|
||||||
|
user_decryption["v2UpgradeToken"] = v2_upgrade_token;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Json(json!({
|
Ok(Json(json!({
|
||||||
"profile": user_json,
|
"profile": user_json,
|
||||||
@@ -563,6 +566,40 @@ pub async fn update_cipher_from_data(
|
|||||||
conn: &DbConn,
|
conn: &DbConn,
|
||||||
nt: &Notify<'_>,
|
nt: &Notify<'_>,
|
||||||
ut: UpdateType,
|
ut: UpdateType,
|
||||||
|
) -> EmptyResult {
|
||||||
|
enforce_personal_ownership_policy(Some(&data), headers, conn).await?;
|
||||||
|
save_cipher_data(cipher, data, headers, shared_to_collections, conn, nt, ut).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [`update_cipher_from_data`] for a rotation: like upstream, the personal ownership policy doesn't apply.
|
||||||
|
pub async fn rotate_cipher_data(
|
||||||
|
cipher: &mut Cipher,
|
||||||
|
data: CipherData,
|
||||||
|
headers: &Headers,
|
||||||
|
conn: &DbConn,
|
||||||
|
nt: &Notify<'_>,
|
||||||
|
) -> EmptyResult {
|
||||||
|
save_cipher_data(cipher, data, headers, None, conn, nt, UpdateType::None).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The checks of [`rotate_cipher_data`] that need the database, to run on every cipher before the first is saved
|
||||||
|
pub async fn validate_rotated_cipher(
|
||||||
|
cipher: &Cipher,
|
||||||
|
data: &CipherData,
|
||||||
|
headers: &Headers,
|
||||||
|
conn: &DbConn,
|
||||||
|
) -> EmptyResult {
|
||||||
|
validate_cipher_update(cipher, data, headers, conn, UpdateType::None).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn save_cipher_data(
|
||||||
|
cipher: &mut Cipher,
|
||||||
|
data: CipherData,
|
||||||
|
headers: &Headers,
|
||||||
|
shared_to_collections: Option<Vec<CollectionId>>,
|
||||||
|
conn: &DbConn,
|
||||||
|
nt: &Notify<'_>,
|
||||||
|
ut: UpdateType,
|
||||||
) -> EmptyResult {
|
) -> EmptyResult {
|
||||||
// Cleanup cipher data, like removing the 'Response' key.
|
// Cleanup cipher data, like removing the 'Response' key.
|
||||||
// This key is somewhere generated during Javascript so no way for us this fix this.
|
// This key is somewhere generated during Javascript so no way for us this fix this.
|
||||||
@@ -578,8 +615,6 @@ pub async fn update_cipher_from_data(
|
|||||||
json_data
|
json_data
|
||||||
}
|
}
|
||||||
|
|
||||||
enforce_personal_ownership_policy(Some(&data), headers, conn).await?;
|
|
||||||
|
|
||||||
let is_blob = data.is_blob();
|
let is_blob = data.is_blob();
|
||||||
data.validate_content(is_blob)?;
|
data.validate_content(is_blob)?;
|
||||||
data.validate_type_data(is_blob)?;
|
data.validate_type_data(is_blob)?;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
CONFIG,
|
CONFIG,
|
||||||
api::admin::FAKE_ADMIN_UUID,
|
api::admin::FAKE_ADMIN_UUID,
|
||||||
api::{
|
api::{
|
||||||
EmptyResult, JsonResult, Notify, PasswordOrOtpData, UpdateType,
|
ApiResult, EmptyResult, JsonResult, Notify, PasswordOrOtpData, UpdateType,
|
||||||
core::{CipherSyncData, CipherSyncType, accept_org_invite, log_event, two_factor},
|
core::{CipherSyncData, CipherSyncType, accept_org_invite, log_event, two_factor},
|
||||||
},
|
},
|
||||||
auth::{AdminHeaders, Headers, ManagerHeaders, ManagerHeadersLoose, OrgMemberHeaders, OwnerHeaders, decode_invite},
|
auth::{AdminHeaders, Headers, ManagerHeaders, ManagerHeadersLoose, OrgMemberHeaders, OwnerHeaders, decode_invite},
|
||||||
@@ -2849,8 +2849,26 @@ struct OrganizationUserRecoverAccountRequest {
|
|||||||
// But the clients do not seem to use this at all
|
// But the clients do not seem to use this at all
|
||||||
// Just add it here in case they will
|
// Just add it here in case they will
|
||||||
#[get("/organizations/<org_id>/public-key")]
|
#[get("/organizations/<org_id>/public-key")]
|
||||||
async fn get_organization_public_key(org_id: OrganizationId, headers: OrgMemberHeaders, conn: DbConn) -> JsonResult {
|
async fn get_organization_public_key(
|
||||||
if org_id != headers.membership.org_uuid {
|
org_id: OrganizationId,
|
||||||
|
headers: Headers,
|
||||||
|
member: Result<OrgMemberHeaders, &'static str>,
|
||||||
|
conn: DbConn,
|
||||||
|
) -> JsonResult {
|
||||||
|
// SSO users without an org get the fake one, whose key the v2 JIT password flow fetches anyway
|
||||||
|
if org_id.eq_ignore_ascii_case(FAKE_SSO_IDENTIFIER) && headers.user.private_key.is_none() {
|
||||||
|
return Ok(Json(json!({
|
||||||
|
"object": "organizationPublicKey",
|
||||||
|
"publicKey": fake_sso_org_public_key().await?,
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
let member = match member {
|
||||||
|
Ok(member) => member,
|
||||||
|
// The guard already logged it
|
||||||
|
Err(e) => return Err(crate::error::Error::new_msg(e).with_code(Status::Unauthorized.code)),
|
||||||
|
};
|
||||||
|
|
||||||
|
if org_id != member.membership.org_uuid {
|
||||||
err!("Organization not found", "Organization id's do not match");
|
err!("Organization not found", "Organization id's do not match");
|
||||||
}
|
}
|
||||||
let Some(org) = Organization::find_by_uuid(&org_id, &conn).await else {
|
let Some(org) = Organization::find_by_uuid(&org_id, &conn).await else {
|
||||||
@@ -2863,11 +2881,30 @@ async fn get_organization_public_key(org_id: OrganizationId, headers: OrgMemberH
|
|||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The SDK only uses this key to wrap an account recovery key that it never sends for the fake org,
|
||||||
|
/// so it is made once and its private half dropped.
|
||||||
|
async fn fake_sso_org_public_key() -> ApiResult<String> {
|
||||||
|
static PUBLIC_KEY: std::sync::LazyLock<Option<String>> = std::sync::LazyLock::new(|| {
|
||||||
|
let der = openssl::rsa::Rsa::generate(2048).and_then(|rsa| rsa.public_key_to_der()).ok()?;
|
||||||
|
Some(data_encoding::BASE64.encode(&der))
|
||||||
|
});
|
||||||
|
|
||||||
|
let Ok(Some(public_key)) = tokio::task::spawn_blocking(|| PUBLIC_KEY.clone()).await else {
|
||||||
|
err!("Failed to generate the organization key")
|
||||||
|
};
|
||||||
|
Ok(public_key)
|
||||||
|
}
|
||||||
|
|
||||||
// Obsolete - Renamed to public-key (2023.8), left for backwards compatibility with older clients
|
// Obsolete - Renamed to public-key (2023.8), left for backwards compatibility with older clients
|
||||||
// https://github.com/bitwarden/server/blob/9ebe16587175b1c0e9208f84397bb75d0d595510/src/Api/AdminConsole/Controllers/OrganizationsController.cs#L487-L492
|
// https://github.com/bitwarden/server/blob/9ebe16587175b1c0e9208f84397bb75d0d595510/src/Api/AdminConsole/Controllers/OrganizationsController.cs#L487-L492
|
||||||
#[get("/organizations/<org_id>/keys")]
|
#[get("/organizations/<org_id>/keys")]
|
||||||
async fn get_organization_keys(org_id: OrganizationId, headers: OrgMemberHeaders, conn: DbConn) -> JsonResult {
|
async fn get_organization_keys(
|
||||||
get_organization_public_key(org_id, headers, conn).await
|
org_id: OrganizationId,
|
||||||
|
headers: Headers,
|
||||||
|
member: Result<OrgMemberHeaders, &'static str>,
|
||||||
|
conn: DbConn,
|
||||||
|
) -> JsonResult {
|
||||||
|
get_organization_public_key(org_id, headers, member, conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will allow to reset 2FA too
|
// Will allow to reset 2FA too
|
||||||
|
|||||||
+101
-33
@@ -77,14 +77,14 @@ async fn login(data: Form<ConnectData>, client_header: ClientHeaders, conn: DbCo
|
|||||||
check_is_some(data.device_name.as_ref(), "device_name cannot be blank")?;
|
check_is_some(data.device_name.as_ref(), "device_name cannot be blank")?;
|
||||||
check_is_some(data.device_type.as_ref(), "device_type cannot be blank")?;
|
check_is_some(data.device_type.as_ref(), "device_type cannot be blank")?;
|
||||||
|
|
||||||
password_login(data, &mut user_id, &conn, &client_header.ip).await
|
password_login(data, &mut user_id, &conn, &client_header.ip, client_header.client_version.as_ref()).await
|
||||||
}
|
}
|
||||||
"client_credentials" => {
|
"client_credentials" => {
|
||||||
check_is_some(data.client_id.as_ref(), "client_id cannot be blank")?;
|
check_is_some(data.client_id.as_ref(), "client_id cannot be blank")?;
|
||||||
check_is_some(data.client_secret.as_ref(), "client_secret cannot be blank")?;
|
check_is_some(data.client_secret.as_ref(), "client_secret cannot be blank")?;
|
||||||
check_is_some(data.scope.as_ref(), "scope cannot be blank")?;
|
check_is_some(data.scope.as_ref(), "scope cannot be blank")?;
|
||||||
|
|
||||||
api_key_login(data, &mut user_id, &conn, &client_header.ip).await
|
api_key_login(data, &mut user_id, &conn, &client_header.ip, client_header.client_version.as_ref()).await
|
||||||
}
|
}
|
||||||
"authorization_code" if CONFIG.sso_enabled() => {
|
"authorization_code" if CONFIG.sso_enabled() => {
|
||||||
check_is_some(data.client_id.as_ref(), "client_id cannot be blank")?;
|
check_is_some(data.client_id.as_ref(), "client_id cannot be blank")?;
|
||||||
@@ -95,7 +95,7 @@ async fn login(data: Form<ConnectData>, client_header: ClientHeaders, conn: DbCo
|
|||||||
check_is_some(data.device_name.as_ref(), "device_name cannot be blank")?;
|
check_is_some(data.device_name.as_ref(), "device_name cannot be blank")?;
|
||||||
check_is_some(data.device_type.as_ref(), "device_type cannot be blank")?;
|
check_is_some(data.device_type.as_ref(), "device_type cannot be blank")?;
|
||||||
|
|
||||||
sso_login(data, &mut user_id, &conn, &client_header.ip).await
|
sso_login(data, &mut user_id, &conn, &client_header.ip, client_header.client_version.as_ref()).await
|
||||||
}
|
}
|
||||||
"authorization_code" => err!("SSO sign-in is not available"),
|
"authorization_code" => err!("SSO sign-in is not available"),
|
||||||
"send_access" => {
|
"send_access" => {
|
||||||
@@ -179,7 +179,13 @@ async fn refresh_login(data: ConnectData, conn: &DbConn, ip: &ClientIp) -> JsonR
|
|||||||
}
|
}
|
||||||
|
|
||||||
// After exchanging the code we need to check first if 2FA is needed before continuing
|
// After exchanging the code we need to check first if 2FA is needed before continuing
|
||||||
async fn sso_login(data: ConnectData, user_id: &mut Option<UserId>, conn: &DbConn, ip: &ClientIp) -> JsonResult {
|
async fn sso_login(
|
||||||
|
data: ConnectData,
|
||||||
|
user_id: &mut Option<UserId>,
|
||||||
|
conn: &DbConn,
|
||||||
|
ip: &ClientIp,
|
||||||
|
client_version: Option<&semver::Version>,
|
||||||
|
) -> JsonResult {
|
||||||
AuthMethod::Sso.check_scope(data.scope.as_ref())?;
|
AuthMethod::Sso.check_scope(data.scope.as_ref())?;
|
||||||
|
|
||||||
// Ratelimit the login
|
// Ratelimit the login
|
||||||
@@ -325,6 +331,8 @@ async fn sso_login(data: ConnectData, user_id: &mut Option<UserId>, conn: &DbCon
|
|||||||
(user, device, None, None)
|
(user, device, None, None)
|
||||||
}
|
}
|
||||||
Some((user, _)) if !user.enabled => {
|
Some((user, _)) if !user.enabled => {
|
||||||
|
// Set in both arms, not only after the match, so that their failed logins are logged
|
||||||
|
*user_id = Some(user.uuid.clone());
|
||||||
err!(
|
err!(
|
||||||
"This user has been disabled",
|
"This user has been disabled",
|
||||||
format!("IP: {}. Username: {}.", ip.ip, user.email),
|
format!("IP: {}. Username: {}.", ip.ip, user.email),
|
||||||
@@ -334,6 +342,9 @@ async fn sso_login(data: ConnectData, user_id: &mut Option<UserId>, conn: &DbCon
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Some((mut user, sso_user)) => {
|
Some((mut user, sso_user)) => {
|
||||||
|
*user_id = Some(user.uuid.clone());
|
||||||
|
check_client_version(&user, client_version, ip)?;
|
||||||
|
|
||||||
let mut device = get_device(&data, conn, &user).await?;
|
let mut device = get_device(&data, conn, &user).await?;
|
||||||
|
|
||||||
let twofactor_token = twofactor_auth(&mut user, &data, &mut device, ip, conn).await?;
|
let twofactor_token = twofactor_auth(&mut user, &data, &mut device, ip, conn).await?;
|
||||||
@@ -368,7 +379,13 @@ async fn sso_login(data: ConnectData, user_id: &mut Option<UserId>, conn: &DbCon
|
|||||||
authenticated_response(&user, &mut device, auth_tokens, twofactor_token, conn, ip).await
|
authenticated_response(&user, &mut device, auth_tokens, twofactor_token, conn, ip).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn password_login(data: ConnectData, user_id: &mut Option<UserId>, conn: &DbConn, ip: &ClientIp) -> JsonResult {
|
async fn password_login(
|
||||||
|
data: ConnectData,
|
||||||
|
user_id: &mut Option<UserId>,
|
||||||
|
conn: &DbConn,
|
||||||
|
ip: &ClientIp,
|
||||||
|
client_version: Option<&semver::Version>,
|
||||||
|
) -> JsonResult {
|
||||||
// Validate scope
|
// Validate scope
|
||||||
AuthMethod::Password.check_scope(data.scope.as_ref())?;
|
AuthMethod::Password.check_scope(data.scope.as_ref())?;
|
||||||
|
|
||||||
@@ -438,6 +455,8 @@ async fn password_login(data: ConnectData, user_id: &mut Option<UserId>, conn: &
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_client_version(&user, client_version, ip)?;
|
||||||
|
|
||||||
// Change the KDF Iterations (only when not logging in with an auth request)
|
// Change the KDF Iterations (only when not logging in with an auth request)
|
||||||
if data.auth_request.is_none() {
|
if data.auth_request.is_none() {
|
||||||
kdf_upgrade(&mut user, password, conn).await?;
|
kdf_upgrade(&mut user, password, conn).await?;
|
||||||
@@ -499,6 +518,47 @@ async fn password_login(data: ConnectData, user_id: &mut Option<UserId>, conn: &
|
|||||||
authenticated_response(&user, &mut device, auth_tokens, twofactor_token, conn, ip).await
|
authenticated_response(&user, &mut device, auth_tokens, twofactor_token, conn, ip).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Like upstream's `ClientVersionValidator`, a V2 account ([`User::has_v2_encryption`]) logs in only from a client that
|
||||||
|
/// sends its version and is at least 2025.11.0 (upstream also refuses a missing header for V1 accounts). Called right
|
||||||
|
/// after the credentials are checked, like upstream, so that it doesn't tell anyone else which accounts are V2.
|
||||||
|
///
|
||||||
|
/// Ref: <https://github.com/bitwarden/server/blob/8da186ad73f80d37157fe6fd42323e4284e83ec1/src/Identity/IdentityServer/RequestValidators/ClientVersionValidator.cs#L31-L72>
|
||||||
|
fn check_client_version(user: &User, client_version: Option<&semver::Version>, ip: &ClientIp) -> EmptyResult {
|
||||||
|
let Some((error, description)) = client_version_error(user.has_v2_encryption(), client_version) else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
Err(crate::error::Error::from((
|
||||||
|
format!("IP: {}. Username: {}. {error}", ip.ip, user.email),
|
||||||
|
json!({
|
||||||
|
"error": error,
|
||||||
|
"error_description": description,
|
||||||
|
"ErrorModel": { "Message": description, "Object": "error" },
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.with_event(crate::error::ErrorEvent {
|
||||||
|
event: EventType::UserFailedLogIn,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The error id and message of [`check_client_version`], `None` when the client may log in.
|
||||||
|
fn client_version_error(is_v2: bool, client_version: Option<&semver::Version>) -> Option<(&'static str, &'static str)> {
|
||||||
|
const MIN_V2_CLIENT: semver::Version = semver::Version::new(2025, 11, 0);
|
||||||
|
|
||||||
|
if !is_v2 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
match client_version {
|
||||||
|
None => Some((
|
||||||
|
"version_header_missing",
|
||||||
|
"No client version header found, required to prevent encryption errors. Please confirm your client is supplying the header: \"Bitwarden-Client-Version\"",
|
||||||
|
)),
|
||||||
|
Some(version) if *version < MIN_V2_CLIENT => {
|
||||||
|
Some(("invalid_client_version", "Please update your app to continue using Bitwarden"))
|
||||||
|
}
|
||||||
|
Some(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn authenticated_response(
|
async fn authenticated_response(
|
||||||
user: &User,
|
user: &User,
|
||||||
device: &mut Device,
|
device: &mut Device,
|
||||||
@@ -546,24 +606,13 @@ async fn authenticated_response(
|
|||||||
// https://github.com/bitwarden/android/blob/release/2025.12-rc41/network/src/main/kotlin/com/bitwarden/network/model/MasterPasswordUnlockDataJson.kt#L22-L26
|
// https://github.com/bitwarden/android/blob/release/2025.12-rc41/network/src/main/kotlin/com/bitwarden/network/model/MasterPasswordUnlockDataJson.kt#L22-L26
|
||||||
"MasterKeyEncryptedUserKey": user.akey,
|
"MasterKeyEncryptedUserKey": user.akey,
|
||||||
"MasterKeyWrappedUserKey": user.akey,
|
"MasterKeyWrappedUserKey": user.akey,
|
||||||
"Salt": user.email
|
"Salt": user.master_password_salt()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Value::Null
|
Value::Null
|
||||||
};
|
};
|
||||||
|
|
||||||
let account_keys = if user.private_key.is_some() {
|
let account_keys = user.account_keys_json(conn).await;
|
||||||
json!({
|
|
||||||
"publicKeyEncryptionKeyPair": {
|
|
||||||
"wrappedPrivateKey": user.private_key,
|
|
||||||
"publicKey": user.public_key,
|
|
||||||
"Object": "publicKeyEncryptionKeyPair"
|
|
||||||
},
|
|
||||||
"Object": "privateKeys"
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Value::Null
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut result = json!({
|
let mut result = json!({
|
||||||
"access_token": auth_tokens.access_token(),
|
"access_token": auth_tokens.access_token(),
|
||||||
@@ -598,7 +647,13 @@ async fn authenticated_response(
|
|||||||
Ok(Json(result))
|
Ok(Json(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn api_key_login(data: ConnectData, user_id: &mut Option<UserId>, conn: &DbConn, ip: &ClientIp) -> JsonResult {
|
async fn api_key_login(
|
||||||
|
data: ConnectData,
|
||||||
|
user_id: &mut Option<UserId>,
|
||||||
|
conn: &DbConn,
|
||||||
|
ip: &ClientIp,
|
||||||
|
client_version: Option<&semver::Version>,
|
||||||
|
) -> JsonResult {
|
||||||
// Ratelimit the login
|
// Ratelimit the login
|
||||||
crate::ratelimit::check_limit_login(&ip.ip)?;
|
crate::ratelimit::check_limit_login(&ip.ip)?;
|
||||||
|
|
||||||
@@ -610,7 +665,7 @@ async fn api_key_login(data: ConnectData, user_id: &mut Option<UserId>, conn: &D
|
|||||||
check_is_some(data.device_name.as_ref(), "device_name cannot be blank")?;
|
check_is_some(data.device_name.as_ref(), "device_name cannot be blank")?;
|
||||||
check_is_some(data.device_type.as_ref(), "device_type cannot be blank")?;
|
check_is_some(data.device_type.as_ref(), "device_type cannot be blank")?;
|
||||||
|
|
||||||
user_api_key_login(data, user_id, conn, ip).await
|
user_api_key_login(data, user_id, conn, ip, client_version).await
|
||||||
}
|
}
|
||||||
Some(scope) if scope == &AuthMethod::OrgApiKey.scope() => organization_api_key_login(data, conn, ip).await,
|
Some(scope) if scope == &AuthMethod::OrgApiKey.scope() => organization_api_key_login(data, conn, ip).await,
|
||||||
_ => err!("Scope not supported"),
|
_ => err!("Scope not supported"),
|
||||||
@@ -622,6 +677,7 @@ async fn user_api_key_login(
|
|||||||
user_id: &mut Option<UserId>,
|
user_id: &mut Option<UserId>,
|
||||||
conn: &DbConn,
|
conn: &DbConn,
|
||||||
ip: &ClientIp,
|
ip: &ClientIp,
|
||||||
|
client_version: Option<&semver::Version>,
|
||||||
) -> JsonResult {
|
) -> JsonResult {
|
||||||
// Get the user via the client_id
|
// Get the user via the client_id
|
||||||
let client_id = data.client_id.as_ref().unwrap();
|
let client_id = data.client_id.as_ref().unwrap();
|
||||||
@@ -659,6 +715,8 @@ async fn user_api_key_login(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_client_version(&user, client_version, ip)?;
|
||||||
|
|
||||||
let mut device = get_device(&data, conn, &user).await?;
|
let mut device = get_device(&data, conn, &user).await?;
|
||||||
|
|
||||||
if CONFIG.mail_enabled() && device.is_new() {
|
if CONFIG.mail_enabled() && device.is_new() {
|
||||||
@@ -703,24 +761,13 @@ async fn user_api_key_login(
|
|||||||
// https://github.com/bitwarden/android/blob/release/2025.12-rc41/network/src/main/kotlin/com/bitwarden/network/model/MasterPasswordUnlockDataJson.kt#L22-L26
|
// https://github.com/bitwarden/android/blob/release/2025.12-rc41/network/src/main/kotlin/com/bitwarden/network/model/MasterPasswordUnlockDataJson.kt#L22-L26
|
||||||
"MasterKeyEncryptedUserKey": user.akey,
|
"MasterKeyEncryptedUserKey": user.akey,
|
||||||
"MasterKeyWrappedUserKey": user.akey,
|
"MasterKeyWrappedUserKey": user.akey,
|
||||||
"Salt": user.email
|
"Salt": user.master_password_salt()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Value::Null
|
Value::Null
|
||||||
};
|
};
|
||||||
|
|
||||||
let account_keys = if user.private_key.is_some() {
|
let account_keys = user.account_keys_json(conn).await;
|
||||||
json!({
|
|
||||||
"publicKeyEncryptionKeyPair": {
|
|
||||||
"wrappedPrivateKey": user.private_key,
|
|
||||||
"publicKey": user.public_key,
|
|
||||||
"Object": "publicKeyEncryptionKeyPair"
|
|
||||||
},
|
|
||||||
"Object": "privateKeys"
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Value::Null
|
|
||||||
};
|
|
||||||
|
|
||||||
// Note: No refresh_token is returned. The CLI just repeats the
|
// Note: No refresh_token is returned. The CLI just repeats the
|
||||||
// client_credentials login flow when the existing token expires.
|
// client_credentials login flow when the existing token expires.
|
||||||
@@ -1351,3 +1398,24 @@ async fn authorize(data: AuthorizeData, cookies: &CookieJar<'_>, secure: Secure,
|
|||||||
|
|
||||||
Ok(Redirect::temporary(String::from(auth_url)))
|
Ok(Redirect::temporary(String::from(auth_url)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_client_version_error() {
|
||||||
|
let version = |v| semver::Version::parse(v).unwrap();
|
||||||
|
// V1 accounts aren't checked, with or without a version
|
||||||
|
assert_eq!(client_version_error(false, None), None);
|
||||||
|
assert_eq!(client_version_error(false, Some(&version("2024.1.0"))), None);
|
||||||
|
// V2 accounts need the header and 2025.11.0 or newer
|
||||||
|
assert_eq!(client_version_error(true, None).map(|e| e.0), Some("version_header_missing"));
|
||||||
|
assert_eq!(
|
||||||
|
client_version_error(true, Some(&version("2025.10.3"))).map(|e| e.0),
|
||||||
|
Some("invalid_client_version")
|
||||||
|
);
|
||||||
|
assert_eq!(client_version_error(true, Some(&version("2025.11.0"))), None);
|
||||||
|
assert_eq!(client_version_error(true, Some(&version("2026.10.1"))), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -23,7 +23,7 @@ pub use crate::api::{
|
|||||||
icons::routes as icons_routes,
|
icons::routes as icons_routes,
|
||||||
identity::routes as identity_routes,
|
identity::routes as identity_routes,
|
||||||
notifications::routes as notifications_routes,
|
notifications::routes as notifications_routes,
|
||||||
notifications::{AnonymousNotify, Notify, UpdateType, WS_ANONYMOUS_SUBSCRIPTIONS, WS_USERS},
|
notifications::{AnonymousNotify, LogOutReason, Notify, UpdateType, WS_ANONYMOUS_SUBSCRIPTIONS, WS_USERS},
|
||||||
push::{
|
push::{
|
||||||
push_cipher_update, push_folder_update, push_logout, push_logout_to_relay, push_send_update, push_user_update,
|
push_cipher_update, push_folder_update, push_logout, push_logout_to_relay, push_send_update, push_user_update,
|
||||||
register_push_device, unregister_push_device,
|
register_push_device, unregister_push_device,
|
||||||
|
|||||||
@@ -412,23 +412,35 @@ impl WebSocketUsers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_logout(&self, user: &User, acting_device: Option<&Device>, conn: &DbConn) {
|
pub async fn send_logout(&self, user: &User, acting_device: Option<&Device>, conn: &DbConn) {
|
||||||
|
self.send_logout_with_reason(user, acting_device, None, conn).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A logout that clients may handle differently depending on `reason`
|
||||||
|
pub async fn send_logout_with_reason(
|
||||||
|
&self,
|
||||||
|
user: &User,
|
||||||
|
acting_device: Option<&Device>,
|
||||||
|
reason: Option<LogOutReason>,
|
||||||
|
conn: &DbConn,
|
||||||
|
) {
|
||||||
// Skip any processing if both WebSockets and Push are not active
|
// Skip any processing if both WebSockets and Push are not active
|
||||||
if *NOTIFICATIONS_DISABLED {
|
if *NOTIFICATIONS_DISABLED {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let acting_device_id = acting_device.map(|d| d.uuid.clone());
|
let acting_device_id = acting_device.map(|d| d.uuid.clone());
|
||||||
let data = create_update(
|
let mut payload =
|
||||||
vec![("UserId".into(), user.uuid.to_string().into()), ("Date".into(), serialize_date(user.updated_at))],
|
vec![("UserId".into(), user.uuid.to_string().into()), ("Date".into(), serialize_date(user.updated_at))];
|
||||||
UpdateType::LogOut,
|
if let Some(reason) = reason {
|
||||||
acting_device_id,
|
payload.push(("Reason".into(), (reason as i32).into()));
|
||||||
);
|
}
|
||||||
|
let data = create_update(payload, UpdateType::LogOut, acting_device_id);
|
||||||
|
|
||||||
if CONFIG.enable_websocket() {
|
if CONFIG.enable_websocket() {
|
||||||
self.send_update(&user.uuid, &data).await;
|
self.send_update(&user.uuid, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
if CONFIG.push_enabled() {
|
if CONFIG.push_enabled() {
|
||||||
push_logout(user, acting_device, conn).await;
|
push_logout(user, acting_device, reason, conn).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,6 +704,14 @@ fn create_anonymous_update(payload: Vec<(Value, Value)>, ut: UpdateType, user_id
|
|||||||
serialize(&value)
|
serialize(&value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Why a logout was pushed, absent for a plain one. `KdfChange` isn't sent yet.
|
||||||
|
///
|
||||||
|
/// Ref: <https://github.com/bitwarden/server/blob/9030c42bf7d8f9ac2ff9fee85c39588d5eb81499/src/Core/Enums/PushNotificationLogOutReason.cs#L3-L7>
|
||||||
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
|
pub enum LogOutReason {
|
||||||
|
KeyRotation = 1,
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.com/bitwarden/server/blob/375af7c43b10d9da03525d41452f95de3f921541/src/Core/Enums/PushType.cs
|
// https://github.com/bitwarden/server/blob/375af7c43b10d9da03525d41452f95de3f921541/src/Core/Enums/PushType.cs
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
pub enum UpdateType {
|
pub enum UpdateType {
|
||||||
|
|||||||
+6
-5
@@ -12,7 +12,7 @@ use tokio::sync::RwLock;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
CONFIG,
|
CONFIG,
|
||||||
api::{ApiResult, EmptyResult, UpdateType},
|
api::{ApiResult, EmptyResult, LogOutReason, UpdateType},
|
||||||
db::{
|
db::{
|
||||||
DbConn,
|
DbConn,
|
||||||
models::{AuthRequestId, Cipher, Device, Folder, PushId, Send, User, UserId},
|
models::{AuthRequestId, Cipher, Device, Folder, PushId, Send, User, UserId},
|
||||||
@@ -192,15 +192,15 @@ pub async fn push_cipher_update(ut: UpdateType, cipher: &Cipher, device: &Device
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn push_logout(user: &User, acting_device: Option<&Device>, conn: &DbConn) {
|
pub async fn push_logout(user: &User, acting_device: Option<&Device>, reason: Option<LogOutReason>, conn: &DbConn) {
|
||||||
if Device::check_user_has_push_device(&user.uuid, conn).await {
|
if Device::check_user_has_push_device(&user.uuid, conn).await {
|
||||||
push_logout_to_relay(user, acting_device);
|
push_logout_to_relay(user, acting_device, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends the logout without checking for push devices first.
|
// Sends the logout without checking for push devices first.
|
||||||
// Needed after deleting a user, when the devices are already gone from the database.
|
// Needed after deleting a user, when the devices are already gone from the database.
|
||||||
pub fn push_logout_to_relay(user: &User, acting_device: Option<&Device>) {
|
pub fn push_logout_to_relay(user: &User, acting_device: Option<&Device>, reason: Option<LogOutReason>) {
|
||||||
tokio::task::spawn(send_to_push_relay(json!({
|
tokio::task::spawn(send_to_push_relay(json!({
|
||||||
"userId": user.uuid,
|
"userId": user.uuid,
|
||||||
"organizationId": (),
|
"organizationId": (),
|
||||||
@@ -209,7 +209,8 @@ pub fn push_logout_to_relay(user: &User, acting_device: Option<&Device>) {
|
|||||||
"type": UpdateType::LogOut as i32,
|
"type": UpdateType::LogOut as i32,
|
||||||
"payload": {
|
"payload": {
|
||||||
"userId": user.uuid,
|
"userId": user.uuid,
|
||||||
"date": format_date(&user.updated_at)
|
"date": format_date(&user.updated_at),
|
||||||
|
"reason": reason.map(|r| r as i32),
|
||||||
},
|
},
|
||||||
"clientType": null,
|
"clientType": null,
|
||||||
"installationId": null
|
"installationId": null
|
||||||
|
|||||||
+9
-22
@@ -34,7 +34,7 @@ use crate::{
|
|||||||
models::{
|
models::{
|
||||||
AttachmentId, CipherId, Collection, CollectionId, Device, DeviceId, DeviceType, EmergencyAccessId,
|
AttachmentId, CipherId, Collection, CollectionId, Device, DeviceId, DeviceType, EmergencyAccessId,
|
||||||
EventType, Membership, MembershipId, MembershipStatus, MembershipType, OrgApiKeyId, OrganizationId,
|
EventType, Membership, MembershipId, MembershipStatus, MembershipType, OrgApiKeyId, OrganizationId,
|
||||||
SendFileId, SendId, User, UserId, UserStampException,
|
SendFileId, SendId, User, UserId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
error::Error,
|
error::Error,
|
||||||
@@ -632,6 +632,9 @@ impl<'r> FromRequest<'r> for Host {
|
|||||||
pub struct ClientHeaders {
|
pub struct ClientHeaders {
|
||||||
pub device_type: i32,
|
pub device_type: i32,
|
||||||
pub ip: ClientIp,
|
pub ip: ClientIp,
|
||||||
|
/// `Bitwarden-Client-Version`, `None` when missing or not a version. Unlike the [`ClientVersion`] guard, this
|
||||||
|
/// doesn't log an error, as not every client sends it.
|
||||||
|
pub client_version: Option<semver::Version>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
@@ -648,10 +651,13 @@ impl<'r> FromRequest<'r> for ClientHeaders {
|
|||||||
.get_one("device-type")
|
.get_one("device-type")
|
||||||
.and_then(|d| d.parse().ok())
|
.and_then(|d| d.parse().ok())
|
||||||
.unwrap_or(DeviceType::UnknownBrowser as i32);
|
.unwrap_or(DeviceType::UnknownBrowser as i32);
|
||||||
|
let client_version =
|
||||||
|
request.headers().get_one("Bitwarden-Client-Version").and_then(|v| semver::Version::parse(v).ok());
|
||||||
|
|
||||||
Outcome::Success(ClientHeaders {
|
Outcome::Success(ClientHeaders {
|
||||||
device_type,
|
device_type,
|
||||||
ip,
|
ip,
|
||||||
|
client_version,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -707,31 +713,12 @@ impl<'r> FromRequest<'r> for Headers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if user.security_stamp != claims.sstamp {
|
if user.security_stamp != claims.sstamp {
|
||||||
if let Some(stamp_exception) =
|
|
||||||
user.stamp_exception.as_deref().and_then(|s| serde_json::from_str::<UserStampException>(s).ok())
|
|
||||||
{
|
|
||||||
let Some(current_route) = request.route().and_then(|r| r.name.as_deref()) else {
|
let Some(current_route) = request.route().and_then(|r| r.name.as_deref()) else {
|
||||||
err_handler!("Error getting current route for stamp exception")
|
err_handler!("Error getting current route for stamp exception")
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if the stamp exception has expired first.
|
// Expired exceptions are only dropped on reset; writing them back here could undo a newer reset
|
||||||
// Then, check if the current route matches any of the allowed routes.
|
if !user.stamp_exceptions().iter().any(|e| e.allows(&claims.sstamp, current_route)) {
|
||||||
// After that check the stamp in exception matches the one in the claims.
|
|
||||||
if Utc::now().timestamp() > stamp_exception.expire {
|
|
||||||
// If the stamp exception has been expired remove it from the database.
|
|
||||||
// This prevents checking this stamp exception for new requests.
|
|
||||||
let mut user = user;
|
|
||||||
user.reset_stamp_exception();
|
|
||||||
if let Err(e) = user.save(&conn).await {
|
|
||||||
error!("Error updating user: {e:#?}");
|
|
||||||
}
|
|
||||||
err_handler!("Stamp exception is expired")
|
|
||||||
} else if !stamp_exception.routes.contains(¤t_route.to_owned()) {
|
|
||||||
err_handler!("Invalid security stamp: Current route and exception route do not match")
|
|
||||||
} else if stamp_exception.security_stamp != claims.sstamp {
|
|
||||||
err_handler!("Invalid security stamp for matched stamp exception")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err_handler!("Invalid security stamp")
|
err_handler!("Invalid security stamp")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1508,6 +1508,11 @@ pub const SUPPORTED_FEATURE_FLAGS: &[&str] = &[
|
|||||||
// Key Management Team
|
// Key Management Team
|
||||||
"biometrics-sdk-ipc",
|
"biometrics-sdk-ipc",
|
||||||
"windows-native-credential-sync",
|
"windows-native-credential-sync",
|
||||||
|
"pm-30144-sdk-key-rotation",
|
||||||
|
"pm-31050-no-logout-key-upgrade-rotation",
|
||||||
|
"enable-account-encryption-v2-jit-password-registration",
|
||||||
|
"pm-27278-v2-password-registration",
|
||||||
|
"force-upgrade-v2-encryption",
|
||||||
// Mobile Team
|
// Mobile Team
|
||||||
"pm-34171-card-scanner",
|
"pm-34171-card-scanner",
|
||||||
// Platform Team
|
// Platform Team
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ mod two_factor;
|
|||||||
mod two_factor_duo_context;
|
mod two_factor_duo_context;
|
||||||
mod two_factor_incomplete;
|
mod two_factor_incomplete;
|
||||||
mod user;
|
mod user;
|
||||||
|
mod user_signature_key_pair;
|
||||||
|
|
||||||
pub use self::archive::Archive;
|
pub use self::archive::Archive;
|
||||||
pub use self::attachment::{Attachment, AttachmentId};
|
pub use self::attachment::{Attachment, AttachmentId};
|
||||||
@@ -41,4 +42,5 @@ pub use self::sso_auth::{OIDCAuthenticatedUser, OIDCCodeResponseError, SsoAuth};
|
|||||||
pub use self::two_factor::{TwoFactor, TwoFactorType};
|
pub use self::two_factor::{TwoFactor, TwoFactorType};
|
||||||
pub use self::two_factor_duo_context::TwoFactorDuoContext;
|
pub use self::two_factor_duo_context::TwoFactorDuoContext;
|
||||||
pub use self::two_factor_incomplete::TwoFactorIncomplete;
|
pub use self::two_factor_incomplete::TwoFactorIncomplete;
|
||||||
pub use self::user::{Invitation, KeyId, SsoUser, User, UserId, UserKdfType, UserStampException};
|
pub use self::user::{Invitation, KeyId, SsoUser, User, UserId, UserKdfType};
|
||||||
|
pub use self::user_signature_key_pair::{SignatureAlgorithm, UserSignatureKeyPair};
|
||||||
@@ -54,6 +54,8 @@ pub struct Membership {
|
|||||||
pub atype: i32,
|
pub atype: i32,
|
||||||
pub reset_password_key: Option<String>,
|
pub reset_password_key: Option<String>,
|
||||||
pub external_id: Option<String>,
|
pub external_id: Option<String>,
|
||||||
|
/// The user's v2 upgrade token, for the org to unwrap the v2 user key after an upgrade. Opaque to us.
|
||||||
|
pub v2_upgrade_token: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Insertable, AsChangeset)]
|
#[derive(Identifiable, Queryable, Insertable, AsChangeset)]
|
||||||
@@ -271,6 +273,7 @@ impl Membership {
|
|||||||
atype: MembershipType::User as i32,
|
atype: MembershipType::User as i32,
|
||||||
reset_password_key: None,
|
reset_password_key: None,
|
||||||
external_id: None,
|
external_id: None,
|
||||||
|
v2_upgrade_token: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+185
-28
@@ -6,6 +6,7 @@ use serde_json::Value;
|
|||||||
use crate::{
|
use crate::{
|
||||||
CONFIG,
|
CONFIG,
|
||||||
api::EmptyResult,
|
api::EmptyResult,
|
||||||
|
auth::DEFAULT_ACCESS_VALIDITY,
|
||||||
crypto,
|
crypto,
|
||||||
db::{
|
db::{
|
||||||
DbConn,
|
DbConn,
|
||||||
@@ -20,7 +21,7 @@ use macros::UuidFromParam;
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
AuthRequest, Cipher, Device, EmergencyAccess, Favorite, Folder, Membership, MembershipType, TwoFactor,
|
AuthRequest, Cipher, Device, EmergencyAccess, Favorite, Folder, Membership, MembershipType, TwoFactor,
|
||||||
TwoFactorIncomplete,
|
TwoFactorIncomplete, UserSignatureKeyPair,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Insertable, AsChangeset, Selectable)]
|
#[derive(Identifiable, Queryable, Insertable, AsChangeset, Selectable)]
|
||||||
@@ -72,6 +73,13 @@ pub struct User {
|
|||||||
pub external_id: Option<String>, // Todo: Needs to be removed in the future, this is not used anymore.
|
pub external_id: Option<String>, // Todo: Needs to be removed in the future, this is not used anymore.
|
||||||
|
|
||||||
pub key_id: Option<KeyId>,
|
pub key_id: Option<KeyId>,
|
||||||
|
|
||||||
|
// The v2 state: all set, with a `user_signature_key_pairs` row, or none, see `User::is_v2`
|
||||||
|
pub signed_public_key: Option<String>,
|
||||||
|
pub security_state: Option<String>,
|
||||||
|
pub security_version: Option<i32>,
|
||||||
|
/// JSON `{"wrappedUserKey1", "wrappedUserKey2"}` for sessions that still hold the v1 user key. Opaque to us.
|
||||||
|
pub v2_upgrade_token: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Insertable)]
|
#[derive(Identifiable, Queryable, Insertable)]
|
||||||
@@ -100,13 +108,28 @@ enum UserStatus {
|
|||||||
_Disabled = 2,
|
_Disabled = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A previous security stamp that is still accepted, until `expire`.
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct UserStampException {
|
pub struct UserStampException {
|
||||||
pub routes: Vec<String>,
|
/// The routes the stamp is still accepted on, or `None` for any route.
|
||||||
|
pub routes: Option<Vec<String>>,
|
||||||
pub security_stamp: String,
|
pub security_stamp: String,
|
||||||
pub expire: i64,
|
pub expire: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl UserStampException {
|
||||||
|
pub fn is_expired(&self) -> bool {
|
||||||
|
Utc::now().timestamp() > self.expire
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether this exception lets a token carrying `security_stamp` through on `route`.
|
||||||
|
pub fn allows(&self, security_stamp: &str, route: &str) -> bool {
|
||||||
|
!self.is_expired()
|
||||||
|
&& self.security_stamp == security_stamp
|
||||||
|
&& self.routes.as_ref().is_none_or(|routes| routes.iter().any(|r| r == route))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Local methods
|
/// Local methods
|
||||||
impl User {
|
impl User {
|
||||||
pub const CLIENT_KDF_TYPE_DEFAULT: i32 = UserKdfType::Pbkdf2 as i32;
|
pub const CLIENT_KDF_TYPE_DEFAULT: i32 = UserKdfType::Pbkdf2 as i32;
|
||||||
@@ -159,9 +182,31 @@ impl User {
|
|||||||
external_id: None, // Todo: Needs to be removed in the future, this is not used anymore.
|
external_id: None, // Todo: Needs to be removed in the future, this is not used anymore.
|
||||||
|
|
||||||
key_id: None,
|
key_id: None,
|
||||||
|
|
||||||
|
signed_public_key: None,
|
||||||
|
security_state: None,
|
||||||
|
security_version: None,
|
||||||
|
v2_upgrade_token: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_v2(&self) -> bool {
|
||||||
|
self.signed_public_key.is_some() && self.security_state.is_some() && self.security_version.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Upstream's `HasV2Encryption`: a private key wrapped as `CoseEncrypt0B64` (type 7) and security version 2.
|
||||||
|
/// Upstream only uses it to decide which accounts need a v2-capable client.
|
||||||
|
///
|
||||||
|
/// Ref: <https://github.com/bitwarden/server/blob/8da186ad73f80d37157fe6fd42323e4284e83ec1/src/Core/Entities/User.cs#L245-L278>
|
||||||
|
pub fn has_v2_encryption(&self) -> bool {
|
||||||
|
self.security_version == Some(2)
|
||||||
|
&& self
|
||||||
|
.private_key
|
||||||
|
.as_deref()
|
||||||
|
.and_then(|private_key| private_key.split_once('.'))
|
||||||
|
.is_some_and(|(enc_type, _)| enc_type.parse::<u8>() == Ok(7))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn check_valid_password(&self, password: &str) -> bool {
|
pub fn check_valid_password(&self, password: &str) -> bool {
|
||||||
crypto::verify_password_hash(
|
crypto::verify_password_hash(
|
||||||
password.as_bytes(),
|
password.as_bytes(),
|
||||||
@@ -171,6 +216,7 @@ impl User {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Upstream's `GetMasterPasswordSalt`: there is no separate salt, so the normalized email
|
||||||
pub fn master_password_salt(&self) -> String {
|
pub fn master_password_salt(&self) -> String {
|
||||||
self.email.trim().to_lowercase()
|
self.email.trim().to_lowercase()
|
||||||
}
|
}
|
||||||
@@ -225,10 +271,33 @@ impl User {
|
|||||||
|
|
||||||
pub async fn reset_security_stamp(&mut self, conn: &DbConn) -> EmptyResult {
|
pub async fn reset_security_stamp(&mut self, conn: &DbConn) -> EmptyResult {
|
||||||
self.security_stamp = get_uuid();
|
self.security_stamp = get_uuid();
|
||||||
|
// Keeps the unexpired route exceptions, set for the stamp being replaced, and drops a rotation's grace
|
||||||
|
let mut exceptions = self.stamp_exceptions();
|
||||||
|
exceptions.retain(|e| e.routes.is_some() && !e.is_expired());
|
||||||
|
self.set_stamp_exceptions(&exceptions);
|
||||||
Device::rotate_refresh_tokens_by_user(&self.uuid, conn).await?;
|
Device::rotate_refresh_tokens_by_user(&self.uuid, conn).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resets the stamp but lets issued access tokens run out, as upstream only checks it on refresh.
|
||||||
|
pub async fn reset_security_stamp_after_key_rotation(&mut self, conn: &DbConn) -> EmptyResult {
|
||||||
|
let previous_stamp = self.security_stamp.clone();
|
||||||
|
let mut grace: Vec<UserStampException> =
|
||||||
|
self.stamp_exceptions().into_iter().filter(|e| e.routes.is_none() && !e.is_expired()).collect();
|
||||||
|
|
||||||
|
self.reset_security_stamp(conn).await?;
|
||||||
|
|
||||||
|
grace.push(UserStampException {
|
||||||
|
routes: None,
|
||||||
|
security_stamp: previous_stamp,
|
||||||
|
expire: (Utc::now() + *DEFAULT_ACCESS_VALIDITY).timestamp(),
|
||||||
|
});
|
||||||
|
let mut exceptions = self.stamp_exceptions();
|
||||||
|
exceptions.extend(grace);
|
||||||
|
self.set_stamp_exceptions(&exceptions);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the stamp_exception to only allow a subsequent request matching a specific route using the current security-stamp.
|
/// Set the stamp_exception to only allow a subsequent request matching a specific route using the current security-stamp.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
@@ -237,17 +306,30 @@ impl User {
|
|||||||
/// After these 2 minutes this stamp will expire.
|
/// After these 2 minutes this stamp will expire.
|
||||||
///
|
///
|
||||||
pub fn set_stamp_exception(&mut self, route_exception: Vec<String>) {
|
pub fn set_stamp_exception(&mut self, route_exception: Vec<String>) {
|
||||||
let stamp_exception = UserStampException {
|
self.set_stamp_exceptions(&[UserStampException {
|
||||||
routes: route_exception,
|
routes: Some(route_exception),
|
||||||
security_stamp: self.security_stamp.clone(),
|
security_stamp: self.security_stamp.clone(),
|
||||||
expire: (Utc::now() + TimeDelta::try_minutes(2).unwrap()).timestamp(),
|
expire: (Utc::now() + TimeDelta::try_minutes(2).unwrap()).timestamp(),
|
||||||
};
|
}]);
|
||||||
self.stamp_exception = Some(serde_json::to_string(&stamp_exception).unwrap_or_default());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets the stamp_exception to prevent re-use of the previous security-stamp
|
/// The previous security stamps that are still accepted, expired ones included.
|
||||||
pub fn reset_stamp_exception(&mut self) {
|
pub fn stamp_exceptions(&self) -> Vec<UserStampException> {
|
||||||
self.stamp_exception = None;
|
let Some(stored) = self.stamp_exception.as_deref() else {
|
||||||
|
return Vec::new();
|
||||||
|
};
|
||||||
|
// Before key rotations kept sessions alive, only a single route exception was stored.
|
||||||
|
serde_json::from_str::<Vec<UserStampException>>(stored)
|
||||||
|
.or_else(|_| serde_json::from_str::<UserStampException>(stored).map(|e| vec![e]))
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_stamp_exceptions(&mut self, exceptions: &[UserStampException]) {
|
||||||
|
self.stamp_exception = if exceptions.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(serde_json::to_string(&exceptions).unwrap_or_default())
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn display_name(&self) -> &str {
|
pub fn display_name(&self) -> &str {
|
||||||
@@ -266,18 +348,37 @@ impl User {
|
|||||||
!CONFIG.mail_enabled() || self.verified_at.is_some()
|
!CONFIG.mail_enabled() || self.verified_at.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn v2_signature_key_pair(&self, conn: &DbConn) -> Option<UserSignatureKeyPair> {
|
||||||
|
if !self.is_v2() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
UserSignatureKeyPair::find_by_user(&self.uuid, conn).await
|
||||||
|
}
|
||||||
|
|
||||||
/// The `accountKeys` object (upstream's `PrivateKeysResponseModel`), null without a key pair
|
/// The `accountKeys` object (upstream's `PrivateKeysResponseModel`), null without a key pair
|
||||||
pub fn account_keys_json(&self) -> Value {
|
pub async fn account_keys_json(&self, conn: &DbConn) -> Value {
|
||||||
if self.private_key.is_some() {
|
if self.private_key.is_some() {
|
||||||
|
let (signed_public_key, signature_key_pair, security_state) = match self.v2_signature_key_pair(conn).await {
|
||||||
|
Some(key_pair) => (
|
||||||
|
json!(self.signed_public_key),
|
||||||
|
key_pair.to_json(),
|
||||||
|
json!({
|
||||||
|
"securityState": self.security_state,
|
||||||
|
"securityVersion": self.security_version,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
None => (Value::Null, Value::Null, Value::Null),
|
||||||
|
};
|
||||||
|
|
||||||
json!({
|
json!({
|
||||||
"publicKeyEncryptionKeyPair": {
|
"publicKeyEncryptionKeyPair": {
|
||||||
"wrappedPrivateKey": self.private_key,
|
"wrappedPrivateKey": self.private_key,
|
||||||
"publicKey": self.public_key,
|
"publicKey": self.public_key,
|
||||||
"signedPublicKey": null,
|
"signedPublicKey": signed_public_key,
|
||||||
"object": "publicKeyEncryptionKeyPair",
|
"object": "publicKeyEncryptionKeyPair",
|
||||||
},
|
},
|
||||||
"securityState": null,
|
"securityState": security_state,
|
||||||
"signatureKeyPair": null,
|
"signatureKeyPair": signature_key_pair,
|
||||||
"object": "privateKeys"
|
"object": "privateKeys"
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -285,6 +386,24 @@ impl User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn public_keys_json(&self, conn: &DbConn) -> Value {
|
||||||
|
let (signed_public_key, verifying_key) = match self.v2_signature_key_pair(conn).await {
|
||||||
|
Some(key_pair) => (json!(self.signed_public_key), json!(key_pair.verifying_key)),
|
||||||
|
None => (Value::Null, Value::Null),
|
||||||
|
};
|
||||||
|
|
||||||
|
json!({
|
||||||
|
"publicKey": self.public_key,
|
||||||
|
"signedPublicKey": signed_public_key,
|
||||||
|
"verifyingKey": verifying_key,
|
||||||
|
"object": "publicKeys"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn v2_upgrade_token_json(&self) -> Option<Value> {
|
||||||
|
self.v2_upgrade_token.as_ref().and_then(|token| serde_json::from_str(token).ok())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn to_json(&self, conn: &DbConn) -> Value {
|
pub async fn to_json(&self, conn: &DbConn) -> Value {
|
||||||
let mut orgs_json = Vec::new();
|
let mut orgs_json = Vec::new();
|
||||||
for c in Membership::find_confirmed_by_user(&self.uuid, conn).await {
|
for c in Membership::find_confirmed_by_user(&self.uuid, conn).await {
|
||||||
@@ -305,7 +424,7 @@ impl User {
|
|||||||
UserStatus::Enabled
|
UserStatus::Enabled
|
||||||
};
|
};
|
||||||
|
|
||||||
let account_keys = self.account_keys_json();
|
let account_keys = self.account_keys_json(conn).await;
|
||||||
|
|
||||||
json!({
|
json!({
|
||||||
"_status": status as i32,
|
"_status": status as i32,
|
||||||
@@ -382,6 +501,7 @@ impl User {
|
|||||||
Device::delete_all_by_user(&self.uuid, conn).await?;
|
Device::delete_all_by_user(&self.uuid, conn).await?;
|
||||||
TwoFactor::delete_all_by_user(&self.uuid, conn).await?;
|
TwoFactor::delete_all_by_user(&self.uuid, conn).await?;
|
||||||
TwoFactorIncomplete::delete_all_by_user(&self.uuid, conn).await?;
|
TwoFactorIncomplete::delete_all_by_user(&self.uuid, conn).await?;
|
||||||
|
UserSignatureKeyPair::delete_all_by_user(&self.uuid, conn).await?;
|
||||||
Invitation::take(&self.email, conn).await; // Delete invitation if any
|
Invitation::take(&self.email, conn).await; // Delete invitation if any
|
||||||
|
|
||||||
conn.run(move |conn| {
|
conn.run(move |conn| {
|
||||||
@@ -553,25 +673,26 @@ impl Invitation {
|
|||||||
pub struct UserId(String);
|
pub struct UserId(String);
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone,
|
Clone, Debug, DieselNewType, FromForm, PartialEq, Eq, Hash, Serialize, AsRef, Deref, Display, From, UuidFromParam,
|
||||||
Debug,
|
|
||||||
DieselNewType,
|
|
||||||
FromForm,
|
|
||||||
PartialEq,
|
|
||||||
Eq,
|
|
||||||
Hash,
|
|
||||||
Serialize,
|
|
||||||
Deserialize,
|
|
||||||
AsRef,
|
|
||||||
Deref,
|
|
||||||
Display,
|
|
||||||
From,
|
|
||||||
UuidFromParam,
|
|
||||||
)]
|
)]
|
||||||
#[deref(forward)]
|
#[deref(forward)]
|
||||||
#[from(forward)]
|
#[from(forward)]
|
||||||
pub struct KeyId(String);
|
pub struct KeyId(String);
|
||||||
|
|
||||||
|
/// Like upstream, a key id is 32 lowercase hex characters. Key ids are compared as strings, so one in any other
|
||||||
|
/// format would never match the id the clients send.
|
||||||
|
///
|
||||||
|
/// Ref: <https://github.com/bitwarden/server/blob/8da186ad73f80d37157fe6fd42323e4284e83ec1/src/Core/KeyManagement/Models/Data/KeyId.cs#L20-L42>
|
||||||
|
impl<'de> serde::Deserialize<'de> for KeyId {
|
||||||
|
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||||
|
let key_id = String::deserialize(deserializer)?;
|
||||||
|
if key_id.len() != 32 || !key_id.bytes().all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'f')) {
|
||||||
|
return Err(serde::de::Error::custom("Key id must be 32 lowercase hex characters"));
|
||||||
|
}
|
||||||
|
Ok(Self(key_id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SsoUser {
|
impl SsoUser {
|
||||||
pub async fn save(&self, conn: &DbConn) -> EmptyResult {
|
pub async fn save(&self, conn: &DbConn) -> EmptyResult {
|
||||||
db_run! { conn:
|
db_run! { conn:
|
||||||
@@ -625,3 +746,39 @@ impl SsoUser {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_key_id_format() {
|
||||||
|
let key_id: KeyId = serde_json::from_str(r#""0123456789abcdef0123456789abcdef""#).unwrap();
|
||||||
|
assert_eq!(key_id.as_ref(), "0123456789abcdef0123456789abcdef");
|
||||||
|
|
||||||
|
for invalid in ["", "0123456789ABCDEF0123456789ABCDEF", "0123456789abcdef", "0123456789abcdef0123456789abcdeg"]
|
||||||
|
{
|
||||||
|
assert!(serde_json::from_str::<KeyId>(&format!("\"{invalid}\"")).is_err(), "{invalid:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// An absent key id stays optional
|
||||||
|
assert_eq!(serde_json::from_str::<Option<KeyId>>("null").unwrap(), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_has_v2_encryption() {
|
||||||
|
let user = |private_key: Option<&str>, security_version: Option<i32>| {
|
||||||
|
let mut user = User::new("user@example.com", None);
|
||||||
|
user.private_key = private_key.map(String::from);
|
||||||
|
user.security_version = security_version;
|
||||||
|
user
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(user(Some("7.cose"), Some(2)).has_v2_encryption());
|
||||||
|
assert!(!user(Some("7.cose"), Some(1)).has_v2_encryption());
|
||||||
|
assert!(!user(Some("7.cose"), None).has_v2_encryption());
|
||||||
|
assert!(!user(Some("2.iv|data|mac"), Some(2)).has_v2_encryption());
|
||||||
|
assert!(!user(Some("7"), Some(2)).has_v2_encryption());
|
||||||
|
assert!(!user(None, Some(2)).has_v2_encryption());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
use chrono::{NaiveDateTime, Utc};
|
||||||
|
use derive_more::{AsRef, Deref, Display, From};
|
||||||
|
use diesel::prelude::*;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
api::EmptyResult,
|
||||||
|
db::{DbConn, schema::user_signature_key_pairs},
|
||||||
|
error::MapResult,
|
||||||
|
util::get_uuid,
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::UserId;
|
||||||
|
|
||||||
|
/// A user's signature key pair, part of the v2 state, in its own table like upstream.
|
||||||
|
///
|
||||||
|
/// Ref: <https://github.com/bitwarden/server/blob/9030c42bf7d8f9ac2ff9fee85c39588d5eb81499/src/Sql/dbo/KeyManagement/Tables/UserSignatureKeyPair.sql#L1-L15>
|
||||||
|
#[derive(Identifiable, Queryable, Insertable, AsChangeset, Selectable)]
|
||||||
|
#[diesel(table_name = user_signature_key_pairs)]
|
||||||
|
#[diesel(treat_none_as_null = true)]
|
||||||
|
#[diesel(primary_key(uuid))]
|
||||||
|
pub struct UserSignatureKeyPair {
|
||||||
|
pub uuid: UserSignatureKeyPairId,
|
||||||
|
pub user_uuid: UserId,
|
||||||
|
|
||||||
|
pub signature_algorithm: i32,
|
||||||
|
/// The signing (private) key, wrapped by the user key.
|
||||||
|
pub signing_key: String,
|
||||||
|
/// The COSE-encoded public verifying key.
|
||||||
|
pub verifying_key: String,
|
||||||
|
|
||||||
|
pub created_at: NaiveDateTime,
|
||||||
|
pub updated_at: NaiveDateTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ref: <https://github.com/bitwarden/server/blob/9030c42bf7d8f9ac2ff9fee85c39588d5eb81499/src/Core/KeyManagement/Enums/SignatureAlgorithm.cs#L6-L10>
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum SignatureAlgorithm {
|
||||||
|
Ed25519 = 0,
|
||||||
|
MlDsa44 = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SignatureAlgorithm {
|
||||||
|
pub fn parse(algorithm: &str) -> Option<Self> {
|
||||||
|
match algorithm {
|
||||||
|
"ed25519" => Some(Self::Ed25519),
|
||||||
|
"mldsa44" => Some(Self::MlDsa44),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Local methods
|
||||||
|
impl UserSignatureKeyPair {
|
||||||
|
pub fn new(
|
||||||
|
user_uuid: UserId,
|
||||||
|
signature_algorithm: SignatureAlgorithm,
|
||||||
|
signing_key: String,
|
||||||
|
verifying_key: String,
|
||||||
|
) -> Self {
|
||||||
|
let now = Utc::now().naive_utc();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
uuid: UserSignatureKeyPairId(get_uuid()),
|
||||||
|
user_uuid,
|
||||||
|
signature_algorithm: signature_algorithm as i32,
|
||||||
|
signing_key,
|
||||||
|
verifying_key,
|
||||||
|
created_at: now,
|
||||||
|
updated_at: now,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_json(&self) -> Value {
|
||||||
|
json!({
|
||||||
|
"wrappedSigningKey": self.signing_key,
|
||||||
|
"verifyingKey": self.verifying_key,
|
||||||
|
"object": "signatureKeyPair",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Database methods
|
||||||
|
impl UserSignatureKeyPair {
|
||||||
|
pub async fn save(&mut self, conn: &DbConn) -> EmptyResult {
|
||||||
|
self.updated_at = Utc::now().naive_utc();
|
||||||
|
|
||||||
|
db_run! { conn:
|
||||||
|
mysql {
|
||||||
|
diesel::insert_into(user_signature_key_pairs::table)
|
||||||
|
.values(&*self)
|
||||||
|
.on_conflict(diesel::dsl::DuplicatedKeys)
|
||||||
|
.do_update()
|
||||||
|
.set(&*self)
|
||||||
|
.execute(conn)
|
||||||
|
.map_res("Error saving user signature key pair")
|
||||||
|
}
|
||||||
|
postgresql, sqlite {
|
||||||
|
diesel::insert_into(user_signature_key_pairs::table)
|
||||||
|
.values(&*self)
|
||||||
|
.on_conflict(user_signature_key_pairs::user_uuid)
|
||||||
|
.do_update()
|
||||||
|
.set(&*self)
|
||||||
|
.execute(conn)
|
||||||
|
.map_res("Error saving user signature key pair")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The user's key pair. There is at most one, enforced by a unique index on `user_uuid`.
|
||||||
|
pub async fn find_by_user(user_uuid: &UserId, conn: &DbConn) -> Option<Self> {
|
||||||
|
conn.run(move |conn| {
|
||||||
|
user_signature_key_pairs::table
|
||||||
|
.filter(user_signature_key_pairs::user_uuid.eq(user_uuid))
|
||||||
|
.first::<Self>(conn)
|
||||||
|
.ok()
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete_all_by_user(user_uuid: &UserId, conn: &DbConn) -> EmptyResult {
|
||||||
|
conn.run(move |conn| {
|
||||||
|
diesel::delete(user_signature_key_pairs::table.filter(user_signature_key_pairs::user_uuid.eq(user_uuid)))
|
||||||
|
.execute(conn)
|
||||||
|
.map_res("Error deleting user signature key pairs")
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, AsRef, Deref, DieselNewType, Display, From, Hash, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
pub struct UserSignatureKeyPairId(String);
|
||||||
@@ -219,6 +219,22 @@ table! {
|
|||||||
avatar_color -> Nullable<Text>,
|
avatar_color -> Nullable<Text>,
|
||||||
external_id -> Nullable<Text>,
|
external_id -> Nullable<Text>,
|
||||||
key_id -> Nullable<Text>,
|
key_id -> Nullable<Text>,
|
||||||
|
signed_public_key -> Nullable<Text>,
|
||||||
|
security_state -> Nullable<Text>,
|
||||||
|
security_version -> Nullable<Integer>,
|
||||||
|
v2_upgrade_token -> Nullable<Text>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
user_signature_key_pairs (uuid) {
|
||||||
|
uuid -> Text,
|
||||||
|
user_uuid -> Text,
|
||||||
|
signature_algorithm -> Integer,
|
||||||
|
signing_key -> Text,
|
||||||
|
verifying_key -> Text,
|
||||||
|
created_at -> Timestamp,
|
||||||
|
updated_at -> Timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,6 +260,7 @@ table! {
|
|||||||
atype -> Integer,
|
atype -> Integer,
|
||||||
reset_password_key -> Nullable<Text>,
|
reset_password_key -> Nullable<Text>,
|
||||||
external_id -> Nullable<Text>,
|
external_id -> Nullable<Text>,
|
||||||
|
v2_upgrade_token -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,6 +401,7 @@ joinable!(collections_groups -> groups (groups_uuid));
|
|||||||
joinable!(event -> users_organizations (uuid));
|
joinable!(event -> users_organizations (uuid));
|
||||||
joinable!(auth_requests -> users (user_uuid));
|
joinable!(auth_requests -> users (user_uuid));
|
||||||
joinable!(sso_users -> users (user_uuid));
|
joinable!(sso_users -> users (user_uuid));
|
||||||
|
joinable!(user_signature_key_pairs -> users (user_uuid));
|
||||||
|
|
||||||
allow_tables_to_appear_in_same_query!(
|
allow_tables_to_appear_in_same_query!(
|
||||||
archives,
|
archives,
|
||||||
@@ -410,4 +428,5 @@ allow_tables_to_appear_in_same_query!(
|
|||||||
collections_groups,
|
collections_groups,
|
||||||
event,
|
event,
|
||||||
auth_requests,
|
auth_requests,
|
||||||
|
user_signature_key_pairs,
|
||||||
);
|
);
|
||||||
@@ -884,6 +884,12 @@ pub fn parse_experimental_client_feature_flags(
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the admin enabled this supported client feature flag
|
||||||
|
pub fn is_client_feature_flag_enabled(flag: &str) -> bool {
|
||||||
|
parse_experimental_client_feature_flags(&CONFIG.experimental_client_feature_flags(), &FeatureFlagFilter::ValidOnly)
|
||||||
|
.contains_key(flag)
|
||||||
|
}
|
||||||
|
|
||||||
/// TODO: This is extracted from IpAddr::is_global, which is unstable:
|
/// TODO: This is extracted from IpAddr::is_global, which is unstable:
|
||||||
/// https://doc.rust-lang.org/nightly/std/net/enum.IpAddr.html#method.is_global
|
/// https://doc.rust-lang.org/nightly/std/net/enum.IpAddr.html#method.is_global
|
||||||
/// Remove once https://github.com/rust-lang/rust/issues/27709 is merged
|
/// Remove once https://github.com/rust-lang/rust/issues/27709 is merged
|
||||||
|
|||||||
Executable
+129
@@ -0,0 +1,129 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Registers the account of an sdk-internal test vector on a vaultwarden server, as a client would.
|
||||||
|
|
||||||
|
Usage: register_vector.py <vector.json> <server-url>
|
||||||
|
|
||||||
|
A V1 vector is registered with the flat `keys` object, a V2 one with `accountKeys` and the user key
|
||||||
|
id. Prints the account's email and password on two lines, for the caller to log in with.
|
||||||
|
|
||||||
|
Exits with SKIP, and the reason on stderr, for a vector the live tests can't use.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import urllib.error
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
SKIP = 3
|
||||||
|
MIN_PBKDF2_ITERATIONS = 100_000
|
||||||
|
|
||||||
|
|
||||||
|
def skip_reason(vector):
|
||||||
|
if not any("masterPasswordUnlock" in m for m in vector["unlockMethods"]):
|
||||||
|
return "it has no master password, which the live tests log in with"
|
||||||
|
pbkdf2 = vector["account"]["kdf"].get("pBKDF2")
|
||||||
|
if pbkdf2 is not None and pbkdf2["iterations"] < MIN_PBKDF2_ITERATIONS:
|
||||||
|
return f"registration requires at least {MIN_PBKDF2_ITERATIONS} PBKDF2 iterations (upstream 600000)"
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def kdf_of(account):
|
||||||
|
kind, params = next(iter(account["kdf"].items()))
|
||||||
|
if kind == "pBKDF2":
|
||||||
|
return {"kdfType": 0, "iterations": params["iterations"]}
|
||||||
|
return {
|
||||||
|
"kdfType": 1,
|
||||||
|
"iterations": params["iterations"],
|
||||||
|
"memory": params["memory"],
|
||||||
|
"parallelism": params["parallelism"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def register_body(vector):
|
||||||
|
account = vector["account"]
|
||||||
|
raw = vector["rawCryptographicState"]
|
||||||
|
version, state = next(iter(account["accountCryptographicState"].items()))
|
||||||
|
kdf = kdf_of(account)
|
||||||
|
unlock = next(m["masterPasswordUnlock"] for m in vector["unlockMethods"] if "masterPasswordUnlock" in m)
|
||||||
|
mp_unlock = unlock["master_password_unlock"]
|
||||||
|
|
||||||
|
body = {
|
||||||
|
"email": account["email"],
|
||||||
|
"masterPasswordHint": None,
|
||||||
|
"masterPasswordAuthentication": {
|
||||||
|
"kdf": kdf,
|
||||||
|
"salt": mp_unlock["salt"],
|
||||||
|
"masterPasswordAuthenticationHash": vector["masterPasswordAuthenticationHash"],
|
||||||
|
},
|
||||||
|
"masterPasswordUnlock": {
|
||||||
|
"kdf": kdf,
|
||||||
|
"salt": mp_unlock["salt"],
|
||||||
|
"masterKeyWrappedUserKey": mp_unlock["masterKeyWrappedUserKey"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if version == "V2":
|
||||||
|
body["masterPasswordUnlock"]["containedKeyId"] = raw["userKeyId"]
|
||||||
|
body["accountKeys"] = {
|
||||||
|
"userKeyEncryptedAccountPrivateKey": state["private_key"],
|
||||||
|
"accountPublicKey": raw["publicKey"],
|
||||||
|
"publicKeyEncryptionKeyPair": {
|
||||||
|
"wrappedPrivateKey": state["private_key"],
|
||||||
|
"publicKey": raw["publicKey"],
|
||||||
|
"signedPublicKey": state["signed_public_key"],
|
||||||
|
},
|
||||||
|
"signatureKeyPair": {
|
||||||
|
"signatureAlgorithm": "ed25519",
|
||||||
|
"wrappedSigningKey": state["signing_key"],
|
||||||
|
"verifyingKey": raw["verifyingKey"],
|
||||||
|
},
|
||||||
|
"securityState": {
|
||||||
|
"securityState": state["security_state"],
|
||||||
|
"securityVersion": account["securityVersion"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
body["keys"] = {"encryptedPrivateKey": state["private_key"], "publicKey": raw["publicKey"]}
|
||||||
|
|
||||||
|
return body, unlock["password"]
|
||||||
|
|
||||||
|
|
||||||
|
def post(url, body):
|
||||||
|
request = urllib.request.Request(
|
||||||
|
url,
|
||||||
|
data=json.dumps(body).encode(),
|
||||||
|
headers={"Content-Type": "application/json", "Accept": "application/json"},
|
||||||
|
method="POST",
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(request) as response:
|
||||||
|
return response.read()
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
sys.exit(f"Registering {body['email']} failed at {url}: {e.code} {e.read().decode()}")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with open(sys.argv[1]) as f:
|
||||||
|
vector = json.load(f)
|
||||||
|
server = sys.argv[2].rstrip("/")
|
||||||
|
|
||||||
|
reason = skip_reason(vector)
|
||||||
|
if reason is not None:
|
||||||
|
print(f"Skipped: {reason}", file=sys.stderr)
|
||||||
|
sys.exit(SKIP)
|
||||||
|
|
||||||
|
body, password = register_body(vector)
|
||||||
|
# With signup verification off, the server returns the token instead of mailing it
|
||||||
|
token = post(
|
||||||
|
f"{server}/identity/accounts/register/send-verification-email",
|
||||||
|
{"email": body["email"], "name": vector["name"]},
|
||||||
|
)
|
||||||
|
body["emailVerificationToken"] = json.loads(token)
|
||||||
|
post(f"{server}/identity/accounts/register/finish", body)
|
||||||
|
|
||||||
|
print(body["email"])
|
||||||
|
print(password)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Executable
+61
@@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Runs the live-server integration tests of bitwarden/sdk-internal against vaultwarden.
|
||||||
|
#
|
||||||
|
# Usage: tools/sdk-live-tests/run.sh --sdk-dir <path> [--skip-sdk-build]
|
||||||
|
#
|
||||||
|
# Every test vector of the SDK (test-vectors/users/) that the tests can log in with gets a fresh
|
||||||
|
# server and database, since the tests rotate the account's keys. Stops at the first failure; the
|
||||||
|
# server logs are in target/sdk-live-tests/. Building the SDK needs its Rust toolchain with the
|
||||||
|
# wasm32-unknown-unknown target and rust-src, Node.js, and binaryen (`npm i -g binaryen@132.0.0`).
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
VW_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||||
|
OUT_DIR="${VW_DIR}/target/sdk-live-tests"
|
||||||
|
URL="http://127.0.0.1:8099"
|
||||||
|
SKIP=3 # register_vector.py's exit code for a vector the tests can't use
|
||||||
|
|
||||||
|
SDK_DIR=""
|
||||||
|
BUILD_SDK=1
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--sdk-dir) SDK_DIR="$(cd "$2" && pwd)"; shift 2 ;;
|
||||||
|
--skip-sdk-build) BUILD_SDK=0; shift ;;
|
||||||
|
*) echo "Unknown argument: $1" >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
[[ -n "${SDK_DIR}" ]] || { echo "--sdk-dir is required" >&2; exit 2; }
|
||||||
|
TESTS_DIR="${SDK_DIR}/crates/bitwarden-wasm-internal/integration-tests"
|
||||||
|
|
||||||
|
(cd "${VW_DIR}" && cargo build --features sqlite)
|
||||||
|
if [[ ${BUILD_SDK} -eq 1 ]]; then
|
||||||
|
bash "${SDK_DIR}/crates/bitwarden-wasm-internal/build.sh"
|
||||||
|
(cd "${TESTS_DIR}" && npm ci)
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap 'kill $(jobs -p) 2>/dev/null || true' EXIT
|
||||||
|
|
||||||
|
for vector_file in "${SDK_DIR}"/test-vectors/users/*.json; do
|
||||||
|
vector="$(basename "${vector_file}" .json)"
|
||||||
|
echo "=== ${vector}"
|
||||||
|
data_dir="${OUT_DIR}/${vector}"
|
||||||
|
rm -rf "${data_dir}" && mkdir -p "${data_dir}"
|
||||||
|
|
||||||
|
DATA_FOLDER="${data_dir}" DATABASE_URL="sqlite://${data_dir}/db.sqlite3" \
|
||||||
|
ROCKET_ADDRESS=127.0.0.1 ROCKET_PORT=8099 DOMAIN="${URL}" WEB_VAULT_ENABLED=false \
|
||||||
|
SIGNUPS_ALLOWED=true SIGNUPS_VERIFY=false LOGIN_RATELIMIT_MAX_BURST=1000 \
|
||||||
|
"${VW_DIR}/target/debug/vaultwarden" > "${data_dir}/vaultwarden.log" 2>&1 &
|
||||||
|
server=$!
|
||||||
|
curl -sf --retry 30 --retry-connrefused --retry-delay 1 "${URL}/alive" > /dev/null
|
||||||
|
|
||||||
|
status=0
|
||||||
|
credentials="$(python3 "${VW_DIR}/tools/sdk-live-tests/register_vector.py" "${vector_file}" "${URL}")" || status=$?
|
||||||
|
if [[ ${status} -eq 0 ]]; then
|
||||||
|
(cd "${TESTS_DIR}" && BW_LIVE_SERVER_URL="${URL}" BW_LIVE_EMAIL="$(sed -n 1p <<< "${credentials}")" \
|
||||||
|
BW_LIVE_PASSWORD="$(sed -n 2p <<< "${credentials}")" npm run test:live)
|
||||||
|
elif [[ ${status} -ne ${SKIP} ]]; then
|
||||||
|
exit "${status}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
kill "${server}" && wait "${server}" || true
|
||||||
|
done
|
||||||
|
echo "All test vectors passed"
|
||||||
Reference in new issue
Block a user