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

[Bug]: Get firmware version failed #2583

Closed
yanguoyu opened this issue Feb 10, 2023 · 1 comment
Closed

[Bug]: Get firmware version failed #2583

yanguoyu opened this issue Feb 10, 2023 · 1 comment
Labels
bug Something isn't working libraries Impacts the Libraries triage In need of triage

Comments

@yanguoyu
Copy link

yanguoyu commented Feb 10, 2023

Impacted Library name

@ledgerhq/hw-transport-node-hid

Impacted Library version

6.27.6

Describe the bug

Ledger Nano S Plus V0.5.5
Here is my code:

const HID = require('@ledgerhq/hw-transport-node-hid').default
const { Observable, timer } = require('rxjs')
const { takeUntil, filter, scan } = require('rxjs/operators')

async function main() {
    const devices = await Promise.all([
        new Observable(HID.listen)
            .pipe(
                // searching for 2 seconds
                takeUntil(timer(2000)),
                filter(e => e.type === 'add'),
                scan((acc, e) => {
                    return [
                        ...acc,
                        {
                            descriptor: e.descriptor,
                            vendorId: e.device.vendorId,
                            manufacturer: e.device.manufacturer,
                            product: e.device.product,
                        }
                    ]
                }, []),
            )
            .toPromise()
            // If the computer does not have Bluetooth support, ledgerjs may throw an error.
            .catch((err) => {
                console.log(err)
            })
    ])
    const device = devices.flat()[0]
    if (!device) {
        return
    }
    console.log(device.descriptor)
    const transport = await HID.open()
    const res = await transport.send(0xe0, 0x01, 0x00, 0x00)
    const byteArray = [...res]
    const data = byteArray.slice(0, byteArray.length - 2)
    const versionLength = data[4]
    const version = Buffer.from(data.slice(5, 5 + versionLength)).toString()
    console.log(version)
    return version
}

main()

It will throw an Error

Error
    at new TransportStatusError (/Users/wangxiaoxiao/Documents/ygy/test/node_modules/@ledgerhq/errors/lib/index.js:258:18)
    at TransportNodeHid.<anonymous> (/Users/wangxiaoxiao/Documents/ygy/test/node_modules/@ledgerhq/hw-transport-node-hid-noevents/node_modules/@ledgerhq/hw-transport/lib/Transport.js:127:39)
    at step (/Users/wangxiaoxiao/Documents/ygy/test/node_modules/@ledgerhq/hw-transport-node-hid-noevents/node_modules/@ledgerhq/hw-transport/lib/Transport.js:33:23)
    at Object.next (/Users/wangxiaoxiao/Documents/ygy/test/node_modules/@ledgerhq/hw-transport-node-hid-noevents/node_modules/@ledgerhq/hw-transport/lib/Transport.js:14:53)
    at fulfilled (/Users/wangxiaoxiao/Documents/ygy/test/node_modules/@ledgerhq/hw-transport-node-hid-noevents/node_modules/@ledgerhq/hw-transport/lib/Transport.js:5:58) {
  message: 'Ledger device: CLA_NOT_SUPPORTED (0x6e00)',
  statusCode: 28160,
  statusText: 'CLA_NOT_SUPPORTED'

Expected behavior

I can successfully get the firmware version.

Additional context

I also try it on @ledgerhq/[email protected], but it also failed. Maybe it's caused by the ledger version. I upgrade the ledger version recently.

@juan-cortes
Copy link
Contributor

juan-cortes commented Feb 23, 2023

Hello @yanguoyu , sorry for the late response.

An easy way to test out the responses from the device is to use the repl tool we have made available. If you connect a Nano S Plus and send the getVersion APDU e001000000 you need to be in the dashboard and unlocked so if the device is running an application open it wont work.

Looking at the linked issues in here I assume that the app in question would be Nervos 0.5.5 and the exchange matches what you describe. With the application open, you are getting basically this. This is not a bug, it's the expected behaviour from the device.

=> e001000000
<= 6e00

The repository for the app in question is located here.
As the logs explain, CLA_NOT_SUPPORTED or INS_NOT_SUPPORTED mean that you are sending a message that the current application can't handle. Some APDU messages such as b001000000 will work regardless of the app running and will give you information about the current app running on the device. Depending on what you are trying to do, perhaps we can help better on Discord for development.

Since this is not a bug, I'm going to close the issue.
Good luck with the project and don't hesitate to contact us if you find an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libraries Impacts the Libraries triage In need of triage
Projects
None yet
Development

No branches or pull requests

2 participants