Skip to content
Open
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
17 changes: 14 additions & 3 deletions lib/templates/keyinfo.tpl.xml.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
var escapehtml = require('escape-html');

module.exports = ({ encryptionPublicCert, encryptedKey, keyEncryptionMethod, keyEncryptionDigest }) => `
const DIGEST_ALGORITHMS = {
'sha1': 'http://www.w3.org/2000/09/xmldsig#sha1',
'sha256': 'http://www.w3.org/2001/04/xmlenc#sha256',

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Not at the current time.

'sha512': 'http://www.w3.org/2001/04/xmlenc#sha512'
};

module.exports = ({ encryptionPublicCert, encryptedKey, keyEncryptionMethod, keyEncryptionDigest }) => {
const digestUri = DIGEST_ALGORITHMS[keyEncryptionDigest] || keyEncryptionDigest;

// RSA-OAEP requires it. RSA-1.5 must NOT have it.
const isOAEP = keyEncryptionMethod && keyEncryptionMethod.includes('rsa-oaep');
return `
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<e:EncryptedKey xmlns:e="http://www.w3.org/2001/04/xmlenc#">
<e:EncryptionMethod Algorithm="${escapehtml(keyEncryptionMethod)}">
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#${escapehtml(keyEncryptionDigest)}" />
${isOAEP ? `<DigestMethod Algorithm="${escapehtml(digestUri)}" />` : ''}
</e:EncryptionMethod>
<KeyInfo>
${encryptionPublicCert}
Expand All @@ -15,4 +26,4 @@ module.exports = ({ encryptionPublicCert, encryptedKey, keyEncryptionMethod, key
</e:EncryptedKey>
</KeyInfo>
`;

}
4 changes: 3 additions & 1 deletion lib/xmlenc.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,11 @@ function decryptKeyInfo(doc, options) {
if (keyDigestMethod) {
const keyDigestMethodAlgorithm = keyDigestMethod.getAttribute('Algorithm');
switch (keyDigestMethodAlgorithm) {
case 'http://www.w3.org/2000/09/xmldsig#sha256':
case 'http://www.w3.org/2001/04/xmlenc#sha256':
case 'http://www.w3.org/2000/09/xmldsig#sha256': // backwards compatibility for previous wrong usage

Choose a reason for hiding this comment

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

Same question about the list of algs above, plus, are there any tests for these?

Copy link
Author

Choose a reason for hiding this comment

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

Not adding more at the current time.

And there are tests, you can find them here: 36e6993#diff-494628f41cebbf744840def8de0f425815eb3180c035032000913b9f9e95f800R41-R90

oaepHash = 'sha256';
break;
case 'http://www.w3.org/2001/04/xmlenc#sha512':
case 'http://www.w3.org/2000/09/xmldsig#sha512':
oaepHash = 'sha512';
break;
Expand Down