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

[SG-720] Trim c null characters getting padded at end of messages #3724

Merged
merged 5 commits into from
Oct 10, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions apps/desktop/src/services/nativeMessageHandler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,27 @@ export class NativeMessageHandlerService {
this.ddgSharedSecret = SymmetricCryptoKey.fromJSON({ keyB64: storedKey });
}

return JSON.parse(
await this.cryptoService.decryptToUtf8(
try {
let decryptedResult = await this.cryptoService.decryptToUtf8(
message.encryptedCommand as EncString,
this.ddgSharedSecret
)
);
);

// Trim any characters that get padded at the end of messages. This happens with C encryption libraries.
// None of valid received commands are contained in an array, so safe to check for }
decryptedResult = decryptedResult.substring(0, decryptedResult.lastIndexOf("}") + 1);
differsthecat marked this conversation as resolved.
Show resolved Hide resolved

return JSON.parse(decryptedResult);
} catch {
this.sendResponse({
messageId: message.messageId,
version: NativeMessagingVersion.Latest,
payload: {
error: "cannot-decrypt",
},
});
return;
}
}

private async sendEncryptedResponse(
Expand Down