Skip to content

Commit

Permalink
fix: blind fix for disconnects during fw update due to bad HSM data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-cortes authored Jun 13, 2023
1 parent bf4fb87 commit 88063df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-dancers-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

Sanitize the bulk exchange payload from HSM before exchanging it with the device
21 changes: 12 additions & 9 deletions libs/ledger-live-common/src/socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,20 @@ export const createDeviceSocket = (
await new Promise((resolve, reject) => {
let i = 0;
notify(0);
// if the bulk payload includes trailing empty strings we end up
// sending empty data to the device and causing a disconnect.
const cleanData = data
.map(d => (d !== "" ? Buffer.from(d, "hex") : null))
.filter(Boolean);

// we also use a subscription to be able to cancel the bulk if the user unsubscribes
bulkSubscription = transport.exchangeBulk(
data.map(d => Buffer.from(d, "hex")),
{
next: () => {
notify(++i);
},
error: e => reject(e),
complete: () => resolve(null),
bulkSubscription = transport.exchangeBulk(cleanData, {
next: () => {
notify(++i);
},
);
error: e => reject(e),
complete: () => resolve(null),
});
});
if (unsubscribed) {
log("socket", "unsubscribed before end of bulk");
Expand Down

1 comment on commit 88063df

@vercel
Copy link

@vercel vercel bot commented on 88063df Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.