@webex/internal-plugin-encryption 2.60.1-next.9 → 2.60.2
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.
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/encryption.js +20 -23
- package/dist/encryption.js.map +1 -1
- package/dist/ensure-buffer.browser.js.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/kms-batcher.js +4 -3
- package/dist/kms-batcher.js.map +1 -1
- package/dist/kms-certificate-validation.js +10 -8
- package/dist/kms-certificate-validation.js.map +1 -1
- package/dist/kms-dry-error-interceptor.js +3 -4
- package/dist/kms-dry-error-interceptor.js.map +1 -1
- package/dist/kms-errors.js +8 -17
- package/dist/kms-errors.js.map +1 -1
- package/dist/kms.js +8 -10
- package/dist/kms.js.map +1 -1
- package/package.json +20 -21
- package/src/encryption.js +23 -30
- package/src/kms-batcher.js +1 -3
- package/src/kms-certificate-validation.js +3 -3
- package/src/kms-errors.js +0 -20
- package/test/integration/spec/encryption.js +1 -2
- package/test/integration/spec/kms.js +1 -0
- package/test/unit/spec/encryption.js +10 -10
- package/test/unit/spec/kms-certificate-validation.js +1 -34
- package/dist/constants.js +0 -11
- package/dist/constants.js.map +0 -1
- package/src/constants.js +0 -3
- package/test/unit/spec/kms-errors.js +0 -70
package/dist/config.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
/*!
|
|
9
9
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
10
10
|
*/
|
|
11
|
-
var _default =
|
|
11
|
+
var _default = {
|
|
12
12
|
encryption: {
|
|
13
13
|
joseOptions: {
|
|
14
14
|
compact: true,
|
|
@@ -48,4 +48,5 @@ var _default = exports.default = {
|
|
|
48
48
|
batcherMaxWait: 150
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
+
exports.default = _default;
|
|
51
52
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_default","
|
|
1
|
+
{"version":3,"names":["_default","encryption","joseOptions","compact","contentAlg","protect","kmsInitialTimeout","kmsMaxTimeout","ecdhMaxTimeout","batcherWait","batcherMaxCalls","batcherMaxWait","exports","default"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport default {\n encryption: {\n joseOptions: {\n compact: true,\n contentAlg: 'A256GCM',\n protect: '*',\n },\n\n /**\n * Initial timeout before contacting KMS with a new request\n * @type {Number}\n */\n kmsInitialTimeout: 6000,\n\n /**\n * Maximum timeout before negotiating a new ECDH key\n * and contacting KMS with a new request\n * @type {Number}\n */\n kmsMaxTimeout: 32000,\n\n /**\n * Maximum timeout after negotiating several ECDH keys\n * @type {Number}\n */\n ecdhMaxTimeout: 32000 * 3,\n\n /**\n * Debounce wait before sending a kms request\n * @type {Number}\n */\n batcherWait: 50,\n\n /**\n * Maximum queue size before sending a kms request\n * @type {Number}\n */\n batcherMaxCalls: 50,\n\n /**\n * Debounce max wait before sending a kms metric\n * @type {Number}\n */\n batcherMaxWait: 150,\n },\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAFA,IAAAA,QAAA,GAIe;EACbC,UAAU,EAAE;IACVC,WAAW,EAAE;MACXC,OAAO,EAAE,IAAI;MACbC,UAAU,EAAE,SAAS;MACrBC,OAAO,EAAE;IACX,CAAC;IAED;AACJ;AACA;AACA;IACIC,iBAAiB,EAAE,IAAI;IAEvB;AACJ;AACA;AACA;AACA;IACIC,aAAa,EAAE,KAAK;IAEpB;AACJ;AACA;AACA;IACIC,cAAc,EAAE,KAAK,GAAG,CAAC;IAEzB;AACJ;AACA;AACA;IACIC,WAAW,EAAE,EAAE;IAEf;AACJ;AACA;AACA;IACIC,eAAe,EAAE,EAAE;IAEnB;AACJ;AACA;AACA;IACIC,cAAc,EAAE;EAClB;AACF,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAb,QAAA"}
|
package/dist/encryption.js
CHANGED
|
@@ -22,10 +22,8 @@ var _nodeJose = _interopRequireDefault(require("node-jose"));
|
|
|
22
22
|
var _nodeScr = _interopRequireDefault(require("node-scr"));
|
|
23
23
|
var _ensureBuffer = _interopRequireDefault(require("./ensure-buffer"));
|
|
24
24
|
var _kms = _interopRequireDefault(require("./kms"));
|
|
25
|
-
function ownKeys(
|
|
26
|
-
function _objectSpread(
|
|
27
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
28
|
-
*/
|
|
25
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
26
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
27
|
var Encryption = _webexCore.WebexPlugin.extend({
|
|
30
28
|
children: {
|
|
31
29
|
kms: _kms.default
|
|
@@ -75,19 +73,19 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
75
73
|
},
|
|
76
74
|
/**
|
|
77
75
|
* Validate and initiate a Download request for requested file
|
|
78
|
-
*
|
|
76
|
+
*
|
|
79
77
|
* @param {Object} scr - Plaintext
|
|
80
78
|
* @param {Object} options - optional parameters to download a file
|
|
81
79
|
* @returns {promise}
|
|
82
80
|
*/
|
|
83
|
-
download: function download(
|
|
81
|
+
download: function download(scr, options) {
|
|
84
82
|
var _this = this;
|
|
85
83
|
/* istanbul ignore if */
|
|
86
|
-
if (!
|
|
87
|
-
return _promise.default.reject(new Error('`scr`
|
|
84
|
+
if (!scr.loc) {
|
|
85
|
+
return _promise.default.reject(new Error('`scr.loc` is required'));
|
|
88
86
|
}
|
|
89
87
|
var shunt = new _events.EventEmitter();
|
|
90
|
-
var promise = this._fetchDownloadUrl(
|
|
88
|
+
var promise = this._fetchDownloadUrl(scr, options).then(function (uri) {
|
|
91
89
|
// eslint-disable-next-line no-shadow
|
|
92
90
|
var options = {
|
|
93
91
|
method: 'GET',
|
|
@@ -105,21 +103,22 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
105
103
|
},
|
|
106
104
|
/**
|
|
107
105
|
* Fetch Download URL for the requested file
|
|
108
|
-
*
|
|
106
|
+
*
|
|
107
|
+
* @param {Object} scr - Plaintext
|
|
109
108
|
* @param {Object} options - optional parameters to download a file
|
|
110
109
|
* @returns {promise} url of the downloadable file
|
|
111
110
|
*/
|
|
112
|
-
_fetchDownloadUrl: function _fetchDownloadUrl(
|
|
111
|
+
_fetchDownloadUrl: function _fetchDownloadUrl(scr, options) {
|
|
113
112
|
var _this2 = this;
|
|
114
113
|
this.logger.info('encryption: retrieving download url for encrypted file');
|
|
115
|
-
if (process.env.NODE_ENV !== 'production' &&
|
|
114
|
+
if (process.env.NODE_ENV !== 'production' && scr.loc.includes('localhost')) {
|
|
116
115
|
this.logger.info('encryption: bypassing webex files because this looks to be a test file on localhost');
|
|
117
|
-
return _promise.default.resolve(
|
|
116
|
+
return _promise.default.resolve(scr.loc);
|
|
118
117
|
}
|
|
119
118
|
var inputBody = {
|
|
120
|
-
endpoints: [
|
|
119
|
+
endpoints: [scr.loc]
|
|
121
120
|
};
|
|
122
|
-
var endpointUrl = _url.default.parse(
|
|
121
|
+
var endpointUrl = _url.default.parse(scr.loc);
|
|
123
122
|
|
|
124
123
|
// hardcode the url to use 'https' and the file service '/v1/download/endpoints' api
|
|
125
124
|
endpointUrl.protocol = 'https';
|
|
@@ -132,16 +131,13 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
132
131
|
}) : inputBody
|
|
133
132
|
}).then(function (res) {
|
|
134
133
|
// eslint-disable-next-line no-shadow
|
|
135
|
-
var url = res.body.endpoints[
|
|
134
|
+
var url = res.body.endpoints[scr.loc];
|
|
136
135
|
if (!url) {
|
|
137
|
-
_this2.logger.warn('encryption: could not determine download url for `
|
|
138
|
-
return
|
|
136
|
+
_this2.logger.warn('encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly');
|
|
137
|
+
return scr.loc;
|
|
139
138
|
}
|
|
140
139
|
_this2.logger.info('encryption: retrieved download url for encrypted file');
|
|
141
140
|
return url;
|
|
142
|
-
}).catch(function (err) {
|
|
143
|
-
_this2.logger.warn("encryption: ".concat(err, " could not determine download url for ").concat(fileUrl, "; attempting to download ").concat(fileUrl, " directly"));
|
|
144
|
-
return fileUrl;
|
|
145
141
|
});
|
|
146
142
|
},
|
|
147
143
|
encryptBinary: function encryptBinary(file) {
|
|
@@ -229,7 +225,7 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
229
225
|
}));
|
|
230
226
|
});
|
|
231
227
|
},
|
|
232
|
-
version: "2.60.
|
|
228
|
+
version: "2.60.2"
|
|
233
229
|
});
|
|
234
230
|
|
|
235
231
|
/**
|
|
@@ -247,5 +243,6 @@ function replacer(k, v) {
|
|
|
247
243
|
}
|
|
248
244
|
return v;
|
|
249
245
|
}
|
|
250
|
-
var _default =
|
|
246
|
+
var _default = Encryption;
|
|
247
|
+
exports.default = _default;
|
|
251
248
|
//# sourceMappingURL=encryption.js.map
|
package/dist/encryption.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_events","require","_url","_interopRequireDefault","_webexCore","_common","_nodeJose","_nodeScr","_ensureBuffer","_kms","ownKeys","e","r","t","_Object$keys","_Object$getOwnPropertySymbols","o","filter","_Object$getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","Object","forEach","_defineProperty2","default","_Object$getOwnPropertyDescriptors","_Object$defineProperties","_Object$defineProperty","Encryption","WebexPlugin","extend","children","kms","KMS","namespace","processKmsMessageEvent","event","decryptBinary","scr","buffer","ensureBuffer","then","b","byteLength","_promise","reject","Error","decrypt","decryptScr","key","cipherScr","options","getKey","k","SCR","fromJWE","jwk","decryptText","ciphertext","jose","JWE","createDecrypt","result","plaintext","toString","download","fileUrl","_this","shunt","EventEmitter","promise","_fetchDownloadUrl","uri","method","responseType","ret","request","transferEvents","res","body","proxyEvents","_this2","logger","info","process","env","NODE_ENV","includes","resolve","inputBody","endpoints","endpointUrl","url","parse","protocol","pathname","format","allow","params","warn","catch","err","concat","encryptBinary","file","create","encrypt","cdata","encryptScr","loc","toJWE","encryptText","_this3","createEncrypt","config","joseOptions","header","alg","reference","final","_this4","_ref","undefined","onBehalfOf","asKey","storageKey","unboundedStorage","get","keyString","JSON","keyObject","fetchKey","tap","put","_stringify","replacer","version","v","json","toJSON","_default","exports"],"sources":["encryption.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {EventEmitter} from 'events';\nimport url from 'url';\n\nimport {WebexPlugin} from '@webex/webex-core';\nimport {proxyEvents, tap, transferEvents} from '@webex/common';\nimport jose from 'node-jose';\nimport SCR from 'node-scr';\n\nimport ensureBuffer from './ensure-buffer';\nimport KMS from './kms';\n\nconst Encryption = WebexPlugin.extend({\n children: {\n kms: KMS,\n },\n\n namespace: 'Encryption',\n\n processKmsMessageEvent(event) {\n return this.kms.processKmsMessageEvent(event);\n },\n\n decryptBinary(scr, buffer) {\n return ensureBuffer(buffer).then((b) => {\n /* istanbul ignore if */\n if (buffer.length === 0 || buffer.byteLength === 0) {\n return Promise.reject(new Error('Attempted to decrypt zero-length buffer'));\n }\n\n return scr.decrypt(b);\n });\n },\n\n /**\n * Decrypt a SCR (Secure Content Resource) using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {Object} cipherScr - An encrypted SCR\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {Object} Decrypted SCR\n */\n decryptScr(key, cipherScr, options) {\n return this.getKey(key, options).then((k) => SCR.fromJWE(k.jwk, cipherScr));\n },\n\n /**\n * Decrypt text using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {string} ciphertext - Encrypted text\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Decrypted plaintext\n */\n decryptText(key, ciphertext, options) {\n return this.getKey(key, options).then((k) =>\n jose.JWE.createDecrypt(k.jwk)\n .decrypt(ciphertext)\n .then((result) => result.plaintext.toString())\n );\n },\n\n /**\n * Validate and initiate a Download request for requested file\n * @param {Object} fileUrl - Plaintext\n * @param {Object} scr - Plaintext\n * @param {Object} options - optional parameters to download a file\n * @returns {promise}\n */\n download(fileUrl, scr, options) {\n /* istanbul ignore if */\n if (!fileUrl || !scr) {\n return Promise.reject(new Error('`scr` and `fileUrl` are required'));\n }\n\n const shunt = new EventEmitter();\n const promise = this._fetchDownloadUrl(fileUrl, options)\n .then((uri) => {\n // eslint-disable-next-line no-shadow\n const options = {\n method: 'GET',\n uri,\n responseType: 'buffer',\n };\n\n const ret = this.request(options);\n\n transferEvents('progress', options.download, shunt);\n\n return ret;\n })\n .then((res) => this.decryptBinary(scr, res.body));\n\n proxyEvents(shunt, promise);\n\n return promise;\n },\n\n /**\n * Fetch Download URL for the requested file\n * @param {Object} fileUrl - Plaintext\n * @param {Object} options - optional parameters to download a file\n * @returns {promise} url of the downloadable file\n */\n _fetchDownloadUrl(fileUrl, options) {\n this.logger.info('encryption: retrieving download url for encrypted file');\n\n if (process.env.NODE_ENV !== 'production' && fileUrl.includes('localhost')) {\n this.logger.info(\n 'encryption: bypassing webex files because this looks to be a test file on localhost'\n );\n\n return Promise.resolve(fileUrl);\n }\n\n const inputBody = {\n endpoints: [fileUrl],\n };\n const endpointUrl = url.parse(fileUrl);\n\n // hardcode the url to use 'https' and the file service '/v1/download/endpoints' api\n endpointUrl.protocol = 'https';\n endpointUrl.pathname = '/v1/download/endpoints';\n\n return this.request({\n method: 'POST',\n uri: url.format(endpointUrl),\n body: options\n ? {\n ...inputBody,\n allow: options.params.allow,\n }\n : inputBody,\n })\n .then((res) => {\n // eslint-disable-next-line no-shadow\n const url = res.body.endpoints[fileUrl];\n\n if (!url) {\n this.logger.warn(\n 'encryption: could not determine download url for `fileUrl`; attempting to download `fileUrl` directly'\n );\n\n return fileUrl;\n }\n this.logger.info('encryption: retrieved download url for encrypted file');\n\n return url;\n })\n .catch((err) => {\n this.logger.warn(\n `encryption: ${err} could not determine download url for ${fileUrl}; attempting to download ${fileUrl} directly`\n );\n\n return fileUrl;\n });\n },\n\n encryptBinary(file) {\n return ensureBuffer(file).then((buffer) =>\n SCR.create().then((scr) =>\n scr\n .encrypt(buffer)\n .then(ensureBuffer)\n // eslint-disable-next-line max-nested-callbacks\n .then((cdata) => ({scr, cdata}))\n )\n );\n },\n\n /**\n * Encrypt a SCR (Secure Content Resource) using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {Object} scr - Plaintext\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Encrypted SCR\n */\n encryptScr(key, scr, options) {\n /* istanbul ignore if */\n if (!scr.loc) {\n return Promise.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));\n }\n\n return this.getKey(key, options).then((k) => scr.toJWE(k.jwk));\n },\n\n /**\n * Encrypt plaintext using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {string} plaintext\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Encrypted text\n */\n encryptText(key, plaintext, options) {\n return this.getKey(key, options).then((k) =>\n jose.JWE.createEncrypt(this.config.joseOptions, {\n key: k.jwk,\n header: {\n alg: 'dir',\n },\n reference: null,\n }).final(plaintext, 'utf8')\n );\n },\n\n /**\n * Fetch the key associated with the supplied KMS uri.\n *\n * @param {string} uri - The uri of a key stored in KMS\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Key\n */\n getKey(uri, {onBehalfOf} = {}) {\n if (uri.jwk) {\n return this.kms.asKey(uri);\n }\n\n let storageKey = uri;\n\n if (onBehalfOf) {\n storageKey += `/onBehalfOf/${onBehalfOf}`;\n }\n\n return this.unboundedStorage\n .get(storageKey)\n .then((keyString) => JSON.parse(keyString))\n .then((keyObject) => this.kms.asKey(keyObject))\n .catch(() =>\n this.kms\n .fetchKey({uri, onBehalfOf})\n .then(tap((key) => this.unboundedStorage.put(storageKey, JSON.stringify(key, replacer))))\n );\n },\n});\n\n/**\n * JSON.stringify replacer that ensures private key data is serialized.\n * @param {string} k\n * @param {mixed} v\n * @returns {mixed}\n */\nfunction replacer(k, v) {\n if (k === 'jwk') {\n // note: this[k] and v may be different representations of the same value\n // eslint-disable-next-line no-invalid-this\n const json = this[k].toJSON(true);\n\n return json;\n }\n\n return v;\n}\n\nexport default Encryption;\n"],"mappings":";;;;;;;;;;;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,QAAA,GAAAJ,sBAAA,CAAAF,OAAA;AAEA,IAAAO,aAAA,GAAAL,sBAAA,CAAAF,OAAA;AACA,IAAA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C,KAAK,KAAK,EAAE;IACf;IACA;IACA,IAAMqF,IAAI,GAAG,IAAI,CAACrF,CAAC,CAAC,CAACsF,MAAM,CAAC,IAAI,CAAC;IAEjC,OAAOD,IAAI;EACb;EAEA,OAAOD,CAAC;AACV;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAArH,OAAA,GAEcI,UAAU"}
|
|
1
|
+
{"version":3,"names":["_events","require","_url","_interopRequireDefault","_webexCore","_common","_nodeJose","_nodeScr","_ensureBuffer","_kms","ownKeys","object","enumerableOnly","keys","_Object$keys","_Object$getOwnPropertySymbols","symbols","filter","sym","_Object$getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","Object","forEach","key","_defineProperty2","default","_Object$getOwnPropertyDescriptors","_Object$defineProperties","_Object$defineProperty","Encryption","WebexPlugin","extend","children","kms","KMS","namespace","processKmsMessageEvent","event","decryptBinary","scr","buffer","ensureBuffer","then","b","byteLength","_promise","reject","Error","decrypt","decryptScr","cipherScr","options","getKey","k","SCR","fromJWE","jwk","decryptText","ciphertext","jose","JWE","createDecrypt","result","plaintext","toString","download","_this","loc","shunt","EventEmitter","promise","_fetchDownloadUrl","uri","method","responseType","ret","request","transferEvents","res","body","proxyEvents","_this2","logger","info","process","env","NODE_ENV","includes","resolve","inputBody","endpoints","endpointUrl","url","parse","protocol","pathname","format","allow","params","warn","encryptBinary","file","create","encrypt","cdata","encryptScr","toJWE","encryptText","_this3","createEncrypt","config","joseOptions","header","alg","reference","final","_this4","_ref","undefined","onBehalfOf","asKey","storageKey","concat","unboundedStorage","get","keyString","JSON","keyObject","catch","fetchKey","tap","put","_stringify","replacer","version","v","json","toJSON","_default","exports"],"sources":["encryption.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {EventEmitter} from 'events';\nimport url from 'url';\n\nimport {WebexPlugin} from '@webex/webex-core';\nimport {proxyEvents, tap, transferEvents} from '@webex/common';\nimport jose from 'node-jose';\nimport SCR from 'node-scr';\n\nimport ensureBuffer from './ensure-buffer';\nimport KMS from './kms';\n\nconst Encryption = WebexPlugin.extend({\n children: {\n kms: KMS,\n },\n\n namespace: 'Encryption',\n\n processKmsMessageEvent(event) {\n return this.kms.processKmsMessageEvent(event);\n },\n\n decryptBinary(scr, buffer) {\n return ensureBuffer(buffer).then((b) => {\n /* istanbul ignore if */\n if (buffer.length === 0 || buffer.byteLength === 0) {\n return Promise.reject(new Error('Attempted to decrypt zero-length buffer'));\n }\n\n return scr.decrypt(b);\n });\n },\n\n /**\n * Decrypt a SCR (Secure Content Resource) using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {Object} cipherScr - An encrypted SCR\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {Object} Decrypted SCR\n */\n decryptScr(key, cipherScr, options) {\n return this.getKey(key, options).then((k) => SCR.fromJWE(k.jwk, cipherScr));\n },\n\n /**\n * Decrypt text using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {string} ciphertext - Encrypted text\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Decrypted plaintext\n */\n decryptText(key, ciphertext, options) {\n return this.getKey(key, options).then((k) =>\n jose.JWE.createDecrypt(k.jwk)\n .decrypt(ciphertext)\n .then((result) => result.plaintext.toString())\n );\n },\n\n /**\n * Validate and initiate a Download request for requested file\n *\n * @param {Object} scr - Plaintext\n * @param {Object} options - optional parameters to download a file\n * @returns {promise}\n */\n download(scr, options) {\n /* istanbul ignore if */\n if (!scr.loc) {\n return Promise.reject(new Error('`scr.loc` is required'));\n }\n\n const shunt = new EventEmitter();\n const promise = this._fetchDownloadUrl(scr, options)\n .then((uri) => {\n // eslint-disable-next-line no-shadow\n const options = {\n method: 'GET',\n uri,\n responseType: 'buffer',\n };\n\n const ret = this.request(options);\n\n transferEvents('progress', options.download, shunt);\n\n return ret;\n })\n .then((res) => this.decryptBinary(scr, res.body));\n\n proxyEvents(shunt, promise);\n\n return promise;\n },\n\n /**\n * Fetch Download URL for the requested file\n *\n * @param {Object} scr - Plaintext\n * @param {Object} options - optional parameters to download a file\n * @returns {promise} url of the downloadable file\n */\n _fetchDownloadUrl(scr, options) {\n this.logger.info('encryption: retrieving download url for encrypted file');\n\n if (process.env.NODE_ENV !== 'production' && scr.loc.includes('localhost')) {\n this.logger.info(\n 'encryption: bypassing webex files because this looks to be a test file on localhost'\n );\n\n return Promise.resolve(scr.loc);\n }\n\n const inputBody = {\n endpoints: [scr.loc],\n };\n const endpointUrl = url.parse(scr.loc);\n\n // hardcode the url to use 'https' and the file service '/v1/download/endpoints' api\n endpointUrl.protocol = 'https';\n endpointUrl.pathname = '/v1/download/endpoints';\n\n return this.request({\n method: 'POST',\n uri: url.format(endpointUrl),\n body: options\n ? {\n ...inputBody,\n allow: options.params.allow,\n }\n : inputBody,\n }).then((res) => {\n // eslint-disable-next-line no-shadow\n const url = res.body.endpoints[scr.loc];\n\n if (!url) {\n this.logger.warn(\n 'encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly'\n );\n\n return scr.loc;\n }\n this.logger.info('encryption: retrieved download url for encrypted file');\n\n return url;\n });\n },\n\n encryptBinary(file) {\n return ensureBuffer(file).then((buffer) =>\n SCR.create().then((scr) =>\n scr\n .encrypt(buffer)\n .then(ensureBuffer)\n // eslint-disable-next-line max-nested-callbacks\n .then((cdata) => ({scr, cdata}))\n )\n );\n },\n\n /**\n * Encrypt a SCR (Secure Content Resource) using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {Object} scr - Plaintext\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Encrypted SCR\n */\n encryptScr(key, scr, options) {\n /* istanbul ignore if */\n if (!scr.loc) {\n return Promise.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));\n }\n\n return this.getKey(key, options).then((k) => scr.toJWE(k.jwk));\n },\n\n /**\n * Encrypt plaintext using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {string} plaintext\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Encrypted text\n */\n encryptText(key, plaintext, options) {\n return this.getKey(key, options).then((k) =>\n jose.JWE.createEncrypt(this.config.joseOptions, {\n key: k.jwk,\n header: {\n alg: 'dir',\n },\n reference: null,\n }).final(plaintext, 'utf8')\n );\n },\n\n /**\n * Fetch the key associated with the supplied KMS uri.\n *\n * @param {string} uri - The uri of a key stored in KMS\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Key\n */\n getKey(uri, {onBehalfOf} = {}) {\n if (uri.jwk) {\n return this.kms.asKey(uri);\n }\n\n let storageKey = uri;\n\n if (onBehalfOf) {\n storageKey += `/onBehalfOf/${onBehalfOf}`;\n }\n\n return this.unboundedStorage\n .get(storageKey)\n .then((keyString) => JSON.parse(keyString))\n .then((keyObject) => this.kms.asKey(keyObject))\n .catch(() =>\n this.kms\n .fetchKey({uri, onBehalfOf})\n .then(tap((key) => this.unboundedStorage.put(storageKey, JSON.stringify(key, replacer))))\n );\n },\n});\n\n/**\n * JSON.stringify replacer that ensures private key data is serialized.\n * @param {string} k\n * @param {mixed} v\n * @returns {mixed}\n */\nfunction replacer(k, v) {\n if (k === 'jwk') {\n // note: this[k] and v may be different representations of the same value\n // eslint-disable-next-line no-invalid-this\n const json = this[k].toJSON(true);\n\n return json;\n }\n\n return v;\n}\n\nexport default Encryption;\n"],"mappings":";;;;;;;;;;;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,G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A;AACA,SAASD,QAAQA,CAAChF,CAAC,EAAEkF,CAAC,EAAE;EACtB,IAAIlF,CAAC,KAAK,KAAK,EAAE;IACf;IACA;IACA,IAAMmF,IAAI,GAAG,IAAI,CAACnF,CAAC,CAAC,CAACoF,MAAM,CAAC,IAAI,CAAC;IAEjC,OAAOD,IAAI;EACb;EAEA,OAAOD,CAAC;AACV;AAAC,IAAAG,QAAA,GAEc7G,UAAU;AAAA8G,OAAA,CAAAlH,OAAA,GAAAiH,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ensureBuffer","buffer","ArrayBuffer","_promise","default","resolve","toArrayBuffer","reject","fr","FileReader","onload","Uint8Array","result","onerror","readAsArrayBuffer"],"sources":["ensure-buffer.browser.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env: browser */\n\n/**\n * Ensures the provider buffer is, indeed, an ArrayBuffer; converts File and\n * Blob objects to ArrayBuffers.\n * @param {mixed} buffer\n * @returns {Promise<ArrayBuffer>}\n */\nexport default function ensureBuffer(buffer) {\n if (buffer instanceof ArrayBuffer) {\n return Promise.resolve(buffer);\n }\n\n if (buffer.toArrayBuffer) {\n return Promise.resolve(buffer.toArrayBuffer());\n }\n\n if (buffer.buffer) {\n return Promise.resolve(buffer.buffer);\n }\n\n return new Promise((resolve, reject) => {\n const fr = new FileReader();\n\n fr.onload = function onload() {\n resolve(new Uint8Array(this.result));\n };\n\n fr.onerror = reject;\n\n fr.readAsArrayBuffer(buffer);\n });\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAYA,CAACC,MAAM,EAAE;EAC3C,IAAIA,MAAM,YAAYC,WAAW,EAAE;IACjC,OAAOC,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAAC;EAChC;EAEA,IAAIA,MAAM,CAACK,aAAa,EAAE;IACxB,OAAOH,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAACK,aAAa,
|
|
1
|
+
{"version":3,"names":["ensureBuffer","buffer","ArrayBuffer","_promise","default","resolve","toArrayBuffer","reject","fr","FileReader","onload","Uint8Array","result","onerror","readAsArrayBuffer"],"sources":["ensure-buffer.browser.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env: browser */\n\n/**\n * Ensures the provider buffer is, indeed, an ArrayBuffer; converts File and\n * Blob objects to ArrayBuffers.\n * @param {mixed} buffer\n * @returns {Promise<ArrayBuffer>}\n */\nexport default function ensureBuffer(buffer) {\n if (buffer instanceof ArrayBuffer) {\n return Promise.resolve(buffer);\n }\n\n if (buffer.toArrayBuffer) {\n return Promise.resolve(buffer.toArrayBuffer());\n }\n\n if (buffer.buffer) {\n return Promise.resolve(buffer.buffer);\n }\n\n return new Promise((resolve, reject) => {\n const fr = new FileReader();\n\n fr.onload = function onload() {\n resolve(new Uint8Array(this.result));\n };\n\n fr.onerror = reject;\n\n fr.readAsArrayBuffer(buffer);\n });\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAYA,CAACC,MAAM,EAAE;EAC3C,IAAIA,MAAM,YAAYC,WAAW,EAAE;IACjC,OAAOC,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAAC;EAChC;EAEA,IAAIA,MAAM,CAACK,aAAa,EAAE;IACxB,OAAOH,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAACK,aAAa,EAAE,CAAC;EAChD;EAEA,IAAIL,MAAM,CAACA,MAAM,EAAE;IACjB,OAAOE,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAACA,MAAM,CAAC;EACvC;EAEA,OAAO,IAAAE,QAAA,CAAAC,OAAA,CAAY,UAACC,OAAO,EAAEE,MAAM,EAAK;IACtC,IAAMC,EAAE,GAAG,IAAIC,UAAU,EAAE;IAE3BD,EAAE,CAACE,MAAM,GAAG,SAASA,MAAMA,CAAA,EAAG;MAC5BL,OAAO,CAAC,IAAIM,UAAU,CAAC,IAAI,CAACC,MAAM,CAAC,CAAC;IACtC,CAAC;IAEDJ,EAAE,CAACK,OAAO,GAAGN,MAAM;IAEnBC,EAAE,CAACM,iBAAiB,CAACb,MAAM,CAAC;EAC9B,CAAC,CAAC;AACJ"}
|
package/dist/index.js
CHANGED
|
@@ -30,10 +30,12 @@ _Object$defineProperty(exports, "default", {
|
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
32
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
33
|
+
var _isString2 = _interopRequireDefault(require("lodash/isString"));
|
|
34
|
+
var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
|
|
35
|
+
var _has2 = _interopRequireDefault(require("lodash/has"));
|
|
33
36
|
require("@webex/internal-plugin-device");
|
|
34
37
|
require("@webex/internal-plugin-mercury");
|
|
35
38
|
var _webexCore = require("@webex/webex-core");
|
|
36
|
-
var _lodash = require("lodash");
|
|
37
39
|
var _encryption = _interopRequireDefault(require("./encryption"));
|
|
38
40
|
var _config = _interopRequireDefault(require("./config"));
|
|
39
41
|
var _kmsErrors = require("./kms-errors");
|
|
@@ -63,10 +65,10 @@ if (process.env.NODE_ENV === 'test') {
|
|
|
63
65
|
// I don't see any practical way to reduce complexity here.
|
|
64
66
|
// eslint-disable-next-line complexity
|
|
65
67
|
test: function test(ctx, options) {
|
|
66
|
-
if (!(0,
|
|
68
|
+
if (!(0, _has2.default)(options, 'body.kmsMessage')) {
|
|
67
69
|
return _promise.default.resolve(false);
|
|
68
70
|
}
|
|
69
|
-
if (!(0,
|
|
71
|
+
if (!(0, _isObject2.default)(options.body.kmsMessage)) {
|
|
70
72
|
return _promise.default.resolve(false);
|
|
71
73
|
}
|
|
72
74
|
|
|
@@ -92,7 +94,7 @@ if (process.env.NODE_ENV === 'test') {
|
|
|
92
94
|
name: 'decryptKmsMessage',
|
|
93
95
|
direction: 'inbound',
|
|
94
96
|
test: function test(ctx, response) {
|
|
95
|
-
return _promise.default.resolve((0,
|
|
97
|
+
return _promise.default.resolve((0, _has2.default)(response, 'body.kmsMessage') && (0, _isString2.default)(response.body.kmsMessage));
|
|
96
98
|
},
|
|
97
99
|
extract: function extract(response) {
|
|
98
100
|
return _promise.default.resolve(response.body);
|
|
@@ -116,7 +118,7 @@ if (process.env.NODE_ENV === 'test') {
|
|
|
116
118
|
if (!object.kmsMessage) {
|
|
117
119
|
return _promise.default.resolve();
|
|
118
120
|
}
|
|
119
|
-
if ((0,
|
|
121
|
+
if ((0, _isString2.default)(object.kmsMessage)) {
|
|
120
122
|
return _promise.default.resolve();
|
|
121
123
|
}
|
|
122
124
|
return ctx.webex.internal.encryption.kms.prepareRequest(object.kmsMessage).then(function (req) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require","_webexCore","_lodash","_encryption","_interopRequireDefault","_config","_kmsErrors","_kmsDryErrorInterceptor","_kms","interceptors","process","env","NODE_ENV","KmsDryErrorInterceptor","create","registerInternalPlugin","Encryption","payloadTransformer","predicates","name","direction","test","ctx","options","has","_promise","default","resolve","isObject","body","kmsMessage","keyUris","length","resourceUri","includes","uri","extract","response","isString","reason","Boolean","errorCode","transforms","fn","object","webex","internal","encryption","kms","prepareRequest","then","req","wrapped","decryptKmsMessage","promises","errors","map","error","description","desc","push","message","all","reject","DryError","config"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n// Note: There's a bug where if bind gets replayed because of a timeout in which\n// the original request eventually completed, there'll be an error indicating\n// the key can't be bound (because it already has been). This could be mitigated\n// by using Promise.race to resolve replays (as more requests get enqueue for a\n// specific action, accept whichever one completes first).\n\nimport '@webex/internal-plugin-device';\n\nimport '@webex/internal-plugin-mercury';\n\nimport {registerInternalPlugin} from '@webex/webex-core';\nimport {has, isObject, isString} from 'lodash';\n\nimport Encryption from './encryption';\nimport config from './config';\nimport {DryError} from './kms-errors';\n\nimport KmsDryErrorInterceptor from './kms-dry-error-interceptor';\n\nlet interceptors;\n\nif (process.env.NODE_ENV === 'test') {\n interceptors = {\n KmsDryErrorInterceptor: KmsDryErrorInterceptor.create,\n };\n}\n\nregisterInternalPlugin('encryption', Encryption, {\n payloadTransformer: {\n predicates: [\n {\n name: 'encryptKmsMessage',\n direction: 'outbound',\n // I don't see any practical way to reduce complexity here.\n // eslint-disable-next-line complexity\n test(ctx, options) {\n if (!has(options, 'body.kmsMessage')) {\n return Promise.resolve(false);\n }\n\n if (!isObject(options.body.kmsMessage)) {\n return Promise.resolve(false);\n }\n\n // If this is a template for a kms message, assume another transform\n // will fill it in later. This is a bit of a leaky abstraction, but the\n // alternative is building a complex rules engine for controlling\n // ordering of transforms\n if (options.body.kmsMessage.keyUris && options.body.kmsMessage.keyUris.length === 0) {\n return Promise.resolve(false);\n }\n if (\n options.body.kmsMessage.resourceUri &&\n (options.body.kmsMessage.resourceUri.includes('<KRO>') ||\n options.body.kmsMessage.resourceUri.includes('<KEYURL>'))\n ) {\n return Promise.resolve(false);\n }\n if (\n options.body.kmsMessage.uri &&\n (options.body.kmsMessage.uri.includes('<KRO>') ||\n options.body.kmsMessage.uri.includes('<KEYURL>'))\n ) {\n return Promise.resolve(false);\n }\n\n return Promise.resolve(true);\n },\n extract(options) {\n return Promise.resolve(options.body);\n },\n },\n {\n name: 'decryptKmsMessage',\n direction: 'inbound',\n test(ctx, response) {\n return Promise.resolve(\n has(response, 'body.kmsMessage') && isString(response.body.kmsMessage)\n );\n },\n extract(response) {\n return Promise.resolve(response.body);\n },\n },\n {\n name: 'decryptErrorResponse',\n direction: 'inbound',\n test(ctx, reason) {\n return Promise.resolve(Boolean(reason.body && reason.body.errorCode === 1900000));\n },\n extract(reason) {\n return Promise.resolve(reason);\n },\n },\n ],\n transforms: [\n {\n name: 'encryptKmsMessage',\n fn(ctx, object) {\n if (!object) {\n return Promise.resolve();\n }\n\n if (!object.kmsMessage) {\n return Promise.resolve();\n }\n\n if (isString(object.kmsMessage)) {\n return Promise.resolve();\n }\n\n return ctx.webex.internal.encryption.kms.prepareRequest(object.kmsMessage).then((req) => {\n object.kmsMessage = req.wrapped;\n });\n },\n },\n {\n name: 'decryptKmsMessage',\n fn(ctx, object) {\n return ctx.webex.internal.encryption.kms\n .decryptKmsMessage(object.kmsMessage)\n .then((kmsMessage) => {\n object.kmsMessage = kmsMessage;\n });\n },\n },\n {\n name: 'decryptErrorResponse',\n fn(ctx, reason) {\n const promises = reason.body.errors.map((error) =>\n ctx.webex.internal.encryption.kms.decryptKmsMessage(error.description).then((desc) => {\n error.description = desc;\n })\n );\n\n promises.push(\n ctx.webex.internal.encryption.kms\n .decryptKmsMessage(reason.body.message)\n .then((kmsMessage) => {\n reason.body.message = kmsMessage;\n })\n );\n\n return Promise.all(promises).then(() => Promise.reject(new DryError(reason)));\n },\n },\n ],\n },\n interceptors,\n config,\n});\n\nexport {default} from './encryption';\nexport {default as KMS} from './kms';\nexport {KmsError, DryError} from './kms-errors';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUAA,OAAA;AAEAA,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AAEA,IAAAO,uBAAA,GAAAH,sBAAA,CAAAJ,OAAA;AAwIA,IAAAQ,IAAA,GAAAJ,sBAAA,CAAAJ,OAAA;AA7JA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAeA,IAAIS,YAAY;AAEhB,IAAIC,OAAO,CAACC,GAAG,C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ACK,iBAAiB,CAACI,KAAK,CAACC,WAAW,CAAC,CAACR,IAAI,CAAC,UAACS,IAAI,EAAK;YACpFF,KAAK,CAACC,WAAW,GAAGC,IAAI;UAC1B,CAAC,CAAC;QAAA,CACJ,CAAC;QAEDL,QAAQ,CAACM,IAAI,CACXtC,GAAG,CAACuB,KAAK,CAACC,QAAQ,CAACC,UAAU,CAACC,GAAG,CAC9BK,iBAAiB,CAACd,MAAM,CAACV,IAAI,CAACgC,OAAO,CAAC,CACtCX,IAAI,CAAC,UAACpB,UAAU,EAAK;UACpBS,MAAM,CAACV,IAAI,CAACgC,OAAO,GAAG/B,UAAU;QAClC,CAAC,CACL,CAAC;QAED,OAAOL,QAAA,CAAAC,OAAA,CAAQoC,GAAG,CAACR,QAAQ,CAAC,CAACJ,IAAI,CAAC;UAAA,OAAMzB,QAAA,CAAAC,OAAA,CAAQqC,MAAM,CAAC,IAAIC,mBAAQ,CAACzB,MAAM,CAAC,CAAC;QAAA,EAAC;MAC/E;IACF,CAAC;EAEL,CAAC;EACD9B,YAAY,EAAZA,YAAY;EACZwD,MAAM,EAANA;AACF,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"names":["require","_webexCore","_encryption","_interopRequireDefault","_config","_kmsErrors","_kmsDryErrorInterceptor","_kms","interceptors","process","env","NODE_ENV","KmsDryErrorInterceptor","create","registerInternalPlugin","Encryption","payloadTransformer","predicates","name","direction","test","ctx","options","_has2","default","_promise","resolve","_isObject2","body","kmsMessage","keyUris","length","resourceUri","includes","uri","extract","response","_isString2","reason","Boolean","errorCode","transforms","fn","object","webex","internal","encryption","kms","prepareRequest","then","req","wrapped","decryptKmsMessage","promises","errors","map","error","description","desc","push","message","all","reject","DryError","config"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n// Note: There's a bug where if bind gets replayed because of a timeout in which\n// the original request eventually completed, there'll be an error indicating\n// the key can't be bound (because it already has been). This could be mitigated\n// by using Promise.race to resolve replays (as more requests get enqueue for a\n// specific action, accept whichever one completes first).\n\nimport '@webex/internal-plugin-device';\n\nimport '@webex/internal-plugin-mercury';\n\nimport {registerInternalPlugin} from '@webex/webex-core';\nimport {has, isObject, isString} from 'lodash';\n\nimport Encryption from './encryption';\nimport config from './config';\nimport {DryError} from './kms-errors';\n\nimport KmsDryErrorInterceptor from './kms-dry-error-interceptor';\n\nlet interceptors;\n\nif (process.env.NODE_ENV === 'test') {\n interceptors = {\n KmsDryErrorInterceptor: KmsDryErrorInterceptor.create,\n };\n}\n\nregisterInternalPlugin('encryption', Encryption, {\n payloadTransformer: {\n predicates: [\n {\n name: 'encryptKmsMessage',\n direction: 'outbound',\n // I don't see any practical way to reduce complexity here.\n // eslint-disable-next-line complexity\n test(ctx, options) {\n if (!has(options, 'body.kmsMessage')) {\n return Promise.resolve(false);\n }\n\n if (!isObject(options.body.kmsMessage)) {\n return Promise.resolve(false);\n }\n\n // If this is a template for a kms message, assume another transform\n // will fill it in later. This is a bit of a leaky abstraction, but the\n // alternative is building a complex rules engine for controlling\n // ordering of transforms\n if (options.body.kmsMessage.keyUris && options.body.kmsMessage.keyUris.length === 0) {\n return Promise.resolve(false);\n }\n if (\n options.body.kmsMessage.resourceUri &&\n (options.body.kmsMessage.resourceUri.includes('<KRO>') ||\n options.body.kmsMessage.resourceUri.includes('<KEYURL>'))\n ) {\n return Promise.resolve(false);\n }\n if (\n options.body.kmsMessage.uri &&\n (options.body.kmsMessage.uri.includes('<KRO>') ||\n options.body.kmsMessage.uri.includes('<KEYURL>'))\n ) {\n return Promise.resolve(false);\n }\n\n return Promise.resolve(true);\n },\n extract(options) {\n return Promise.resolve(options.body);\n },\n },\n {\n name: 'decryptKmsMessage',\n direction: 'inbound',\n test(ctx, response) {\n return Promise.resolve(\n has(response, 'body.kmsMessage') && isString(response.body.kmsMessage)\n );\n },\n extract(response) {\n return Promise.resolve(response.body);\n },\n },\n {\n name: 'decryptErrorResponse',\n direction: 'inbound',\n test(ctx, reason) {\n return Promise.resolve(Boolean(reason.body && reason.body.errorCode === 1900000));\n },\n extract(reason) {\n return Promise.resolve(reason);\n },\n },\n ],\n transforms: [\n {\n name: 'encryptKmsMessage',\n fn(ctx, object) {\n if (!object) {\n return Promise.resolve();\n }\n\n if (!object.kmsMessage) {\n return Promise.resolve();\n }\n\n if (isString(object.kmsMessage)) {\n return Promise.resolve();\n }\n\n return ctx.webex.internal.encryption.kms.prepareRequest(object.kmsMessage).then((req) => {\n object.kmsMessage = req.wrapped;\n });\n },\n },\n {\n name: 'decryptKmsMessage',\n fn(ctx, object) {\n return ctx.webex.internal.encryption.kms\n .decryptKmsMessage(object.kmsMessage)\n .then((kmsMessage) => {\n object.kmsMessage = kmsMessage;\n });\n },\n },\n {\n name: 'decryptErrorResponse',\n fn(ctx, reason) {\n const promises = reason.body.errors.map((error) =>\n ctx.webex.internal.encryption.kms.decryptKmsMessage(error.description).then((desc) => {\n error.description = desc;\n })\n );\n\n promises.push(\n ctx.webex.internal.encryption.kms\n .decryptKmsMessage(reason.body.message)\n .then((kmsMessage) => {\n reason.body.message = kmsMessage;\n })\n );\n\n return Promise.all(promises).then(() => Promise.reject(new DryError(reason)));\n },\n },\n ],\n },\n interceptors,\n config,\n});\n\nexport {default} from './encryption';\nexport {default as KMS} from './kms';\nexport {KmsError, DryError} from './kms-errors';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUAA,OAAA;AAEAA,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAGA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAEA,IAAAM,uBAAA,GAAAH,sBAAA,CAAAH,OAAA;AAwIA,IAAAO,IAAA,GAAAJ,sBAAA,CAAAH,OAAA;AA7JA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAeA,IAAIQ,YAAY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AAK;UAAA,OAC5CnC,GAAG,CAACuB,KAAK,CAACC,QAAQ,CAACC,UAAU,CAACC,GAAG,CAACK,iBAAiB,CAACI,KAAK,CAACC,WAAW,CAAC,CAACR,IAAI,CAAC,UAACS,IAAI,EAAK;YACpFF,KAAK,CAACC,WAAW,GAAGC,IAAI;UAC1B,CAAC,CAAC;QAAA,EACH;QAEDL,QAAQ,CAACM,IAAI,CACXtC,GAAG,CAACuB,KAAK,CAACC,QAAQ,CAACC,UAAU,CAACC,GAAG,CAC9BK,iBAAiB,CAACd,MAAM,CAACV,IAAI,CAACgC,OAAO,CAAC,CACtCX,IAAI,CAAC,UAACpB,UAAU,EAAK;UACpBS,MAAM,CAACV,IAAI,CAACgC,OAAO,GAAG/B,UAAU;QAClC,CAAC,CAAC,CACL;QAED,OAAOJ,QAAA,CAAAD,OAAA,CAAQqC,GAAG,CAACR,QAAQ,CAAC,CAACJ,IAAI,CAAC;UAAA,OAAMxB,QAAA,CAAAD,OAAA,CAAQsC,MAAM,CAAC,IAAIC,mBAAQ,CAACzB,MAAM,CAAC,CAAC;QAAA,EAAC;MAC/E;IACF,CAAC;EAEL,CAAC;EACD9B,YAAY,EAAZA,YAAY;EACZwD,MAAM,EAANA;AACF,CAAC,CAAC"}
|
package/dist/kms-batcher.js
CHANGED
|
@@ -15,11 +15,12 @@ var _kmsErrors = require("./kms-errors");
|
|
|
15
15
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
var TIMEOUT_SYMBOL =
|
|
18
|
+
var TIMEOUT_SYMBOL = (0, _symbol.default)('TIMEOUT_SYMBOL');
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @class
|
|
22
22
|
*/
|
|
23
|
+
exports.TIMEOUT_SYMBOL = TIMEOUT_SYMBOL;
|
|
23
24
|
var KmsBatcher = _webexCore.Batcher.extend({
|
|
24
25
|
namespace: 'Encryption',
|
|
25
26
|
/**
|
|
@@ -130,7 +131,6 @@ var KmsBatcher = _webexCore.Batcher.extend({
|
|
|
130
131
|
* @returns {Promise}
|
|
131
132
|
*/
|
|
132
133
|
handleItemFailure: function handleItemFailure(item, reason) {
|
|
133
|
-
(0, _kmsErrors.handleKmsKeyRevokedEncryptionFailure)(item, this.webex);
|
|
134
134
|
return this.getDeferredForResponse(item).then(function (defer) {
|
|
135
135
|
defer.reject(reason || new _kmsErrors.KmsError(item.body));
|
|
136
136
|
});
|
|
@@ -150,5 +150,6 @@ var KmsBatcher = _webexCore.Batcher.extend({
|
|
|
150
150
|
return _promise.default.resolve(item.requestId);
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
|
-
var _default =
|
|
153
|
+
var _default = KmsBatcher;
|
|
154
|
+
exports.default = _default;
|
|
154
155
|
//# sourceMappingURL=kms-batcher.js.map
|
package/dist/kms-batcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_commonTimers","require","_webexCore","_kmsErrors","TIMEOUT_SYMBOL","
|
|
1
|
+
{"version":3,"names":["_commonTimers","require","_webexCore","_kmsErrors","TIMEOUT_SYMBOL","_symbol","default","exports","KmsBatcher","Batcher","extend","namespace","processKmsMessageEvent","event","_this","logger","info","_promise","all","encryption","kmsMessages","map","kmsMessage","resolve","process","env","NODE_ENV","body","acceptItem","prepareItem","item","_this2","getDeferredForRequest","then","defer","timeout","Error","timer","safeSetTimeout","warn","concat","requestId","handleItemFailure","KmsTimeoutError","request","promise","clearTimeout","catch","prepareRequest","queue","webex","internal","kms","_getKMSCluster","cluster","destination","req","wrapped","submitHttpRequest","payload","length","method","service","resource","handleHttpSuccess","didItemFail","status","handleItemSuccess","getDeferredForResponse","reason","reject","KmsError","fingerprintRequest","fingerprintResponse","_default"],"sources":["kms-batcher.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {safeSetTimeout} from '@webex/common-timers';\nimport {Batcher} from '@webex/webex-core';\n\nimport {KmsError, KmsTimeoutError} from './kms-errors';\n\nexport const TIMEOUT_SYMBOL = Symbol('TIMEOUT_SYMBOL');\n\n/**\n * @class\n */\nconst KmsBatcher = Batcher.extend({\n namespace: 'Encryption',\n\n /**\n * Accepts a kmsMessage event and passes its contents to acceptItem\n * @param {Object} event\n * @returns {Promise}\n */\n processKmsMessageEvent(event) {\n this.logger.info('kms-batcher: received kms message');\n\n return Promise.all(\n event.encryption.kmsMessages.map(\n (kmsMessage) =>\n new Promise((resolve) => {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n this.logger.info('kms-batcher:', kmsMessage.body);\n }\n\n resolve(this.acceptItem(kmsMessage));\n })\n )\n );\n },\n\n /**\n * Attaches a timeout to the given KMS message\n * @param {Object} item\n * @returns {Promise<Object>}\n */\n prepareItem(item) {\n return this.getDeferredForRequest(item).then((defer) => {\n const timeout = item[TIMEOUT_SYMBOL];\n\n /* istanbul ignore if */\n if (!timeout) {\n throw new Error('timeout is required');\n }\n\n const timer = safeSetTimeout(() => {\n this.logger.warn(\n `kms: request timed out; request id: ${item.requestId}; timeout: ${timeout}`\n );\n this.handleItemFailure(\n item,\n new KmsTimeoutError({\n timeout,\n request: item,\n })\n );\n }, timeout);\n\n // Reminder: reassign `promise` is not a viable means of inserting into\n // the Promise chain\n defer.promise.then(() => clearTimeout(timer));\n defer.promise.catch(() => clearTimeout(timer));\n\n return item;\n });\n },\n\n /**\n * Attaches the final bits of cluster info to the payload\n * @param {Array} queue\n * @returns {Promise<Array>}\n */\n prepareRequest(queue) {\n return this.webex.internal.encryption.kms._getKMSCluster().then((cluster) => ({\n destination: cluster,\n kmsMessages: queue.map((req) => req.wrapped),\n }));\n },\n\n /**\n * @param {Object} payload\n * @returns {Promise<HttpResponseObject>}\n */\n submitHttpRequest(payload) {\n this.logger.info('kms: batched-request-length', payload.kmsMessages.length);\n\n return this.webex.request({\n method: 'POST',\n service: 'encryption',\n resource: '/kms/messages',\n body: payload,\n });\n },\n\n /**\n * Does nothing; the http response doesn't carry our response data\n * @returns {Promise}\n */\n handleHttpSuccess() {\n return Promise.resolve();\n },\n\n /**\n * @param {Object} item\n * @returns {Promise<boolean>}\n */\n didItemFail(item) {\n return Promise.resolve(item.status >= 400);\n },\n\n /**\n * @param {Object} item\n * @returns {Promise}\n */\n handleItemSuccess(item) {\n return this.getDeferredForResponse(item).then((defer) => {\n defer.resolve(item.body);\n });\n },\n\n /**\n * @param {Object} item\n * @param {KmsError} [reason]\n * @returns {Promise}\n */\n handleItemFailure(item, reason) {\n return this.getDeferredForResponse(item).then((defer) => {\n defer.reject(reason || new KmsError(item.body));\n });\n },\n\n /**\n * @param {Object} item\n * @returns {Promise}\n */\n fingerprintRequest(item) {\n return Promise.resolve(item.requestId);\n },\n\n /**\n * @param {Object} item\n * @returns {Promise}\n */\n fingerprintResponse(item) {\n return Promise.resolve(item.requestId);\n },\n});\n\nexport default KmsBatcher;\n"],"mappings":";;;;;;;;;;AAIA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAPA;AACA;AACA;;AAOO,IAAMG,cAAc,GAAG,IAAAC,OAAA,CAAAC,OAAA,EAAO,gBAAgB,CAAC;;AAEtD;AACA;AACA;AAFAC,OAAA,CAAAH,cAAA,GAAAA,cAAA;AAGA,IAAMI,UAAU,GAAGC,kBAAO,CAACC,MAAM,CAAC;EAChCC,SAAS,EAAE,YAAY;EAEvB;AACF;AACA;AACA;AACA;EACEC,sBAAsB,WAAAA,uBAACC,KAAK,EAAE;IAAA,IAAAC,KAAA;IAC5B,IAAI,CAACC,MAAM,CAACC,IAAI,CAAC,mCAAmC,CAAC;IAErD,OAAOC,QAAA,CAAAX,OAAA,CAAQY,GAAG,CAChBL,KAAK,CAACM,UAAU,CAACC,WAAW,CAACC,GAAG,CAC9B,UAACC,UAAU;MAAA,OACT,IAAAL,QAAA,CAAAX,OAAA,CAAY,UAACiB,O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AE;IAC9B,OAAO,IAAI,CAACD,sBAAsB,CAACtC,IAAI,CAAC,CAACG,IAAI,CAAC,UAACC,KAAK,EAAK;MACvDA,KAAK,CAACoC,MAAM,CAACD,MAAM,IAAI,IAAIE,mBAAQ,CAACzC,IAAI,CAACH,IAAI,CAAC,CAAC;IACjD,CAAC,CAAC;EACJ,CAAC;EAED;AACF;AACA;AACA;EACE6C,kBAAkB,WAAAA,mBAAC1C,IAAI,EAAE;IACvB,OAAOb,QAAA,CAAAX,OAAA,CAAQiB,OAAO,CAACO,IAAI,CAACW,SAAS,CAAC;EACxC,CAAC;EAED;AACF;AACA;AACA;EACEgC,mBAAmB,WAAAA,oBAAC3C,IAAI,EAAE;IACxB,OAAOb,QAAA,CAAAX,OAAA,CAAQiB,OAAO,CAACO,IAAI,CAACW,SAAS,CAAC;EACxC;AACF,CAAC,CAAC;AAAC,IAAAiC,QAAA,GAEYlE,UAAU;AAAAD,OAAA,CAAAD,OAAA,GAAAoE,QAAA"}
|
|
@@ -10,7 +10,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequ
|
|
|
10
10
|
_Object$defineProperty(exports, "__esModule", {
|
|
11
11
|
value: true
|
|
12
12
|
});
|
|
13
|
-
exports.
|
|
13
|
+
exports.default = exports.KMSError = void 0;
|
|
14
14
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
15
15
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
|
|
16
16
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
|
@@ -19,11 +19,11 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/
|
|
|
19
19
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
|
|
20
20
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
|
|
21
21
|
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/wrapNativeSuper"));
|
|
22
|
+
var _isArray2 = _interopRequireDefault(require("lodash/isArray"));
|
|
22
23
|
var _url = require("url");
|
|
23
24
|
var _validUrl = require("valid-url");
|
|
24
25
|
var _asn1js = require("asn1js");
|
|
25
26
|
var _pkijs = require("pkijs");
|
|
26
|
-
var _lodash = require("lodash");
|
|
27
27
|
var _nodeJose = _interopRequireDefault(require("node-jose"));
|
|
28
28
|
var _isomorphicWebcrypto = _interopRequireDefault(require("isomorphic-webcrypto"));
|
|
29
29
|
var _safeBuffer = require("safe-buffer");
|
|
@@ -40,13 +40,13 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_R
|
|
|
40
40
|
var VALID_KTY = 'RSA';
|
|
41
41
|
var VALID_KID_PROTOCOL = 'kms:';
|
|
42
42
|
var X509_COMMON_NAME_KEY = '2.5.4.3';
|
|
43
|
-
var X509_SUBJECT_ALT_NAME_KEY =
|
|
43
|
+
var X509_SUBJECT_ALT_NAME_KEY = '2.5.29.17';
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Customize Error so the SDK knows to quit retrying and notify
|
|
47
47
|
* the user
|
|
48
48
|
*/
|
|
49
|
-
var KMSError =
|
|
49
|
+
var KMSError = /*#__PURE__*/function (_Error) {
|
|
50
50
|
(0, _inherits2.default)(KMSError, _Error);
|
|
51
51
|
var _super = _createSuper(KMSError);
|
|
52
52
|
/**
|
|
@@ -62,6 +62,7 @@ var KMSError = exports.KMSError = /*#__PURE__*/function (_Error) {
|
|
|
62
62
|
}
|
|
63
63
|
return (0, _createClass2.default)(KMSError);
|
|
64
64
|
}( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
|
65
|
+
exports.KMSError = KMSError;
|
|
65
66
|
var throwError = function throwError(err) {
|
|
66
67
|
throw new KMSError("INVALID KMS: ".concat(err));
|
|
67
68
|
};
|
|
@@ -116,7 +117,7 @@ var validateKidHeader = function validateKidHeader(_ref2) {
|
|
|
116
117
|
* @throws {KMSError} if unable to validate certificate against KMS credentials
|
|
117
118
|
* @returns {void}
|
|
118
119
|
*/
|
|
119
|
-
var validateCommonName =
|
|
120
|
+
var validateCommonName = function validateCommonName(_ref3, _ref4) {
|
|
120
121
|
var _ref5 = (0, _slicedToArray2.default)(_ref3, 1),
|
|
121
122
|
certificate = _ref5[0];
|
|
122
123
|
var kid = _ref4.kid;
|
|
@@ -136,7 +137,7 @@ var validateCommonName = exports.validateCommonName = function validateCommonNam
|
|
|
136
137
|
try {
|
|
137
138
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
138
139
|
var entry = _step2.value;
|
|
139
|
-
var san = entry.value
|
|
140
|
+
var san = entry.value;
|
|
140
141
|
validationSuccessful = san === kidHostname;
|
|
141
142
|
if (validationSuccessful) {
|
|
142
143
|
break;
|
|
@@ -256,7 +257,7 @@ var validateKMS = function validateKMS(caroots) {
|
|
|
256
257
|
return _promise.default.resolve().then(function () {
|
|
257
258
|
validateKtyHeader(jwt);
|
|
258
259
|
validateKidHeader(jwt);
|
|
259
|
-
if (!((0,
|
|
260
|
+
if (!((0, _isArray2.default)(jwt.x5c) && jwt.x5c.length > 0)) {
|
|
260
261
|
throwError('JWK does not contain a list of certificates');
|
|
261
262
|
}
|
|
262
263
|
var certificates = jwt.x5c.map(decodeCert);
|
|
@@ -271,5 +272,6 @@ var validateKMS = function validateKMS(caroots) {
|
|
|
271
272
|
});
|
|
272
273
|
};
|
|
273
274
|
};
|
|
274
|
-
var _default =
|
|
275
|
+
var _default = validateKMS;
|
|
276
|
+
exports.default = _default;
|
|
275
277
|
//# sourceMappingURL=kms-certificate-validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_url","require","_validUrl","_asn1js","_pkijs","_lodash","_nodeJose","_interopRequireDefault","_isomorphicWebcrypto","_safeBuffer","_createForOfIteratorHelper","o","allowArrayLike","it","_Symbol","_Symbol$iterator","_Array$isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","_Array$from","test","arr","len","arr2","Array","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf2","default","result","NewTarget","_Reflect$construct","arguments","apply","_possibleConstructorReturn2","Reflect","sham","Proxy","Boolean","valueOf","setEngine","crypto","CryptoEngine","subtle","VALID_KTY","VALID_KID_PROTOCOL","X509_COMMON_NAME_KEY","X509_SUBJECT_ALT_NAME_KEY","exports","KMSError","_Error","_inherits2","_super","message","_this","_classCallCheck2","kmsError","_createClass2","_wrapNativeSuper2","Error","throwError","concat","decodeCert","pem","der","Buffer","from","ber","Uint8Array","buffer","asn1","fromBER","Certificate","schema","validateKtyHeader","_ref","kty","validateKidHeader","_ref2","kid","isUri","parseUrl","protocol","validateCommonName","_ref3","_ref4","_ref5","_slicedToArray2","certificate","kidHostname","hostname","validationSuccessful","extensions","_iterator","_step","extension","extnID","altNames","parsedValue","_iterator2","_step2","entry","san","toLowerCase","subjectAttributes","subject","typesAndValues","_iterator3","_step3","attribute","type","commonName","valueBlock","validatePublicCertificate","_ref6","_ref7","_ref8","publicExponent","modulus","encode","jose","util","base64url","publicKey","subjectPublicKeyInfo","subjectPublicKey","asn1PublicCert","valueHex","publicCert","RSAPublicKey","publicExponentHex","modulusHex","validateCertificatesSignature","certificates","caroots","undefined","certificateEngine","CertificateChainValidationEngine","trustedCerts","map","certs","verify","then","_ref9","resultCode","resultMessage","validateKMS","jwt","_promise","resolve","isArray","x5c","promise","_default"],"sources":["kms-certificate-validation.js"],"sourcesContent":["import {parse as parseUrl} from 'url';\n\nimport {isUri} from 'valid-url';\nimport {fromBER} from 'asn1js';\nimport {\n Certificate,\n RSAPublicKey,\n CertificateChainValidationEngine,\n CryptoEngine,\n setEngine,\n} from 'pkijs';\nimport {isArray} from 'lodash';\nimport jose from 'node-jose';\nimport crypto from 'isomorphic-webcrypto';\nimport {Buffer} from 'safe-buffer';\n\nsetEngine(\n 'newEngine',\n crypto,\n new CryptoEngine({\n name: '',\n crypto,\n subtle: crypto.subtle,\n })\n);\n\nconst VALID_KTY = 'RSA';\nconst VALID_KID_PROTOCOL = 'kms:';\n\nconst X509_COMMON_NAME_KEY = '2.5.4.3';\n\nexport const X509_SUBJECT_ALT_NAME_KEY = '2.5.29.17';\n\n/**\n * Customize Error so the SDK knows to quit retrying and notify\n * the user\n */\nexport class KMSError extends Error {\n /**\n * add kmsError field to notify\n * @param {string} message\n */\n constructor(message) {\n super(message);\n this.kmsError = true;\n }\n}\n\nconst throwError = (err) => {\n throw new KMSError(`INVALID KMS: ${err}`);\n};\n\n/**\n * Converts the PEM string to a pkijs certificate object\n * @param {string} pem PEM representation of a certificate\n * @returns {Certificate} pkijs object of the certificate\n */\nconst decodeCert = (pem) => {\n if (typeof pem !== 'string') {\n throwError('certificate needs to be a string');\n }\n\n const der = Buffer.from(pem, 'base64');\n const ber = new Uint8Array(der).buffer;\n\n const asn1 = fromBER(ber);\n\n return new Certificate({schema: asn1.result});\n};\n\n/**\n * Validate the 'kty' property of the KMS credentials\n * @param {Object} JWT KMS credentials\n * @param {string} JWT.kty type of certificate\n * @throws {KMSError} if kty is not a valid type\n * @returns {void}\n */\nconst validateKtyHeader = ({kty}) => {\n if (kty !== VALID_KTY) {\n throwError(`'kty' header must be '${VALID_KTY}'`);\n }\n};\n\nconst validateKidHeader = ({kid}) => {\n if (!isUri(kid)) {\n throwError(\"'kid' is not a valid URI\");\n }\n\n if (parseUrl(kid).protocol !== VALID_KID_PROTOCOL) {\n throwError(`'kid' protocol must be '${VALID_KID_PROTOCOL}'`);\n }\n};\n\n/**\n * Checks the first certificate matches the 'kid' in the JWT.\n * It first checks the Subject Alternative Name then it checks\n * the Common Name\n * @param {Certificate} certificate represents the KMS\n * @param {Object} JWT KMS credentials\n * @param {string} JWT.kid the uri of the KMS\n * @throws {KMSError} if unable to validate certificate against KMS credentials\n * @returns {void}\n */\nexport const validateCommonName = ([certificate], {kid}) => {\n const kidHostname = parseUrl(kid).hostname;\n let validationSuccessful = false;\n\n if (certificate.extensions) {\n // Subject Alt Names are in here\n for (const extension of certificate.extensions) {\n if (extension.extnID === X509_SUBJECT_ALT_NAME_KEY) {\n const {altNames} = extension.parsedValue;\n\n for (const entry of altNames) {\n const san = entry.value.toLowerCase();\n\n validationSuccessful = san === kidHostname;\n if (validationSuccessful) {\n break;\n }\n }\n\n if (validationSuccessful) {\n break;\n }\n }\n }\n }\n\n if (!validationSuccessful) {\n // Didn't match kid in the Subject Alt Names, checking the Common Name\n const subjectAttributes = certificate.subject.typesAndValues;\n\n for (const attribute of subjectAttributes) {\n if (attribute.type === X509_COMMON_NAME_KEY) {\n const commonName = attribute.value.valueBlock.value;\n\n validationSuccessful = commonName === kidHostname;\n if (validationSuccessful) {\n break;\n }\n }\n }\n }\n\n if (!validationSuccessful) {\n throwError(\"hostname of the 1st certificate does not match 'kid'\");\n }\n};\n\n/**\n * Validate the first KMS certificate against the information\n * provided in the JWT\n * @param {Certificate} certificate first certificate the identifies the KMS\n * @param {Object} JWT credentials of the KMS\n * @param {string} JWT.e Public exponent of the first certificate\n * @param {string} KWT.n Modulus of the first certificate\n * @throws {KMSError} if e or n doesn't match the first certificate\n * @returns {void}\n */\nconst validatePublicCertificate = ([certificate], {e: publicExponent, n: modulus}) => {\n const {encode} = jose.util.base64url;\n\n const publicKey = certificate.subjectPublicKeyInfo.subjectPublicKey;\n const asn1PublicCert = fromBER(publicKey.valueBlock.valueHex);\n const publicCert = new RSAPublicKey({schema: asn1PublicCert.result});\n const publicExponentHex = publicCert.publicExponent.valueBlock.valueHex;\n const modulusHex = publicCert.modulus.valueBlock.valueHex;\n\n if (publicExponent !== encode(publicExponentHex)) {\n throwError('Public exponent is invalid');\n }\n if (modulus !== encode(modulusHex)) {\n throwError('Modulus is invalid');\n }\n};\n\n/**\n * Validates the list of certificates against the CAs provided\n * @param {certificate[]} certificates list of certificates provided\n * by the KMS to certify itself\n * @param {string[]} [caroots=[]] list of Certificate Authorities used to\n * validate the KMS's certificates\n * @returns {Promise} rejects if unable to validate the certificates\n */\nconst validateCertificatesSignature = (certificates, caroots = []) => {\n const certificateEngine = new CertificateChainValidationEngine({\n trustedCerts: caroots.map(decodeCert),\n certs: certificates,\n });\n\n return certificateEngine.verify().then(({result, resultCode, resultMessage}) => {\n if (!result) {\n throwError(`Certificate Validation failed [${resultCode}]: ${resultMessage}`);\n }\n });\n};\n\n/**\n * Validates the information provided by the KMS. This is a curried function.\n * The first function takes the caroots param and returns a second function.\n * The second function takes the credentials of the KMS and validates it\n * @param {string[]} caroots PEM encoded certificates that will be used\n * as Certificate Authorities\n * @param {Object} jwt Object containing the fields necessary to\n * validate the KMS\n * @returns {Promise} when resolved will return the jwt\n */\nconst validateKMS =\n (caroots) =>\n (jwt = {}) =>\n Promise.resolve().then(() => {\n validateKtyHeader(jwt);\n validateKidHeader(jwt);\n\n if (!(isArray(jwt.x5c) && jwt.x5c.length > 0)) {\n throwError('JWK does not contain a list of certificates');\n }\n const certificates = jwt.x5c.map(decodeCert);\n\n validateCommonName(certificates, jwt);\n validatePublicCertificate(certificates, jwt);\n\n // Skip validating signatures if no CA roots were provided\n const promise = caroots\n ? validateCertificatesSignature(certificates, caroots)\n : Promise.resolve();\n\n return promise.then(() => jwt);\n });\n\nexport default validateKMS;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAOA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,oBAAA,GAAAD,sBAAA,CAAAN,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AAA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AAC,YAAM;MAC3BpE,iBAAiB,CAACyE,GAAG,CAAC;MACtBtE,iBAAiB,CAACsE,GAAG,CAAC;MAEtB,IAAI,EAAE,IAAAG,eAAO,EAACH,GAAG,CAACI,GAAG,CAAC,IAAIJ,GAAG,CAACI,GAAG,CAACnK,MAAM,GAAG,CAAC,CAAC,EAAE;QAC7CwE,UAAU,CAAC,6CAA6C,CAAC;MAC3D;MACA,IAAMyE,YAAY,GAAGc,GAAG,CAACI,GAAG,CAACZ,GAAG,CAAC7E,UAAU,CAAC;MAE5CqB,kBAAkB,CAACkD,YAAY,EAAEc,GAAG,CAAC;MACrClC,yBAAyB,CAACoB,YAAY,EAAEc,GAAG,CAAC;;MAE5C;MACA,IAAMK,OAAO,GAAGlB,OAAO,GACnBF,6BAA6B,CAACC,YAAY,EAAEC,OAAO,CAAC,GACpDc,QAAA,CAAAxH,OAAA,CAAQyH,OAAO,CAAC,CAAC;MAErB,OAAOG,OAAO,CAACV,IAAI,CAAC;QAAA,OAAMK,GAAG;MAAA,EAAC;IAChC,CAAC,CAAC;EAAA;AAAA;AAAC,IAAAM,QAAA,GAAAzG,OAAA,CAAApB,OAAA,GAEQsH,WAAW"}
|
|
1
|
+
{"version":3,"names":["_url","require","_validUrl","_asn1js","_pkijs","_nodeJose","_interopRequireDefault","_isomorphicWebcrypto","_safeBuffer","_createForOfIteratorHelper","o","allowArrayLike","it","_Symbol","_Symbol$iterator","_Array$isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","_Array$from","test","arr","len","arr2","Array","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf2","default","result","NewTarget","_Reflect$construct","arguments","apply","_possibleConstructorReturn2","Reflect","sham","Proxy","Boolean","valueOf","setEngine","crypto","CryptoEngine","subtle","VALID_KTY","VALID_KID_PROTOCOL","X509_COMMON_NAME_KEY","X509_SUBJECT_ALT_NAME_KEY","KMSError","_Error","_inherits2","_super","message","_this","_classCallCheck2","kmsError","_createClass2","_wrapNativeSuper2","Error","exports","throwError","concat","decodeCert","pem","der","Buffer","from","ber","Uint8Array","buffer","asn1","fromBER","Certificate","schema","validateKtyHeader","_ref","kty","validateKidHeader","_ref2","kid","isUri","parseUrl","protocol","validateCommonName","_ref3","_ref4","_ref5","_slicedToArray2","certificate","kidHostname","hostname","validationSuccessful","extensions","_iterator","_step","extension","extnID","altNames","parsedValue","_iterator2","_step2","entry","san","subjectAttributes","subject","typesAndValues","_iterator3","_step3","attribute","type","commonName","valueBlock","validatePublicCertificate","_ref6","_ref7","_ref8","publicExponent","modulus","encode","jose","util","base64url","publicKey","subjectPublicKeyInfo","subjectPublicKey","asn1PublicCert","valueHex","publicCert","RSAPublicKey","publicExponentHex","modulusHex","validateCertificatesSignature","certificates","caroots","undefined","certificateEngine","CertificateChainValidationEngine","trustedCerts","map","certs","verify","then","_ref9","resultCode","resultMessage","validateKMS","jwt","_promise","resolve","_isArray2","x5c","promise","_default"],"sources":["kms-certificate-validation.js"],"sourcesContent":["import {parse as parseUrl} from 'url';\n\nimport {isUri} from 'valid-url';\nimport {fromBER} from 'asn1js';\nimport {\n Certificate,\n RSAPublicKey,\n CertificateChainValidationEngine,\n CryptoEngine,\n setEngine,\n} from 'pkijs';\nimport {isArray} from 'lodash';\nimport jose from 'node-jose';\nimport crypto from 'isomorphic-webcrypto';\nimport {Buffer} from 'safe-buffer';\n\nsetEngine(\n 'newEngine',\n crypto,\n new CryptoEngine({\n name: '',\n crypto,\n subtle: crypto.subtle,\n })\n);\n\nconst VALID_KTY = 'RSA';\nconst VALID_KID_PROTOCOL = 'kms:';\n\nconst X509_COMMON_NAME_KEY = '2.5.4.3';\n\nconst X509_SUBJECT_ALT_NAME_KEY = '2.5.29.17';\n\n/**\n * Customize Error so the SDK knows to quit retrying and notify\n * the user\n */\nexport class KMSError extends Error {\n /**\n * add kmsError field to notify\n * @param {string} message\n */\n constructor(message) {\n super(message);\n this.kmsError = true;\n }\n}\n\nconst throwError = (err) => {\n throw new KMSError(`INVALID KMS: ${err}`);\n};\n\n/**\n * Converts the PEM string to a pkijs certificate object\n * @param {string} pem PEM representation of a certificate\n * @returns {Certificate} pkijs object of the certificate\n */\nconst decodeCert = (pem) => {\n if (typeof pem !== 'string') {\n throwError('certificate needs to be a string');\n }\n\n const der = Buffer.from(pem, 'base64');\n const ber = new Uint8Array(der).buffer;\n\n const asn1 = fromBER(ber);\n\n return new Certificate({schema: asn1.result});\n};\n\n/**\n * Validate the 'kty' property of the KMS credentials\n * @param {Object} JWT KMS credentials\n * @param {string} JWT.kty type of certificate\n * @throws {KMSError} if kty is not a valid type\n * @returns {void}\n */\nconst validateKtyHeader = ({kty}) => {\n if (kty !== VALID_KTY) {\n throwError(`'kty' header must be '${VALID_KTY}'`);\n }\n};\n\nconst validateKidHeader = ({kid}) => {\n if (!isUri(kid)) {\n throwError(\"'kid' is not a valid URI\");\n }\n\n if (parseUrl(kid).protocol !== VALID_KID_PROTOCOL) {\n throwError(`'kid' protocol must be '${VALID_KID_PROTOCOL}'`);\n }\n};\n\n/**\n * Checks the first certificate matches the 'kid' in the JWT.\n * It first checks the Subject Alternative Name then it checks\n * the Common Name\n * @param {Certificate} certificate represents the KMS\n * @param {Object} JWT KMS credentials\n * @param {string} JWT.kid the uri of the KMS\n * @throws {KMSError} if unable to validate certificate against KMS credentials\n * @returns {void}\n */\nconst validateCommonName = ([certificate], {kid}) => {\n const kidHostname = parseUrl(kid).hostname;\n let validationSuccessful = false;\n\n if (certificate.extensions) {\n // Subject Alt Names are in here\n for (const extension of certificate.extensions) {\n if (extension.extnID === X509_SUBJECT_ALT_NAME_KEY) {\n const {altNames} = extension.parsedValue;\n\n for (const entry of altNames) {\n const san = entry.value;\n\n validationSuccessful = san === kidHostname;\n if (validationSuccessful) {\n break;\n }\n }\n\n if (validationSuccessful) {\n break;\n }\n }\n }\n }\n\n if (!validationSuccessful) {\n // Didn't match kid in the Subject Alt Names, checking the Common Name\n const subjectAttributes = certificate.subject.typesAndValues;\n\n for (const attribute of subjectAttributes) {\n if (attribute.type === X509_COMMON_NAME_KEY) {\n const commonName = attribute.value.valueBlock.value;\n\n validationSuccessful = commonName === kidHostname;\n if (validationSuccessful) {\n break;\n }\n }\n }\n }\n\n if (!validationSuccessful) {\n throwError(\"hostname of the 1st certificate does not match 'kid'\");\n }\n};\n\n/**\n * Validate the first KMS certificate against the information\n * provided in the JWT\n * @param {Certificate} certificate first certificate the identifies the KMS\n * @param {Object} JWT credentials of the KMS\n * @param {string} JWT.e Public exponent of the first certificate\n * @param {string} KWT.n Modulus of the first certificate\n * @throws {KMSError} if e or n doesn't match the first certificate\n * @returns {void}\n */\nconst validatePublicCertificate = ([certificate], {e: publicExponent, n: modulus}) => {\n const {encode} = jose.util.base64url;\n\n const publicKey = certificate.subjectPublicKeyInfo.subjectPublicKey;\n const asn1PublicCert = fromBER(publicKey.valueBlock.valueHex);\n const publicCert = new RSAPublicKey({schema: asn1PublicCert.result});\n const publicExponentHex = publicCert.publicExponent.valueBlock.valueHex;\n const modulusHex = publicCert.modulus.valueBlock.valueHex;\n\n if (publicExponent !== encode(publicExponentHex)) {\n throwError('Public exponent is invalid');\n }\n if (modulus !== encode(modulusHex)) {\n throwError('Modulus is invalid');\n }\n};\n\n/**\n * Validates the list of certificates against the CAs provided\n * @param {certificate[]} certificates list of certificates provided\n * by the KMS to certify itself\n * @param {string[]} [caroots=[]] list of Certificate Authorities used to\n * validate the KMS's certificates\n * @returns {Promise} rejects if unable to validate the certificates\n */\nconst validateCertificatesSignature = (certificates, caroots = []) => {\n const certificateEngine = new CertificateChainValidationEngine({\n trustedCerts: caroots.map(decodeCert),\n certs: certificates,\n });\n\n return certificateEngine.verify().then(({result, resultCode, resultMessage}) => {\n if (!result) {\n throwError(`Certificate Validation failed [${resultCode}]: ${resultMessage}`);\n }\n });\n};\n\n/**\n * Validates the information provided by the KMS. This is a curried function.\n * The first function takes the caroots param and returns a second function.\n * The second function takes the credentials of the KMS and validates it\n * @param {string[]} caroots PEM encoded certificates that will be used\n * as Certificate Authorities\n * @param {Object} jwt Object containing the fields necessary to\n * validate the KMS\n * @returns {Promise} when resolved will return the jwt\n */\nconst validateKMS =\n (caroots) =>\n (jwt = {}) =>\n Promise.resolve().then(() => {\n validateKtyHeader(jwt);\n validateKidHeader(jwt);\n\n if (!(isArray(jwt.x5c) && jwt.x5c.length > 0)) {\n throwError('JWK does not contain a list of certificates');\n }\n const certificates = jwt.x5c.map(decodeCert);\n\n validateCommonName(certificates, jwt);\n validatePublicCertificate(certificates, jwt);\n\n // Skip validating signatures if no CA roots were provided\n const promise = caroots\n ? validateCertificatesSignature(certificates, caroots)\n : Promise.resolve();\n\n return promise.then(() => jwt);\n });\n\nexport default validateKMS;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAQA,IAAAI,SAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,oBAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAAmC,SAAAQ,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,OAAA,oBAAAH,CAAA,CAAAI,gBAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,cAAA,CAAAL,CAAA,MAAAE,EAAA,GAAAI,2BAAA,CAAAN,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAO,MAAA,qBAAAL,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAM,CAAA,UAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,QAAAH,CAAA,IAAAR,CAAA,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ACC,YAAY,EAAEC,OAAO,CAAC,GACpDc,QAAA,CAAAvH,OAAA,CAAQwH,OAAO,EAAE;MAErB,OAAOG,OAAO,CAACV,IAAI,CAAC;QAAA,OAAMK,GAAG;MAAA,EAAC;IAChC,CAAC,CAAC;EAAA;AAAA;AAAC,IAAAM,QAAA,GAEQP,WAAW;AAAAtF,OAAA,CAAA/B,OAAA,GAAA4H,QAAA"}
|
|
@@ -16,15 +16,13 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/he
|
|
|
16
16
|
var _httpCore = require("@webex/http-core");
|
|
17
17
|
var _kmsErrors = require("./kms-errors");
|
|
18
18
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
19
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
21
|
-
*/
|
|
19
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
22
20
|
/**
|
|
23
21
|
* Interceptor (only to be used in test mode) intended to replay requests that
|
|
24
22
|
* fail as a result of the test-user incompatibility in KMS.
|
|
25
23
|
* @class
|
|
26
24
|
*/
|
|
27
|
-
var KmsDryErrorInterceptor =
|
|
25
|
+
var KmsDryErrorInterceptor = /*#__PURE__*/function (_Interceptor) {
|
|
28
26
|
(0, _inherits2.default)(KmsDryErrorInterceptor, _Interceptor);
|
|
29
27
|
var _super = _createSuper(KmsDryErrorInterceptor);
|
|
30
28
|
function KmsDryErrorInterceptor() {
|
|
@@ -83,4 +81,5 @@ var KmsDryErrorInterceptor = exports.default = /*#__PURE__*/function (_Intercept
|
|
|
83
81
|
}]);
|
|
84
82
|
return KmsDryErrorInterceptor;
|
|
85
83
|
}(_httpCore.Interceptor);
|
|
84
|
+
exports.default = KmsDryErrorInterceptor;
|
|
86
85
|
//# sourceMappingURL=kms-dry-error-interceptor.js.map
|