@webex/internal-plugin-encryption 3.0.0-beta.169 → 3.0.0-beta.170

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.
@@ -73,19 +73,19 @@ var Encryption = _webexCore.WebexPlugin.extend({
73
73
  },
74
74
  /**
75
75
  * Validate and initiate a Download request for requested file
76
- *
76
+ * @param {Object} fileUrl - Plaintext
77
77
  * @param {Object} scr - Plaintext
78
78
  * @param {Object} options - optional parameters to download a file
79
79
  * @returns {promise}
80
80
  */
81
- download: function download(scr, options) {
81
+ download: function download(fileUrl, scr, options) {
82
82
  var _this = this;
83
83
  /* istanbul ignore if */
84
- if (!scr.loc) {
85
- return _promise.default.reject(new Error('`scr.loc` is required'));
84
+ if (!fileUrl || !scr) {
85
+ return _promise.default.reject(new Error('`scr` and `fileUrl` are required'));
86
86
  }
87
87
  var shunt = new _events.EventEmitter();
88
- var promise = this._fetchDownloadUrl(scr, options).then(function (uri) {
88
+ var promise = this._fetchDownloadUrl(fileUrl, options).then(function (uri) {
89
89
  // eslint-disable-next-line no-shadow
90
90
  var options = {
91
91
  method: 'GET',
@@ -103,22 +103,21 @@ var Encryption = _webexCore.WebexPlugin.extend({
103
103
  },
104
104
  /**
105
105
  * Fetch Download URL for the requested file
106
- *
107
- * @param {Object} scr - Plaintext
106
+ * @param {Object} fileUrl - Plaintext
108
107
  * @param {Object} options - optional parameters to download a file
109
108
  * @returns {promise} url of the downloadable file
110
109
  */
111
- _fetchDownloadUrl: function _fetchDownloadUrl(scr, options) {
110
+ _fetchDownloadUrl: function _fetchDownloadUrl(fileUrl, options) {
112
111
  var _this2 = this;
113
112
  this.logger.info('encryption: retrieving download url for encrypted file');
114
- if (process.env.NODE_ENV !== 'production' && scr.loc.includes('localhost')) {
113
+ if (process.env.NODE_ENV !== 'production' && fileUrl.includes('localhost')) {
115
114
  this.logger.info('encryption: bypassing webex files because this looks to be a test file on localhost');
116
- return _promise.default.resolve(scr.loc);
115
+ return _promise.default.resolve(fileUrl);
117
116
  }
118
117
  var inputBody = {
119
- endpoints: [scr.loc]
118
+ endpoints: [fileUrl]
120
119
  };
121
- var endpointUrl = _url.default.parse(scr.loc);
120
+ var endpointUrl = _url.default.parse(fileUrl);
122
121
 
123
122
  // hardcode the url to use 'https' and the file service '/v1/download/endpoints' api
124
123
  endpointUrl.protocol = 'https';
@@ -131,13 +130,16 @@ var Encryption = _webexCore.WebexPlugin.extend({
131
130
  }) : inputBody
132
131
  }).then(function (res) {
133
132
  // eslint-disable-next-line no-shadow
134
- var url = res.body.endpoints[scr.loc];
133
+ var url = res.body.endpoints[fileUrl];
135
134
  if (!url) {
136
- _this2.logger.warn('encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly');
137
- return scr.loc;
135
+ _this2.logger.warn('encryption: could not determine download url for `fileUrl`; attempting to download `fileUrl` directly');
136
+ return fileUrl;
138
137
  }
139
138
  _this2.logger.info('encryption: retrieved download url for encrypted file');
140
139
  return url;
140
+ }).catch(function (err) {
141
+ _this2.logger.warn("encryption: ".concat(err, " could not determine download url for ").concat(fileUrl, "; attempting to download ").concat(fileUrl, " directly"));
142
+ return fileUrl;
141
143
  });
142
144
  },
143
145
  encryptBinary: function encryptBinary(file) {
@@ -225,7 +227,7 @@ var Encryption = _webexCore.WebexPlugin.extend({
225
227
  }));
226
228
  });
227
229
  },
228
- version: "3.0.0-beta.169"
230
+ version: "3.0.0-beta.170"
229
231
  });
230
232
 
231
233
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["Encryption","WebexPlugin","extend","children","kms","KMS","namespace","processKmsMessageEvent","event","decryptBinary","scr","buffer","ensureBuffer","then","b","length","byteLength","reject","Error","decrypt","decryptScr","key","cipherScr","options","getKey","k","SCR","fromJWE","jwk","decryptText","ciphertext","jose","JWE","createDecrypt","result","plaintext","toString","download","loc","shunt","EventEmitter","promise","_fetchDownloadUrl","uri","method","responseType","ret","request","transferEvents","res","body","proxyEvents","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","createEncrypt","config","joseOptions","header","alg","reference","final","onBehalfOf","asKey","storageKey","unboundedStorage","get","keyString","JSON","keyObject","catch","fetchKey","tap","put","replacer","v","json","toJSON"],"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;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AAAwB;AAAA;AAExB,IAAMA,UAAU,GAAGC,sBAAW,CAACC,MAAM,CAAC;EACpCC,QAAQ,EAAE;IACRC,GAAG,EAAEC;EACP,CAAC;EAEDC,SAAS,EAAE,YAAY;EAEvBC,sBAAsB,kCAACC,KAAK,EAAE;IAC5B,OAAO,IAAI,CAACJ,GAAG,CAACG,sBAAsB,CAACC,KAAK,CAAC;EAC/C,CAAC;EAEDC,aAAa,yBAACC,GAAG,EAAEC,MAAM,EAAE;IACzB,OAAO,IAAAC,qBAAY,EAACD,MAAM,CAAC,CAACE,IAAI,CAAC,UAACC,CAAC,EAAK;MACtC;MACA,IAAIH,MAAM,CAACI,MAAM,KAAK,CAAC,IAAIJ,MAAM,CAACK,UAAU,KAAK,CAAC,EAAE;QAClD,OAAO,iBAAQC,MAAM,CAAC,IAAIC,KAAK,CAAC,yCAAyC,CAAC,CAAC;MAC7E;MAEA,OAAOR,GAAG,CAACS,OAAO,CAACL,CAAC,CAAC;IACvB,CAAC,CAAC;EACJ,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEM,UAAU,sBAACC,GAAG,EAAEC,SAAS,EAAEC,OAAO,EAAE;IAClC,OAAO,IAAI,CAACC,MAAM,CAACH,GAAG,EAAEE,OAAO,CAAC,CAACV,IAAI,CAAC,UAACY,CAAC;MAAA,OAAKC,gBA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AAC;EAAA;AACH,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,CAACxE,CAAC,EAAEyE,CAAC,EAAE;EACtB,IAAIzE,CAAC,KAAK,KAAK,EAAE;IACf;IACA;IACA,IAAM0E,IAAI,GAAG,IAAI,CAAC1E,CAAC,CAAC,CAAC2E,MAAM,CAAC,IAAI,CAAC;IAEjC,OAAOD,IAAI;EACb;EAEA,OAAOD,CAAC;AACV;AAAC,eAEclG,UAAU;AAAA"}
1
+ {"version":3,"names":["Encryption","WebexPlugin","extend","children","kms","KMS","namespace","processKmsMessageEvent","event","decryptBinary","scr","buffer","ensureBuffer","then","b","length","byteLength","reject","Error","decrypt","decryptScr","key","cipherScr","options","getKey","k","SCR","fromJWE","jwk","decryptText","ciphertext","jose","JWE","createDecrypt","result","plaintext","toString","download","fileUrl","shunt","EventEmitter","promise","_fetchDownloadUrl","uri","method","responseType","ret","request","transferEvents","res","body","proxyEvents","logger","info","process","env","NODE_ENV","includes","resolve","inputBody","endpoints","endpointUrl","url","parse","protocol","pathname","format","allow","params","warn","catch","err","encryptBinary","file","create","encrypt","cdata","encryptScr","loc","toJWE","encryptText","createEncrypt","config","joseOptions","header","alg","reference","final","onBehalfOf","asKey","storageKey","unboundedStorage","get","keyString","JSON","keyObject","fetchKey","tap","put","replacer","v","json","toJSON"],"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;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AAAwB;AAAA;AAExB,IAAMA,UAAU,GAAGC,sBAAW,CAACC,MAAM,CAAC;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ebexPlugin.extend((_dec = (0, _common.oneFlight)({
802
802
  context.ephemeralKey = originalContext.ephemeralKey;
803
803
  return context;
804
804
  },
805
- version: "3.0.0-beta.169"
805
+ version: "3.0.0-beta.170"
806
806
  }, ((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)));
807
807
  var _default = KMS;
808
808
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webex/internal-plugin-encryption",
3
- "version": "3.0.0-beta.169",
3
+ "version": "3.0.0-beta.170",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -24,22 +24,22 @@
24
24
  ]
25
25
  },
26
26
  "devDependencies": {
27
- "@webex/test-helper-chai": "3.0.0-beta.169",
28
- "@webex/test-helper-make-local-url": "3.0.0-beta.169",
29
- "@webex/test-helper-mocha": "3.0.0-beta.169",
30
- "@webex/test-helper-mock-webex": "3.0.0-beta.169",
31
- "@webex/test-helper-test-users": "3.0.0-beta.169",
27
+ "@webex/test-helper-chai": "3.0.0-beta.170",
28
+ "@webex/test-helper-make-local-url": "3.0.0-beta.170",
29
+ "@webex/test-helper-mocha": "3.0.0-beta.170",
30
+ "@webex/test-helper-mock-webex": "3.0.0-beta.170",
31
+ "@webex/test-helper-test-users": "3.0.0-beta.170",
32
32
  "sinon": "^9.2.4"
33
33
  },
34
34
  "dependencies": {
35
- "@webex/common": "3.0.0-beta.169",
36
- "@webex/common-timers": "3.0.0-beta.169",
37
- "@webex/http-core": "3.0.0-beta.169",
38
- "@webex/internal-plugin-device": "3.0.0-beta.169",
39
- "@webex/internal-plugin-encryption": "3.0.0-beta.169",
40
- "@webex/internal-plugin-mercury": "3.0.0-beta.169",
41
- "@webex/test-helper-file": "3.0.0-beta.169",
42
- "@webex/webex-core": "3.0.0-beta.169",
35
+ "@webex/common": "3.0.0-beta.170",
36
+ "@webex/common-timers": "3.0.0-beta.170",
37
+ "@webex/http-core": "3.0.0-beta.170",
38
+ "@webex/internal-plugin-device": "3.0.0-beta.170",
39
+ "@webex/internal-plugin-encryption": "3.0.0-beta.170",
40
+ "@webex/internal-plugin-mercury": "3.0.0-beta.170",
41
+ "@webex/test-helper-file": "3.0.0-beta.170",
42
+ "@webex/webex-core": "3.0.0-beta.170",
43
43
  "asn1js": "^2.0.26",
44
44
  "debug": "^4.3.4",
45
45
  "isomorphic-webcrypto": "^2.3.8",
package/src/encryption.js CHANGED
@@ -67,19 +67,19 @@ const Encryption = WebexPlugin.extend({
67
67
 
68
68
  /**
69
69
  * Validate and initiate a Download request for requested file
70
- *
70
+ * @param {Object} fileUrl - Plaintext
71
71
  * @param {Object} scr - Plaintext
72
72
  * @param {Object} options - optional parameters to download a file
73
73
  * @returns {promise}
74
74
  */
75
- download(scr, options) {
75
+ download(fileUrl, scr, options) {
76
76
  /* istanbul ignore if */
77
- if (!scr.loc) {
78
- return Promise.reject(new Error('`scr.loc` is required'));
77
+ if (!fileUrl || !scr) {
78
+ return Promise.reject(new Error('`scr` and `fileUrl` are required'));
79
79
  }
80
80
 
81
81
  const shunt = new EventEmitter();
82
- const promise = this._fetchDownloadUrl(scr, options)
82
+ const promise = this._fetchDownloadUrl(fileUrl, options)
83
83
  .then((uri) => {
84
84
  // eslint-disable-next-line no-shadow
85
85
  const options = {
@@ -103,26 +103,25 @@ const Encryption = WebexPlugin.extend({
103
103
 
104
104
  /**
105
105
  * Fetch Download URL for the requested file
106
- *
107
- * @param {Object} scr - Plaintext
106
+ * @param {Object} fileUrl - Plaintext
108
107
  * @param {Object} options - optional parameters to download a file
109
108
  * @returns {promise} url of the downloadable file
110
109
  */
111
- _fetchDownloadUrl(scr, options) {
110
+ _fetchDownloadUrl(fileUrl, options) {
112
111
  this.logger.info('encryption: retrieving download url for encrypted file');
113
112
 
114
- if (process.env.NODE_ENV !== 'production' && scr.loc.includes('localhost')) {
113
+ if (process.env.NODE_ENV !== 'production' && fileUrl.includes('localhost')) {
115
114
  this.logger.info(
116
115
  'encryption: bypassing webex files because this looks to be a test file on localhost'
117
116
  );
118
117
 
119
- return Promise.resolve(scr.loc);
118
+ return Promise.resolve(fileUrl);
120
119
  }
121
120
 
122
121
  const inputBody = {
123
- endpoints: [scr.loc],
122
+ endpoints: [fileUrl],
124
123
  };
125
- const endpointUrl = url.parse(scr.loc);
124
+ const endpointUrl = url.parse(fileUrl);
126
125
 
127
126
  // hardcode the url to use 'https' and the file service '/v1/download/endpoints' api
128
127
  endpointUrl.protocol = 'https';
@@ -137,21 +136,29 @@ const Encryption = WebexPlugin.extend({
137
136
  allow: options.params.allow,
138
137
  }
139
138
  : inputBody,
140
- }).then((res) => {
141
- // eslint-disable-next-line no-shadow
142
- const url = res.body.endpoints[scr.loc];
139
+ })
140
+ .then((res) => {
141
+ // eslint-disable-next-line no-shadow
142
+ const url = res.body.endpoints[fileUrl];
143
+
144
+ if (!url) {
145
+ this.logger.warn(
146
+ 'encryption: could not determine download url for `fileUrl`; attempting to download `fileUrl` directly'
147
+ );
143
148
 
144
- if (!url) {
149
+ return fileUrl;
150
+ }
151
+ this.logger.info('encryption: retrieved download url for encrypted file');
152
+
153
+ return url;
154
+ })
155
+ .catch((err) => {
145
156
  this.logger.warn(
146
- 'encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly'
157
+ `encryption: ${err} could not determine download url for ${fileUrl}; attempting to download ${fileUrl} directly`
147
158
  );
148
159
 
149
- return scr.loc;
150
- }
151
- this.logger.info('encryption: retrieved download url for encrypted file');
152
-
153
- return url;
154
- });
160
+ return fileUrl;
161
+ });
155
162
  },
156
163
 
157
164
  encryptBinary(file) {
@@ -22,18 +22,18 @@ describe('internal-plugin-encryption', () => {
22
22
  });
23
23
 
24
24
  describe('check _fetchDownloadUrl()', () => {
25
- const scrArray = [
25
+ const fileArray = [
26
26
  {
27
- loc: 'https://files-api-intb1.ciscospark.com/v1/spaces/a0cba376-fc05-4b88-af4b-cfffa7465f9a/contents/1d3931e7-9e31-46bc-8084-d766a8f72c99/versions/5fa9caf87a98410aae49e0173856a974/bytes',
27
+ url: 'https://files-api-intb1.ciscospark.com/v1/spaces/a0cba376-fc05-4b88-af4b-cfffa7465f9a/contents/1d3931e7-9e31-46bc-8084-d766a8f72c99/versions/5fa9caf87a98410aae49e0173856a974/bytes',
28
28
  },
29
29
  {
30
- loc: 'https://files-api-intb2.ciscospark.com/v1/spaces/a0cba376-fc05-4b88-af4b-cfffa7465f9a/contents/1d3931e7-9e31-46bc-8084-d766a8f72c99/versions/5fa9caf87a98410aae49e0173856a974/bytes',
30
+ url: 'https://files-api-intb2.ciscospark.com/v1/spaces/a0cba376-fc05-4b88-af4b-cfffa7465f9a/contents/1d3931e7-9e31-46bc-8084-d766a8f72c99/versions/5fa9caf87a98410aae49e0173856a974/bytes',
31
31
  },
32
32
  {
33
- loc: 'https://www.test-api.com/v1/spaces/test-path-name-space/contents/test-path-name-contents/versions/test-version/bytes',
33
+ url: 'https://www.test-api.com/v1/spaces/test-path-name-space/contents/test-path-name-contents/versions/test-version/bytes',
34
34
  },
35
35
  {
36
- loc: 'http://www.test-api.com/v1/spaces/test-path-name-space/contents/test-path-name-contents/versions/test-version/bytes',
36
+ url: 'http://www.test-api.com/v1/spaces/test-path-name-space/contents/test-path-name-contents/versions/test-version/bytes',
37
37
  },
38
38
  ];
39
39
  const options = undefined;
@@ -44,7 +44,7 @@ describe('internal-plugin-encryption', () => {
44
44
 
45
45
  spyStub = sinon.stub(webex.internal.encryption, 'request').callsFake(returnStub);
46
46
 
47
- scrArray.forEach((scr) => webex.internal.encryption._fetchDownloadUrl(scr, options));
47
+ fileArray.forEach((file) => webex.internal.encryption._fetchDownloadUrl(file.url, options));
48
48
  });
49
49
 
50
50
  it('verifying file service uris', () => {
@@ -68,10 +68,10 @@ describe('internal-plugin-encryption', () => {
68
68
  });
69
69
 
70
70
  it('verifying endpoints', () => {
71
- assert.equal(spyStub.args[0][0].body.endpoints[0], scrArray[0].loc);
72
- assert.equal(spyStub.args[1][0].body.endpoints[0], scrArray[1].loc);
73
- assert.equal(spyStub.args[2][0].body.endpoints[0], scrArray[2].loc);
74
- assert.equal(spyStub.args[3][0].body.endpoints[0], scrArray[3].loc);
71
+ assert.equal(spyStub.args[0][0].body.endpoints[0], fileArray[0].url);
72
+ assert.equal(spyStub.args[1][0].body.endpoints[0], fileArray[1].url);
73
+ assert.equal(spyStub.args[2][0].body.endpoints[0], fileArray[2].url);
74
+ assert.equal(spyStub.args[3][0].body.endpoints[0], fileArray[3].url);
75
75
  });
76
76
 
77
77
  afterEach(() => {