@webex/internal-plugin-encryption 3.0.0-beta.15 → 3.0.0-beta.17
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 +0 -9
- package/dist/config.js.map +1 -1
- package/dist/encryption.js +7 -60
- package/dist/encryption.js.map +1 -1
- package/dist/ensure-buffer.browser.js +0 -10
- package/dist/ensure-buffer.browser.js.map +1 -1
- package/dist/ensure-buffer.js +0 -7
- package/dist/ensure-buffer.js.map +1 -1
- package/dist/index.js +5 -31
- package/dist/index.js.map +1 -1
- package/dist/kms-batcher.js +6 -30
- package/dist/kms-batcher.js.map +1 -1
- package/dist/kms-certificate-validation.js +18 -86
- package/dist/kms-certificate-validation.js.map +1 -1
- package/dist/kms-dry-error-interceptor.js +1 -23
- package/dist/kms-dry-error-interceptor.js.map +1 -1
- package/dist/kms-errors.js +3 -50
- package/dist/kms-errors.js.map +1 -1
- package/dist/kms.js +58 -197
- package/dist/kms.js.map +1 -1
- package/package.json +14 -14
package/dist/config.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
_Object$defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
|
|
9
7
|
exports.default = void 0;
|
|
10
|
-
|
|
11
8
|
/*!
|
|
12
9
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
13
10
|
*/
|
|
@@ -18,38 +15,32 @@ var _default = {
|
|
|
18
15
|
contentAlg: 'A256GCM',
|
|
19
16
|
protect: '*'
|
|
20
17
|
},
|
|
21
|
-
|
|
22
18
|
/**
|
|
23
19
|
* Initial timeout before contacting KMS with a new request
|
|
24
20
|
* @type {Number}
|
|
25
21
|
*/
|
|
26
22
|
kmsInitialTimeout: 6000,
|
|
27
|
-
|
|
28
23
|
/**
|
|
29
24
|
* Maximum timeout before negotiating a new ECDH key
|
|
30
25
|
* and contacting KMS with a new request
|
|
31
26
|
* @type {Number}
|
|
32
27
|
*/
|
|
33
28
|
kmsMaxTimeout: 32000,
|
|
34
|
-
|
|
35
29
|
/**
|
|
36
30
|
* Maximum timeout after negotiating several ECDH keys
|
|
37
31
|
* @type {Number}
|
|
38
32
|
*/
|
|
39
33
|
ecdhMaxTimeout: 32000 * 3,
|
|
40
|
-
|
|
41
34
|
/**
|
|
42
35
|
* Debounce wait before sending a kms request
|
|
43
36
|
* @type {Number}
|
|
44
37
|
*/
|
|
45
38
|
batcherWait: 50,
|
|
46
|
-
|
|
47
39
|
/**
|
|
48
40
|
* Maximum queue size before sending a kms request
|
|
49
41
|
* @type {Number}
|
|
50
42
|
*/
|
|
51
43
|
batcherMaxCalls: 50,
|
|
52
|
-
|
|
53
44
|
/**
|
|
54
45
|
* Debounce max wait before sending a kms metric
|
|
55
46
|
* @type {Number}
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["encryption","joseOptions","compact","contentAlg","protect","kmsInitialTimeout","kmsMaxTimeout","ecdhMaxTimeout","batcherWait","batcherMaxCalls","batcherMaxWait"],"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":"
|
|
1
|
+
{"version":3,"names":["encryption","joseOptions","compact","contentAlg","protect","kmsInitialTimeout","kmsMaxTimeout","ecdhMaxTimeout","batcherWait","batcherMaxCalls","batcherMaxWait"],"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,eAIe;EACbA,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;AAAA"}
|
package/dist/encryption.js
CHANGED
|
@@ -1,51 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
|
|
4
|
-
|
|
5
4
|
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
|
|
6
|
-
|
|
7
5
|
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
|
8
|
-
|
|
9
6
|
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
|
|
10
|
-
|
|
11
7
|
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
|
|
12
|
-
|
|
13
8
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
14
|
-
|
|
15
9
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
16
|
-
|
|
17
10
|
_Object$defineProperty(exports, "__esModule", {
|
|
18
11
|
value: true
|
|
19
12
|
});
|
|
20
|
-
|
|
21
13
|
exports.default = void 0;
|
|
22
|
-
|
|
23
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
24
|
-
|
|
25
15
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
26
|
-
|
|
27
16
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
|
|
28
|
-
|
|
29
17
|
var _events = require("events");
|
|
30
|
-
|
|
31
18
|
var _url = _interopRequireDefault(require("url"));
|
|
32
|
-
|
|
33
19
|
var _webexCore = require("@webex/webex-core");
|
|
34
|
-
|
|
35
20
|
var _common = require("@webex/common");
|
|
36
|
-
|
|
37
21
|
var _nodeJose = _interopRequireDefault(require("node-jose"));
|
|
38
|
-
|
|
39
22
|
var _nodeScr = _interopRequireDefault(require("node-scr"));
|
|
40
|
-
|
|
41
23
|
var _ensureBuffer = _interopRequireDefault(require("./ensure-buffer"));
|
|
42
|
-
|
|
43
24
|
var _kms = _interopRequireDefault(require("./kms"));
|
|
44
|
-
|
|
45
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; }
|
|
46
|
-
|
|
47
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; }
|
|
48
|
-
|
|
49
27
|
var Encryption = _webexCore.WebexPlugin.extend({
|
|
50
28
|
children: {
|
|
51
29
|
kms: _kms.default
|
|
@@ -60,11 +38,9 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
60
38
|
if (buffer.length === 0 || buffer.byteLength === 0) {
|
|
61
39
|
return _promise.default.reject(new Error('Attempted to decrypt zero-length buffer'));
|
|
62
40
|
}
|
|
63
|
-
|
|
64
41
|
return scr.decrypt(b);
|
|
65
42
|
});
|
|
66
43
|
},
|
|
67
|
-
|
|
68
44
|
/**
|
|
69
45
|
* Decrypt a SCR (Secure Content Resource) using the supplied key uri.
|
|
70
46
|
*
|
|
@@ -79,7 +55,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
79
55
|
return _nodeScr.default.fromJWE(k.jwk, cipherScr);
|
|
80
56
|
});
|
|
81
57
|
},
|
|
82
|
-
|
|
83
58
|
/**
|
|
84
59
|
* Decrypt text using the supplied key uri.
|
|
85
60
|
*
|
|
@@ -96,7 +71,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
96
71
|
});
|
|
97
72
|
});
|
|
98
73
|
},
|
|
99
|
-
|
|
100
74
|
/**
|
|
101
75
|
* Validate and initiate a Download request for requested file
|
|
102
76
|
*
|
|
@@ -106,14 +80,11 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
106
80
|
*/
|
|
107
81
|
download: function download(scr, options) {
|
|
108
82
|
var _this = this;
|
|
109
|
-
|
|
110
83
|
/* istanbul ignore if */
|
|
111
84
|
if (!scr.loc) {
|
|
112
85
|
return _promise.default.reject(new Error('`scr.loc` is required'));
|
|
113
86
|
}
|
|
114
|
-
|
|
115
87
|
var shunt = new _events.EventEmitter();
|
|
116
|
-
|
|
117
88
|
var promise = this._fetchDownloadUrl(scr, options).then(function (uri) {
|
|
118
89
|
// eslint-disable-next-line no-shadow
|
|
119
90
|
var options = {
|
|
@@ -121,19 +92,15 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
121
92
|
uri: uri,
|
|
122
93
|
responseType: 'buffer'
|
|
123
94
|
};
|
|
124
|
-
|
|
125
95
|
var ret = _this.request(options);
|
|
126
|
-
|
|
127
96
|
(0, _common.transferEvents)('progress', options.download, shunt);
|
|
128
97
|
return ret;
|
|
129
98
|
}).then(function (res) {
|
|
130
99
|
return _this.decryptBinary(scr, res.body);
|
|
131
100
|
});
|
|
132
|
-
|
|
133
101
|
(0, _common.proxyEvents)(shunt, promise);
|
|
134
102
|
return promise;
|
|
135
103
|
},
|
|
136
|
-
|
|
137
104
|
/**
|
|
138
105
|
* Fetch Download URL for the requested file
|
|
139
106
|
*
|
|
@@ -143,21 +110,17 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
143
110
|
*/
|
|
144
111
|
_fetchDownloadUrl: function _fetchDownloadUrl(scr, options) {
|
|
145
112
|
var _this2 = this;
|
|
146
|
-
|
|
147
113
|
this.logger.info('encryption: retrieving download url for encrypted file');
|
|
148
|
-
|
|
149
114
|
if (process.env.NODE_ENV !== 'production' && scr.loc.includes('localhost')) {
|
|
150
115
|
this.logger.info('encryption: bypassing webex files because this looks to be a test file on localhost');
|
|
151
116
|
return _promise.default.resolve(scr.loc);
|
|
152
117
|
}
|
|
153
|
-
|
|
154
118
|
var inputBody = {
|
|
155
119
|
endpoints: [scr.loc]
|
|
156
120
|
};
|
|
121
|
+
var endpointUrl = _url.default.parse(scr.loc);
|
|
157
122
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
123
|
+
// hardcode the url to use 'https' and the file service '/v1/download/endpoints' api
|
|
161
124
|
endpointUrl.protocol = 'https';
|
|
162
125
|
endpointUrl.pathname = '/v1/download/endpoints';
|
|
163
126
|
return this.request({
|
|
@@ -169,22 +132,19 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
169
132
|
}).then(function (res) {
|
|
170
133
|
// eslint-disable-next-line no-shadow
|
|
171
134
|
var url = res.body.endpoints[scr.loc];
|
|
172
|
-
|
|
173
135
|
if (!url) {
|
|
174
136
|
_this2.logger.warn('encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly');
|
|
175
|
-
|
|
176
137
|
return scr.loc;
|
|
177
138
|
}
|
|
178
|
-
|
|
179
139
|
_this2.logger.info('encryption: retrieved download url for encrypted file');
|
|
180
|
-
|
|
181
140
|
return url;
|
|
182
141
|
});
|
|
183
142
|
},
|
|
184
143
|
encryptBinary: function encryptBinary(file) {
|
|
185
144
|
return (0, _ensureBuffer.default)(file).then(function (buffer) {
|
|
186
145
|
return _nodeScr.default.create().then(function (scr) {
|
|
187
|
-
return scr.encrypt(buffer).then(_ensureBuffer.default)
|
|
146
|
+
return scr.encrypt(buffer).then(_ensureBuffer.default)
|
|
147
|
+
// eslint-disable-next-line max-nested-callbacks
|
|
188
148
|
.then(function (cdata) {
|
|
189
149
|
return {
|
|
190
150
|
scr: scr,
|
|
@@ -194,7 +154,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
194
154
|
});
|
|
195
155
|
});
|
|
196
156
|
},
|
|
197
|
-
|
|
198
157
|
/**
|
|
199
158
|
* Encrypt a SCR (Secure Content Resource) using the supplied key uri.
|
|
200
159
|
*
|
|
@@ -209,12 +168,10 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
209
168
|
if (!scr.loc) {
|
|
210
169
|
return _promise.default.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));
|
|
211
170
|
}
|
|
212
|
-
|
|
213
171
|
return this.getKey(key, options).then(function (k) {
|
|
214
172
|
return scr.toJWE(k.jwk);
|
|
215
173
|
});
|
|
216
174
|
},
|
|
217
|
-
|
|
218
175
|
/**
|
|
219
176
|
* Encrypt plaintext using the supplied key uri.
|
|
220
177
|
*
|
|
@@ -226,7 +183,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
226
183
|
*/
|
|
227
184
|
encryptText: function encryptText(key, plaintext, options) {
|
|
228
185
|
var _this3 = this;
|
|
229
|
-
|
|
230
186
|
return this.getKey(key, options).then(function (k) {
|
|
231
187
|
return _nodeJose.default.JWE.createEncrypt(_this3.config.joseOptions, {
|
|
232
188
|
key: k.jwk,
|
|
@@ -237,7 +193,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
237
193
|
}).final(plaintext, 'utf8');
|
|
238
194
|
});
|
|
239
195
|
},
|
|
240
|
-
|
|
241
196
|
/**
|
|
242
197
|
* Fetch the key associated with the supplied KMS uri.
|
|
243
198
|
*
|
|
@@ -248,20 +203,15 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
248
203
|
*/
|
|
249
204
|
getKey: function getKey(uri) {
|
|
250
205
|
var _this4 = this;
|
|
251
|
-
|
|
252
206
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
253
|
-
|
|
254
|
-
|
|
207
|
+
onBehalfOf = _ref.onBehalfOf;
|
|
255
208
|
if (uri.jwk) {
|
|
256
209
|
return this.kms.asKey(uri);
|
|
257
210
|
}
|
|
258
|
-
|
|
259
211
|
var storageKey = uri;
|
|
260
|
-
|
|
261
212
|
if (onBehalfOf) {
|
|
262
213
|
storageKey += "/onBehalfOf/".concat(onBehalfOf);
|
|
263
214
|
}
|
|
264
|
-
|
|
265
215
|
return this.unboundedStorage.get(storageKey).then(function (keyString) {
|
|
266
216
|
return JSON.parse(keyString);
|
|
267
217
|
}).then(function (keyObject) {
|
|
@@ -275,16 +225,15 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
275
225
|
}));
|
|
276
226
|
});
|
|
277
227
|
},
|
|
278
|
-
version: "3.0.0-beta.
|
|
228
|
+
version: "3.0.0-beta.17"
|
|
279
229
|
});
|
|
230
|
+
|
|
280
231
|
/**
|
|
281
232
|
* JSON.stringify replacer that ensures private key data is serialized.
|
|
282
233
|
* @param {string} k
|
|
283
234
|
* @param {mixed} v
|
|
284
235
|
* @returns {mixed}
|
|
285
236
|
*/
|
|
286
|
-
|
|
287
|
-
|
|
288
237
|
function replacer(k, v) {
|
|
289
238
|
if (k === 'jwk') {
|
|
290
239
|
// note: this[k] and v may be different representations of the same value
|
|
@@ -292,10 +241,8 @@ function replacer(k, v) {
|
|
|
292
241
|
var json = this[k].toJSON(true);
|
|
293
242
|
return json;
|
|
294
243
|
}
|
|
295
|
-
|
|
296
244
|
return v;
|
|
297
245
|
}
|
|
298
|
-
|
|
299
246
|
var _default = Encryption;
|
|
300
247
|
exports.default = _default;
|
|
301
248
|
//# sourceMappingURL=encryption.js.map
|
package/dist/encryption.js.map
CHANGED
|
@@ -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;;;;;;AAEA,IAAMA,UAAU,GAAGC,sBAAA,CAAYC,MAAZ,CAAmB;EACpCC,QAAQ,EAAE;IACRC,GAAG,EAAEC;EADG,CAD0B;EAKpCC,SAAS,EAAE,YALyB;EAOpCC,sBAPoC,kCAObC,KAPa,EAON;IAC5B,OAAO,KAAKJ,GAAL,CAASG,sBAAT,CAAgCC,KAAhC,CAAP;EACD,CATmC;EAWpCC,aAXoC,yBAWtBC,GAXsB,EAWjBC,MAXiB,EAWT;IACzB,OAAO,IAAAC,qBAAA,EAAaD,MAAb,EAAqBE,IAArB,CAA0B,UAACC,CAAD,EAAO;MACtC;MACA,IAAIH,MAAM,CAACI,MAAP,KAAkB,CAAlB,IAAuBJ,MAAM,CAACK,UAAP,KAAsB,CAAjD,EAAoD;QAClD,OAAO,iBAAQC,MAAR,CAAe,IAAIC,KAAJ,CAAU,yCAAV,CAAf,CAAP;MACD;;MAED,OAAOR,GAAG,CAACS,OAAJ,CAAYL,CAAZ,CAAP;IACD,CAPM,CAAP;EAQD,CApBmC;;EAsBpC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEM,UA/BoC,sBA+BzBC,GA/ByB,EA+BpB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;MAAA,OACL,MAAI,CAACzF,GAAL,CACG0F,QADH,CACY;QAACnD,GAAG,EAAHA,GAAD;QAAM0C,UAAU,EAAVA;MAAN,CADZ,EAEGxE,IAFH,CAEQ,IAAAkF,WAAA,EAAI,UAAC1E,GAAD;QAAA,OAAS,MAAI,CAACmE,gBAAL,CAAsBQ,GAAtB,CAA0BT,UAA1B,EAAsC,wBAAelE,GAAf,EAAoB4E,QAApB,CAAtC,CAAT;MAAA,CAAJ,CAFR,CADK;IAAA,CAJF,CAAP;EASD,CA5NmC;EAAA;AAAA,CAAnB,CAAnB;AA+NA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASA,QAAT,CAAkBxE,CAAlB,EAAqByE,CAArB,EAAwB;EACtB,IAAIzE,CAAC,KAAK,KAAV,EAAiB;IACf;IACA;IACA,IAAM0E,IAAI,GAAG,KAAK1E,CAAL,EAAQ2E,MAAR,CAAe,IAAf,CAAb;IAEA,OAAOD,IAAP;EACD;;EAED,OAAOD,CAAP;AACD;;eAEclG,U"}
|
|
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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;AACV;AAAC,eAEclG,UAAU;AAAA"}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = ensureBuffer;
|
|
12
|
-
|
|
13
9
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
14
|
-
|
|
15
10
|
/*!
|
|
16
11
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
17
12
|
*/
|
|
@@ -28,22 +23,17 @@ function ensureBuffer(buffer) {
|
|
|
28
23
|
if (buffer instanceof ArrayBuffer) {
|
|
29
24
|
return _promise.default.resolve(buffer);
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
if (buffer.toArrayBuffer) {
|
|
33
27
|
return _promise.default.resolve(buffer.toArrayBuffer());
|
|
34
28
|
}
|
|
35
|
-
|
|
36
29
|
if (buffer.buffer) {
|
|
37
30
|
return _promise.default.resolve(buffer.buffer);
|
|
38
31
|
}
|
|
39
|
-
|
|
40
32
|
return new _promise.default(function (resolve, reject) {
|
|
41
33
|
var fr = new FileReader();
|
|
42
|
-
|
|
43
34
|
fr.onload = function onload() {
|
|
44
35
|
resolve(new Uint8Array(this.result));
|
|
45
36
|
};
|
|
46
|
-
|
|
47
37
|
fr.onerror = reject;
|
|
48
38
|
fr.readAsArrayBuffer(buffer);
|
|
49
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ensureBuffer","buffer","ArrayBuffer","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":"
|
|
1
|
+
{"version":3,"names":["ensureBuffer","buffer","ArrayBuffer","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,YAAY,CAACC,MAAM,EAAE;EAC3C,IAAIA,MAAM,YAAYC,WAAW,EAAE;IACjC,OAAO,iBAAQC,OAAO,CAACF,MAAM,CAAC;EAChC;EAEA,IAAIA,MAAM,CAACG,aAAa,EAAE;IACxB,OAAO,iBAAQD,OAAO,CAACF,MAAM,CAACG,aAAa,EAAE,CAAC;EAChD;EAEA,IAAIH,MAAM,CAACA,MAAM,EAAE;IACjB,OAAO,iBAAQE,OAAO,CAACF,MAAM,CAACA,MAAM,CAAC;EACvC;EAEA,OAAO,qBAAY,UAACE,OAAO,EAAEE,MAAM,EAAK;IACtC,IAAMC,EAAE,GAAG,IAAIC,UAAU,EAAE;IAE3BD,EAAE,CAACE,MAAM,GAAG,SAASA,MAAM,GAAG;MAC5BL,OAAO,CAAC,IAAIM,UAAU,CAAC,IAAI,CAACC,MAAM,CAAC,CAAC;IACtC,CAAC;IAEDJ,EAAE,CAACK,OAAO,GAAGN,MAAM;IAEnBC,EAAE,CAACM,iBAAiB,CAACX,MAAM,CAAC;EAC9B,CAAC,CAAC;AACJ"}
|
package/dist/ensure-buffer.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = ensureBuffer;
|
|
12
|
-
|
|
13
9
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
14
|
-
|
|
15
10
|
var _common = require("@webex/common");
|
|
16
|
-
|
|
17
11
|
/*!
|
|
18
12
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
19
13
|
*/
|
|
@@ -29,7 +23,6 @@ function ensureBuffer(buffer) {
|
|
|
29
23
|
if (!(0, _common.isBuffer)(buffer)) {
|
|
30
24
|
return _promise.default.reject(new Error('`buffer` must be a buffer'));
|
|
31
25
|
}
|
|
32
|
-
|
|
33
26
|
return _promise.default.resolve(buffer);
|
|
34
27
|
}
|
|
35
28
|
//# sourceMappingURL=ensure-buffer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ensureBuffer","buffer","isBuffer","reject","Error","resolve"],"sources":["ensure-buffer.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {isBuffer} from '@webex/common';\n\n/**\n * Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be\n * byte-arrays instead of proper Buffer objects.\n * @param {mixed} buffer\n * @returns {Promise<Buffer>}\n */\nexport default function ensureBuffer(buffer) {\n /* istanbul ignore if */\n if (!isBuffer(buffer)) {\n return Promise.reject(new Error('`buffer` must be a buffer'));\n }\n\n return Promise.resolve(buffer);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["ensureBuffer","buffer","isBuffer","reject","Error","resolve"],"sources":["ensure-buffer.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {isBuffer} from '@webex/common';\n\n/**\n * Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be\n * byte-arrays instead of proper Buffer objects.\n * @param {mixed} buffer\n * @returns {Promise<Buffer>}\n */\nexport default function ensureBuffer(buffer) {\n /* istanbul ignore if */\n if (!isBuffer(buffer)) {\n return Promise.reject(new Error('`buffer` must be a buffer'));\n }\n\n return Promise.resolve(buffer);\n}\n"],"mappings":";;;;;;;;;AAIA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAY,CAACC,MAAM,EAAE;EAC3C;EACA,IAAI,CAAC,IAAAC,gBAAQ,EAACD,MAAM,CAAC,EAAE;IACrB,OAAO,iBAAQE,MAAM,CAAC,IAAIC,KAAK,CAAC,2BAA2B,CAAC,CAAC;EAC/D;EAEA,OAAO,iBAAQC,OAAO,CAACJ,MAAM,CAAC;AAChC"}
|
package/dist/index.js
CHANGED
|
@@ -1,81 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
_Object$defineProperty(exports, "DryError", {
|
|
12
9
|
enumerable: true,
|
|
13
10
|
get: function get() {
|
|
14
11
|
return _kmsErrors.DryError;
|
|
15
12
|
}
|
|
16
13
|
});
|
|
17
|
-
|
|
18
14
|
_Object$defineProperty(exports, "KMS", {
|
|
19
15
|
enumerable: true,
|
|
20
16
|
get: function get() {
|
|
21
17
|
return _kms.default;
|
|
22
18
|
}
|
|
23
19
|
});
|
|
24
|
-
|
|
25
20
|
_Object$defineProperty(exports, "KmsError", {
|
|
26
21
|
enumerable: true,
|
|
27
22
|
get: function get() {
|
|
28
23
|
return _kmsErrors.KmsError;
|
|
29
24
|
}
|
|
30
25
|
});
|
|
31
|
-
|
|
32
26
|
_Object$defineProperty(exports, "default", {
|
|
33
27
|
enumerable: true,
|
|
34
28
|
get: function get() {
|
|
35
29
|
return _encryption.default;
|
|
36
30
|
}
|
|
37
31
|
});
|
|
38
|
-
|
|
39
32
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
40
|
-
|
|
41
33
|
var _isString2 = _interopRequireDefault(require("lodash/isString"));
|
|
42
|
-
|
|
43
34
|
var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
|
|
44
|
-
|
|
45
35
|
var _has2 = _interopRequireDefault(require("lodash/has"));
|
|
46
|
-
|
|
47
36
|
require("@webex/internal-plugin-device");
|
|
48
|
-
|
|
49
37
|
require("@webex/internal-plugin-mercury");
|
|
50
|
-
|
|
51
38
|
var _webexCore = require("@webex/webex-core");
|
|
52
|
-
|
|
53
39
|
var _encryption = _interopRequireDefault(require("./encryption"));
|
|
54
|
-
|
|
55
40
|
var _config = _interopRequireDefault(require("./config"));
|
|
56
|
-
|
|
57
41
|
var _kmsErrors = require("./kms-errors");
|
|
58
|
-
|
|
59
42
|
var _kmsDryErrorInterceptor = _interopRequireDefault(require("./kms-dry-error-interceptor"));
|
|
60
|
-
|
|
61
43
|
var _kms = _interopRequireDefault(require("./kms"));
|
|
62
|
-
|
|
63
44
|
/*!
|
|
64
45
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
65
46
|
*/
|
|
47
|
+
|
|
66
48
|
// Note: There's a bug where if bind gets replayed because of a timeout in which
|
|
67
49
|
// the original request eventually completed, there'll be an error indicating
|
|
68
50
|
// the key can't be bound (because it already has been). This could be mitigated
|
|
69
51
|
// by using Promise.race to resolve replays (as more requests get enqueue for a
|
|
70
52
|
// specific action, accept whichever one completes first).
|
|
71
|
-
var interceptors;
|
|
72
53
|
|
|
54
|
+
var interceptors;
|
|
73
55
|
if (process.env.NODE_ENV === 'test') {
|
|
74
56
|
interceptors = {
|
|
75
57
|
KmsDryErrorInterceptor: _kmsDryErrorInterceptor.default.create
|
|
76
58
|
};
|
|
77
59
|
}
|
|
78
|
-
|
|
79
60
|
(0, _webexCore.registerInternalPlugin)('encryption', _encryption.default, {
|
|
80
61
|
payloadTransformer: {
|
|
81
62
|
predicates: [{
|
|
@@ -87,27 +68,23 @@ if (process.env.NODE_ENV === 'test') {
|
|
|
87
68
|
if (!(0, _has2.default)(options, 'body.kmsMessage')) {
|
|
88
69
|
return _promise.default.resolve(false);
|
|
89
70
|
}
|
|
90
|
-
|
|
91
71
|
if (!(0, _isObject2.default)(options.body.kmsMessage)) {
|
|
92
72
|
return _promise.default.resolve(false);
|
|
93
|
-
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// If this is a template for a kms message, assume another transform
|
|
94
76
|
// will fill it in later. This is a bit of a leaky abstraction, but the
|
|
95
77
|
// alternative is building a complex rules engine for controlling
|
|
96
78
|
// ordering of transforms
|
|
97
|
-
|
|
98
|
-
|
|
99
79
|
if (options.body.kmsMessage.keyUris && options.body.kmsMessage.keyUris.length === 0) {
|
|
100
80
|
return _promise.default.resolve(false);
|
|
101
81
|
}
|
|
102
|
-
|
|
103
82
|
if (options.body.kmsMessage.resourceUri && (options.body.kmsMessage.resourceUri.includes('<KRO>') || options.body.kmsMessage.resourceUri.includes('<KEYURL>'))) {
|
|
104
83
|
return _promise.default.resolve(false);
|
|
105
84
|
}
|
|
106
|
-
|
|
107
85
|
if (options.body.kmsMessage.uri && (options.body.kmsMessage.uri.includes('<KRO>') || options.body.kmsMessage.uri.includes('<KEYURL>'))) {
|
|
108
86
|
return _promise.default.resolve(false);
|
|
109
87
|
}
|
|
110
|
-
|
|
111
88
|
return _promise.default.resolve(true);
|
|
112
89
|
},
|
|
113
90
|
extract: function extract(options) {
|
|
@@ -138,15 +115,12 @@ if (process.env.NODE_ENV === 'test') {
|
|
|
138
115
|
if (!object) {
|
|
139
116
|
return _promise.default.resolve();
|
|
140
117
|
}
|
|
141
|
-
|
|
142
118
|
if (!object.kmsMessage) {
|
|
143
119
|
return _promise.default.resolve();
|
|
144
120
|
}
|
|
145
|
-
|
|
146
121
|
if ((0, _isString2.default)(object.kmsMessage)) {
|
|
147
122
|
return _promise.default.resolve();
|
|
148
123
|
}
|
|
149
|
-
|
|
150
124
|
return ctx.webex.internal.encryption.kms.prepareRequest(object.kmsMessage).then(function (req) {
|
|
151
125
|
object.kmsMessage = req.wrapped;
|
|
152
126
|
});
|