-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support non-human-readable notation values (#983)
This change adds support for binary (non-human-readable) values in signature notations through `rawNotations` property on signature objects. Human-readable notations will additionally appear in `notations` object where the value of the notation will be deserialized into a string. Additionally the check for human-readable flag was modified to check the existence of the flag instead of comparison with the whole value.
- Loading branch information
Showing
3 changed files
with
72 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -819,13 +819,26 @@ V+HOQJQxXJkVRYa3QrFUehiMzTeqqMdgC6ZqJy7+ | |
|
||
const key = (await openpgp.key.readArmored(pubkey)).keys[0]; | ||
|
||
const notations = key.users[0].selfCertifications[0].notations; | ||
|
||
expect(notations.length).to.equal(2); | ||
expect(notations[0][0]).to.equal('[email protected]'); | ||
expect(notations[0][1]).to.equal('2'); | ||
expect(notations[1][0]).to.equal('[email protected]'); | ||
expect(notations[1][1]).to.equal('3'); | ||
const { notations, rawNotations } = key.users[0].selfCertifications[0]; | ||
|
||
// Even though there are two notations with the same keys | ||
// the `notations` property reads only the single one: | ||
// the last one encountered during parse | ||
expect(Object.keys(notations).length).to.equal(1); | ||
expect(notations['[email protected]']).to.equal('3'); | ||
|
||
// On the other hand `rawNotations` property provides access to all | ||
// notations, even non human-readable. The values are not deserialized | ||
// and they are byte-arrays. | ||
expect(rawNotations.length).to.equal(2); | ||
|
||
expect(rawNotations[0].name).to.equal('[email protected]'); | ||
expect(rawNotations[0].value).to.deep.equal(Uint8Array.from(['2'.charCodeAt(0)])); | ||
expect(rawNotations[0].humanReadable).to.equal(true); | ||
|
||
expect(rawNotations[1].name).to.equal('[email protected]'); | ||
expect(rawNotations[1].value).to.deep.equal(Uint8Array.from(['3'.charCodeAt(0)])); | ||
expect(rawNotations[1].humanReadable).to.equal(true); | ||
}); | ||
|
||
it('Writing and encryption of a secret key packet.', function() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -831,6 +831,15 @@ vwjE8mqJXetNMfj8r2SCyvkEnlVRYR+/mnge+ib56FdJ8uKtqSxyvgA= | |
=fRXs | ||
-----END PGP MESSAGE-----`; | ||
|
||
const signature_with_non_human_readable_notations = `-----BEGIN PGP SIGNATURE----- | ||
wncEARYKAB8FAl2TS9MYFAAAAAAADAADdGVzdEBrZXkuY29tAQIDAAoJEGZ9 | ||
gtV/iL8hrhMBAOQ/UgqRTbx1Z8inGmRdUx1cJU1SR4Pnq/eJNH/CFk5DAP0Q | ||
hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw== | ||
=ZGXr | ||
-----END PGP SIGNATURE----- | ||
`; | ||
|
||
it('Testing signature checking on CAST5-enciphered message', async function() { | ||
const { reject_message_hash_algorithms } = openpgp.config; | ||
Object.assign(openpgp.config, { reject_message_hash_algorithms: new Set([openpgp.enums.hash.md5, openpgp.enums.hash.ripemd]) }); | ||
|
@@ -887,6 +896,21 @@ vwjE8mqJXetNMfj8r2SCyvkEnlVRYR+/mnge+ib56FdJ8uKtqSxyvgA= | |
expect(sig.data).to.match(/-----END PGP MESSAGE-----\r\n$/); | ||
}); | ||
|
||
it('Supports non-human-readable notations', async function() { | ||
const { packets: [signature] } = await openpgp.message.readArmored(signature_with_non_human_readable_notations); | ||
// There are no human-readable notations so `notations` property does not | ||
// expose the `[email protected]` notation. | ||
expect(Object.keys(signature.notations).length).to.equal(0); | ||
expect(signature.notations['[email protected]']).to.equal(undefined); | ||
|
||
// The notation is readable through `rawNotations` property: | ||
expect(signature.rawNotations.length).to.equal(1); | ||
const notation = signature.rawNotations[0]; | ||
expect(notation.name).to.equal('[email protected]'); | ||
expect(notation.value).to.deep.equal(Uint8Array.from([0x01, 0x02, 0x03])); | ||
expect(notation.humanReadable).to.equal(false); | ||
}); | ||
|
||
it('Verify V4 signature. Hash: SHA1. PK: RSA. Signature Type: 0x00 (binary document)', async function() { | ||
const { reject_message_hash_algorithms } = openpgp.config; | ||
Object.assign(openpgp.config, { reject_message_hash_algorithms: new Set([openpgp.enums.hash.md5, openpgp.enums.hash.ripemd]) }); | ||
|