Browse Source

Merge pull request #256 from meriadec/master

More robust filter on valid devices
master
Loëck Vézien 7 years ago
committed by GitHub
parent
commit
a3088a4e5d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      src/internals/usb/devices.js
  2. 2
      src/types/electron.js

33
src/internals/usb/devices.js

@ -1,12 +1,27 @@
// @flow
import CommNodeHid from '@ledgerhq/hw-transport-node-hid'
import noop from 'lodash/noop'
import type Transport from '@ledgerhq/hw-transport'
import { APDUS } from 'internals/usb/manager/constants'
import type { IPCSend } from 'types/electron'
export default send => ({
export default (send: IPCSend) => ({
listen: () => {
CommNodeHid.listen({
next: e => {
error: noop,
complete: noop,
next: async e => {
if (!e.device) {
return
}
if (e.type === 'add') {
const isValid = await isValidHIDDevice(e.device.path)
if (isValid) {
send('device.add', e.device, { kill: false })
}
}
if (e.type === 'remove') {
send('device.remove', e.device, { kill: false })
@ -15,3 +30,17 @@ export default send => ({
})
},
})
/**
* Attempt to get firmware infos from device
* If it fails, we consider it is an invalid device
*/
async function isValidHIDDevice(devicePath: string): Promise<boolean> {
try {
const transport: Transport<*> = await CommNodeHid.open(devicePath)
await transport.send(...APDUS.GET_FIRMWARE)
return true
} catch (err) {
return false
}
}

2
src/types/electron.js

@ -1,3 +1,3 @@
// @flow
export type IPCSend = (string, any) => void
export type IPCSend = (string, any, any) => void

Loading…
Cancel
Save