@webex/internal-plugin-encryption 3.8.0-next.13 → 3.8.0-next.15
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/encryption.js +34 -11
- package/dist/encryption.js.map +1 -1
- package/dist/kms.js +1 -1
- package/package.json +13 -13
- package/src/encryption.js +34 -8
package/dist/encryption.js
CHANGED
|
@@ -87,7 +87,9 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
87
87
|
return _promise.default.reject(new Error('`scr` and `fileUrl` are required'));
|
|
88
88
|
}
|
|
89
89
|
var shunt = new _events.EventEmitter();
|
|
90
|
-
var promise = this._fetchDownloadUrl(fileUrl,
|
|
90
|
+
var promise = this._fetchDownloadUrl(fileUrl, _objectSpread({
|
|
91
|
+
useFileService: true
|
|
92
|
+
}, options)).then(function (uri) {
|
|
91
93
|
// eslint-disable-next-line no-shadow
|
|
92
94
|
var options = {
|
|
93
95
|
method: 'GET',
|
|
@@ -110,12 +112,20 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
110
112
|
* @returns {promise} url of the downloadable file
|
|
111
113
|
*/
|
|
112
114
|
_fetchDownloadUrl: function _fetchDownloadUrl(fileUrl, options) {
|
|
113
|
-
var
|
|
115
|
+
var _options$params,
|
|
116
|
+
_this2 = this;
|
|
114
117
|
this.logger.info('encryption: retrieving download url for encrypted file');
|
|
115
118
|
if (process.env.NODE_ENV !== 'production' && fileUrl.includes('localhost')) {
|
|
116
119
|
this.logger.info('encryption: bypassing webex files because this looks to be a test file on localhost');
|
|
117
120
|
return _promise.default.resolve(fileUrl);
|
|
118
121
|
}
|
|
122
|
+
if (options && options.useFileService === false) {
|
|
123
|
+
if (!fileUrl.startsWith('https://')) {
|
|
124
|
+
this.logger.error('encryption: direct file URLs must use HTTPS');
|
|
125
|
+
return _promise.default.reject(new Error('Direct file URLs must use HTTPS'));
|
|
126
|
+
}
|
|
127
|
+
return _promise.default.resolve(fileUrl);
|
|
128
|
+
}
|
|
119
129
|
var inputBody = {
|
|
120
130
|
endpoints: [fileUrl]
|
|
121
131
|
};
|
|
@@ -127,7 +137,7 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
127
137
|
return this.request({
|
|
128
138
|
method: 'POST',
|
|
129
139
|
uri: _url.default.format(endpointUrl),
|
|
130
|
-
body: options ? _objectSpread(_objectSpread({}, inputBody), {}, {
|
|
140
|
+
body: (options === null || options === void 0 ? void 0 : (_options$params = options.params) === null || _options$params === void 0 ? void 0 : _options$params.allow) != null ? _objectSpread(_objectSpread({}, inputBody), {}, {
|
|
131
141
|
allow: options.params.allow
|
|
132
142
|
}) : inputBody
|
|
133
143
|
}).then(function (res) {
|
|
@@ -168,12 +178,25 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
168
178
|
* @returns {string} Encrypted SCR
|
|
169
179
|
*/
|
|
170
180
|
encryptScr: function encryptScr(key, scr, options) {
|
|
181
|
+
var _this3 = this;
|
|
171
182
|
/* istanbul ignore if */
|
|
172
183
|
if (!scr.loc) {
|
|
173
184
|
return _promise.default.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));
|
|
174
185
|
}
|
|
186
|
+
|
|
187
|
+
// first we get the scr json, then we create an SCR instance using the key json and then we create a JWE using the key jwk
|
|
175
188
|
return this.getKey(key, options).then(function (k) {
|
|
176
|
-
|
|
189
|
+
if (!(k !== null && k !== void 0 && k.jwk)) {
|
|
190
|
+
_this3.logger.error('encryption: Invalid key or JWK');
|
|
191
|
+
throw new Error('Invalid key or JWK');
|
|
192
|
+
}
|
|
193
|
+
return _nodeScr.default.fromJSON(scr).then(function (encScr) {
|
|
194
|
+
if (!encScr) {
|
|
195
|
+
_this3.logger.error('encryption: Failed to create SCR instance');
|
|
196
|
+
throw new Error('Failed to create SCR instance');
|
|
197
|
+
}
|
|
198
|
+
return encScr.toJWE(k.jwk);
|
|
199
|
+
});
|
|
177
200
|
});
|
|
178
201
|
},
|
|
179
202
|
/**
|
|
@@ -186,9 +209,9 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
186
209
|
* @returns {string} Encrypted text
|
|
187
210
|
*/
|
|
188
211
|
encryptText: function encryptText(key, plaintext, options) {
|
|
189
|
-
var
|
|
212
|
+
var _this4 = this;
|
|
190
213
|
return this.getKey(key, options).then(function (k) {
|
|
191
|
-
return _nodeJose.default.JWE.createEncrypt(
|
|
214
|
+
return _nodeJose.default.JWE.createEncrypt(_this4.config.joseOptions, {
|
|
192
215
|
key: k.jwk,
|
|
193
216
|
header: {
|
|
194
217
|
alg: 'dir'
|
|
@@ -206,7 +229,7 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
206
229
|
* @returns {string} Key
|
|
207
230
|
*/
|
|
208
231
|
getKey: function getKey(uri) {
|
|
209
|
-
var
|
|
232
|
+
var _this5 = this;
|
|
210
233
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
211
234
|
onBehalfOf = _ref.onBehalfOf;
|
|
212
235
|
if (uri.jwk) {
|
|
@@ -219,17 +242,17 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
219
242
|
return this.unboundedStorage.get(storageKey).then(function (keyString) {
|
|
220
243
|
return JSON.parse(keyString);
|
|
221
244
|
}).then(function (keyObject) {
|
|
222
|
-
return
|
|
245
|
+
return _this5.kms.asKey(keyObject);
|
|
223
246
|
}).catch(function () {
|
|
224
|
-
return
|
|
247
|
+
return _this5.kms.fetchKey({
|
|
225
248
|
uri: uri,
|
|
226
249
|
onBehalfOf: onBehalfOf
|
|
227
250
|
}).then((0, _common.tap)(function (key) {
|
|
228
|
-
return
|
|
251
|
+
return _this5.unboundedStorage.put(storageKey, (0, _stringify.default)(key, replacer));
|
|
229
252
|
}));
|
|
230
253
|
});
|
|
231
254
|
},
|
|
232
|
-
version: "3.8.0-next.
|
|
255
|
+
version: "3.8.0-next.15"
|
|
233
256
|
});
|
|
234
257
|
|
|
235
258
|
/**
|
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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AC,CAAC;IAAA,CAC7F,CAAC;EACL,CAAC;EAAAC,OAAA;AACH,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,SAASD,QAAQA,CAAClF,CAAC,EAAEoF,CAAC,EAAE;EACtB,IAAIpF,CAAC,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","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","useFileService","uri","method","responseType","ret","request","transferEvents","res","body","proxyEvents","_options$params","_this2","logger","info","process","env","NODE_ENV","includes","resolve","startsWith","error","inputBody","endpoints","endpointUrl","url","parse","protocol","pathname","format","params","allow","warn","catch","err","concat","encryptBinary","file","create","encrypt","cdata","encryptScr","_this3","loc","fromJSON","encScr","toJWE","encryptText","_this4","createEncrypt","config","joseOptions","header","alg","reference","final","_this5","_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, {useFileService: true, ...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 if (options && options.useFileService === false) {\n if (!fileUrl.startsWith('https://')) {\n this.logger.error('encryption: direct file URLs must use HTTPS');\n\n return Promise.reject(new Error('Direct file URLs must use HTTPS'));\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:\n options?.params?.allow != null\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 // first we get the scr json, then we create an SCR instance using the key json and then we create a JWE using the key jwk\n return this.getKey(key, options).then((k) => {\n if (!k?.jwk) {\n this.logger.error('encryption: Invalid key or JWK');\n throw new Error('Invalid key or JWK');\n }\n\n return SCR.fromJSON(scr).then((encScr) => {\n if (!encScr) {\n this.logger.error('encryption: Failed to create SCR instance');\n throw new Error('Failed to create SCR instance');\n }\n\n return encScr.toJWE(k.jwk);\n });\n });\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,IAAAQ,IAAA,GAAAN,sBAAA,CAAAF,OAAA;AAAwB,SAAAS,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,YAAA,CAAAH,CAAA,OAAAI,6BAAA,QAAAC,CAAA,GAAAD,6BAAA,CAAAJ,CAAA,GAAAC,CAAA,KAAAI,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAL,CAAA,WAAAM,g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AAO,IAAI,CAACG,gBAAgB,CACzBC,GAAG,CAACF,UAAU,CAAC,CACf3F,IAAI,CAAC,UAAC8F,SAAS;MAAA,OAAKC,IAAI,CAACvC,KAAK,CAACsC,SAAS,CAAC;IAAA,EAAC,CAC1C9F,IAAI,CAAC,UAACgG,SAAS;MAAA,OAAKV,MAAI,CAAC/F,GAAG,CAACmG,KAAK,CAACM,SAAS,CAAC;IAAA,EAAC,CAC9CjC,KAAK,CAAC;MAAA,OACLuB,MAAI,CAAC/F,GAAG,CACL0G,QAAQ,CAAC;QAACjE,GAAG,EAAHA,GAAG;QAAEyD,UAAU,EAAVA;MAAU,CAAC,CAAC,CAC3BzF,IAAI,CAAC,IAAAkG,WAAG,EAAC,UAAC1F,GAAG;QAAA,OAAK8E,MAAI,CAACM,gBAAgB,CAACO,GAAG,CAACR,UAAU,EAAE,IAAAS,UAAA,CAAArH,OAAA,EAAeyB,GAAG,EAAE6F,QAAQ,CAAC,CAAC;MAAA,EAAC,CAAC;IAAA,CAC7F,CAAC;EACL,CAAC;EAAAC,OAAA;AACH,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,SAASD,QAAQA,CAACzF,CAAC,EAAE2F,CAAC,EAAE;EACtB,IAAI3F,CAAC,KAAK,KAAK,EAAE;IACf;IACA;IACA,IAAM4F,IAAI,GAAG,IAAI,CAAC5F,CAAC,CAAC,CAAC6F,MAAM,CAAC,IAAI,CAAC;IAEjC,OAAOD,IAAI;EACb;EAEA,OAAOD,CAAC;AACV;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAA5H,OAAA,GAEcI,UAAU"}
|
package/dist/kms.js
CHANGED
|
@@ -809,7 +809,7 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
|
|
|
809
809
|
context.ephemeralKey = originalContext.ephemeralKey;
|
|
810
810
|
return context;
|
|
811
811
|
},
|
|
812
|
-
version: "3.8.0-next.
|
|
812
|
+
version: "3.8.0-next.15"
|
|
813
813
|
}, ((0, _applyDecoratedDescriptor2.default)(_obj, "fetchKey", [_dec], (0, _getOwnPropertyDescriptor.default)(_obj, "fetchKey"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "_getContext", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "_getContext"), _obj)), _obj)));
|
|
814
814
|
var _default = exports.default = KMS;
|
|
815
815
|
//# sourceMappingURL=kms.js.map
|
package/package.json
CHANGED
|
@@ -28,23 +28,23 @@
|
|
|
28
28
|
"@webex/eslint-config-legacy": "0.0.0",
|
|
29
29
|
"@webex/jest-config-legacy": "0.0.0",
|
|
30
30
|
"@webex/legacy-tools": "0.0.0",
|
|
31
|
-
"@webex/test-helper-chai": "3.8.0-next.
|
|
32
|
-
"@webex/test-helper-make-local-url": "3.8.0-next.
|
|
33
|
-
"@webex/test-helper-mocha": "3.8.0-next.
|
|
34
|
-
"@webex/test-helper-mock-webex": "3.8.0-next.
|
|
35
|
-
"@webex/test-helper-test-users": "3.8.0-next.
|
|
31
|
+
"@webex/test-helper-chai": "3.8.0-next.12",
|
|
32
|
+
"@webex/test-helper-make-local-url": "3.8.0-next.12",
|
|
33
|
+
"@webex/test-helper-mocha": "3.8.0-next.12",
|
|
34
|
+
"@webex/test-helper-mock-webex": "3.8.0-next.12",
|
|
35
|
+
"@webex/test-helper-test-users": "3.8.0-next.12",
|
|
36
36
|
"eslint": "^8.24.0",
|
|
37
37
|
"prettier": "^2.7.1",
|
|
38
38
|
"sinon": "^9.2.4"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@webex/common": "3.8.0-next.
|
|
42
|
-
"@webex/common-timers": "3.8.0-next.
|
|
43
|
-
"@webex/http-core": "3.8.0-next.
|
|
44
|
-
"@webex/internal-plugin-device": "3.8.0-next.
|
|
45
|
-
"@webex/internal-plugin-mercury": "3.8.0-next.
|
|
46
|
-
"@webex/test-helper-file": "3.8.0-next.
|
|
47
|
-
"@webex/webex-core": "3.8.0-next.
|
|
41
|
+
"@webex/common": "3.8.0-next.12",
|
|
42
|
+
"@webex/common-timers": "3.8.0-next.12",
|
|
43
|
+
"@webex/http-core": "3.8.0-next.12",
|
|
44
|
+
"@webex/internal-plugin-device": "3.8.0-next.12",
|
|
45
|
+
"@webex/internal-plugin-mercury": "3.8.0-next.14",
|
|
46
|
+
"@webex/test-helper-file": "3.8.0-next.12",
|
|
47
|
+
"@webex/webex-core": "3.8.0-next.12",
|
|
48
48
|
"asn1js": "^2.0.26",
|
|
49
49
|
"debug": "^4.3.4",
|
|
50
50
|
"isomorphic-webcrypto": "^2.3.8",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"test:style": "eslint ./src/**/*.*",
|
|
68
68
|
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
69
69
|
},
|
|
70
|
-
"version": "3.8.0-next.
|
|
70
|
+
"version": "3.8.0-next.15"
|
|
71
71
|
}
|
package/src/encryption.js
CHANGED
|
@@ -79,7 +79,7 @@ const Encryption = WebexPlugin.extend({
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
const shunt = new EventEmitter();
|
|
82
|
-
const promise = this._fetchDownloadUrl(fileUrl, options)
|
|
82
|
+
const promise = this._fetchDownloadUrl(fileUrl, {useFileService: true, ...options})
|
|
83
83
|
.then((uri) => {
|
|
84
84
|
// eslint-disable-next-line no-shadow
|
|
85
85
|
const options = {
|
|
@@ -118,6 +118,16 @@ const Encryption = WebexPlugin.extend({
|
|
|
118
118
|
return Promise.resolve(fileUrl);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
if (options && options.useFileService === false) {
|
|
122
|
+
if (!fileUrl.startsWith('https://')) {
|
|
123
|
+
this.logger.error('encryption: direct file URLs must use HTTPS');
|
|
124
|
+
|
|
125
|
+
return Promise.reject(new Error('Direct file URLs must use HTTPS'));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return Promise.resolve(fileUrl);
|
|
129
|
+
}
|
|
130
|
+
|
|
121
131
|
const inputBody = {
|
|
122
132
|
endpoints: [fileUrl],
|
|
123
133
|
};
|
|
@@ -130,12 +140,13 @@ const Encryption = WebexPlugin.extend({
|
|
|
130
140
|
return this.request({
|
|
131
141
|
method: 'POST',
|
|
132
142
|
uri: url.format(endpointUrl),
|
|
133
|
-
body:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
body:
|
|
144
|
+
options?.params?.allow != null
|
|
145
|
+
? {
|
|
146
|
+
...inputBody,
|
|
147
|
+
allow: options.params.allow,
|
|
148
|
+
}
|
|
149
|
+
: inputBody,
|
|
139
150
|
})
|
|
140
151
|
.then((res) => {
|
|
141
152
|
// eslint-disable-next-line no-shadow
|
|
@@ -188,7 +199,22 @@ const Encryption = WebexPlugin.extend({
|
|
|
188
199
|
return Promise.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));
|
|
189
200
|
}
|
|
190
201
|
|
|
191
|
-
|
|
202
|
+
// first we get the scr json, then we create an SCR instance using the key json and then we create a JWE using the key jwk
|
|
203
|
+
return this.getKey(key, options).then((k) => {
|
|
204
|
+
if (!k?.jwk) {
|
|
205
|
+
this.logger.error('encryption: Invalid key or JWK');
|
|
206
|
+
throw new Error('Invalid key or JWK');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return SCR.fromJSON(scr).then((encScr) => {
|
|
210
|
+
if (!encScr) {
|
|
211
|
+
this.logger.error('encryption: Failed to create SCR instance');
|
|
212
|
+
throw new Error('Failed to create SCR instance');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return encScr.toJWE(k.jwk);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
192
218
|
},
|
|
193
219
|
|
|
194
220
|
/**
|