|
1 | 1 | var fs = require('fs'); |
2 | 2 | var path = require('path'); |
| 3 | +var async = require('async'); |
3 | 4 | var Parser = require('xmldom').DOMParser; |
4 | | -var xmlenc = require('xml-encryption'); |
5 | 5 | var moment = require('moment'); |
6 | 6 | var xmlNameValidator = require('xml-name-validator'); |
7 | 7 | var is_uri = require('valid-url').is_uri; |
8 | 8 |
|
| 9 | +var EncryptXml = require('./xml/encrypt'); |
9 | 10 | var SignXml = require('./xml/sign'); |
10 | 11 | var utils = require('./utils'); |
11 | 12 |
|
@@ -69,37 +70,6 @@ function extractSaml20Options(opts) { |
69 | 70 | }; |
70 | 71 | } |
71 | 72 |
|
72 | | -var EncryptXml = Object.freeze({ |
73 | | - fromEncryptXmlOptions: function (options) { |
74 | | - if (!options.encryptionCert) { |
75 | | - return this.unencrypted; |
76 | | - } else { |
77 | | - return this.encrypted({ |
78 | | - rsa_pub: options.encryptionPublicKey, |
79 | | - pem: options.encryptionCert, |
80 | | - encryptionAlgorithm: options.encryptionAlgorithm || 'http://www.w3.org/2001/04/xmlenc#aes256-cbc', |
81 | | - keyEncryptionAlgorighm: options.keyEncryptionAlgorighm || 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' |
82 | | - }) |
83 | | - } |
84 | | - }, |
85 | | - unencrypted: function(xml, callback) { |
86 | | - if (callback) { |
87 | | - return setImmediate(callback, null, xml); |
88 | | - } else { |
89 | | - return xml; |
90 | | - } |
91 | | - }, |
92 | | - encrypted: function (encryptOptions) { |
93 | | - return function encrypt(xml, callback) { |
94 | | - xmlenc.encrypt(xml, encryptOptions, function(err, encrypted) { |
95 | | - if (err) return callback(err); |
96 | | - encrypted = '<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">' + encrypted + '</saml:EncryptedAssertion>'; |
97 | | - callback(null, utils.removeWhitespace(encrypted)); |
98 | | - }); |
99 | | - }; |
100 | | - } |
101 | | -}); |
102 | | - |
103 | 73 | /** |
104 | 74 | * Creates a signed SAML 2.0 assertion from the given options. |
105 | 75 | * |
@@ -297,5 +267,17 @@ function createAssertion(options, strategies, callback) { |
297 | 267 | return utils.reportError(err, callback); |
298 | 268 | } |
299 | 269 |
|
300 | | - return strategies.encryptXml(signed, callback); |
| 270 | + if (strategies.encryptXml === EncryptXml.unencrypted) { |
| 271 | + return strategies.encryptXml(signed, callback); |
| 272 | + } |
| 273 | + |
| 274 | + async.waterfall([ |
| 275 | + function (cb) { |
| 276 | + strategies.encryptXml(signed, cb) |
| 277 | + }, |
| 278 | + function (encrypted, cb) { |
| 279 | + var assertion = '<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">' + encrypted + '</saml:EncryptedAssertion>'; |
| 280 | + cb(null, utils.removeWhitespace(assertion)); |
| 281 | + }, |
| 282 | + ], callback); |
301 | 283 | } |
0 commit comments