soap 0.20.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.editorconfig +23 -23
  2. package/.jshintrc +29 -29
  3. package/.travis.yml +22 -22
  4. package/CONTRIBUTING.md +52 -58
  5. package/History.md +52 -2
  6. package/LICENSE +7 -7
  7. package/PUBLISHING.md +28 -28
  8. package/Readme.md +1062 -931
  9. package/coverage/coverage.json +1 -0
  10. package/coverage/lcov-report/base.css +212 -0
  11. package/coverage/lcov-report/index.html +119 -0
  12. package/coverage/lcov-report/node-soap/index.html +93 -0
  13. package/coverage/lcov-report/node-soap/index.js.html +74 -0
  14. package/coverage/lcov-report/node-soap/lib/client.js.html +1001 -0
  15. package/coverage/lcov-report/node-soap/lib/http.js.html +416 -0
  16. package/coverage/lcov-report/node-soap/lib/index.html +171 -0
  17. package/coverage/lcov-report/node-soap/lib/nscontext.js.html +734 -0
  18. package/coverage/lcov-report/node-soap/lib/security/BasicAuthSecurity.js.html +137 -0
  19. package/coverage/lcov-report/node-soap/lib/security/BearerSecurity.js.html +134 -0
  20. package/coverage/lcov-report/node-soap/lib/security/ClientSSLSecurity.js.html +296 -0
  21. package/coverage/lcov-report/node-soap/lib/security/ClientSSLSecurityPFX.js.html +218 -0
  22. package/coverage/lcov-report/node-soap/lib/security/WSSecurity.js.html +278 -0
  23. package/coverage/lcov-report/node-soap/lib/security/index.html +158 -0
  24. package/coverage/lcov-report/node-soap/lib/security/index.js.html +92 -0
  25. package/coverage/lcov-report/node-soap/lib/server.js.html +1139 -0
  26. package/coverage/lcov-report/node-soap/lib/soap.js.html +314 -0
  27. package/coverage/lcov-report/node-soap/lib/utils.js.html +161 -0
  28. package/coverage/lcov-report/node-soap/lib/wsdl.js.html +6275 -0
  29. package/coverage/lcov-report/prettify.css +1 -0
  30. package/coverage/lcov-report/prettify.js +1 -0
  31. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  32. package/coverage/lcov-report/sorter.js +158 -0
  33. package/coverage/lcov.info +3325 -0
  34. package/index.js +3 -3
  35. package/lib/client.js +434 -425
  36. package/lib/http.js +129 -129
  37. package/lib/nscontext.js +223 -223
  38. package/lib/security/BasicAuthSecurity.js +24 -24
  39. package/lib/security/BearerSecurity.js +23 -23
  40. package/lib/security/ClientSSLSecurity.js +82 -65
  41. package/lib/security/ClientSSLSecurityPFX.js +51 -51
  42. package/lib/security/WSSecurity.js +90 -90
  43. package/lib/security/WSSecurityCert.js +78 -78
  44. package/lib/security/index.js +10 -10
  45. package/lib/security/templates/wsse-security-header.ejs +12 -12
  46. package/lib/security/templates/wsse-security-token.ejs +3 -3
  47. package/lib/server.js +474 -444
  48. package/lib/soap.d.ts +220 -0
  49. package/lib/soap.js +110 -110
  50. package/lib/utils.js +30 -30
  51. package/lib/wsdl.js +2272 -2234
  52. package/package.json +8 -8
  53. package/soap-stub.js +148 -148
  54. package/.npmignore +0 -2
@@ -1,65 +1,82 @@
1
- 'use strict';
2
-
3
- var fs = require('fs')
4
- , https = require('https')
5
- , _ = require('lodash');
6
-
7
- /**
8
- * activates SSL for an already existing client
9
- *
10
- * @module ClientSSLSecurity
11
- * @param {Buffer|String} key
12
- * @param {Buffer|String} cert
13
- * @param {Buffer|String|Array} [ca]
14
- * @param {Object} [defaults]
15
- * @constructor
16
- */
17
- function ClientSSLSecurity(key, cert, ca, defaults) {
18
- if (key) {
19
- if(Buffer.isBuffer(key)) {
20
- this.key = key;
21
- } else if (typeof key === 'string') {
22
- this.key = fs.readFileSync(key);
23
- } else {
24
- throw new Error('key should be a buffer or a string!');
25
- }
26
- }
27
-
28
- if (cert) {
29
- if(Buffer.isBuffer(cert)) {
30
- this.cert = cert;
31
- } else if (typeof cert === 'string') {
32
- this.cert = fs.readFileSync(cert);
33
- } else {
34
- throw new Error('cert should be a buffer or a string!');
35
- }
36
- }
37
-
38
- if (ca) {
39
- if(Buffer.isBuffer(ca) || Array.isArray(ca)) {
40
- this.ca = ca;
41
- } else if (typeof ca === 'string') {
42
- this.ca = fs.readFileSync(ca);
43
- } else {
44
- defaults = ca;
45
- this.ca = null;
46
- }
47
- }
48
-
49
- this.defaults = {};
50
- _.merge(this.defaults, defaults);
51
- }
52
-
53
- ClientSSLSecurity.prototype.toXML = function(headers) {
54
- return '';
55
- };
56
-
57
- ClientSSLSecurity.prototype.addOptions = function(options) {
58
- options.key = this.key;
59
- options.cert = this.cert;
60
- options.ca = this.ca;
61
- _.merge(options, this.defaults);
62
- options.agent = new https.Agent(options);
63
- };
64
-
65
- module.exports = ClientSSLSecurity;
1
+ 'use strict';
2
+
3
+ var fs = require('fs')
4
+ , https = require('https')
5
+ , _ = require('lodash');
6
+
7
+ /**
8
+ * activates SSL for an already existing client
9
+ *
10
+ * @module ClientSSLSecurity
11
+ * @param {Buffer|String} key
12
+ * @param {Buffer|String} cert
13
+ * @param {Buffer|String|Array} [ca]
14
+ * @param {Object} [defaults]
15
+ * @constructor
16
+ */
17
+ function ClientSSLSecurity(key, cert, ca, defaults) {
18
+ if (key) {
19
+ if(Buffer.isBuffer(key)) {
20
+ this.key = key;
21
+ } else if (typeof key === 'string') {
22
+ this.key = fs.readFileSync(key);
23
+ } else {
24
+ throw new Error('key should be a buffer or a string!');
25
+ }
26
+ }
27
+
28
+ if (cert) {
29
+ if(Buffer.isBuffer(cert)) {
30
+ this.cert = cert;
31
+ } else if (typeof cert === 'string') {
32
+ this.cert = fs.readFileSync(cert);
33
+ } else {
34
+ throw new Error('cert should be a buffer or a string!');
35
+ }
36
+ }
37
+
38
+ if (ca) {
39
+ if(Buffer.isBuffer(ca) || Array.isArray(ca)) {
40
+ this.ca = ca;
41
+ } else if (typeof ca === 'string') {
42
+ this.ca = fs.readFileSync(ca);
43
+ } else {
44
+ defaults = ca;
45
+ this.ca = null;
46
+ }
47
+ }
48
+
49
+ this.defaults = {};
50
+ _.merge(this.defaults, defaults);
51
+
52
+ this.agent = null;
53
+ }
54
+
55
+ ClientSSLSecurity.prototype.toXML = function(headers) {
56
+ return '';
57
+ };
58
+
59
+ ClientSSLSecurity.prototype.addOptions = function(options) {
60
+ var httpsAgent = null;
61
+
62
+ options.key = this.key;
63
+ options.cert = this.cert;
64
+ options.ca = this.ca;
65
+ _.merge(options, this.defaults);
66
+
67
+ if (!!options.forever) {
68
+ if (!this.agent) {
69
+ options.keepAlive = true;
70
+
71
+ this.agent = new https.Agent(options);
72
+ }
73
+
74
+ httpsAgent = this.agent;
75
+ } else {
76
+ httpsAgent = new https.Agent(options);
77
+ }
78
+
79
+ options.agent = httpsAgent;
80
+ };
81
+
82
+ module.exports = ClientSSLSecurity;
@@ -1,51 +1,51 @@
1
- 'use strict';
2
-
3
- var fs = require('fs')
4
- , https = require('https')
5
- , _ = require('lodash');
6
-
7
- /**
8
- * activates SSL for an already existing client using a PFX cert
9
- *
10
- * @module ClientSSLSecurityPFX
11
- * @param {Buffer|String} pfx
12
- * @param {String} passphrase
13
- * @constructor
14
- */
15
- function ClientSSLSecurityPFX(pfx, passphrase, defaults) {
16
- if (typeof passphrase === 'object') {
17
- defaults = passphrase;
18
- }
19
- if (pfx) {
20
- if (Buffer.isBuffer(pfx)) {
21
- this.pfx = pfx;
22
- } else if (typeof pfx === 'string') {
23
- this.pfx = fs.readFileSync(pfx);
24
- } else {
25
- throw new Error('supplied pfx file should be a buffer or a file location');
26
- }
27
- }
28
-
29
- if (passphrase) {
30
- if (typeof passphrase === 'string') {
31
- this.passphrase = passphrase;
32
- }
33
- }
34
- this.defaults = {};
35
- _.merge(this.defaults, defaults);
36
- }
37
-
38
- ClientSSLSecurityPFX.prototype.toXML = function(headers) {
39
- return '';
40
- };
41
-
42
- ClientSSLSecurityPFX.prototype.addOptions = function(options) {
43
- options.pfx = this.pfx;
44
- if (this.passphrase) {
45
- options.passphrase = this.passphrase;
46
- }
47
- _.merge(options, this.defaults);
48
- options.agent = new https.Agent(options);
49
- };
50
-
51
- module.exports = ClientSSLSecurityPFX;
1
+ 'use strict';
2
+
3
+ var fs = require('fs')
4
+ , https = require('https')
5
+ , _ = require('lodash');
6
+
7
+ /**
8
+ * activates SSL for an already existing client using a PFX cert
9
+ *
10
+ * @module ClientSSLSecurityPFX
11
+ * @param {Buffer|String} pfx
12
+ * @param {String} passphrase
13
+ * @constructor
14
+ */
15
+ function ClientSSLSecurityPFX(pfx, passphrase, defaults) {
16
+ if (typeof passphrase === 'object') {
17
+ defaults = passphrase;
18
+ }
19
+ if (pfx) {
20
+ if (Buffer.isBuffer(pfx)) {
21
+ this.pfx = pfx;
22
+ } else if (typeof pfx === 'string') {
23
+ this.pfx = fs.readFileSync(pfx);
24
+ } else {
25
+ throw new Error('supplied pfx file should be a buffer or a file location');
26
+ }
27
+ }
28
+
29
+ if (passphrase) {
30
+ if (typeof passphrase === 'string') {
31
+ this.passphrase = passphrase;
32
+ }
33
+ }
34
+ this.defaults = {};
35
+ _.merge(this.defaults, defaults);
36
+ }
37
+
38
+ ClientSSLSecurityPFX.prototype.toXML = function(headers) {
39
+ return '';
40
+ };
41
+
42
+ ClientSSLSecurityPFX.prototype.addOptions = function(options) {
43
+ options.pfx = this.pfx;
44
+ if (this.passphrase) {
45
+ options.passphrase = this.passphrase;
46
+ }
47
+ _.merge(options, this.defaults);
48
+ options.agent = new https.Agent(options);
49
+ };
50
+
51
+ module.exports = ClientSSLSecurityPFX;
@@ -1,90 +1,90 @@
1
- "use strict";
2
-
3
- var crypto = require('crypto');
4
- var passwordDigest = require('../utils').passwordDigest;
5
- var validPasswordTypes = ['PasswordDigest', 'PasswordText'];
6
-
7
- function WSSecurity(username, password, options) {
8
- options = options || {};
9
- this._username = username;
10
- this._password = password;
11
- //must account for backward compatibility for passwordType String param as well as object options defaults: passwordType = 'PasswordText', hasTimeStamp = true
12
- if (typeof options === 'string') {
13
- this._passwordType = options ? options : 'PasswordText';
14
- options = {};
15
- } else {
16
- this._passwordType = options.passwordType ? options.passwordType : 'PasswordText';
17
- }
18
-
19
- if (validPasswordTypes.indexOf(this._passwordType) === -1) {
20
- this._passwordType = 'PasswordText';
21
- }
22
-
23
- this._hasTimeStamp = options.hasTimeStamp || typeof options.hasTimeStamp === 'boolean' ? !!options.hasTimeStamp : true;
24
- /*jshint eqnull:true */
25
- if (options.hasNonce != null) {
26
- this._hasNonce = !!options.hasNonce;
27
- }
28
- this._hasTokenCreated = options.hasTokenCreated || typeof options.hasTokenCreated === 'boolean' ? !!options.hasTokenCreated : true;
29
- if (options.actor != null) {
30
- this._actor = options.actor;
31
- }
32
- if (options.mustUnderstand != null) {
33
- this._mustUnderstand = !!options.mustUnderstand;
34
- }
35
- }
36
-
37
- WSSecurity.prototype.toXML = function() {
38
- // avoid dependency on date formatting libraries
39
- function getDate(d) {
40
- function pad(n) {
41
- return n < 10 ? '0' + n : n;
42
- }
43
- return d.getUTCFullYear() + '-'
44
- + pad(d.getUTCMonth() + 1) + '-'
45
- + pad(d.getUTCDate()) + 'T'
46
- + pad(d.getUTCHours()) + ':'
47
- + pad(d.getUTCMinutes()) + ':'
48
- + pad(d.getUTCSeconds()) + 'Z';
49
- }
50
- var now = new Date();
51
- var created = getDate(now);
52
- var timeStampXml = '';
53
- if (this._hasTimeStamp) {
54
- var expires = getDate( new Date(now.getTime() + (1000 * 600)) );
55
- timeStampXml = "<wsu:Timestamp wsu:Id=\"Timestamp-"+created+"\">" +
56
- "<wsu:Created>"+created+"</wsu:Created>" +
57
- "<wsu:Expires>"+expires+"</wsu:Expires>" +
58
- "</wsu:Timestamp>";
59
- }
60
-
61
- var password, nonce;
62
- if (this._hasNonce || this._passwordType !== 'PasswordText') {
63
- // nonce = base64 ( sha1 ( created + random ) )
64
- var nHash = crypto.createHash('sha1');
65
- nHash.update(created + Math.random());
66
- nonce = nHash.digest('base64');
67
- }
68
- if (this._passwordType === 'PasswordText') {
69
- password = "<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">" + this._password + "</wsse:Password>";
70
- if (nonce) {
71
- password += "<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">" + nonce + "</wsse:Nonce>";
72
- }
73
- } else {
74
- password = "<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">" + passwordDigest(nonce, created, this._password) + "</wsse:Password>" +
75
- "<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">" + nonce + "</wsse:Nonce>";
76
- }
77
-
78
- return "<wsse:Security " + (this._actor ? "soap:actor=\"" + this._actor + "\" " : "") +
79
- (this._mustUnderstand ? "soap:mustUnderstand=\"1\" " : "") +
80
- "xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" +
81
- timeStampXml +
82
- "<wsse:UsernameToken xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"SecurityToken-" + created + "\">" +
83
- "<wsse:Username>" + this._username + "</wsse:Username>" +
84
- password +
85
- (this._hasTokenCreated ? "<wsu:Created>" + created + "</wsu:Created>" : "") +
86
- "</wsse:UsernameToken>" +
87
- "</wsse:Security>";
88
- };
89
-
90
- module.exports = WSSecurity;
1
+ "use strict";
2
+
3
+ var crypto = require('crypto');
4
+ var passwordDigest = require('../utils').passwordDigest;
5
+ var validPasswordTypes = ['PasswordDigest', 'PasswordText'];
6
+
7
+ function WSSecurity(username, password, options) {
8
+ options = options || {};
9
+ this._username = username;
10
+ this._password = password;
11
+ //must account for backward compatibility for passwordType String param as well as object options defaults: passwordType = 'PasswordText', hasTimeStamp = true
12
+ if (typeof options === 'string') {
13
+ this._passwordType = options ? options : 'PasswordText';
14
+ options = {};
15
+ } else {
16
+ this._passwordType = options.passwordType ? options.passwordType : 'PasswordText';
17
+ }
18
+
19
+ if (validPasswordTypes.indexOf(this._passwordType) === -1) {
20
+ this._passwordType = 'PasswordText';
21
+ }
22
+
23
+ this._hasTimeStamp = options.hasTimeStamp || typeof options.hasTimeStamp === 'boolean' ? !!options.hasTimeStamp : true;
24
+ /*jshint eqnull:true */
25
+ if (options.hasNonce != null) {
26
+ this._hasNonce = !!options.hasNonce;
27
+ }
28
+ this._hasTokenCreated = options.hasTokenCreated || typeof options.hasTokenCreated === 'boolean' ? !!options.hasTokenCreated : true;
29
+ if (options.actor != null) {
30
+ this._actor = options.actor;
31
+ }
32
+ if (options.mustUnderstand != null) {
33
+ this._mustUnderstand = !!options.mustUnderstand;
34
+ }
35
+ }
36
+
37
+ WSSecurity.prototype.toXML = function() {
38
+ // avoid dependency on date formatting libraries
39
+ function getDate(d) {
40
+ function pad(n) {
41
+ return n < 10 ? '0' + n : n;
42
+ }
43
+ return d.getUTCFullYear() + '-'
44
+ + pad(d.getUTCMonth() + 1) + '-'
45
+ + pad(d.getUTCDate()) + 'T'
46
+ + pad(d.getUTCHours()) + ':'
47
+ + pad(d.getUTCMinutes()) + ':'
48
+ + pad(d.getUTCSeconds()) + 'Z';
49
+ }
50
+ var now = new Date();
51
+ var created = getDate(now);
52
+ var timeStampXml = '';
53
+ if (this._hasTimeStamp) {
54
+ var expires = getDate( new Date(now.getTime() + (1000 * 600)) );
55
+ timeStampXml = "<wsu:Timestamp wsu:Id=\"Timestamp-"+created+"\">" +
56
+ "<wsu:Created>"+created+"</wsu:Created>" +
57
+ "<wsu:Expires>"+expires+"</wsu:Expires>" +
58
+ "</wsu:Timestamp>";
59
+ }
60
+
61
+ var password, nonce;
62
+ if (this._hasNonce || this._passwordType !== 'PasswordText') {
63
+ // nonce = base64 ( sha1 ( created + random ) )
64
+ var nHash = crypto.createHash('sha1');
65
+ nHash.update(created + Math.random());
66
+ nonce = nHash.digest('base64');
67
+ }
68
+ if (this._passwordType === 'PasswordText') {
69
+ password = "<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">" + this._password + "</wsse:Password>";
70
+ if (nonce) {
71
+ password += "<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">" + nonce + "</wsse:Nonce>";
72
+ }
73
+ } else {
74
+ password = "<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">" + passwordDigest(nonce, created, this._password) + "</wsse:Password>" +
75
+ "<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">" + nonce + "</wsse:Nonce>";
76
+ }
77
+
78
+ return "<wsse:Security " + (this._actor ? "soap:actor=\"" + this._actor + "\" " : "") +
79
+ (this._mustUnderstand ? "soap:mustUnderstand=\"1\" " : "") +
80
+ "xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" +
81
+ timeStampXml +
82
+ "<wsse:UsernameToken xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"SecurityToken-" + created + "\">" +
83
+ "<wsse:Username>" + this._username + "</wsse:Username>" +
84
+ password +
85
+ (this._hasTokenCreated ? "<wsu:Created>" + created + "</wsu:Created>" : "") +
86
+ "</wsse:UsernameToken>" +
87
+ "</wsse:Security>";
88
+ };
89
+
90
+ module.exports = WSSecurity;
@@ -1,78 +1,78 @@
1
- "use strict";
2
-
3
- var fs = require('fs');
4
- var path = require('path');
5
- var ejs = require('ejs');
6
- var SignedXml = require('xml-crypto').SignedXml;
7
- var uuid = require('uuid');
8
- var wsseSecurityHeaderTemplate = ejs.compile(fs.readFileSync(path.join(__dirname, 'templates', 'wsse-security-header.ejs')).toString());
9
- var wsseSecurityTokenTemplate = ejs.compile(fs.readFileSync(path.join(__dirname, 'templates', 'wsse-security-token.ejs')).toString());
10
-
11
- function addMinutes(date, minutes) {
12
- return new Date(date.getTime() + minutes * 60000);
13
- }
14
-
15
- function dateStringForSOAP(date) {
16
- return date.getUTCFullYear() + '-' + ('0' + (date.getUTCMonth() + 1)).slice(-2) + '-' +
17
- ('0' + date.getUTCDate()).slice(-2) + 'T' + ('0' + date.getUTCHours()).slice(-2) + ":" +
18
- ('0' + date.getUTCMinutes()).slice(-2) + ":" + ('0' + date.getUTCSeconds()).slice(-2) + "Z";
19
- }
20
-
21
- function generateCreated() {
22
- return dateStringForSOAP(new Date());
23
- }
24
-
25
- function generateExpires() {
26
- return dateStringForSOAP(addMinutes(new Date(), 10));
27
- }
28
-
29
- function insertStr(src, dst, pos) {
30
- return [dst.slice(0, pos), src, dst.slice(pos)].join('');
31
- }
32
-
33
- function generateId() {
34
- return uuid.v4().replace(/-/gm, '');
35
- }
36
-
37
- function WSSecurityCert(privatePEM, publicP12PEM, password) {
38
- this.publicP12PEM = publicP12PEM.toString().replace('-----BEGIN CERTIFICATE-----', '').replace('-----END CERTIFICATE-----', '').replace(/(\r\n|\n|\r)/gm, '');
39
-
40
- this.signer = new SignedXml();
41
- this.signer.signingKey = {
42
- key: privatePEM,
43
- passphrase: password
44
- };
45
- this.x509Id = "x509-" + generateId();
46
-
47
- var _this = this;
48
- this.signer.keyInfoProvider = {};
49
- this.signer.keyInfoProvider.getKeyInfo = function (key) {
50
- return wsseSecurityTokenTemplate({ x509Id: _this.x509Id });
51
- };
52
- }
53
-
54
- WSSecurityCert.prototype.postProcess = function (xml, envelopeKey) {
55
- this.created = generateCreated();
56
- this.expires = generateExpires();
57
-
58
- var secHeader = wsseSecurityHeaderTemplate({
59
- binaryToken: this.publicP12PEM,
60
- created: this.created,
61
- expires: this.expires,
62
- id: this.x509Id
63
- });
64
-
65
- var xmlWithSec = insertStr(secHeader, xml, xml.indexOf('</soap:Header>'));
66
-
67
- var references = ["http://www.w3.org/2000/09/xmldsig#enveloped-signature",
68
- "http://www.w3.org/2001/10/xml-exc-c14n#"];
69
-
70
- this.signer.addReference("//*[name(.)='" + envelopeKey + ":Body']", references);
71
- this.signer.addReference("//*[name(.)='wsse:Security']/*[local-name(.)='Timestamp']", references);
72
-
73
- this.signer.computeSignature(xmlWithSec);
74
-
75
- return insertStr(this.signer.getSignatureXml(), xmlWithSec, xmlWithSec.indexOf('</wsse:Security>'));
76
- };
77
-
78
- module.exports = WSSecurityCert;
1
+ "use strict";
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var ejs = require('ejs');
6
+ var SignedXml = require('xml-crypto').SignedXml;
7
+ var uuid4 = require('uuid/v4');
8
+ var wsseSecurityHeaderTemplate = ejs.compile(fs.readFileSync(path.join(__dirname, 'templates', 'wsse-security-header.ejs')).toString());
9
+ var wsseSecurityTokenTemplate = ejs.compile(fs.readFileSync(path.join(__dirname, 'templates', 'wsse-security-token.ejs')).toString());
10
+
11
+ function addMinutes(date, minutes) {
12
+ return new Date(date.getTime() + minutes * 60000);
13
+ }
14
+
15
+ function dateStringForSOAP(date) {
16
+ return date.getUTCFullYear() + '-' + ('0' + (date.getUTCMonth() + 1)).slice(-2) + '-' +
17
+ ('0' + date.getUTCDate()).slice(-2) + 'T' + ('0' + date.getUTCHours()).slice(-2) + ":" +
18
+ ('0' + date.getUTCMinutes()).slice(-2) + ":" + ('0' + date.getUTCSeconds()).slice(-2) + "Z";
19
+ }
20
+
21
+ function generateCreated() {
22
+ return dateStringForSOAP(new Date());
23
+ }
24
+
25
+ function generateExpires() {
26
+ return dateStringForSOAP(addMinutes(new Date(), 10));
27
+ }
28
+
29
+ function insertStr(src, dst, pos) {
30
+ return [dst.slice(0, pos), src, dst.slice(pos)].join('');
31
+ }
32
+
33
+ function generateId() {
34
+ return uuid4().replace(/-/gm, '');
35
+ }
36
+
37
+ function WSSecurityCert(privatePEM, publicP12PEM, password) {
38
+ this.publicP12PEM = publicP12PEM.toString().replace('-----BEGIN CERTIFICATE-----', '').replace('-----END CERTIFICATE-----', '').replace(/(\r\n|\n|\r)/gm, '');
39
+
40
+ this.signer = new SignedXml();
41
+ this.signer.signingKey = {
42
+ key: privatePEM,
43
+ passphrase: password
44
+ };
45
+ this.x509Id = "x509-" + generateId();
46
+
47
+ var _this = this;
48
+ this.signer.keyInfoProvider = {};
49
+ this.signer.keyInfoProvider.getKeyInfo = function (key) {
50
+ return wsseSecurityTokenTemplate({ x509Id: _this.x509Id });
51
+ };
52
+ }
53
+
54
+ WSSecurityCert.prototype.postProcess = function (xml, envelopeKey) {
55
+ this.created = generateCreated();
56
+ this.expires = generateExpires();
57
+
58
+ var secHeader = wsseSecurityHeaderTemplate({
59
+ binaryToken: this.publicP12PEM,
60
+ created: this.created,
61
+ expires: this.expires,
62
+ id: this.x509Id
63
+ });
64
+
65
+ var xmlWithSec = insertStr(secHeader, xml, xml.indexOf('</soap:Header>'));
66
+
67
+ var references = ["http://www.w3.org/2000/09/xmldsig#enveloped-signature",
68
+ "http://www.w3.org/2001/10/xml-exc-c14n#"];
69
+
70
+ this.signer.addReference("//*[name(.)='" + envelopeKey + ":Body']", references);
71
+ this.signer.addReference("//*[name(.)='wsse:Security']/*[local-name(.)='Timestamp']", references);
72
+
73
+ this.signer.computeSignature(xmlWithSec);
74
+
75
+ return insertStr(this.signer.getSignatureXml(), xmlWithSec, xmlWithSec.indexOf('</wsse:Security>'));
76
+ };
77
+
78
+ module.exports = WSSecurityCert;
@@ -1,10 +1,10 @@
1
- "use strict";
2
-
3
- module.exports = {
4
- BasicAuthSecurity: require('./BasicAuthSecurity')
5
- , ClientSSLSecurity: require('./ClientSSLSecurity')
6
- , ClientSSLSecurityPFX: require('./ClientSSLSecurityPFX')
7
- , WSSecurity: require('./WSSecurity')
8
- , BearerSecurity: require('./BearerSecurity')
9
- , WSSecurityCert: require('./WSSecurityCert')
10
- };
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ BasicAuthSecurity: require('./BasicAuthSecurity')
5
+ , ClientSSLSecurity: require('./ClientSSLSecurity')
6
+ , ClientSSLSecurityPFX: require('./ClientSSLSecurityPFX')
7
+ , WSSecurity: require('./WSSecurity')
8
+ , BearerSecurity: require('./BearerSecurity')
9
+ , WSSecurityCert: require('./WSSecurityCert')
10
+ };
@@ -1,12 +1,12 @@
1
- <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
2
- xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
3
- soap:mustUnderstand="1">
4
- <wsse:BinarySecurityToken
5
- EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
6
- ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"
7
- wsu:Id="<%-id%>"><%-binaryToken%></wsse:BinarySecurityToken>
8
- <Timestamp xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" Id="_1">
9
- <Created><%-created%></Created>
10
- <Expires><%-expires%></Expires>
11
- </Timestamp>
12
- </wsse:Security>
1
+ <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
2
+ xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
3
+ soap:mustUnderstand="1">
4
+ <wsse:BinarySecurityToken
5
+ EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
6
+ ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"
7
+ wsu:Id="<%-id%>"><%-binaryToken%></wsse:BinarySecurityToken>
8
+ <Timestamp xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" Id="_1">
9
+ <Created><%-created%></Created>
10
+ <Expires><%-expires%></Expires>
11
+ </Timestamp>
12
+ </wsse:Security>
@@ -1,3 +1,3 @@
1
- <wsse:SecurityTokenReference>
2
- <wsse:Reference URI="#<%-x509Id%>" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
3
- </wsse:SecurityTokenReference>
1
+ <wsse:SecurityTokenReference>
2
+ <wsse:Reference URI="#<%-x509Id%>" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
3
+ </wsse:SecurityTokenReference>