Skip to content

api/firmware: add option to skip noise pairing confirmation #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/firmware/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ type Device struct {
mu sync.RWMutex
onEvent func(Event, interface{})
log Logger

options *deviceOptions
}

// BluetoothInfo contains Bluetooth-related info.
Expand Down Expand Up @@ -144,17 +146,23 @@ func NewDevice(
config ConfigInterface,
communication Communication,
log Logger,
opts ...DeviceOption,
) *Device {
if (version == nil) != (product == nil) {
panic("both version and product have to be specified, or none")
}
options := &deviceOptions{}
for _, opt := range opts {
opt(options)
}
return &Device{
communication: communication,
version: version,
product: product,
config: config,
status: StatusConnected,
log: log,
options: options,
}
}

Expand Down
35 changes: 35 additions & 0 deletions api/firmware/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2025 Shift Crypto 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.

package firmware

type deviceOptions struct {
// If true, the host does not require noise pairing confirmation before communicating over the
// encrypted noise channel.
optionalNoisePairingConfirmation bool
}

// DeviceOption provides functional options.
type DeviceOption func(*deviceOptions)

// WithOptionalNoisePairingConfirmation allows the host to communicate over the encrypted noise
// channel without requiring a pairing confirmation on the BitBox.
//
// SECURITY NOTE: this enables a MITM in the noise channel to go undetected. Use only if the noise
// channel is wrapped in another secure transport layer, e.g. a paired Bluetooth connection.
func WithOptionalNoisePairingConfirmation(optional bool) DeviceOption {
return func(o *deviceOptions) {
o.optionalNoisePairingConfirmation = optional
}
}
3 changes: 1 addition & 2 deletions api/firmware/pairing.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ func (device *Device) pair() error {
panic(errp.New("expected 32 byte remote static pubkey"))
}

pairingVerificationRequiredByApp := !device.config.ContainsDeviceStaticPubkey(
device.deviceNoiseStaticPubkey)
pairingVerificationRequiredByApp := !device.options.optionalNoisePairingConfirmation && !device.config.ContainsDeviceStaticPubkey(device.deviceNoiseStaticPubkey)
pairingVerificationRequiredByDevice := string(responseBytes) == "\x01"

if pairingVerificationRequiredByDevice || pairingVerificationRequiredByApp {
Expand Down
Loading