Skip to content

Commit 52a395d

Browse files
elbuo8claude
andcommitted
fix: read OAEPparams and MGF through the DOM helpers
These three lookups were added on top of the XPath implementation and are the last remaining callers. Route them through dom.child so the OAEP additions use the same scoped resolution as the rest of decryptKeyInfo. test/dom-select.js wraps its fixtures with MGF1-SHA1 here, since rsa-oaep-mgf1p fixes the mask generation function regardless of DigestMethod and crypto.publicEncrypt cannot set the two digests independently. 121 passing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 0483662 commit 52a395d

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

lib/xmlenc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,21 +341,21 @@ function decryptKeyInfo(doc, options) {
341341
}
342342

343343
// Read the OAEP label from the optional OAEPparams element (XML-Enc 1.1 5.5.2).
344-
const oaepParams = xpath.select("./*[local-name(.)='OAEPparams']", keyEncryptionMethod)[0];
344+
const oaepParams = dom.child(keyEncryptionMethod, 'OAEPparams');
345345
const oaepLabel = oaepParams ? Buffer.from(oaepParams.textContent, 'base64') : Buffer.alloc(0);
346346

347347
switch (keyEncryptionAlgorithm) {
348348
case 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p':
349349
// The identifier fixes MGF1 to SHA-1 (XML-Enc 1.1 5.5.2); DigestMethod
350350
// selects only the OAEP message digest. An xenc11:MGF child is a MUST NOT.
351-
if (xpath.select("./*[local-name(.)='MGF']", keyEncryptionMethod)[0]) {
351+
if (dom.child(keyEncryptionMethod, 'MGF')) {
352352
throw new Error('MGF element must not be present with ' + keyEncryptionAlgorithm);
353353
}
354354
return decryptKeyInfoWithScheme(encryptedKey, options, crypto.constants.RSA_PKCS1_OAEP_PADDING, oaepHash, 'sha1', oaepLabel);
355355

356356
case 'http://www.w3.org/2009/xmlenc11#rsa-oaep': {
357357
// MGF1 comes from the optional xenc11:MGF child; default MGF1-SHA1.
358-
const mgfElement = xpath.select("./*[local-name(.)='MGF']", keyEncryptionMethod)[0];
358+
const mgfElement = dom.child(keyEncryptionMethod, 'MGF');
359359
let mgf1Hash = 'sha1';
360360
if (mgfElement) {
361361
const mgfAlgorithm = mgfElement.getAttribute('Algorithm');

test/dom-select.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var assert = require('assert');
2-
var crypto = require('crypto');
32
var fs = require('fs');
43
var xmldom = require('@xmldom/xmldom');
54
var xpath = require('xpath');
65
var dom = require('../lib/dom-select');
6+
var oaep = require('../lib/oaep');
77
var xmlenc = require('../lib/xmlenc');
88

99
var XENC = 'http://www.w3.org/2001/04/xmlenc#';
@@ -187,13 +187,11 @@ describe('decryptKeyInfo element resolution', function () {
187187
var pub = fs.readFileSync(__dirname + '/test-auth0_rsa.pub');
188188
var key = fs.readFileSync(__dirname + '/test-auth0.key');
189189

190-
// master's decrypt path uses crypto directly; oaepHash follows DigestMethod.
190+
// rsa-oaep-mgf1p fixes MGF1 to SHA-1, so these fixtures must be wrapped that
191+
// way whatever the DigestMethod says. crypto.publicEncrypt cannot express the
192+
// two digests independently.
191193
function wrap(symmetricKey, oaepHash) {
192-
return crypto.publicEncrypt({
193-
key: pub,
194-
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
195-
oaepHash: oaepHash
196-
}, symmetricKey);
194+
return oaep.publicEncryptOaep(pub, symmetricKey, { oaepHash: oaepHash, mgf1Hash: 'sha1' });
197195
}
198196

199197
it('pairs DigestMethod with the EncryptedKey actually in use', function () {

0 commit comments

Comments
 (0)