Skip to content

Commit

Permalink
Satochip Plugin Support (Electron-Cash#1668)
Browse files Browse the repository at this point in the history
* 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

* Rebuilt icons.py for paranoia's sake after SatoChip additions
  • Loading branch information
cculianu authored Nov 13, 2019
1 parent 4c853dc commit 668b0a5
Show file tree
Hide file tree
Showing 25 changed files with 20,293 additions and 16,599 deletions.
2 changes: 2 additions & 0 deletions contrib/build-linux/appimage/Dockerfile_ub1604
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ RUN apt-get update -q && \
gettext=0.19.7-2ubuntu3.1 \
pkg-config=0.29.1-0ubuntu1 \
libdbus-1-3=1.10.6-1ubuntu3.4 \
libpcsclite-dev=1.8.14-1ubuntu1.16.04.1 \
swig=3.0.8-0ubuntu3 \
&& \
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 @@ -38,7 +38,6 @@ download_if_not_exist "$CACHEDIR/Python-$PYTHON_VERSION.tar.xz" "https://www.pyt
verify_hash "$CACHEDIR/Python-$PYTHON_VERSION.tar.xz" $PYTHON_SRC_TARBALL_HASH



info "Building Python"
tar xf "$CACHEDIR/Python-$PYTHON_VERSION.tar.xz" -C "$BUILDDIR"
(
Expand Down Expand Up @@ -129,6 +128,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" "$PROJECT_ROOT"


Expand Down
10 changes: 10 additions & 0 deletions contrib/build-wine/_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ prepare_wine() {
PYINSTALLER_REPO='https://github.com/EchterAgo/pyinstaller.git'
PYINSTALLER_COMMIT=1a8b2d47c277c451f4e358d926a47c096a5615ec

# Satochip pyscard
PYSCARD_FILENAME=pyscard-1.9.9-cp36-cp36m-win32.whl # python 3.6, 32-bit
PYSCARD_URL=https://github.com/cculianu/Electron-Cash-Build-Tools/releases/download/v1.0/pyscard-1.9.9-cp36-cp36m-win32.whl
PYSCARD_SHA256=99d2b450f322f9ed9682fd2a99d95ce781527e371006cded38327efca8158fe7

## These settings probably don't need change
export WINEPREFIX=$HOME/wine64
#export WINEARCH='win32'
Expand Down Expand Up @@ -266,6 +271,11 @@ prepare_wine() {
cp "$here"/../zbar/libzbar-0.dll $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libzbar to its destination"
cp libusb/libusb/.libs/libusb-1.0.dll $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libusb to its destination"

info "Installing pyscard..."
wget -O $PYSCARD_FILENAME "$PYSCARD_URL"
verify_hash $PYSCARD_FILENAME "$PYSCARD_SHA256"
$PYTHON -m pip install --no-warn-script-location $PYSCARD_FILENAME || fail "Could not install pyscard"

popd # out of homedir/tmp
popd # out of $here

Expand Down
6 changes: 5 additions & 1 deletion contrib/build-wine/deterministic.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ for i, x in enumerate(sys.argv):
else:
raise BaseException('no name')


home = 'C:\\electroncash\\'

# see https://github.com/pyinstaller/pyinstaller/issues/2005
Expand All @@ -19,6 +18,8 @@ hiddenimports += ['PyQt5.sip']
hiddenimports += collect_submodules('trezorlib')
hiddenimports += collect_submodules('btchip')
hiddenimports += collect_submodules('keepkeylib')
hiddenimports += collect_submodules('satochip') # Satochip
hiddenimports += collect_submodules('smartcard') # Satochip

# Add libusb binary
binaries = [("c:/tmp/libusb-1.0.dll", ".")]
Expand All @@ -42,6 +43,8 @@ binaries += [('C:/tmp/libzbar-0.dll', '.')]
# Workaround for "Retro Look":
binaries += [b for b in collect_dynamic_libs('PyQt5') if 'qwindowsvista' in b[0]]

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

datas = [
(home+'lib/currencies.json', 'electroncash'),
(home+'lib/servers.json', 'electroncash'),
Expand Down Expand Up @@ -74,6 +77,7 @@ a = Analysis([home+'electron-cash',
home+'plugins/trezor/qt.py',
home+'plugins/keepkey/qt.py',
home+'plugins/ledger/qt.py',
home+'plugins/satochip/qt.py', # Satochip
#home+'packages/requests/utils.py'
],
binaries=binaries,
Expand Down
4 changes: 4 additions & 0 deletions contrib/deterministic-build/requirements-satochip.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyscard==1.9.9 \
--hash=sha256:6620a74f58d5fa9076544263bb4e42c946eb20f315c896d14a7e5743d5431469 \
--hash=sha256:a047738c58d05b4dab15aa9c99fbd92f8d0670900de89c68bec247a422f8d8c7 \
--hash=sha256:e6bde541990183858740793806b1c7f4e798670519ae4c96145f35d5d7944c20
13 changes: 13 additions & 0 deletions contrib/osx/make_osx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ info "Installing dmgbuild, requests, and other build tools we need..."
python3 -m pip install -I --user -r contrib/osx/requirements-osx-build.txt \
|| fail "Could not install osx-requirements"

# This is for the Satochip hardware wallet which relies on the python module
# 'smartcard' which contains a binary which is annoying to build. So we just
# pre-built it and download the wheel from our Electron-Cash-Build-Tools repo.
# Note: when we upgrade to Python 3.7 we will need to re-build this module for
# python 3.7.
info "Installing Python Smartcard Module (pyscard)"
mkdir -p $BUILDDIR
PYSCARD_FNAME="pyscard-1.9.9-cp36-cp36m-macosx_10_11_x86_64.whl"
curl -L https://github.com/cculianu/Electron-Cash-Build-Tools/releases/download/v1.0/$PYSCARD_FNAME > $BUILDDIR/$PYSCARD_FNAME
verify_hash $BUILDDIR/$PYSCARD_FNAME 336b1cc335049e3ac5fad125c63d4e8fd4d25e85147f999359cdc6a9fde36fa7
python3 -m pip install $BUILDDIR/$PYSCARD_FNAME --user && pyenv rehash \
|| fail "Could not install pyscard"

# We use a custom PyInstaller that has deep codesigning as well as AppleEvents
# forwarding. Note both these patches have been submitted to the PyInstaller
# project but have yet to be merged in (they are very backlogged).
Expand Down
3 changes: 3 additions & 0 deletions contrib/osx/osx.spec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ hiddenimports = []
hiddenimports += collect_submodules('trezorlib')
hiddenimports += collect_submodules('btchip')
hiddenimports += collect_submodules('keepkeylib')
hiddenimports += collect_submodules('satochip') # Satochip
hiddenimports += collect_submodules('smartcard') # Satochip

datas = [
(home+'lib/currencies.json', PYPKG),
Expand Down Expand Up @@ -67,6 +69,7 @@ a = Analysis([home+MAIN_SCRIPT,
home+'plugins/trezor/qt.py',
home+'plugins/keepkey/qt.py',
home+'plugins/ledger/qt.py',
home+'plugins/satochip/qt.py', # Satochip
],
binaries=binaries,
datas=datas,
Expand Down
Loading

0 comments on commit 668b0a5

Please sign in to comment.