Skip to content
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

Doesn't build and install using instructions in Ledger SDK Documentation #16

Open
brandoncurtis opened this issue Dec 10, 2017 · 0 comments

Comments

@brandoncurtis
Copy link

To summarize, there are two issues here:

  1. Makefile ignores BOLOS_ENV and BOLOS_SDK
  2. ledgerblue Python modules has issues when icons are passed in

I could not get anything in this repo to build and install using the instructions in the Ledger SDK Documentation.

As warned in the docs, this Makefile does not acknowledge BOLOS_ENV and BOLOS_SDK... instead, you have to specify GCCPATH and CLANGPATH manually.

If I run COIN=bitcoin_testnet make, I get a couple of these errors:

find: ‘/home/brandon/repos/dev-ledger-sdk/qrcode’: No such file or directory

but these appear to be harmless and it does appear to compile.

Now if I run COIN=bitcoin_testnet make load, it errors out due to a TypeError:

TARGET_NAME=TARGET_NANOS TARGET_ID=0x31100002
find: ‘/home/brandon/repos/dev-ledger-sdk/qrcode’: No such file or directory
find: ‘/home/brandon/repos/dev-ledger-sdk/qrcode’: No such file or directory
python -m ledgerblue.loadApp --appFlags 0x50 --curve secp256k1 --targetId 0x31100002 --fileName bin/app.hex --appName "Bitcoin Test" `ICONHEX=\`python /home/brandon/repos/dev-ledger-sdk/icon.py nanos_app_bitcoin_testnet.gif hexbitmaponly 2>/dev/null\` ; [ ! -z "$ICONHEX" ] && echo "--icon $ICONHEX"`   --path ""
Generated random root public key : 04a51c...
Using test master key 04a51c...
Using ephemeral key 049f372...
Broken certificate chain - loading from user key
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/brandon/.virtualenvs/dev-ledger-btc-DoSE2Zou/lib/python2.7/site-packages/ledgerblue/loadApp.py", line 174, in <module>
    loader.createApp(args.appFlags, appLength, args.appName, icon, path, None, None, args.appVersion)
  File "/home/brandon/.virtualenvs/dev-ledger-btc-DoSE2Zou/local/lib/python2.7/site-packages/ledgerblue/hexLoader.py", line 163, in createApp
    data = self.encryptAES(data)
  File "/home/brandon/.virtualenvs/dev-ledger-btc-DoSE2Zou/local/lib/python2.7/site-packages/ledgerblue/hexLoader.py", line 95, in encryptAES
    encryptedData = cipher.encrypt(paddedData)
  File "/home/brandon/.virtualenvs/dev-ledger-btc-DoSE2Zou/local/lib/python2.7/site-packages/Crypto/Cipher/blockalgo.py", line 244, in encrypt
    return self._cipher.encrypt(plaintext)
TypeError: argument must be string or read-only buffer, not bytearray
Makefile:189: recipe for target 'load' failed
make: *** [load] Error 1

Now, if I try again but I pull out the Python one-liner that the Makefile runs, minus the icon part, this loads the app onto the Ledger just fine:

$ python -m ledgerblue.loadApp --appFlags 0x50 --curve secp256k1 --targetId 0x31100002 --fileName bin/app.hex --appName "Bitcoin Test"

This suggests that the problem is in here somewhere, but this also returns properly:

$ python /home/brandon/repos/dev-ledger-sdk/icon.py nanos_app_bitcoin_testnet.gif hexbitmaponly
0100000000ffffff00ffffffffffffbffe0ffc9ff99ff91ff89ff19ff39ff10ff8bffeffffffffffff

This fails:

$ python -m ledgerblue.loadApp --appFlags 0x50 --curve secp256k1 --targetId 0x31100002 --fileName bin/app.hex --appName "Bitcoin Test" --icon "0100000000ffffff00ffffffffffffbffe0ffc9ff99ff91ff89ff19ff39ff10ff8bffeffffffffffff" --path ""

So it's definitely something about how loader.createApp handles that icon hex.

If I screw up the icon hex on purpose by adding a 0x prefix:

$ python -m ledgerblue.loadApp --appFlags 0x50 --curve secp256k1 --targetId 0x31100002 --fileName bin/app.hex --appName "Bitcoin Test" --icon "0x0100000000ffffff00ffffffffffffbffe0ffc9ff99ff91ff89ff19ff39ff10ff8bffeffffffffffff" --path ""
Generated random root public key : 04d4d313382cce448d43e54e085a9732b6935134f6fbc1a5b7c240d2e6cf2bbf473b46f47fbcf0735a94490aa34d680301508156f1bfd62e9d67f2d28443aba450
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/brandon/.virtualenvs/dev-ledger-btc-DoSE2Zou/lib/python2.7/site-packages/ledgerblue/loadApp.py", line 134, in <module>
    icon = bytearray.fromhex(args.icon)
ValueError: non-hexadecimal number found in fromhex() arg at position 0

Now that's interesting, because above it says argument must be string or read-only buffer, not bytearray.

In loader.createApp, the loader part is an instead of HexLoader that comes in via from .hexLoader import HexLoader.

Taking a peek inside ledgerblue/hexLoader.py:

data = b'\x0B' + struct.pack('>I', applength) + struct.pack('>I', appflags) + struct.pack('>B', len(appname)) + appname
...
data = self.encryptAES(data)
...
encryptedData = cipher.encrypt(paddedData)

Ah! Changed it to encryptedData = cipher.encrypt(buffer(paddedData)) and now make load works great.

So, it would appear this is actually a problem in the ledgerblue Python module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant