Skip to content

Commit e119797

Browse files
committed
Add device password change functionality
Implements a new API endpoint to allow users to change their device password without re-entering the BIP39 passphrase. Changes: - Add ChangePasswordRequest message to proto definitions - Implement change_password module in Rust API - Refactor keystore to support password re-encryption: - Add re_encrypt_seed() function to change password while preserving BIP39 seed state - Extract encrypt_and_store_seed_internal() helper to share logic between initial setup and password change - Add Python bindings for change_password workflow - Add comprehensive tests including password verification - Regenerated protobuf files The password change workflow: 1. Unlock device with current password 2. Prompt for new password (entered twice for confirmation) 3. Re-encrypt seed with new password while preserving BIP39 seed This prevents users from having to re-enter their BIP39 passphrase after changing their password.
1 parent 6da1aed commit e119797

File tree

12 files changed

+335
-19
lines changed

12 files changed

+335
-19
lines changed

messages/bitbox02_system.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,6 @@ message SetDeviceNameRequest {
6666
message SetPasswordRequest {
6767
bytes entropy = 1;
6868
}
69+
70+
message ChangePasswordRequest{
71+
}

messages/hww.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ message Request {
6969
CardanoRequest cardano = 27;
7070
BIP85Request bip85 = 28;
7171
BluetoothRequest bluetooth = 29;
72+
ChangePasswordRequest change_password = 30;
7273
}
7374
}
7475

py/bitbox02/bitbox02/bitbox02/bitbox02.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,23 @@ def set_password(self, entropy_size: int = 32) -> bool:
212212
raise
213213
return True
214214

215+
def change_password(self) -> bool:
216+
"""
217+
Returns True if the user changes password successfully by
218+
unlocking with old password and entering and confirming new password.
219+
Returns False otherwise.
220+
"""
221+
# pylint: disable=no-member
222+
request = hww.Request()
223+
request.change_password.CopyFrom(bitbox02_system.ChangePasswordRequest())
224+
try:
225+
self._msg_query(request, expected_response="success")
226+
except Bitbox02Exception as err:
227+
if err.code == ERR_GENERIC:
228+
return False
229+
raise
230+
return True
231+
215232
def create_backup(self) -> bool:
216233
"""
217234
Returns True if the backup was created successfully.

py/bitbox02/bitbox02/communication/generated/bitbox02_system_pb2.py

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/bitbox02/bitbox02/communication/generated/bitbox02_system_pb2.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,13 @@ class SetPasswordRequest(google.protobuf.message.Message):
208208
def ClearField(self, field_name: typing.Literal["entropy", b"entropy"]) -> None: ...
209209

210210
global___SetPasswordRequest = SetPasswordRequest
211+
212+
@typing.final
213+
class ChangePasswordRequest(google.protobuf.message.Message):
214+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
215+
216+
def __init__(
217+
self,
218+
) -> None: ...
219+
220+
global___ChangePasswordRequest = ChangePasswordRequest

py/bitbox02/bitbox02/communication/generated/hww_pb2.py

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)