Skip to content

Commit d64910f

Browse files
committed
Merge branch 'update-hidapi'
2 parents d2da38b + ff528e8 commit d64910f

19 files changed

+84
-49
lines changed

.cargo/config

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[target.x86_64-apple-darwin]
2-
linker = "x86_64-apple-darwin14-clang"
3-
ar = "x86_64-apple-darwin14-ar"
2+
linker = "x86_64-apple-darwin20.2-clang"
3+
ar = "x86_64-apple-darwin20.2-ar"
4+
5+
[target.aarch64-apple-darwin]
6+
linker = "aarch64-apple-darwin20.2-clang"
7+
ar = "aarch64-apple-darwin20.2-ar"
48

59
[target.x86_64-pc-windows-gnu]
610
linker = "x86_64-w64-mingw32-gcc"

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Changelog
22

3-
### 1.3.0
3+
## 1.3.1
4+
5+
- Fix a bug where the bridge crashes if a connected USB devices contains unicode in the HID device info
6+
7+
## 1.3.0
48
- Whitelist bity.com
9+
- Enable builds for Apple's M1 aarch64 platform
10+
- Produce amd64+aarch64 Apple's universal binary
511

612
## 1.2.0
713
- Whitelist pocketbitcoin.com

Cargo.lock

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

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,3 @@ error in case the device is busy.
6060

6161
The bridge should be available on `http://localhost:8178`. Try the `/` endpoint and see if the
6262
bridge is running. Try `/api/v1/devices` to see if your device is listed.
63-
64-
The website is online at [http://dev.shiftcrypto.ch/bridge](http://dev.shiftcrypto.ch/bridge)

bitbox-bridge/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bitbox-bridge"
3-
version = "1.3.0"
3+
version = "1.3.1"
44
authors = ["Niklas Claesson <nicke.claesson@gmail.com>"]
55
edition = "2018"
66
license = "Apache-2.0"
@@ -10,7 +10,6 @@ byteorder = "1.3"
1010
env_logger = "0.7"
1111
futures = "0.3"
1212
futures-util = "0.3"
13-
hidapi = "1.0"
1413
hyper = "0.13"
1514
log = "0.4.8"
1615
percent-encoding = "2.1"

bitbox-bridge/release/Dockerfile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ RUN gem install --no-document fpm
3131

3232

3333
##############################
34-
# llvm 8 (needed because some rust crates compile C code)
34+
# llvm 11 (needed because some rust crates compile C code)
3535
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
36-
RUN add-apt-repository 'deb http://apt.llvm.org/xenial llvm-toolchain-xenial-8 main'
36+
RUN add-apt-repository 'deb http://apt.llvm.org/xenial llvm-toolchain-xenial-11 main'
3737
RUN apt-get update -y && apt-get install -y --no-install-recommends \
38-
llvm-8 \
39-
clang-8
40-
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-8 100
41-
RUN update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-8 100
38+
llvm-11 \
39+
clang-11
40+
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-11 100
41+
RUN update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-11 100
4242

4343

4444
##############################
@@ -63,9 +63,9 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \
6363
libssl-dev
6464
# SDK
6565
RUN git clone https://github.com/tpoechtrager/osxcross /opt/osxcross
66-
RUN cd /opt/osxcross && wget -nc https://s3.dockerproject.org/darwin/v2/MacOSX10.10.sdk.tar.xz
67-
RUN cd /opt/osxcross && mv MacOSX10.10.sdk.tar.xz tarballs/
68-
RUN cd /opt/osxcross && UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh
66+
RUN cd /opt/osxcross && wget -nc https://github.com/joseluisq/macosx-sdks/releases/download/11.1/MacOSX11.1.sdk.tar.xz
67+
RUN cd /opt/osxcross && mv MacOSX11.1.sdk.tar.xz tarballs/
68+
RUN cd /opt/osxcross && UNATTENDED=yes OSX_VERSION_MIN=10.9 ./build.sh
6969

7070

7171
##############################
@@ -75,11 +75,12 @@ ENV RUSTUP_HOME=/opt/rustup
7575
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=/opt/cargo sh -s -- --profile minimal --default-toolchain 1.51.0 -y
7676
RUN rustup target add x86_64-pc-windows-gnu
7777
RUN rustup target add x86_64-apple-darwin
78+
RUN rustup target add aarch64-apple-darwin
7879

7980

8081
##############################
8182
# toml-echo is a tool for echoing toml variables (like the package.version)
82-
RUN CARGO_HOME=/opt/cargo cargo install toml-echo
83+
RUN CARGO_HOME=/opt/cargo cargo install --version 0.3.0 toml-echo
8384

8485

8586
##############################

bitbox-bridge/release/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Packages (deb/rpm/tar.gz2) will be created without further work.
1515
* Run `package.cmd`
1616

1717
## OSX
18+
* Install "toml-echo", `cargo install --version 0.3.0 toml-echo`.
1819
* Copy the whole project to an OSX machine
1920
* Run `bitbox-bridge/release/darwin/package.sh`
2021

bitbox-bridge/release/darwin/distribution.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<background alignment="bottomleft" file="BBBridge_icon_blue_160x125.png" scaling="none" />
66
<background-darkAqua alignment="bottomleft" file="BBBridge_icon_blue_160x125.png" scaling="none" />
77
<domains enable_localSystem="true"/>
8-
<options customize="never" require-scripts="true" rootVolumeOnly="true" />
8+
<options customize="never" require-scripts="true" rootVolumeOnly="true" hostArchitectures="x86_64,arm64"/>
99
<!-- Define documents displayed at various steps -->
1010
<welcome file="welcome.html" mime-type="text/html" />
1111
<conclusion file="conclusion.html" mime-type="text/html" />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<!-- We listen on network ports -->
6+
<key>com.apple.security.network.server</key>
7+
<true/>
8+
<!-- We respond on network ports -->
9+
<key>com.apple.security.network.client</key>
10+
<true/>
11+
<!-- We communicate with usb devices -->
12+
<key>com.apple.security.device.usb</key>
13+
<true/>
14+
</dict>
15+
</plist>

bitbox-bridge/release/darwin/package.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ VERSION=$(toml-echo bitbox-bridge/Cargo.toml package.version)
1010

1111
(
1212
cd bitbox-bridge/release/darwin
13-
pkgbuild --root tmp --scripts scripts --identifier ch.shiftcrypto.bitboxbridge --version "${VERSION}" --ownership recommended bridge.pkg
14-
productbuild --distribution distribution.xml --resources resources --package-path . --version "${VERSION}" "${NAME}-${VERSION}-macOS-installer.pkg"
13+
pkgbuild --root tmp --scripts scripts \
14+
--identifier ch.shiftcrypto.bitboxbridge \
15+
--version "${VERSION}" --ownership recommended bridge.pkg
16+
productbuild --distribution distribution.xml --resources resources \
17+
--package-path . --version "${VERSION}" \
18+
"${NAME}-${VERSION}-macOS-installer.pkg"
1519
)

bitbox-bridge/release/darwin/release.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ set -e
55

66
PATH="/opt/osxcross/target/bin:$PATH" \
77
CARGO_HOME=/tmp/cargo \
8-
TARGET_CC=x86_64-apple-darwin14-clang \
8+
TARGET_CC=x86_64-apple-darwin20.2-clang \
99
cargo build --target x86_64-apple-darwin --release
1010

11-
NAME=BitBoxBridge
12-
VERSION=$(toml-echo bitbox-bridge/Cargo.toml package.version)
11+
PATH="/opt/osxcross/target/bin:$PATH" \
12+
CARGO_HOME=/tmp/cargo \
13+
TARGET_CC=aarch64-apple-darwin20.2-clang \
14+
cargo build --target aarch64-apple-darwin --release
1315

1416
(
1517
cd bitbox-bridge/release/darwin
1618
mkdir -p tmp/opt/shiftcrypto/bitbox-bridge/bin
17-
cp ../../../target/x86_64-apple-darwin/release/bitbox-bridge tmp/opt/shiftcrypto/bitbox-bridge/bin
19+
PATH="/opt/osxcross/target/bin:$PATH" lipo -create \
20+
-output tmp/opt/shiftcrypto/bitbox-bridge/bin/bitbox-bridge \
21+
../../../target/x86_64-apple-darwin/release/bitbox-bridge \
22+
../../../target/aarch64-apple-darwin/release/bitbox-bridge
1823
mkdir -p tmp/Library/LaunchDaemons
1924
cp ch.shiftcrypto.bitboxbridge.plist tmp/Library/LaunchDaemons
2025
)

bitbox-bridge/release/windows/wix/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Package
22

33
1. install wix toolset and visual studio
4-
2. install toml-echo: `cargo install toml-echo`
4+
2. install toml-echo: `cargo install --version 0.3.0 toml-echo`
55
3. launch X64 native tools command prompt for VS 20XX
66
4. run package-unsigned.cmd
77

bitbox-bridge/release/windows/wix/package-unsigned.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FOR /F "tokens=* USEBACKQ" %%F IN (`toml-echo ..\..\..\Cargo.toml package.version`) DO (
1+
FOR /F "tokens=* USEBACKQ" %%F IN (`toml-echo Cargo.toml package.version`) DO (
22
SET VERSION=%%F
33
)
44
ECHO Packaging version %VERSION%

bitbox-bridge/release/windows/wix/package.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FOR /F "tokens=* USEBACKQ" %%F IN (`toml-echo ..\..\..\Cargo.toml package.version`) DO (
1+
FOR /F "tokens=* USEBACKQ" %%F IN (`toml-echo Cargo.toml package.version`) DO (
22
SET VERSION=%%F
33
)
44
ECHO Packaging version %VERSION%

bitbox-bridge/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8686
}
8787
};
8888

89-
let addr = SocketAddr::new("127.0.0.1".parse()?, u16::from_str_radix(port, 10)?);
89+
let addr = SocketAddr::new("127.0.0.1".parse()?, port.parse::<u16>()?);
9090

9191
println!("listening on http://{}", addr);
9292
let server = web::create(usb_devices, notify_tx, addr);

bitbox-bridge/src/usb.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use futures::channel::mpsc;
1616
use futures::channel::oneshot;
1717
use futures::lock::Mutex;
1818
use futures::prelude::*;
19-
use hidapi::HidApi;
20-
use hidapi_async::Device;
19+
use hidapi_async::{Device, HidApi};
2120
use std::collections::{hash_map::Entry, HashMap};
2221
use std::sync::Arc;
2322
use std::time::Duration;
@@ -106,7 +105,7 @@ impl UsbDevices {
106105
d.insert(
107106
"path".into(),
108107
percent_encoding::utf8_percent_encode(
109-
&device.0,
108+
device.0,
110109
percent_encoding::NON_ALPHANUMERIC,
111110
)
112111
.to_string(),
@@ -152,21 +151,21 @@ impl UsbDevices {
152151
self.hidapi.lock().await.refresh_devices()?;
153152
let mut seen = Vec::new();
154153
let mut devices_guard = self.devices.lock().await;
155-
for device in self.hidapi.lock().await.devices() {
154+
for device in self.hidapi.lock().await.device_list() {
156155
// TODO(nc): On windows interface_number is -1. How to distinguish hww?
157-
if device.vendor_id == 0x03eb
158-
&& device.product_id == 0x2403
159-
&& (device.interface_number == 0 || device.interface_number == -1)
156+
if device.vendor_id() == 0x03eb
157+
&& device.product_id() == 0x2403
158+
&& (device.interface_number() == 0 || device.interface_number() == -1)
160159
{
161-
let path = match device.path.as_ref().to_str() {
160+
let path = match device.path().as_ref().to_str() {
162161
Ok(path) => path,
163162
Err(e) => {
164163
warn!("ignored: {}", e);
165164
continue;
166165
}
167166
};
168-
let product = match device.product_string.as_ref() {
169-
Some(product) => product,
167+
let product_string = match device.product_string() {
168+
Some(s) => s,
170169
None => {
171170
warn!("ignored: no product");
172171
continue;
@@ -177,13 +176,13 @@ impl UsbDevices {
177176
Entry::Occupied(_) => (),
178177
Entry::Vacant(v) => {
179178
info!("Found BitBox02 at {}!", path);
180-
v.insert(DeviceEntry::new(&product));
179+
v.insert(DeviceEntry::new(product_string));
181180
}
182181
}
183182
}
184183
}
185184
// Remove all devices that wasn't seen
186-
devices_guard.retain(|k, _| seen.contains(&k));
185+
devices_guard.retain(|k, _| seen.contains(k));
187186
Ok(())
188187
}
189188

bitbox-bridge/src/web.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub fn create(
205205
if let Some(origin) = origin {
206206
match origin.host() {
207207
Some(host) => {
208-
if !is_valid_origin(&host) {
208+
if !is_valid_origin(host) {
209209
warn!("Not whitelisted origin tried to connect: {}", host);
210210
return Err(warp::reject::custom(WebError::NonLocalIp));
211211
}

hidapi-async/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hidapi-async"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Niklas Claesson <nicke.claesson@gmail.com>"]
55
edition = "2018"
66
license = "Apache-2.0"
@@ -12,6 +12,6 @@ repository = "https://github.com/digitalbitbox/bitbox-bridge"
1212
[dependencies]
1313
futures = "0.3.1"
1414
log = "0.4.8"
15-
hidapi = "1.1.0"
15+
hidapi = "1.2.6"
1616
async-std = "1.2.0"
1717
thiserror = "1.0.9"

hidapi-async/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#[macro_use]
1616
extern crate log;
1717

18+
pub use hidapi::HidApi;
19+
1820
use futures::prelude::*;
1921
use futures::task::SpawnError;
2022
use hidapi::{HidDevice, HidError};
@@ -66,7 +68,7 @@ pub struct Device {
6668
impl Clone for Device {
6769
fn clone(&self) -> Self {
6870
Device {
69-
inner: self.inner.as_ref().map(|dev| Arc::clone(&dev)),
71+
inner: self.inner.as_ref().map(|dev| Arc::clone(dev)),
7072
}
7173
}
7274
}

0 commit comments

Comments
 (0)