@webex/internal-plugin-encryption 3.0.0-beta.9 → 3.0.0-bnr.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/dist/config.js +0 -9
- package/dist/config.js.map +1 -1
- package/dist/encryption.js +9 -60
- package/dist/encryption.js.map +1 -1
- package/dist/ensure-buffer.browser.js +0 -12
- package/dist/ensure-buffer.browser.js.map +1 -1
- package/dist/ensure-buffer.js +5 -12
- package/dist/ensure-buffer.js.map +1 -1
- package/dist/index.js +7 -33
- 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 +20 -88
- 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 +74 -213
- package/dist/kms.js.map +1 -1
- package/dist/types/config.d.ts +16 -0
- package/dist/types/encryption.d.ts +2 -0
- package/dist/types/ensure-buffer.browser.d.ts +10 -0
- package/dist/types/ensure-buffer.d.ts +7 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/kms-batcher.d.ts +6 -0
- package/dist/types/kms-certificate-validation.d.ts +24 -0
- package/dist/types/kms-dry-error-interceptor.d.ts +25 -0
- package/dist/types/kms-errors.d.ts +33 -0
- package/dist/types/kms.d.ts +5 -0
- package/package.json +15 -15
- package/src/config.js +3 -3
- package/src/encryption.js +66 -56
- package/src/ensure-buffer.browser.js +0 -1
- package/src/ensure-buffer.js +5 -5
- package/src/index.js +120 -96
- package/src/kms-batcher.js +50 -44
- package/src/kms-certificate-validation.js +45 -47
- package/src/kms-dry-error-interceptor.js +8 -4
- package/src/kms-errors.js +19 -16
- package/src/kms.js +210 -206
- package/test/integration/spec/encryption.js +311 -230
- package/test/integration/spec/kms.js +532 -404
- package/test/integration/spec/payload-transfom.js +69 -69
- package/test/unit/spec/encryption.js +16 -13
- package/test/unit/spec/kms-certificate-validation.js +41 -32
package/README.md
CHANGED
|
@@ -21,14 +21,12 @@ npm install --save @webex/internal-plugin-encryption
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
|
-
|
|
25
24
|
import '@webex/internal-plugin-encryption';
|
|
26
25
|
|
|
27
26
|
import WebexCore from '@webex/webex-core';
|
|
28
27
|
|
|
29
28
|
const webex = new WebexCore();
|
|
30
|
-
webex.internal.encryption.WHATEVER
|
|
31
|
-
|
|
29
|
+
webex.internal.encryption.WHATEVER;
|
|
32
30
|
```
|
|
33
31
|
|
|
34
32
|
## Maintainers
|
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: '*'
|
|
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,33 +80,27 @@ 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) {
|
|
89
|
+
// eslint-disable-next-line no-shadow
|
|
118
90
|
var options = {
|
|
119
91
|
method: 'GET',
|
|
120
92
|
uri: uri,
|
|
121
93
|
responseType: 'buffer'
|
|
122
94
|
};
|
|
123
|
-
|
|
124
95
|
var ret = _this.request(options);
|
|
125
|
-
|
|
126
96
|
(0, _common.transferEvents)('progress', options.download, shunt);
|
|
127
97
|
return ret;
|
|
128
98
|
}).then(function (res) {
|
|
129
99
|
return _this.decryptBinary(scr, res.body);
|
|
130
100
|
});
|
|
131
|
-
|
|
132
101
|
(0, _common.proxyEvents)(shunt, promise);
|
|
133
102
|
return promise;
|
|
134
103
|
},
|
|
135
|
-
|
|
136
104
|
/**
|
|
137
105
|
* Fetch Download URL for the requested file
|
|
138
106
|
*
|
|
@@ -142,21 +110,17 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
142
110
|
*/
|
|
143
111
|
_fetchDownloadUrl: function _fetchDownloadUrl(scr, options) {
|
|
144
112
|
var _this2 = this;
|
|
145
|
-
|
|
146
113
|
this.logger.info('encryption: retrieving download url for encrypted file');
|
|
147
|
-
|
|
148
114
|
if (process.env.NODE_ENV !== 'production' && scr.loc.includes('localhost')) {
|
|
149
115
|
this.logger.info('encryption: bypassing webex files because this looks to be a test file on localhost');
|
|
150
116
|
return _promise.default.resolve(scr.loc);
|
|
151
117
|
}
|
|
152
|
-
|
|
153
118
|
var inputBody = {
|
|
154
119
|
endpoints: [scr.loc]
|
|
155
120
|
};
|
|
121
|
+
var endpointUrl = _url.default.parse(scr.loc);
|
|
156
122
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
123
|
+
// hardcode the url to use 'https' and the file service '/v1/download/endpoints' api
|
|
160
124
|
endpointUrl.protocol = 'https';
|
|
161
125
|
endpointUrl.pathname = '/v1/download/endpoints';
|
|
162
126
|
return this.request({
|
|
@@ -166,23 +130,21 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
166
130
|
allow: options.params.allow
|
|
167
131
|
}) : inputBody
|
|
168
132
|
}).then(function (res) {
|
|
133
|
+
// eslint-disable-next-line no-shadow
|
|
169
134
|
var url = res.body.endpoints[scr.loc];
|
|
170
|
-
|
|
171
135
|
if (!url) {
|
|
172
136
|
_this2.logger.warn('encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly');
|
|
173
|
-
|
|
174
137
|
return scr.loc;
|
|
175
138
|
}
|
|
176
|
-
|
|
177
139
|
_this2.logger.info('encryption: retrieved download url for encrypted file');
|
|
178
|
-
|
|
179
140
|
return url;
|
|
180
141
|
});
|
|
181
142
|
},
|
|
182
143
|
encryptBinary: function encryptBinary(file) {
|
|
183
144
|
return (0, _ensureBuffer.default)(file).then(function (buffer) {
|
|
184
145
|
return _nodeScr.default.create().then(function (scr) {
|
|
185
|
-
return scr.encrypt(buffer).then(_ensureBuffer.default)
|
|
146
|
+
return scr.encrypt(buffer).then(_ensureBuffer.default)
|
|
147
|
+
// eslint-disable-next-line max-nested-callbacks
|
|
186
148
|
.then(function (cdata) {
|
|
187
149
|
return {
|
|
188
150
|
scr: scr,
|
|
@@ -192,7 +154,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
192
154
|
});
|
|
193
155
|
});
|
|
194
156
|
},
|
|
195
|
-
|
|
196
157
|
/**
|
|
197
158
|
* Encrypt a SCR (Secure Content Resource) using the supplied key uri.
|
|
198
159
|
*
|
|
@@ -207,12 +168,10 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
207
168
|
if (!scr.loc) {
|
|
208
169
|
return _promise.default.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));
|
|
209
170
|
}
|
|
210
|
-
|
|
211
171
|
return this.getKey(key, options).then(function (k) {
|
|
212
172
|
return scr.toJWE(k.jwk);
|
|
213
173
|
});
|
|
214
174
|
},
|
|
215
|
-
|
|
216
175
|
/**
|
|
217
176
|
* Encrypt plaintext using the supplied key uri.
|
|
218
177
|
*
|
|
@@ -224,7 +183,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
224
183
|
*/
|
|
225
184
|
encryptText: function encryptText(key, plaintext, options) {
|
|
226
185
|
var _this3 = this;
|
|
227
|
-
|
|
228
186
|
return this.getKey(key, options).then(function (k) {
|
|
229
187
|
return _nodeJose.default.JWE.createEncrypt(_this3.config.joseOptions, {
|
|
230
188
|
key: k.jwk,
|
|
@@ -235,7 +193,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
235
193
|
}).final(plaintext, 'utf8');
|
|
236
194
|
});
|
|
237
195
|
},
|
|
238
|
-
|
|
239
196
|
/**
|
|
240
197
|
* Fetch the key associated with the supplied KMS uri.
|
|
241
198
|
*
|
|
@@ -246,20 +203,15 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
246
203
|
*/
|
|
247
204
|
getKey: function getKey(uri) {
|
|
248
205
|
var _this4 = this;
|
|
249
|
-
|
|
250
206
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
251
|
-
|
|
252
|
-
|
|
207
|
+
onBehalfOf = _ref.onBehalfOf;
|
|
253
208
|
if (uri.jwk) {
|
|
254
209
|
return this.kms.asKey(uri);
|
|
255
210
|
}
|
|
256
|
-
|
|
257
211
|
var storageKey = uri;
|
|
258
|
-
|
|
259
212
|
if (onBehalfOf) {
|
|
260
213
|
storageKey += "/onBehalfOf/".concat(onBehalfOf);
|
|
261
214
|
}
|
|
262
|
-
|
|
263
215
|
return this.unboundedStorage.get(storageKey).then(function (keyString) {
|
|
264
216
|
return JSON.parse(keyString);
|
|
265
217
|
}).then(function (keyObject) {
|
|
@@ -273,16 +225,15 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
273
225
|
}));
|
|
274
226
|
});
|
|
275
227
|
},
|
|
276
|
-
version: "3.0.0-
|
|
228
|
+
version: "3.0.0-bnr.0"
|
|
277
229
|
});
|
|
230
|
+
|
|
278
231
|
/**
|
|
279
232
|
* JSON.stringify replacer that ensures private key data is serialized.
|
|
280
233
|
* @param {string} k
|
|
281
234
|
* @param {mixed} v
|
|
282
235
|
* @returns {mixed}
|
|
283
236
|
*/
|
|
284
|
-
|
|
285
|
-
|
|
286
237
|
function replacer(k, v) {
|
|
287
238
|
if (k === 'jwk') {
|
|
288
239
|
// note: this[k] and v may be different representations of the same value
|
|
@@ -290,10 +241,8 @@ function replacer(k, v) {
|
|
|
290
241
|
var json = this[k].toJSON(true);
|
|
291
242
|
return json;
|
|
292
243
|
}
|
|
293
|
-
|
|
294
244
|
return v;
|
|
295
245
|
}
|
|
296
|
-
|
|
297
246
|
var _default = Encryption;
|
|
298
247
|
exports.default = _default;
|
|
299
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)\n .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)\n .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)\n .then((k) => jose.JWE\n .createDecrypt(k.jwk)\n .decrypt(ciphertext)\n .then((result) => result.plaintext.toString()));\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 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('encryption: bypassing webex files because this looks to be a test file on localhost');\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 ...inputBody,\n allow: options.params.allow\n } : inputBody\n })\n .then((res) => {\n const url = res.body.endpoints[scr.loc];\n\n if (!url) {\n this.logger.warn('encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly');\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)\n .then((buffer) => SCR.create()\n .then((scr) => scr.encrypt(buffer)\n .then(ensureBuffer)\n // eslint-disable-next-line max-nested-callbacks\n .then((cdata) => ({scr, cdata}))));\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)\n .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)\n .then((k) => jose.JWE\n .createEncrypt(this.config.joseOptions, {\n key: k.jwk,\n header: {\n alg: 'dir'\n },\n reference: null\n })\n .final(plaintext, 'utf8'));\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.get(storageKey)\n .then((keyString) => JSON.parse(keyString))\n .then((keyObject) => this.kms.asKey(keyObject))\n .catch(() => this.kms.fetchKey({uri, onBehalfOf})\n .then(tap((key) => this.unboundedStorage.put(storageKey, JSON.stringify(key, replacer)))));\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;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B,IAAI1C,GAAG,CAACf,GAAR,EAAa;MACX,OAAO,KAAKxB,GAAL,CAASkF,KAAT,CAAe3C,GAAf,CAAP;IACD;;IAED,IAAI4C,UAAU,GAAG5C,GAAjB;;IAEA,IAAI0C,UAAJ,EAAgB;MACdE,UAAU,0BAAmBF,UAAnB,CAAV;IACD;;IAED,OAAO,KAAKG,gBAAL,CAAsBC,GAAtB,CAA0BF,UAA1B,EACJ1E,IADI,CACC,UAAC6E,SAAD;MAAA,OAAeC,IAAI,CAAC5B,KAAL,CAAW2B,SAAX,CAAf;IAAA,CADD,EAEJ7E,IAFI,CAEC,UAAC+E,SAAD;MAAA,OAAe,MAAI,CAACxF,GAAL,CAASkF,KAAT,CAAeM,SAAf,CAAf;IAAA,CAFD,EAGJC,KAHI,CAGE;MAAA,OAAM,MAAI,CAACzF,GAAL,CAAS0F,QAAT,CAAkB;QAACnD,GAAG,EAAHA,GAAD;QAAM0C,UAAU,EAAVA;MAAN,CAAlB,EACVxE,IADU,CACL,IAAAkF,WAAA,EAAI,UAAC1E,GAAD;QAAA,OAAS,MAAI,CAACmE,gBAAL,CAAsBQ,GAAtB,CAA0BT,UAA1B,EAAsC,wBAAelE,GAAf,EAAoB4E,QAApB,CAAtC,CAAT;MAAA,CAAJ,CADK,CAAN;IAAA,CAHF,CAAP;EAKD,CAlNmC;EAAA;AAAA,CAAnB,CAAnB;AAqNA;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;\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;EA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CAAC,CAC3BxE,IAAI,CAAC,IAAAkF,WAAG,EAAC,UAAC1E,GAAG;QAAA,OAAK,MAAI,CAACmE,gBAAgB,CAACQ,GAAG,CAACT,UAAU,EAAE,wBAAelE,GAAG,EAAE4E,QAAQ,CAAC,CAAC;MAAA,EAAC,CAAC;IAAA,EAC5F;EACL,CAAC;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,25 +1,18 @@
|
|
|
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
|
*/
|
|
18
13
|
|
|
19
14
|
/* eslint-env: browser */
|
|
20
15
|
|
|
21
|
-
/* global FileReader */
|
|
22
|
-
|
|
23
16
|
/**
|
|
24
17
|
* Ensures the provider buffer is, indeed, an ArrayBuffer; converts File and
|
|
25
18
|
* Blob objects to ArrayBuffers.
|
|
@@ -30,22 +23,17 @@ function ensureBuffer(buffer) {
|
|
|
30
23
|
if (buffer instanceof ArrayBuffer) {
|
|
31
24
|
return _promise.default.resolve(buffer);
|
|
32
25
|
}
|
|
33
|
-
|
|
34
26
|
if (buffer.toArrayBuffer) {
|
|
35
27
|
return _promise.default.resolve(buffer.toArrayBuffer());
|
|
36
28
|
}
|
|
37
|
-
|
|
38
29
|
if (buffer.buffer) {
|
|
39
30
|
return _promise.default.resolve(buffer.buffer);
|
|
40
31
|
}
|
|
41
|
-
|
|
42
32
|
return new _promise.default(function (resolve, reject) {
|
|
43
33
|
var fr = new FileReader();
|
|
44
|
-
|
|
45
34
|
fr.onload = function onload() {
|
|
46
35
|
resolve(new Uint8Array(this.result));
|
|
47
36
|
};
|
|
48
|
-
|
|
49
37
|
fr.onerror = reject;
|
|
50
38
|
fr.readAsArrayBuffer(buffer);
|
|
51
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
|
|
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,35 +1,28 @@
|
|
|
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
|
*/
|
|
20
14
|
|
|
21
15
|
/**
|
|
22
|
-
* Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be
|
|
23
|
-
* byte-arrays instead of proper Buffer objects.
|
|
24
|
-
* @param {mixed} buffer
|
|
25
|
-
* @returns {Promise<Buffer>}
|
|
26
|
-
*/
|
|
16
|
+
* Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be
|
|
17
|
+
* byte-arrays instead of proper Buffer objects.
|
|
18
|
+
* @param {mixed} buffer
|
|
19
|
+
* @returns {Promise<Buffer>}
|
|
20
|
+
*/
|
|
27
21
|
function ensureBuffer(buffer) {
|
|
28
22
|
/* istanbul ignore if */
|
|
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
|
-
|
|
36
|
+
require("@webex/internal-plugin-device");
|
|
37
|
+
require("@webex/internal-plugin-mercury");
|
|
47
38
|
var _webexCore = require("@webex/webex-core");
|
|
48
|
-
|
|
49
39
|
var _encryption = _interopRequireDefault(require("./encryption"));
|
|
50
|
-
|
|
51
40
|
var _config = _interopRequireDefault(require("./config"));
|
|
52
|
-
|
|
53
41
|
var _kmsErrors = require("./kms-errors");
|
|
54
|
-
|
|
55
|
-
require("@webex/internal-plugin-device");
|
|
56
|
-
|
|
57
|
-
require("@webex/internal-plugin-mercury");
|
|
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
|
});
|