Skip to content

fix: Better messages when no keyring succeeded to decrypt #319

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

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ export class WebCryptoDefaultCryptographicMaterialsManager
* and that the unencrypted data key is non-NULL.
* See: cryptographic_materials.ts, `getUnencryptedDataKey`
*/
needs(material.hasValidKey(), 'Unencrypted data key is invalid.')
needs(
material.hasValidKey(),
'No keyring generated an unencrypted data key.' +
'\nYou may not have access to any wrapping keys.'
)

/* Postcondition: The WebCryptoEncryptionMaterial must contain at least 1 EncryptedDataKey. */
needs(
Expand All @@ -113,7 +117,11 @@ export class WebCryptoDefaultCryptographicMaterialsManager
* that the data key matches the algorithm suite specification
* and that the unencrypted data key is non-NULL.
*/
needs(material.hasValidKey(), 'Unencrypted data key is invalid.')
needs(
material.hasValidKey(),
'No keyring attempted to decrypted any of the encrypted data keys.' +
'\nYou may not have access to any wrapping keys.'
)

return material
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ describe('WebCryptoDefaultCryptographicMaterialsManager', () => {

await expect(
cmm.getEncryptionMaterials({ encryptionContext })
).to.rejectedWith(Error)
).to.rejectedWith(Error, 'No keyring generated an unencrypted data key.')
})

it('Postcondition: The WebCryptoEncryptionMaterial must contain at least 1 EncryptedDataKey.', async () => {
Expand Down Expand Up @@ -485,6 +485,9 @@ describe('WebCryptoDefaultCryptographicMaterialsManager', () => {
encryptionContext,
encryptedDataKeys: [edk],
})
).to.rejectedWith(Error)
).to.rejectedWith(
Error,
'No keyring attempted to decrypted any of the encrypted data keys.'
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export class NodeDefaultCryptographicMaterialsManager
* and that the unencrypted data key is non-NULL.
* See: cryptographic_materials.ts, `getUnencryptedDataKey`
*/
needs(material.getUnencryptedDataKey(), 'Unencrypted data key is invalid.')
needs(
material.hasValidKey(),
'No keyring generated an unencrypted data key.' +
'\nYou may not have access to any wrapping keys.'
)

/* Postcondition: The NodeEncryptionMaterial must contain at least 1 EncryptedDataKey. */
needs(
Expand All @@ -105,7 +109,11 @@ export class NodeDefaultCryptographicMaterialsManager
* that the data key matches the algorithm suite specification
* and that the unencrypted data key is non-NULL.
*/
needs(material.getUnencryptedDataKey(), 'Unencrypted data key is invalid.')
needs(
material.hasValidKey(),
'No keyring attempted to decrypted any of the encrypted data keys.' +
'\nYou may not have access to any wrapping keys.'
)

return material
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe('NodeDefaultCryptographicMaterialsManager', () => {

await expect(
cmm.getEncryptionMaterials({ suite, encryptionContext: {} })
).to.rejectedWith(Error)
).to.rejectedWith(Error, 'No keyring generated an unencrypted data key.')
})

it('Postcondition: The NodeEncryptionMaterial must contain at least 1 EncryptedDataKey.', async () => {
Expand Down Expand Up @@ -287,7 +287,10 @@ describe('NodeDefaultCryptographicMaterialsManager', () => {

await expect(
cmm.decryptMaterials({ suite, encryptedDataKeys, encryptionContext: {} })
).to.rejectedWith(Error)
).to.rejectedWith(
Error,
'No keyring attempted to decrypted any of the encrypted data keys.'
)
})

it('Return decryption material', async () => {
Expand Down