Skip to content

Commit c9c38ba

Browse files
committed
refactor(saml11): reuse ./xml/encrypt instead of xmlenc copy-pasta
1 parent f4ee4a4 commit c9c38ba

File tree

2 files changed

+7
-36
lines changed

2 files changed

+7
-36
lines changed

lib/saml11.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var moment = require('moment');
77
var async = require('async');
88
var crypto = require('crypto');
99

10+
var EncryptXml = require('./xml/encrypt');
1011
var SignXml = require('./xml/sign');
1112

1213
var saml11 = fs.readFileSync(path.join(__dirname, 'saml11.template')).toString();
@@ -176,39 +177,6 @@ function createAssertion(options, strategies, callback) {
176177
});
177178
}
178179

179-
var EncryptXml = Object.freeze({
180-
fromEncryptXmlOptions: function (options) {
181-
if (!options.encryptionCert) {
182-
return this.unencrypted;
183-
} else {
184-
var encryptOptions = {
185-
rsa_pub: options.encryptionPublicKey,
186-
pem: options.encryptionCert,
187-
encryptionAlgorithm: options.encryptionAlgorithm || 'http://www.w3.org/2001/04/xmlenc#aes256-cbc',
188-
keyEncryptionAlgorighm: options.keyEncryptionAlgorighm || 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p',
189-
};
190-
191-
// expose the encryptOptions as these are needed when adding the SubjectConfirmation
192-
return Object.assign(this.encrypted(encryptOptions), { encryptOptions: encryptOptions });
193-
}
194-
},
195-
unencrypted: function (xml, callback) {
196-
if (callback) {
197-
setImmediate(callback, null, xml);
198-
} else {
199-
return xml;
200-
}
201-
},
202-
encrypted: function (encryptOptions) {
203-
return function encrypt(xml, callback) {
204-
xmlenc.encrypt(xml, encryptOptions, function (err, encrypted) {
205-
if (err) return callback(err);
206-
callback(null, utils.removeWhitespace(encrypted));
207-
});
208-
};
209-
}
210-
})
211-
212180
function addSubjectConfirmation(encryptOptions, doc, randomBytes, callback) {
213181
xmlenc.encryptKeyInfo(randomBytes, encryptOptions, function(err, keyinfo) {
214182
if (err) return callback(err);

lib/xml/encrypt.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ exports.fromEncryptXmlOptions = function (options) {
66
if (!options.encryptionCert) {
77
return this.unencrypted;
88
} else {
9-
return this.encrypted({
9+
var encryptOptions = {
1010
rsa_pub: options.encryptionPublicKey,
1111
pem: options.encryptionCert,
1212
encryptionAlgorithm: options.encryptionAlgorithm || 'http://www.w3.org/2001/04/xmlenc#aes256-cbc',
13-
keyEncryptionAlgorighm: options.keyEncryptionAlgorighm || 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p'
14-
});
13+
keyEncryptionAlgorighm: options.keyEncryptionAlgorighm || 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p',
14+
};
15+
16+
// expose the encryptOptions as these are needed when adding the SubjectConfirmation
17+
return Object.assign(this.encrypted(encryptOptions), { encryptOptions: encryptOptions });
1518
}
1619
};
1720

0 commit comments

Comments
 (0)