Skip to content

Commit

Permalink
wip: shamir secret sharing
Browse files Browse the repository at this point in the history
- communication works, shamir seems to work too. to be tested
  • Loading branch information
Beerosagos committed Dec 16, 2024
1 parent a924aec commit 10c4bd0
Show file tree
Hide file tree
Showing 508 changed files with 71,792 additions and 156 deletions.
4 changes: 4 additions & 0 deletions messages/hww.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import "eth.proto";
import "keystore.proto";
import "mnemonic.proto";
import "system.proto";
import "shamir.proto";

import "perform_attestation.proto";

Expand Down Expand Up @@ -67,6 +68,9 @@ message Request {
ElectrumEncryptionKeyRequest electrum_encryption_key = 26;
CardanoRequest cardano = 27;
BIP85Request bip85 = 28;
ShowShamirRequest show_shamir = 29;
RestoreFromShamirRequest restore_from_shamir = 30;

}
}

Expand Down
21 changes: 21 additions & 0 deletions messages/shamir.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2019 Shift Cryptosecurity AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";
package shiftcrypto.bitbox02;

message ShowShamirRequest {
}
message RestoreFromShamirRequest {
}
2 changes: 1 addition & 1 deletion py/bitbox02/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

OUT_DIR=bitbox02/communication/generated

PROTO_FILES=hww.proto common.proto backup_commands.proto bitbox02_system.proto btc.proto cardano.proto eth.proto mnemonic.proto system.proto perform_attestation.proto keystore.proto antiklepto.proto
PROTO_FILES=hww.proto common.proto backup_commands.proto bitbox02_system.proto btc.proto cardano.proto eth.proto mnemonic.proto system.proto perform_attestation.proto keystore.proto antiklepto.proto shamir.proto

TARGETS=$(addprefix ${OUT_DIR}/, $(PROTO_FILES:.proto=_pb2.py))

Expand Down
12 changes: 12 additions & 0 deletions py/bitbox02/bitbox02/bitbox02/bitbox02.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from bitbox02.communication.generated import btc_pb2 as btc
from bitbox02.communication.generated import cardano_pb2 as cardano
from bitbox02.communication.generated import mnemonic_pb2 as mnemonic
from bitbox02.communication.generated import shamir_pb2 as shamir
from bitbox02.communication.generated import bitbox02_system_pb2 as bitbox02_system
from bitbox02.communication.generated import backup_commands_pb2 as backup
from bitbox02.communication.generated import common_pb2 as common
Expand Down Expand Up @@ -259,6 +260,17 @@ def show_mnemonic(self) -> None:
request.show_mnemonic.CopyFrom(mnemonic.ShowMnemonicRequest())
self._msg_query(request, expected_response="success")

def show_shamir(self) -> None:
"""
Returns True if shamir mnemonics were successfully shown and confirmed.
Raises a Bitbox02Exception on failure.
"""
# self._require_atleast(semver.VersionInfo(9, 16, 0)) TODO
# pylint: disable=no-member
request = hww.Request()
request.show_shamir.CopyFrom(shamir.ShowShamirRequest())
self._msg_query(request, expected_response="success")

def _btc_msg_query(
self, btc_request: btc.BTCRequest, expected_response: Optional[str] = None
) -> btc.BTCResponse:
Expand Down
19 changes: 10 additions & 9 deletions py/bitbox02/bitbox02/communication/generated/hww_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions py/bitbox02/bitbox02/communication/generated/hww_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import google.protobuf.message
from . import keystore_pb2
from . import mnemonic_pb2
from . import perform_attestation_pb2
from . import shamir_pb2
from . import system_pb2
import typing
import typing_extensions
Expand Down Expand Up @@ -68,6 +69,8 @@ class Request(google.protobuf.message.Message):
ELECTRUM_ENCRYPTION_KEY_FIELD_NUMBER: builtins.int
CARDANO_FIELD_NUMBER: builtins.int
BIP85_FIELD_NUMBER: builtins.int
SHOW_SHAMIR_FIELD_NUMBER: builtins.int
RESTORE_FROM_SHAMIR_FIELD_NUMBER: builtins.int
@property
def device_name(self) -> bitbox02_system_pb2.SetDeviceNameRequest:
"""removed: RandomNumberRequest random_number = 1;"""
Expand Down Expand Up @@ -124,6 +127,10 @@ class Request(google.protobuf.message.Message):
def cardano(self) -> cardano_pb2.CardanoRequest: ...
@property
def bip85(self) -> keystore_pb2.BIP85Request: ...
@property
def show_shamir(self) -> shamir_pb2.ShowShamirRequest: ...
@property
def restore_from_shamir(self) -> shamir_pb2.RestoreFromShamirRequest: ...
def __init__(self,
*,
device_name: typing.Optional[bitbox02_system_pb2.SetDeviceNameRequest] = ...,
Expand Down Expand Up @@ -152,10 +159,12 @@ class Request(google.protobuf.message.Message):
electrum_encryption_key: typing.Optional[keystore_pb2.ElectrumEncryptionKeyRequest] = ...,
cardano: typing.Optional[cardano_pb2.CardanoRequest] = ...,
bip85: typing.Optional[keystore_pb2.BIP85Request] = ...,
show_shamir: typing.Optional[shamir_pb2.ShowShamirRequest] = ...,
restore_from_shamir: typing.Optional[shamir_pb2.RestoreFromShamirRequest] = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["bip85",b"bip85","btc",b"btc","btc_pub",b"btc_pub","btc_sign_init",b"btc_sign_init","btc_sign_input",b"btc_sign_input","btc_sign_output",b"btc_sign_output","cardano",b"cardano","check_backup",b"check_backup","check_sdcard",b"check_sdcard","create_backup",b"create_backup","device_info",b"device_info","device_language",b"device_language","device_name",b"device_name","electrum_encryption_key",b"electrum_encryption_key","eth",b"eth","fingerprint",b"fingerprint","insert_remove_sdcard",b"insert_remove_sdcard","list_backups",b"list_backups","perform_attestation",b"perform_attestation","reboot",b"reboot","request",b"request","reset",b"reset","restore_backup",b"restore_backup","restore_from_mnemonic",b"restore_from_mnemonic","set_mnemonic_passphrase_enabled",b"set_mnemonic_passphrase_enabled","set_password",b"set_password","show_mnemonic",b"show_mnemonic"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["bip85",b"bip85","btc",b"btc","btc_pub",b"btc_pub","btc_sign_init",b"btc_sign_init","btc_sign_input",b"btc_sign_input","btc_sign_output",b"btc_sign_output","cardano",b"cardano","check_backup",b"check_backup","check_sdcard",b"check_sdcard","create_backup",b"create_backup","device_info",b"device_info","device_language",b"device_language","device_name",b"device_name","electrum_encryption_key",b"electrum_encryption_key","eth",b"eth","fingerprint",b"fingerprint","insert_remove_sdcard",b"insert_remove_sdcard","list_backups",b"list_backups","perform_attestation",b"perform_attestation","reboot",b"reboot","request",b"request","reset",b"reset","restore_backup",b"restore_backup","restore_from_mnemonic",b"restore_from_mnemonic","set_mnemonic_passphrase_enabled",b"set_mnemonic_passphrase_enabled","set_password",b"set_password","show_mnemonic",b"show_mnemonic"]) -> None: ...
def WhichOneof(self, oneof_group: typing_extensions.Literal["request",b"request"]) -> typing.Optional[typing_extensions.Literal["device_name","device_language","device_info","set_password","create_backup","show_mnemonic","btc_pub","btc_sign_init","btc_sign_input","btc_sign_output","insert_remove_sdcard","check_sdcard","set_mnemonic_passphrase_enabled","list_backups","restore_backup","perform_attestation","reboot","check_backup","eth","reset","restore_from_mnemonic","fingerprint","btc","electrum_encryption_key","cardano","bip85"]]: ...
def HasField(self, field_name: typing_extensions.Literal["bip85",b"bip85","btc",b"btc","btc_pub",b"btc_pub","btc_sign_init",b"btc_sign_init","btc_sign_input",b"btc_sign_input","btc_sign_output",b"btc_sign_output","cardano",b"cardano","check_backup",b"check_backup","check_sdcard",b"check_sdcard","create_backup",b"create_backup","device_info",b"device_info","device_language",b"device_language","device_name",b"device_name","electrum_encryption_key",b"electrum_encryption_key","eth",b"eth","fingerprint",b"fingerprint","insert_remove_sdcard",b"insert_remove_sdcard","list_backups",b"list_backups","perform_attestation",b"perform_attestation","reboot",b"reboot","request",b"request","reset",b"reset","restore_backup",b"restore_backup","restore_from_mnemonic",b"restore_from_mnemonic","restore_from_shamir",b"restore_from_shamir","set_mnemonic_passphrase_enabled",b"set_mnemonic_passphrase_enabled","set_password",b"set_password","show_mnemonic",b"show_mnemonic","show_shamir",b"show_shamir"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["bip85",b"bip85","btc",b"btc","btc_pub",b"btc_pub","btc_sign_init",b"btc_sign_init","btc_sign_input",b"btc_sign_input","btc_sign_output",b"btc_sign_output","cardano",b"cardano","check_backup",b"check_backup","check_sdcard",b"check_sdcard","create_backup",b"create_backup","device_info",b"device_info","device_language",b"device_language","device_name",b"device_name","electrum_encryption_key",b"electrum_encryption_key","eth",b"eth","fingerprint",b"fingerprint","insert_remove_sdcard",b"insert_remove_sdcard","list_backups",b"list_backups","perform_attestation",b"perform_attestation","reboot",b"reboot","request",b"request","reset",b"reset","restore_backup",b"restore_backup","restore_from_mnemonic",b"restore_from_mnemonic","restore_from_shamir",b"restore_from_shamir","set_mnemonic_passphrase_enabled",b"set_mnemonic_passphrase_enabled","set_password",b"set_password","show_mnemonic",b"show_mnemonic","show_shamir",b"show_shamir"]) -> None: ...
def WhichOneof(self, oneof_group: typing_extensions.Literal["request",b"request"]) -> typing.Optional[typing_extensions.Literal["device_name","device_language","device_info","set_password","create_backup","show_mnemonic","btc_pub","btc_sign_init","btc_sign_input","btc_sign_output","insert_remove_sdcard","check_sdcard","set_mnemonic_passphrase_enabled","list_backups","restore_backup","perform_attestation","reboot","check_backup","eth","reset","restore_from_mnemonic","fingerprint","btc","electrum_encryption_key","cardano","bip85","show_shamir","restore_from_shamir"]]: ...
global___Request = Request

class Response(google.protobuf.message.Message):
Expand Down
Loading

0 comments on commit 10c4bd0

Please sign in to comment.