Skip to content

Dangerous error handling resulting in an all-zero encryptedKey #463

Description

@TaaviE

In PKI.js/src/EnvelopedData.ts, the error is silently ignored, resulting in an all-zero encryptedKey.

PKI.js/src/EnvelopedData.ts

Lines 997 to 1005 in 1bb60c2

const encryptedKey = await crypto.encrypt(publicKey.algorithm, publicKey, exportedSessionKey);
//#region RecipientEncryptedKey
recipientInfo.encryptedKey = new asn1js.OctetString({ valueHex: encryptedKey });
//#endregion
}
catch {
// nothing
}

encrypt can very visibly throw, so this is very dangerous in practice:

throw new Error(`Incorrect curve OID for index ${index}`);

A cryptographic library must not return invalid data nor ignore errors. A flaw like that should get a security advisory.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions