rfjakob / gocryptfs

Encrypted overlay filesystem written in Go
https://nuetzlich.net/gocryptfs/
MIT License
3.48k stars 247 forks source link

trezor: hang when Trezor is in bootloader mode #248

Closed rfjakob closed 6 years ago

rfjakob commented 6 years ago
$ gocryptfs -init -trezorkey /tmp/a
Choose a password for protecting your files.
(hangs)

Backtrace:

SIGABRT: abort
PC=0x481bba m=0 sigcode=0

goroutine 1 [syscall]:
syscall.Syscall6(0x10, 0x6, 0xc0185502, 0xc420183918, 0x0, 0x0, 0x0, 0x0, 0xc42005b348, 0x413078)
    /usr/local/go/src/syscall/asm_linux_amd64.s:44 +0x5 fp=0xc42005b2d8 sp=0xc42005b2d0 pc=0x481b95
github.com/zserge/hid.(*usbDevice).ioctl(0xc420089680, 0xc4c0185502, 0x7072a0, 0xc4201847c0, 0x40, 0x718c00, 0xc420186401)
    /home/jakob/go/src/github.com/zserge/hid/usb_linux.go:57 +0x12e fp=0xc42005b358 sp=0xc42005b2d8 pc=0x60a8de
github.com/zserge/hid.(*usbDevice).intr(0xc420089680, 0x81, 0xc420181640, 0x40, 0x40, 0x64, 0xffffffffffffffff, 0xb7e060, 0xc420186470)
    /home/jakob/go/src/github.com/zserge/hid/usb_linux.go:119 +0x95 fp=0xc42005b3a8 sp=0xc42005b358 pc=0x60b095
github.com/zserge/hid.(*usbDevice).Read(0xc420089680, 0xffffffffffffffff, 0x5f5e100, 0x0, 0x0, 0x0, 0xb7e060, 0xc420186470)
    /home/jakob/go/src/github.com/zserge/hid/usb_linux.go:137 +0xb3 fp=0xc42005b410 sp=0xc42005b3a8 pc=0x60b1c3
github.com/conejoninja/tesoro/transport.(*TransportHID).Read(0xc4200727d0, 0x0, 0x0, 0x0, 0x6003e7, 0x0, 0xb7e060, 0xc420186470)
    /home/jakob/go/src/github.com/conejoninja/tesoro/transport/hid.go:48 +0x5a fp=0xc42005b4c8 sp=0xc42005b410 pc=0x6900da
github.com/conejoninja/tesoro.(*Client).Read(0xc4200a6808, 0x7a3ddb, 0xd, 0xc4201003e7)
    /home/jakob/go/src/github.com/conejoninja/tesoro/tesoro.go:720 +0x48 fp=0xc42005b5b8 sp=0xc42005b4c8 pc=0x6a8f68
github.com/conejoninja/tesoro.(*Client).ReadUntil(0xc4200a6808, 0xc4200c408f, 0x8, 0x11)
    /home/jakob/go/src/github.com/conejoninja/tesoro/tesoro.go:710 +0x2b fp=0xc42005b5e8 sp=0xc42005b5b8 pc=0x6a8edb
github.com/conejoninja/tesoro.(*Client).Call(0xc4200a6808, 0xc4200c4050, 0x47, 0x50, 0x47, 0xc4200c4050, 0x8)
    /home/jakob/go/src/github.com/conejoninja/tesoro/tesoro.go:703 +0x5f fp=0xc42005b618 sp=0xc42005b5e8 pc=0x6a8e6f
github.com/xaionaro-go/cryptoWallet/internal/wallets/satoshilabs/trezor.(*TrezorBase).call(0xc4200a67d0, 0xc4200c4050, 0x47, 0x50, 0xc420108200, 0x40, 0x40)
    /home/jakob/go/src/github.com/xaionaro-go/cryptoWallet/internal/wallets/satoshilabs/trezor/trezor.go:32 +0x78 fp=0xc42005b748 sp=0xc42005b618 pc=0x6abdf8
github.com/xaionaro-go/cryptoWallet/internal/wallets/satoshilabs/trezor.(*TrezorBase).CipherKeyValue(0xc4200a67d0, 0x7a35dc, 0xb, 0xc420108200, 0x7a2ab3, 0x9, 0xc420108200, 0x40, 0x40, 0xbc40f8, ...)
    /home/jakob/go/src/github.com/xaionaro-go/cryptoWallet/internal/wallets/satoshilabs/trezor/trezor.go:114 +0x140 fp=0xc42005b7e8 sp=0xc42005b748 pc=0x6ac9e0
github.com/xaionaro-go/cryptoWallet/internal/wallets/satoshilabs/trezor.(*TrezorBase).DecryptKey(0xc4200a67d0, 0x7a35dc, 0xb, 0xc420080920, 0x20, 0x20, 0xbc40f8, 0x0, 0x0, 0x7a2ab3, ...)
    /home/jakob/go/src/github.com/xaionaro-go/cryptoWallet/internal/wallets/satoshilabs/trezor/trezor.go:175 +0x1a6 fp=0xc42005b918 sp=0xc42005b7e8 pc=0x6acfc6
github.com/rfjakob/gocryptfs/internal/readpassword.Trezor(0xc420076870, 0x7b0710, 0x2c)
    /home/jakob/go/src/github.com/rfjakob/gocryptfs/internal/readpassword/trezor.go:83 +0x2aa fp=0xc42005ba60 sp=0xc42005b918 pc=0x6b032a
main.initDir(0xc420104000)
    /home/jakob/go/src/github.com/rfjakob/gocryptfs/init_dir.go:75 +0x9d fp=0xc42005bbc8 sp=0xc42005ba60 pc=0x6d68ed
main.main()
    /home/jakob/go/src/github.com/rfjakob/gocryptfs/main.go:294 +0x6cc fp=0xc42005bf80 sp=0xc42005bbc8 pc=0x6d858c
runtime.main()
    /usr/local/go/src/runtime/proc.go:195 +0x226 fp=0xc42005bfe0 sp=0xc42005bf80 pc=0x42e876
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42005bfe8 sp=0xc42005bfe0 pc=0x45d7a1
rfjakob commented 6 years ago

lsusb normal vs bootloader: https://gist.github.com/rfjakob/636016a10f0c6acfc295627e8feab4fb

rfjakob commented 6 years ago

Normal mode:

~/go/src/github.com/conejoninja/tesoro/example$ ./example 
Found 1 TREZOR devices connected
>ping 1
1 2
>ping 0
0 2
>init
{"vendor":"bitcointrezor.com","major_version":1,"minor_version":6,"patch_version":1,"device_id":"44FF88209CB15BFDF93BC7A7","pin_protection":false,"passphrase_protection":false,"label":"My TREZOR","coins":[{"coin_name":"Bitcoin","coin_shortcut":"BTC","address_type":0,"maxfee_kb":2000000,"address_type_p2sh":5,"xpub_magic":76067358,"xprv_magic":76066276,"segwit":true,"force_bip143":false},{"coin_name":"Testnet","coin_shortcut":"TEST","address_type":111,"maxfee_kb":10000000,"address_type_p2sh":196,"xpub_magic":70617039,"xprv_magic":70615956,"segwit":true,"force_bip143":false},{"coin_name":"Bcash","coin_shortcut":"BCH","address_type":0,"maxfee_kb":500000,"address_type_p2sh":5,"xpub_magic":76067358,"xprv_magic":76066276,"segwit":false,"forkid":0,"force_bip143":true},{"coin_name":"Namecoin","coin_shortcut":"NMC","address_type":52,"maxfee_kb":10000000,"address_type_p2sh":5,"xpub_magic":27108450,"xprv_magic":27106558,"segwit":false,"force_bip143":false},{"coin_name":"Litecoin","coin_shortcut":"LTC","address_type":48,"maxfee_kb":40000000,"address_type_p2sh":50,"xpub_magic":27108450,"xprv_magic":27106558,"segwit":true,"force_bip143":false},{"coin_name":"Dogecoin","coin_shortcut":"DOGE","address_type":30,"maxfee_kb":1000000000,"address_type_p2sh":22,"xpub_magic":49990397,"xprv_magic":49988504,"segwit":false,"force_bip143":false},{"coin_name":"Dash","coin_shortcut":"DASH","address_type":76,"maxfee_kb":100000,"address_type_p2sh":16,"xpub_magic":50221772,"xprv_magic":50221816,"segwit":false,"force_bip143":false},{"coin_name":"Zcash","coin_shortcut":"ZEC","address_type":7352,"maxfee_kb":1000000,"address_type_p2sh":7357,"xpub_magic":76067358,"xprv_magic":76066276,"segwit":false,"force_bip143":false},{"coin_name":"Bitcoin Gold","coin_shortcut":"BTG","address_type":38,"maxfee_kb":500000,"address_type_p2sh":23,"xpub_magic":76067358,"xprv_magic":76066276,"segwit":true,"forkid":79,"force_bip143":true},{"coin_name":"DigiByte","coin_shortcut":"DGB","address_type":30,"maxfee_kb":500000,"address_type_p2sh":5,"xpub_magic":76067358,"xprv_magic":76066276,"segwit":true,"force_bip143":false},{"coin_name":"Monacoin","coin_shortcut":"MONA","address_type":50,"maxfee_kb":5000000,"address_type_p2sh":55,"xpub_magic":76067358,"xprv_magic":76066276,"segwit":true,"force_bip143":false},{"coin_name":"Fujicoin","coin_shortcut":"FJC","address_type":36,"maxfee_kb":1000000,"address_type_p2sh":16,"xpub_magic":76067358,"xprv_magic":76066276,"segwit":false,"force_bip143":false},{"coin_name":"Vertcoin","coin_shortcut":"VTC","address_type":71,"maxfee_kb":40000000,"address_type_p2sh":5,"xpub_magic":76067358,"xprv_magic":76066276,"segwit":true,"force_bip143":false}],"initialized":true,"revision":"lYjo8nNrYJFvUeRw3rGPVREqbrw=","bootloader_hash":"YzD87BZy+tMLQhtg90+Dmjk5M0Vly3A7K9cYLqLdoBk=","imported":false,"pin_cached":false,"passphrase_cached":false,"needs_backup":true,"flags":0,"model":"1"} 17

Bootloader mode:

~/go/src/github.com/conejoninja/tesoro/example$ ./example 
Found 1 TREZOR devices connected
>init
{"vendor":"bitcointrezor.com","major_version":1,"minor_version":4,"patch_version":0,"bootloader_mode":true,"firmware_present":true} 17
xaionaro commented 6 years ago

Thank you for the details. The problem is fixed: https://github.com/xaionaro-go/gocryptfs/commit/17c90e8d9503dd4aa4534cc946d63c1d599c011a

If the device is not initialized:

$ ./gocryptfs -trezorkey -init /tmp/1
Choose a password for protecting your files.
Cannot reset the Trezor device. Error: The wallet device is not initialized.

If the device is initialized:

$ ./gocryptfs -trezorkey -init /tmp/1
Choose a password for protecting your files.
PIN: 
Passphrase: 
The gocryptfs filesystem has been created successfully.
You can now mount it using: gocryptfs /tmp/1 MOUNTPOINT
rfjakob commented 6 years ago

Fixed by https://github.com/xaionaro-go/cryptoWallet/commit/0fd3c7ee5a64aa36e39727681c707a5477206806 and https://github.com/rfjakob/gocryptfs/pull/247/commits/17c90e8d9503dd4aa4534cc946d63c1d599c011a