Skip to content

Commit fa414f7

Browse files
committed
Follow-up changes
2 parents ddee1bb + 59f40d4 commit fa414f7

File tree

92 files changed

+2192
-613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2192
-613
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ rustflags = ["--cfg", "aes_armv8"]
66

77
[target.wasm32-unknown-unknown]
88
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']
9-
runner = 'wasm-bindgen-test-runner'
9+
runner = 'cargo run -p wasm-bindgen-cli-runner --bin wasm-bindgen-test-runner'
1010

1111
# Enable support for 16k pages on Android, JNA is using these same flags
1212
# https://android-developers.googleblog.com/2024/08/adding-16-kb-page-size-to-android.html

.claude/CLAUDE.md

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,125 @@
11
# Bitwarden Internal SDK
22

3-
Rust SDK centralizing business logic. You're reviewing code as a senior Rust engineer mentoring
4-
teammates.
3+
Cross-platform Rust SDK implementing Bitwarden's core business logic.
54

6-
## Client Pattern
5+
**Rust Edition:** The SDK targets the
6+
[2024](https://doc.rust-lang.org/nightly/edition-guide/rust-2024/index.html) edition of Rust.
77

8-
PasswordManagerClient ([bitwarden-pm](crates/bitwarden-pm/src/lib.rs)) wraps
9-
[bitwarden_core::Client](crates/bitwarden-core/src/client/client.rs) and exposes sub-clients:
10-
`auth()`, `vault()`, `crypto()`, `sends()`, `generators()`, `exporters()`.
8+
**Crate documentation**: Before working in any crate, read available documentation: `CLAUDE.md` for
9+
critical rules, `README.md` for architecture, `examples/` for usage patterns, and `tests/` for
10+
integration tests. **Before making changes or reviewing code, review relevant examples and tests for
11+
the specific functionality you're modifying.**
1112

12-
**Lifecycle**
13+
## Architecture Overview
1314

14-
- Init → Lock/Unlock → Logout (drops instance). Memento pattern for state resurrection.
15+
Monorepo crates organized in **four architectural layers**:
1516

16-
**Storage**
17+
### 1. Foundation Layer
1718

18-
- Consuming apps use `HashMap<UserId, PasswordManagerClient>`.
19+
- **bitwarden-crypto**: Cryptographic primitives and protocols, key store for securely working with
20+
keys held in memory.
21+
- **bitwarden-state**: Type-safe Repository pattern for SDK state (client-managed vs SDK-managed)
22+
- **bitwarden-threading**: ThreadBoundRunner for !Send types in WASM/GUI contexts (uses PhantomData
23+
marker)
24+
- **bitwarden-ipc**: Type-safe IPC framework with pluggable encryption/transport
25+
- **bitwarden-error**: Error handling across platforms (basic/flat/full modes via proc macro)
26+
- **bitwarden-encoding**, **bitwarden-uuid**: Encoding and UUID utilities
1927

20-
## Issues necessitating comments
28+
### 2. Core Infrastructure
2129

22-
**Auto-generated code changes**
30+
- **bitwarden-core**: Base Client struct extended by feature crates via extension traits. **DO NOT
31+
add functionality here - use feature crates instead.**
32+
- **bitwarden-api-api**, **bitwarden-api-identity**: Auto-generated API clients (**DO NOT edit -
33+
regenerate from OpenAPI specs**)
2334

24-
- Changes to `bitwarden-api-api/` or `bitwarden-api-identity/` are generally discouraged. These are
25-
auto-generated from swagger specs.
35+
### 3. Feature Implementations
2636

27-
**Secrets in logs/errors**
37+
- **bitwarden-pm**: PasswordManagerClient wrapping core Client, exposes sub-clients: `auth()`,
38+
`vault()`, `crypto()`, `sends()`, `generators()`, `exporters()`
39+
- Lifecycle: Init → Lock/Unlock → Logout (drops instance)
40+
- Storage: Apps use `HashMap<UserId, PasswordManagerClient>`
41+
- **bitwarden-vault**: Vault item models, encryption/decryption and management
42+
- **bitwarden-collections**: Collection models, encryption/decryption and management
43+
- **bitwarden-auth**: Authentication (send access tokens)
44+
- **bitwarden-send**: Encrypted temporary secret sharing
45+
- **bitwarden-generators**: Password/passphrase generators
46+
- **bitwarden-ssh**: SSH key generation/import
47+
- **bitwarden-exporters**: Vault export/import with multiple formats
48+
- **bitwarden-fido**: FIDO2 two-factor authentication
2849

29-
- Do not log keys, passwords, or vault data in logs or error paths. Redact sensitive data.
50+
### 4. Cross-Platform Bindings
3051

31-
**Business logic in WASM**
52+
- **bitwarden-uniffi**: Mobile bindings (Swift/Kotlin) via UniFFI
53+
- Structs: `#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]`
54+
- Enums: `#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]`
55+
- Include `uniffi::setup_scaffolding!()` in lib.rs
56+
- **bitwarden-wasm-internal**: WebAssembly bindings (**thin bindings only - no business logic**)
57+
- Structs: `#[derive(Serialize, Deserialize)]` with
58+
`#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]`
3259

33-
- `bitwarden-wasm-internal` contains only thin bindings. Move business logic to feature crates.
60+
## Critical Patterns & Rules
3461

35-
**Unsafe without justification**
62+
### Cryptography (bitwarden-crypto)
3663

37-
- Any `unsafe` block needs a comment explaining why it's safe and what invariants are being upheld.
64+
- **DO NOT modify** without careful consideration - backward compatibility is critical
65+
- **KeyStoreContext**: Never hold across await points
66+
- Naming: `derive_` for deterministic key derivation, `make_` for non-deterministic generation
67+
- Use `bitwarden_crypto::safe` module first (password-protected key envelope, data envelope) instead
68+
of more low-level primitives
69+
- IMPORTANT: Use constant time equality checks
70+
- Do not expose low-level / hazmat functions from the crypto crate.
71+
- Do not expose key material from the crypto crate, use key references in the key store instead
3872

39-
**Changes to `bitwarden-crypto/` core functionality**
73+
### State Management (bitwarden-state)
4074

41-
- Generally speaking, this crate should not be modified. Changes need a comment explaining why.
75+
- **Client-managed**: App and SDK share data pool (requires manual setup)
76+
- **SDK-managed**: SDK exclusively handles storage (migration-based, ordering is critical)
77+
- Register types with `register_repository_item!` macro
78+
- Type safety via TypeId-based type erasure with runtime downcast checks
4279

43-
**New crypto algorithms or key derivation**
80+
### Threading (bitwarden-threading)
4481

45-
- Detailed description, review and audit trail required. Document algorithm choice rationale and
46-
test vectors.
82+
- Use ThreadBoundRunner for !Send types (WASM contexts, GUI handles, Rc<T>)
83+
- Pins state to thread via spawn_local, tasks via mpsc channel
84+
- PhantomData<\*const ()> for !Send marker (zero-cost)
4785

48-
**Encryption/decryption modifications**
86+
### Error Handling (bitwarden-error-macro)
4987

50-
- Verify backward compatibility. Existing encrypted data must remain decryptable.
88+
- Three modes: **basic** (string), **flat** (variant), **full** (structure)
89+
- Generates FlatError trait, WASM bindings, TypeScript interfaces, UniFFI errors
90+
- Conditional code generation via cfg! for WASM
5191

52-
**Breaking serialization**
92+
### Security Requirements
5393

54-
- Backward compatibility required. Users must decrypt vaults from older versions.
94+
- **Never log** keys, passwords, or vault data in logs or error paths
95+
- **Redact sensitive data** in all error messages
96+
- **Unsafe blocks** require comments explaining safety and invariants
97+
- **Encryption/decryption changes** must maintain backward compatibility (existing encrypted data
98+
must remain decryptable)
99+
- **Breaking serialization** strongly discouraged - users must decrypt vaults from older versions
55100

56-
**Breaking API changes**
101+
### API Changes
57102

58-
- Document migration path for clients.
103+
- **Breaking changes**: Automated detection via cross-repo workflow (see commit 9574dcc1)
104+
- TypeScript compilation tested against `clients` repo on PR
105+
- Document migration path for clients
106+
107+
## Development Workflow
108+
109+
**Build & Test:**
110+
111+
- `cargo check --all-features --all-targets` - Quick validation
112+
- `cargo test --workspace --all-features` - Full test suite
113+
114+
**Format & Lint:**
115+
116+
- `cargo +nightly fmt --workspace` - Code formatting
117+
- Use `cargo clippy` to lint code and catch common mistakes
118+
119+
**WASM Testing:**
120+
121+
- `cargo test --target wasm32-unknown-unknown --features wasm -p bitwarden-error -p bitwarden-threading -p bitwarden-uuid` -
122+
WASM-specific tests
59123

60124
## References
61125

@@ -66,3 +130,4 @@ PasswordManagerClient ([bitwarden-pm](crates/bitwarden-pm/src/lib.rs)) wraps
66130
- [Code Style](https://contributing.bitwarden.com/contributing/code-style/)
67131
- [Security Whitepaper](https://bitwarden.com/help/bitwarden-security-white-paper/)
68132
- [Security Definitions](https://contributing.bitwarden.com/architecture/security/definitions)
133+
- [Rust 2024 Edition Guide](https://doc.rust-lang.org/edition-guide/rust-2024/)

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66

77
<!-- Describe what the purpose of this PR is, for example what bug you're fixing or new feature you're adding. -->
88

9+
## 🚨 Breaking Changes
10+
11+
<!-- Does this PR introduce any breaking changes? If so, please describe the impact and migration path for clients.
12+
13+
If you're unsure, the automated TypeScript compatibility check will run when you open/update this PR and provide feedback.
14+
15+
For breaking changes:
16+
1. Describe what changed in the client interface
17+
2. Explain why the change was necessary
18+
3. Provide migration steps for client developers
19+
4. Link to any paired client PRs if needed
20+
21+
Otherwise, you can remove this section. -->
22+
923
## ⏰ Reminders before review
1024

1125
- Contributor guidelines followed

.github/renovate.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@
1515
"go": "1.21"
1616
},
1717
"packageRules": [
18+
{
19+
"groupName": "rust",
20+
"matchManagers": ["custom.regex", "dockerfile"],
21+
"matchDepNames": ["rust"]
22+
},
1823
{
1924
"matchManagers": ["cargo"],
2025
"matchUpdateTypes": ["minor", "patch"],
2126
"groupName": "pyo3 non-major",
2227
"matchPackageNames": ["/pyo3*/"]
2328
},
29+
{
30+
"matchManagers": ["cargo"],
31+
"groupName": "wasm-bindgen group",
32+
"matchPackageNames": ["/wasm-bindgen*/"]
33+
},
2434
{
2535
"groupName": "dockerfile minor",
2636
"matchManagers": ["dockerfile"],

.github/workflows/build-android.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
steps:
3535
- name: Checkout repo
3636
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
37+
with:
38+
persist-credentials: false
3739

3840
- name: Install rust
3941
uses: dtolnay/rust-toolchain@6d653acede28d24f02e3cd41383119e8b1b35921 # stable
@@ -54,7 +56,7 @@ jobs:
5456
run: cross build -p bitwarden-uniffi --release --target=${{ matrix.settings.target }}
5557

5658
- name: Upload artifact
57-
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
59+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
5860
with:
5961
name: android-${{ matrix.settings.target }}
6062
path: ./target/${{ matrix.settings.target }}/release/libbitwarden_uniffi.so
@@ -78,12 +80,14 @@ jobs:
7880
with:
7981
fetch-depth: 0
8082
ref: ${{ github.event.pull_request.head.ref }}
83+
persist-credentials: false
8184

8285
- name: Checkout repo (Push or manual run)
8386
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
8487
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
8588
with:
8689
fetch-depth: 0
90+
persist-credentials: false
8791

8892
- name: Install rust
8993
uses: dtolnay/rust-toolchain@6d653acede28d24f02e3cd41383119e8b1b35921 # stable
@@ -102,7 +106,7 @@ jobs:
102106
java-version: 17
103107

104108
- name: Download Artifacts
105-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
109+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
106110

107111
- name: Move artifacts
108112
working-directory: crates/bitwarden-uniffi/kotlin/sdk/src/main/jniLibs

.github/workflows/build-rust-crates.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
steps:
3939
- name: Checkout
4040
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
41+
with:
42+
persist-credentials: false
4143

4244
- name: Install rust
4345
uses: dtolnay/rust-toolchain@6d653acede28d24f02e3cd41383119e8b1b35921 # stable
@@ -60,6 +62,8 @@ jobs:
6062
steps:
6163
- name: Checkout
6264
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
65+
with:
66+
persist-credentials: false
6367

6468
- name: Install rust
6569
uses: dtolnay/rust-toolchain@6d653acede28d24f02e3cd41383119e8b1b35921 # stable

.github/workflows/build-swift.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
steps:
2121
- name: Checkout repo
2222
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
23+
with:
24+
persist-credentials: false
2325

2426
- name: Get Package Version
2527
id: retrieve-version
@@ -38,6 +40,8 @@ jobs:
3840
steps:
3941
- name: Checkout repo
4042
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
43+
with:
44+
persist-credentials: false
4145

4246
- name: Install rust
4347
uses: dtolnay/rust-toolchain@6d653acede28d24f02e3cd41383119e8b1b35921 # stable
@@ -81,14 +85,14 @@ jobs:
8185
cp -rf crates/bitwarden-uniffi/swift/BitwardenFFI.xcframework artifacts
8286
8387
- name: Upload BitwardenFFI.xcframework artifact
84-
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
88+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
8589
with:
8690
name: BitwardenFFI-${{ env._VERSION }}-${{ steps.build.outputs.short-sha }}.xcframework
8791
path: artifacts
8892
if-no-files-found: error
8993

9094
- name: Upload BitwardenSdk sources
91-
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
95+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
9296
with:
9397
name: BitwardenSdk-${{ env._VERSION }}-${{ steps.build.outputs.short-sha }}-sources
9498
path: crates/bitwarden-uniffi/swift/Sources/BitwardenSdk

0 commit comments

Comments
 (0)