Skip to content

Commit

Permalink
Update plugin for Satochip hardware wallet to support latest firmware…
Browse files Browse the repository at this point in the history
… v0.11 (Electron-Cash#1915)

* Electron-Cash-Satochip - Lightweight Bitcoin Cash client for the Satochip Hardware Wallet

Initial(beta) version

* Toporin patch 1 (#1)

Minor patch for packaging application to Windows executable.

* Update deterministic.spec set PYHOME value
* Update _build.sh Pyscard module: use full filename instead of pyscard.whl

* patch error on card removal as described in https://pastebin.com/WGSWCqap

When the card is removed and then inserted again, Electrum fails to transmit commands to the card (PIN missing).
Patch: after card removal and reinsertion, the client retransmits commands and asks user for PIN if necessary.

* Add support for PIN change and seed reset

A new setting menu is available when clicking on the satochip logo in the low right corner of the window.
If 2FA is enabled, resetting the seed requires approval on the second device!

* Support for Satochip v0.8-0.1: reset the seed/eckey/2FA.
2FA required to sign tx/msg and reset seed/eckey/2FA.
2FA can only be disabled when all privkeys are cleared.

Changes:
- card_sign_message(): support 2FA
- card_sign_short_message(): support 2FA
- add card_set_2FA_key()
- add def card_reset_2FA_key()
- removed card_get_counter_2FA(): reset seed is based on authentikey instead of counter
- reset_seed(): request 2FA is required
- setup_device(): separate setup from 2FA initialisation

* Electron Cash 4.0.8-0.8: support for Satochip v0.8-0.1

Merge branch 'pin-seed-mgmt'
* Add support for PIN change and seed reset
* 2FA required to sign tx/msg and reset seed/eckey/2FA.
* 2FA can only be disabled when all privkeys are cleared.

A new setting menu is available when clicking on the satochip logo in the low right corner of the window.
If 2FA is enabled, resetting the seed requires approval on the second device!

Changes:
 - card_sign_message(): support 2FA
 - card_sign_short_message(): support 2FA
 - add card_set_2FA_key()
 - add card_reset_2FA_key()
 - reset_seed(): request 2FA is required
 - setup_device(): separate setup from 2FA initialisation

Patch: in sign-message: hmac should be of type bytes, not list

* Merge branch 'master' of https://github.com/Electron-Cash/Electron-Cash into HEAD

# Conflicts:
#	README.rst
#	contrib/build-wine/_build.sh
#	gui/qt/icons.py

* Satochip merge from Toporin/electrum branch electron-cash-satochip-pr4.0.11-0.8

This resolves some of the conflicts that arose since Toporin forked his
branch in early September and EC has changed since then.  It's basically
rebased off latest EC master, adding Toporin's commits, with minor
whitespace and/or comment nits.

Still a work in progress.

Original commits:

----

Squashed commit of the following:

commit b9ba208e21cc28d25fac24a701d4eb6307e71fb2
Author: Calin Culianu <[email protected]>
Date:   Wed Nov 6 13:05:24 2019 +0200

    Whitespace and other nits

commit 0a05d94829b7de0711eb930091cdc6ba8f84fc88
Author: Toporin <[email protected]>
Date:   Wed Oct 2 12:04:44 2019 +0200

    Buil appImage and install swig+pcsd package in docker file
    Add pyscard in requirements

commit b91714b637f4a228d0c1afbb15ef4bc199dd8720
Author: Toporin <[email protected]>
Date:   Wed Oct 2 12:01:30 2019 +0200

    Build Swig (needed to build pyscard)

commit e2ff56d461f3b27a8fc10f4f2f39cc288762dd7f
Author: Toporin <[email protected]>
Date:   Wed Oct 2 10:03:40 2019 +0200

    Add pyscard 1.9.9 in deterministic hardware requirements

commit b34815a9dfde8117865ef26c0e2d5b514c020f4f
Author: Toporin <[email protected]>
Date:   Sat Sep 28 16:26:55 2019 +0200

    minor changes: clean up code

commit 83cbdca805ed5d7d46a98f5fc5cdf722e5bdf45f
Author: Toporin <[email protected]>
Date:   Fri Sep 27 16:17:01 2019 +0200

    Patch windows build: in deterministic.spec

    binaries += [(C:/python*/Lib/site-packages/smartcard/scard/_scard.cp36-win32.pyd, '.')]

commit ed0439418b6647ebe3415ce9018d32516b0c2d70
Author: Toporin <[email protected]>
Date:   Fri Sep 27 15:14:30 2019 +0200

    removed constant PYHOME = 'c:/python3.6.8' in deterministic.spec

    use constant defined in _build.sh

commit 63da13e4a7e80a6a32d7f2cfd9652c6d93429cd6
Author: Toporin <[email protected]>
Date:   Mon Sep 23 21:15:34 2019 +0200

    minor changes in packaging scripts

commit 1dfed0331187275131e4fe251a06f4be93f44b7f
Author: Toporin <[email protected]>
Date:   Mon Sep 23 21:08:48 2019 +0200

    minor change: removed old readme file

commit a0235aaa8868a782d6e1393ff793f20f7be7ad26
Author: Alcofribas4 <[email protected]>
Date:   Mon Sep 23 14:03:51 2019 +0200

    Merge branch 'master' of https://github.com/Electron-Cash/Electron-Cash into HEAD

    # Conflicts:
    #	README.rst
    #	contrib/build-wine/_build.sh
    #	gui/qt/icons.py

commit d69fd5ce5008c2022c290210804eaf6edc935e41
Author: Toporin <[email protected]>
Date:   Fri Sep 20 12:34:49 2019 +0200

    Electron Cash 4.0.8-0.8: support for Satochip v0.8-0.1

    Merge branch 'pin-seed-mgmt'
    * Add support for PIN change and seed reset
    * 2FA required to sign tx/msg and reset seed/eckey/2FA.
    * 2FA can only be disabled when all privkeys are cleared.

    A new setting menu is available when clicking on the satochip logo in the low right corner of the window.
    If 2FA is enabled, resetting the seed requires approval on the second device!

    Changes:
     - card_sign_message(): support 2FA
     - card_sign_short_message(): support 2FA
     - add card_set_2FA_key()
     - add card_reset_2FA_key()
     - reset_seed(): request 2FA is required
     - setup_device(): separate setup from 2FA initialisation

    Patch: in sign-message: hmac should be of type bytes, not list

commit 1c55add58ca86bf3677eb916c649f458a6f7205c
Author: Toporin <[email protected]>
Date:   Thu Sep 19 11:42:44 2019 +0200

    Support for Satochip v0.8-0.1: reset the seed/eckey/2FA.
    2FA required to sign tx/msg and reset seed/eckey/2FA.
    2FA can only be disabled when all privkeys are cleared.

    Changes:
    - card_sign_message(): support 2FA
    - card_sign_short_message(): support 2FA
    - add card_set_2FA_key()
    - add def card_reset_2FA_key()
    - removed card_get_counter_2FA(): reset seed is based on authentikey instead of counter
    - reset_seed(): request 2FA is required
    - setup_device(): separate setup from 2FA initialisation

commit 575d29262f43c9aa4bd44d366e9b6955742525cb
Author: Toporin <[email protected]>
Date:   Thu Sep 12 13:39:37 2019 +0200

    Add support for PIN change and seed reset

    A new setting menu is available when clicking on the satochip logo in the low right corner of the window.
    If 2FA is enabled, resetting the seed requires approval on the second device!

commit 3ae32bd607a4bde717f6cd48d289e48535d8391a
Author: Toporin <[email protected]>
Date:   Wed Aug 28 14:00:35 2019 +0200

    Toporin patch 1 (#1)

    Minor patch for packaging application to Windows executable.

    * Update deterministic.spec set PYHOME value
    * Update _build.sh Pyscard module: use full filename instead of pyscard.whl

commit 617c04ced1e803076e69a5dfdc3ead1d1b22ab49
Author: Toporin <[email protected]>
Date:   Mon Sep 9 11:22:34 2019 +0200

    patch error on card removal as described in https://pastebin.com/WGSWCqap

    When the card is removed and then inserted again, Electrum fails to transmit commands to the card (PIN missing).
    Patch: after card removal and reinsertion, the client retransmits commands and asks user for PIN if necessary.

commit 7bd3e0ef2b77a0df3dc827a9c8b0ee38cc7536ce
Author: Toporin <[email protected]>
Date:   Mon Aug 26 13:21:16 2019 +0200

    Electron-Cash-Satochip - Lightweight Bitcoin Cash client for the Satochip Hardware Wallet

    Initial(beta) version

* Satochip: Minor nits and fixups

Tried to clean the code a little to use the PrintError mixin class for
debug prints (which is less boilerplatey).

Also tried to clean up the code slightly.

Can't get it to talk to the SatoChip card on my mac.. will try Windows
next.

Plugins seems a bit fragile, and also it hangs the hw wizard for a while
trying to talk to the card reader. FIXME

* Updated pyscard wheel to v1.9.9

* Satochip: Added macOS packaging (pyscard module, etc) for Satochip

This relies on a pre-built wheel pyscard-1.9.9-cp36-cp36m-macosx_10_11_x86_64.whl
which we host at https://github.com/cculianu/Electron-Cash-Build-Tools/releases/tag/v1.0

I built this myself on an El Capitan system and it appears to work with
newer systems too.

We did it this way because building the pyscard module off of PyPI
requires some annoying prerequisites (such as swig3) which I would
rather not add to the build scripts.

This is not unlike a lot of our other packaging stuff where we don't
feel like re-building the world and are ok with downloading some
binaries.

* Satochip: We moved the location of the hosted pyscard wheel to our repo

This should make the WINE build more reliable.  It was failing as
appveyor would sometimes be down.

* Satochip: Bumped pyscard module we download to 1.9.9 for WINE build

* Satochip follow-up: Forgot to set the PYSCARD_FILENAME in the ...

... WINE _build.sh script.

* Minor changes: reduced smartcard timout and updated satochip version support

* remove is_restoring parameter (from Electrum)

credit goes to https://github.com/jcramer
simpleledger@dc356af

* Patch "Recovered authentikey does not correspond to registered authentikey" error

When using passphrase with seed, I am sometimes getting an error: Recovered authentikey does not correspond to registered authentikey!
See simpleledger#101 (comment)

* Update requirements-hw.txt

Nit: Remove a space, add newline at the end

* Update satochip.pr

`self` is not defined in this context. Fixed.

Co-authored-by: Alcofribas4 <[email protected]>
Co-authored-by: Calin Culianu <[email protected]>
  • Loading branch information
3 people authored Jul 29, 2020
1 parent 207727c commit aaa3f34
Show file tree
Hide file tree
Showing 17 changed files with 280 additions and 2,373 deletions.
6 changes: 3 additions & 3 deletions contrib/build-linux/appimage/Dockerfile_ub1604
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ RUN apt-get update -q && \
xz-utils=5.1.1alpha+20120614-2ubuntu2 \
libffi-dev=3.2.1-4 \
libncurses5-dev=6.0+20160213-1ubuntu1 \
libsqlite3-dev=3.11.0-1ubuntu1.4 \
libsqlite3-dev=3.11.0-1ubuntu1.5 \
libusb-1.0-0-dev=2:1.0.20-1 \
libudev-dev=229-4ubuntu21.28 \
gettext=0.19.7-2ubuntu3.1 \
pkg-config=0.29.1-0ubuntu1 \
libdbus-1-3=1.10.6-1ubuntu3.4 \
libdbus-1-3=1.10.6-1ubuntu3.6 \
libpcsclite-dev=1.8.14-1ubuntu1.16.04.1 \
swig=3.0.8-0ubuntu3 \
software-properties-common=0.96.20.9 \
Expand All @@ -26,7 +26,7 @@ RUN apt-get update -q && \
add-apt-repository ppa:git-core/ppa && \
apt-get update -q && \
apt-get install -qy \
git=1:2.26.2-0ppa1~ubuntu16.04.1 \
git \
&& \
rm -rf /var/lib/apt/lists/* && \
apt-get autoremove -y && \
Expand Down
2 changes: 1 addition & 1 deletion contrib/build-linux/appimage/_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mkdir -p "$CACHEDIR/pip_cache"
"$python" -m pip install --no-warn-script-location --cache-dir "$CACHEDIR/pip_cache" -r "$CONTRIB/deterministic-build/requirements.txt"
"$python" -m pip install --no-warn-script-location --cache-dir "$CACHEDIR/pip_cache" -r "$CONTRIB/deterministic-build/requirements-binaries.txt"
"$python" -m pip install --no-warn-script-location --cache-dir "$CACHEDIR/pip_cache" -r "$CONTRIB/deterministic-build/requirements-hw.txt"
"$python" -m pip install --no-warn-script-location --cache-dir "$CACHEDIR/pip_cache" -r "$CONTRIB/deterministic-build/requirements-satochip.txt"
#"$python" -m pip install --no-warn-script-location --cache-dir "$CACHEDIR/pip_cache" -r "$CONTRIB/deterministic-build/requirements-satochip.txt"
"$python" -m pip install --no-warn-script-location --cache-dir "$CACHEDIR/pip_cache" "$PROJECT_ROOT"
"$python" -m pip uninstall -y Cython

Expand Down
15 changes: 12 additions & 3 deletions contrib/deterministic-build/requirements-hw.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Cython==0.29.7 \
--hash=sha256:f3f6c09e2c76f2537d61f907702dd921b04d1c3972f01d5530ef1f748f22bd89 \
--hash=sha256:f749287087f67957c020e1de26906e88b8b0c4ea588facb7349c115a63346f67 \
--hash=sha256:f86b96e014732c0d1ded2c1f51444c80176a98c21856d0da533db4e4aef54070
ecdsa==0.13.2 \
--hash=sha256:20c17e527e75acad8f402290e158a6ac178b91b881f941fc6ea305bfdfb9657c \
--hash=sha256:5c034ffa23413ac923541ceb3ac14ec15a0d2530690413bff58c12b80e56d884
ecdsa==0.15 \
--hash=sha256:867ec9cf6df0b03addc8ef66b56359643cb5d0c1dc329df76ba7ecfe256c8061 \
--hash=sha256:8f12ac317f8a1318efa75757ef0a651abe12e51fc1af8838fb91079445227277
hidapi==0.7.99.post21 \
--hash=sha256:1ac170f4d601c340f2cd52fd06e85c5e77bad7ceac811a7bb54b529f7dc28c24 \
--hash=sha256:6424ad75da0021ce8c1bcd78056a04adada303eff3c561f8d132b85d0a914cb3 \
Expand Down Expand Up @@ -98,6 +98,15 @@ pyblake2==1.1.2 \
--hash=sha256:baa2190bfe549e36163aa44664d4ee3a9080b236fc5d42f50dc6fd36bbdc749e \
--hash=sha256:c53417ee0bbe77db852d5fd1036749f03696ebc2265de359fe17418d800196c4 \
--hash=sha256:fbc9fcde75713930bc2a91b149e97be2401f7c9c56d735b46a109210f58d7358
pysatochip==0.11.2 \
--hash=sha256:52317953c4d4968a6184c2da7a802d8aa50977ba85f39475ba360e4e78063e17 \
--hash=sha256:c9b21b2bf9c001e9cb6e78aae3d242f1db72907d8cf7377aa818688d7d436ed1
pyscard==1.9.9 \
--hash=sha256:6620a74f58d5fa9076544263bb4e42c946eb20f315c896d14a7e5743d5431469 \
--hash=sha256:a047738c58d05b4dab15aa9c99fbd92f8d0670900de89c68bec247a422f8d8c7 \
--hash=sha256:c213a94585a48f8f1ff3c36c06fa3a162d2fd7f2c89240ac632bd38a3fa5df9b \
--hash=sha256:e6bde541990183858740793806b1c7f4e798670519ae4c96145f35d5d7944c20 \
--hash=sha256:99d2b450f322f9ed9682fd2a99d95ce781527e371006cded38327efca8158fe7
requests==2.21.0 \
--hash=sha256:502a824f31acdacb3a35b6690b5fbf0bc41d63a24a45c4004352b0242707598e \
--hash=sha256:7bf2a778576d825600030a110f3c0e3e8edc51dfaafe1c146e39a2027784957b
Expand Down
7 changes: 7 additions & 0 deletions contrib/deterministic-build/requirements-satochip.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
ecdsa==0.15 \
--hash=sha256:867ec9cf6df0b03addc8ef66b56359643cb5d0c1dc329df76ba7ecfe256c8061 \
--hash=sha256:8f12ac317f8a1318efa75757ef0a651abe12e51fc1af8838fb91079445227277
pyscard==1.9.9 \
--hash=sha256:6620a74f58d5fa9076544263bb4e42c946eb20f315c896d14a7e5743d5431469 \
--hash=sha256:a047738c58d05b4dab15aa9c99fbd92f8d0670900de89c68bec247a422f8d8c7 \
--hash=sha256:c213a94585a48f8f1ff3c36c06fa3a162d2fd7f2c89240ac632bd38a3fa5df9b \
--hash=sha256:e6bde541990183858740793806b1c7f4e798670519ae4c96145f35d5d7944c20
pysatochip==0.11.2 \
--hash=sha256:52317953c4d4968a6184c2da7a802d8aa50977ba85f39475ba360e4e78063e17 \
--hash=sha256:c9b21b2bf9c001e9cb6e78aae3d242f1db72907d8cf7377aa818688d7d436ed1
2 changes: 2 additions & 0 deletions contrib/requirements/requirements-hw.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ trezor[hidapi]>=0.11.0
keepkey>=6.1
btchip-python
hidapi
pyscard>=1.9.9
pysatochip>=0.11.2
Loading

0 comments on commit aaa3f34

Please sign in to comment.