@webex/internal-plugin-encryption 3.0.0-beta.4 → 3.0.0-beta.400

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.
Files changed (42) hide show
  1. package/README.md +1 -3
  2. package/dist/config.js +0 -9
  3. package/dist/config.js.map +1 -1
  4. package/dist/constants.js +14 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/encryption.js +25 -74
  7. package/dist/encryption.js.map +1 -1
  8. package/dist/ensure-buffer.browser.js +0 -12
  9. package/dist/ensure-buffer.browser.js.map +1 -1
  10. package/dist/ensure-buffer.js +5 -12
  11. package/dist/ensure-buffer.js.map +1 -1
  12. package/dist/index.js +7 -33
  13. package/dist/index.js.map +1 -1
  14. package/dist/kms-batcher.js +7 -30
  15. package/dist/kms-batcher.js.map +1 -1
  16. package/dist/kms-certificate-validation.js +24 -90
  17. package/dist/kms-certificate-validation.js.map +1 -1
  18. package/dist/kms-dry-error-interceptor.js +1 -23
  19. package/dist/kms-dry-error-interceptor.js.map +1 -1
  20. package/dist/kms-errors.js +21 -51
  21. package/dist/kms-errors.js.map +1 -1
  22. package/dist/kms.js +88 -218
  23. package/dist/kms.js.map +1 -1
  24. package/package.json +15 -15
  25. package/src/config.js +3 -3
  26. package/src/constants.js +3 -0
  27. package/src/encryption.js +74 -57
  28. package/src/ensure-buffer.browser.js +0 -1
  29. package/src/ensure-buffer.js +5 -5
  30. package/src/index.js +120 -96
  31. package/src/kms-batcher.js +53 -45
  32. package/src/kms-certificate-validation.js +48 -50
  33. package/src/kms-dry-error-interceptor.js +8 -4
  34. package/src/kms-errors.js +47 -16
  35. package/src/kms.js +219 -212
  36. package/test/integration/spec/encryption.js +313 -231
  37. package/test/integration/spec/kms.js +532 -405
  38. package/test/integration/spec/payload-transfom.js +69 -69
  39. package/test/unit/spec/encryption.js +21 -18
  40. package/test/unit/spec/kms-certificate-validation.js +76 -34
  41. package/test/unit/spec/kms-errors.js +70 -0
  42. package/test/unit/spec/kms.js +103 -0
package/dist/kms.js CHANGED
@@ -1,77 +1,47 @@
1
1
  "use strict";
2
2
 
3
3
  var _typeof = require("@babel/runtime-corejs2/helpers/typeof");
4
-
5
4
  var _WeakMap2 = require("@babel/runtime-corejs2/core-js/weak-map");
6
-
7
5
  var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
8
-
9
6
  var _Object$getOwnPropertyDescriptor2 = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
10
-
11
7
  var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
12
-
13
8
  _Object$defineProperty(exports, "__esModule", {
14
9
  value: true
15
10
  });
16
-
17
11
  exports.default = void 0;
18
-
19
12
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
20
-
21
13
  var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/applyDecoratedDescriptor"));
22
-
23
14
  var _weakMap = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/weak-map"));
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 _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
30
-
31
18
  var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor"));
32
-
33
19
  var _omit2 = _interopRequireDefault(require("lodash/omit"));
34
-
35
20
  var _querystring = _interopRequireDefault(require("querystring"));
36
-
37
21
  var _util = _interopRequireDefault(require("util"));
38
-
39
22
  var _commonTimers = require("@webex/common-timers");
40
-
41
23
  var _common = require("@webex/common");
42
-
43
24
  var _webexCore = require("@webex/webex-core");
44
-
45
25
  var _nodeKms = require("node-kms");
46
-
47
26
  var _nodeJose = _interopRequireDefault(require("node-jose"));
48
-
49
27
  var _uuid = _interopRequireDefault(require("uuid"));
50
-
51
28
  var _kmsBatcher = _interopRequireWildcard(require("./kms-batcher"));
52
-
53
29
  var _kmsCertificateValidation = _interopRequireWildcard(require("./kms-certificate-validation"));
54
-
55
30
  var _dec, _obj;
56
-
57
31
  function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap2 !== "function") return null; var cacheBabelInterop = new _WeakMap2(); var cacheNodeInterop = new _WeakMap2(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
58
-
59
32
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor2; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor2(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
60
-
61
33
  var contexts = new _weakMap.default();
62
34
  var kmsDetails = new _weakMap.default();
63
35
  var partialContexts = new _weakMap.default();
64
-
65
36
  var consoleDebug = require('debug')('kms');
37
+
66
38
  /**
67
39
  * @class
68
40
  */
69
-
70
-
71
41
  var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
72
42
  keyFactory: function keyFactory(_ref) {
73
43
  var uri = _ref.uri,
74
- onBehalfOf = _ref.onBehalfOf;
44
+ onBehalfOf = _ref.onBehalfOf;
75
45
  return "".concat(uri, "/").concat(onBehalfOf);
76
46
  }
77
47
  }), (_obj = {
@@ -79,7 +49,6 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
79
49
  children: {
80
50
  batcher: _kmsBatcher.default
81
51
  },
82
-
83
52
  /**
84
53
  * Binds a key to a resource
85
54
  * @param {Object} options
@@ -91,37 +60,32 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
91
60
  */
92
61
  bindKey: function bindKey(_ref2) {
93
62
  var _this = this;
94
-
95
63
  var kro = _ref2.kro,
96
- kroUri = _ref2.kroUri,
97
- key = _ref2.key,
98
- keyUri = _ref2.keyUri;
64
+ kroUri = _ref2.kroUri,
65
+ key = _ref2.key,
66
+ keyUri = _ref2.keyUri;
99
67
  kroUri = kroUri || kro.uri;
100
68
  keyUri = keyUri || key.uri;
101
69
  this.logger.info('kms: binding key to resource');
102
- /* istanbul ignore if */
103
70
 
71
+ /* istanbul ignore if */
104
72
  if (!kroUri) {
105
73
  return _promise.default.reject(new Error('`kro` or `kroUri` is required'));
106
74
  }
107
- /* istanbul ignore if */
108
-
109
75
 
76
+ /* istanbul ignore if */
110
77
  if (!keyUri) {
111
78
  return _promise.default.reject(new Error('`key` or `keyUri` is required'));
112
79
  }
113
-
114
80
  return this.request({
115
81
  method: 'update',
116
82
  resourceUri: kroUri,
117
83
  uri: keyUri
118
84
  }).then(function (res) {
119
85
  _this.logger.info('kms: bound key to resource');
120
-
121
86
  return res.key;
122
87
  });
123
88
  },
124
-
125
89
  /**
126
90
  * Creates a new KMS Resource
127
91
  * @param {Object} options
@@ -133,33 +97,28 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
133
97
  */
134
98
  createResource: function createResource(_ref3) {
135
99
  var _this2 = this;
136
-
137
100
  var userIds = _ref3.userIds,
138
- keyUris = _ref3.keyUris,
139
- key = _ref3.key,
140
- keys = _ref3.keys;
101
+ keyUris = _ref3.keyUris,
102
+ key = _ref3.key,
103
+ keys = _ref3.keys;
141
104
  keyUris = keyUris || [];
142
105
  /* istanbul ignore if */
143
-
144
106
  if (keys) {
145
107
  keyUris = keys.reduce(function (uris, k) {
146
108
  uris.push(k.uri);
147
109
  return uris;
148
110
  }, keyUris);
149
111
  }
150
- /* istanbul ignore else */
151
-
152
112
 
113
+ /* istanbul ignore else */
153
114
  if (key) {
154
115
  keyUris.push(key.uri);
155
116
  }
156
- /* istanbul ignore if */
157
-
158
117
 
118
+ /* istanbul ignore if */
159
119
  if (keyUris.length === 0) {
160
120
  return _promise.default.reject(new Error('Cannot create KMS Resource without at least one keyUri'));
161
121
  }
162
-
163
122
  this.logger.info('kms: creating resource');
164
123
  return this.request({
165
124
  method: 'create',
@@ -168,11 +127,9 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
168
127
  keyUris: keyUris
169
128
  }).then(function (res) {
170
129
  _this2.logger.info('kms: created resource');
171
-
172
130
  return res.resource;
173
131
  });
174
132
  },
175
-
176
133
  /**
177
134
  * Authorizes a user or KRO to a KRO
178
135
  * @param {Object} options
@@ -184,30 +141,25 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
184
141
  */
185
142
  addAuthorization: function addAuthorization(_ref4) {
186
143
  var _this3 = this;
187
-
188
144
  var userIds = _ref4.userIds,
189
- authIds = _ref4.authIds,
190
- kro = _ref4.kro,
191
- kroUri = _ref4.kroUri;
145
+ authIds = _ref4.authIds,
146
+ kro = _ref4.kro,
147
+ kroUri = _ref4.kroUri;
192
148
  userIds = userIds || [];
193
149
  kroUri = kroUri || kro.uri;
194
-
195
150
  if (authIds) {
196
151
  userIds = userIds.concat(authIds);
197
152
  }
198
- /* istanbul ignore if */
199
-
200
153
 
154
+ /* istanbul ignore if */
201
155
  if (userIds.length === 0) {
202
156
  return _promise.default.reject(new Error('Cannot add authorization without userIds or authIds'));
203
157
  }
204
- /* istanbul ignore if */
205
-
206
158
 
159
+ /* istanbul ignore if */
207
160
  if (!kroUri) {
208
161
  return _promise.default.reject(new Error('`kro` or `kroUri` is required'));
209
162
  }
210
-
211
163
  this.logger.info('kms: adding authorization to kms resource');
212
164
  return this.request({
213
165
  method: 'create',
@@ -216,11 +168,9 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
216
168
  userIds: userIds
217
169
  }).then(function (res) {
218
170
  _this3.logger.info('kms: added authorization');
219
-
220
171
  return res.authorizations;
221
172
  });
222
173
  },
223
-
224
174
  /**
225
175
  * Retrieve a list of users that have been authorized to the KRO
226
176
  * @param {Object} options
@@ -230,26 +180,21 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
230
180
  */
231
181
  listAuthorizations: function listAuthorizations(_ref5) {
232
182
  var _this4 = this;
233
-
234
183
  var kro = _ref5.kro,
235
- kroUri = _ref5.kroUri;
184
+ kroUri = _ref5.kroUri;
236
185
  kroUri = kroUri || kro.uri;
237
186
  /* istanbul ignore if */
238
-
239
187
  if (!kroUri) {
240
188
  return _promise.default.reject(new Error('`kro` or `kroUri` is required'));
241
189
  }
242
-
243
190
  return this.request({
244
191
  method: 'retrieve',
245
192
  uri: "".concat(kroUri, "/authorizations")
246
193
  }).then(function (res) {
247
194
  _this4.logger.info('kms: retrieved authorization list');
248
-
249
195
  return res.authorizations;
250
196
  });
251
197
  },
252
-
253
198
  /**
254
199
  * Deauthorizes a user or KRO from a KRO
255
200
  * @param {Object} options
@@ -261,25 +206,22 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
261
206
  */
262
207
  removeAuthorization: function removeAuthorization(_ref6) {
263
208
  var _this5 = this;
264
-
265
209
  var authId = _ref6.authId,
266
- userId = _ref6.userId,
267
- kro = _ref6.kro,
268
- kroUri = _ref6.kroUri;
210
+ userId = _ref6.userId,
211
+ kro = _ref6.kro,
212
+ kroUri = _ref6.kroUri;
269
213
  authId = authId || userId;
270
214
  kroUri = kroUri || kro.uri;
271
- /* istanbul ignore if */
272
215
 
216
+ /* istanbul ignore if */
273
217
  if (!authId) {
274
218
  return _promise.default.reject(new Error('Cannot remove authorization without authId'));
275
219
  }
276
- /* istanbul ignore if */
277
-
278
220
 
221
+ /* istanbul ignore if */
279
222
  if (!kroUri) {
280
223
  return _promise.default.reject(new Error('`kro` or `kroUri` is required'));
281
224
  }
282
-
283
225
  this.logger.info('kms: removing authorization from kms resource');
284
226
  return this.request({
285
227
  method: 'delete',
@@ -288,11 +230,9 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
288
230
  }))
289
231
  }).then(function (res) {
290
232
  _this5.logger.info('kms: removed authorization');
291
-
292
233
  return res.authorizations;
293
234
  });
294
235
  },
295
-
296
236
  /**
297
237
  * Requests `count` unbound keys from the kms
298
238
  * @param {Object} options
@@ -301,33 +241,28 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
301
241
  */
302
242
  createUnboundKeys: function createUnboundKeys(_ref7) {
303
243
  var _this6 = this;
304
-
305
244
  var count = _ref7.count;
306
245
  this.logger.info("kms: request ".concat(count, " unbound keys"));
307
- /* istanbul ignore if */
308
246
 
247
+ /* istanbul ignore if */
309
248
  if (!count) {
310
249
  return _promise.default.reject(new Error('`options.count` is required'));
311
250
  }
312
-
313
251
  return this.request({
314
252
  method: 'create',
315
253
  uri: '/keys',
316
254
  count: count
317
255
  }).then(function (res) {
318
256
  _this6.logger.info('kms: received unbound keys');
319
-
320
257
  return _promise.default.all(res.keys.map(_this6.asKey));
321
258
  });
322
259
  },
323
-
324
260
  /**
325
- * @typedef {Object} FetchPublicKeyResponse
326
- * @property {number} status 200,400(Bad Request: Request payload missing info),404(Not Found: HSM Public Key not found),501(Not Implemented: This KMS does not support BYOK),502(Bad Gateway: KMS could not communicate with HSM)
327
- * @property {UUID} requestId this is should be unique, used for debug.
328
- * @property {string} publicKey
329
- */
330
-
261
+ * @typedef {Object} FetchPublicKeyResponse
262
+ * @property {number} status 200,400(Bad Request: Request payload missing info),404(Not Found: HSM Public Key not found),501(Not Implemented: This KMS does not support BYOK),502(Bad Gateway: KMS could not communicate with HSM)
263
+ * @property {UUID} requestId this is should be unique, used for debug.
264
+ * @property {string} publicKey
265
+ */
331
266
  /**
332
267
  * get public key from kms
333
268
  * @param {Object} options
@@ -336,7 +271,6 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
336
271
  */
337
272
  fetchPublicKey: function fetchPublicKey(_ref8) {
338
273
  var _this7 = this;
339
-
340
274
  var assignedOrgId = _ref8.assignedOrgId;
341
275
  this.logger.info('kms: fetch public key for byok');
342
276
  return this.request({
@@ -345,75 +279,71 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
345
279
  assignedOrgId: assignedOrgId
346
280
  }).then(function (res) {
347
281
  _this7.logger.info('kms: received public key');
348
-
349
282
  return res.publicKey;
350
283
  });
351
284
  },
352
-
353
285
  /**
354
- * @typedef {Object} UploadCmkResponse
355
- * @property {number} status
356
- * @property {UUID} requestId
357
- * @property {string} uri
358
- * @property {string} keysState
359
- */
360
-
286
+ * @typedef {Object} UploadCmkResponse
287
+ * @property {number} status
288
+ * @property {UUID} requestId
289
+ * @property {string} uri
290
+ * @property {string} keysState
291
+ */
361
292
  /**
362
293
  * upload master key for one org.
363
294
  * @param {Object} options
364
295
  * @param {UUID} options.assignedOrgId the orgId
365
296
  * @param {string} options.customerMasterKey the master key
297
+ * @param {boolean} options.awsKms enable amazon aws keys
366
298
  * @returns {Promise.<UploadCmkResponse>} response of upload CMK api
367
299
  */
368
300
  uploadCustomerMasterKey: function uploadCustomerMasterKey(_ref9) {
369
301
  var _this8 = this;
370
-
371
302
  var assignedOrgId = _ref9.assignedOrgId,
372
- customerMasterKey = _ref9.customerMasterKey;
303
+ customerMasterKey = _ref9.customerMasterKey,
304
+ _ref9$awsKms = _ref9.awsKms,
305
+ awsKms = _ref9$awsKms === void 0 ? false : _ref9$awsKms;
373
306
  this.logger.info('kms: upload customer master key for byok');
374
307
  return this.request({
375
308
  method: 'create',
376
- uri: '/cmk',
309
+ uri: awsKms ? '/awsKmsCmk' : '/cmk',
377
310
  assignedOrgId: assignedOrgId,
378
311
  customerMasterKey: customerMasterKey,
379
312
  requestId: _uuid.default.v4()
380
313
  }).then(function (res) {
381
314
  _this8.logger.info('kms: finish to upload customer master key');
382
-
383
315
  return res;
384
316
  });
385
317
  },
386
-
387
318
  /**
388
319
  * get all customer master keys for one org.
389
320
  * @param {Object} options
390
321
  * @param {UUID} options.assignedOrgId the orgId
322
+ * @param {boolean} options.awsKms enable amazon aws keys
391
323
  * @returns {Promise.<ActivateCmkResponse>} response of list CMKs api
392
324
  */
393
325
  listAllCustomerMasterKey: function listAllCustomerMasterKey(_ref10) {
394
326
  var _this9 = this;
395
-
396
- var assignedOrgId = _ref10.assignedOrgId;
327
+ var assignedOrgId = _ref10.assignedOrgId,
328
+ _ref10$awsKms = _ref10.awsKms,
329
+ awsKms = _ref10$awsKms === void 0 ? false : _ref10$awsKms;
397
330
  this.logger.info('kms: get all customer master keys for byok');
398
331
  return this.request({
399
332
  method: 'retrieve',
400
- uri: '/cmk',
333
+ uri: awsKms ? '/awsKmsCmk' : '/cmk',
401
334
  assignedOrgId: assignedOrgId,
402
335
  requestId: _uuid.default.v4()
403
336
  }).then(function (res) {
404
337
  _this9.logger.info('kms: finish to get all customer master keys');
405
-
406
338
  return res;
407
339
  });
408
340
  },
409
-
410
341
  /**
411
- * @typedef {Object} ActivateCmkResponse
412
- * @property {number} status
413
- * @property {UUID} requestId
414
- * @property {Array<CMK>} customerMasterKeys
415
- */
416
-
342
+ * @typedef {Object} ActivateCmkResponse
343
+ * @property {number} status
344
+ * @property {UUID} requestId
345
+ * @property {Array<CMK>} customerMasterKeys
346
+ */
417
347
  /**
418
348
  *
419
349
  * @typedef {Object} CMK
@@ -424,7 +354,6 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
424
354
  * @property {Date | undefined} stateUpdatedOn
425
355
  * @property {Date | undefined} rotation
426
356
  */
427
-
428
357
  /**
429
358
  * change one customer master key state for one org.
430
359
  * delete pending key, then the keyState should be 'removedclean';
@@ -438,10 +367,9 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
438
367
  */
439
368
  changeCustomerMasterKeyState: function changeCustomerMasterKeyState(_ref11) {
440
369
  var _this10 = this;
441
-
442
370
  var keyId = _ref11.keyId,
443
- keyState = _ref11.keyState,
444
- assignedOrgId = _ref11.assignedOrgId;
371
+ keyState = _ref11.keyState,
372
+ assignedOrgId = _ref11.assignedOrgId;
445
373
  this.logger.info('kms: change one customer master key state for byok');
446
374
  return this.request({
447
375
  method: 'update',
@@ -451,34 +379,32 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
451
379
  requestId: _uuid.default.v4()
452
380
  }).then(function (res) {
453
381
  _this10.logger.info('kms: finish to change the customer master key state to {}', keyState);
454
-
455
382
  return res;
456
383
  });
457
384
  },
458
-
459
385
  /**
460
386
  * this is for test case. it will delete all CMKs, no matter what their status is. This is mainly for test purpose
461
387
  * @param {Object} options
462
388
  * @param {UUID} options.assignedOrgId the orgId
389
+ * @param {boolean} options.awsKms enable amazon aws keys
463
390
  * @returns {Promise.<{status, requestId}>}
464
391
  */
465
392
  deleteAllCustomerMasterKeys: function deleteAllCustomerMasterKeys(_ref12) {
466
393
  var _this11 = this;
467
-
468
- var assignedOrgId = _ref12.assignedOrgId;
394
+ var assignedOrgId = _ref12.assignedOrgId,
395
+ _ref12$awsKms = _ref12.awsKms,
396
+ awsKms = _ref12$awsKms === void 0 ? false : _ref12$awsKms;
469
397
  this.logger.info('kms: delete all customer master keys at the same time');
470
398
  return this.request({
471
399
  method: 'delete',
472
- uri: '/cmk',
400
+ uri: awsKms ? '/awsKmsCmk' : '/cmk',
473
401
  assignedOrgId: assignedOrgId,
474
402
  requestId: _uuid.default.v4()
475
403
  }).then(function (res) {
476
404
  _this11.logger.info('kms: finish to delete all customer master keys');
477
-
478
405
  return res;
479
406
  });
480
407
  },
481
-
482
408
  /**
483
409
  * return to use global master key for one org.
484
410
  * @param {Object} options
@@ -487,7 +413,6 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
487
413
  */
488
414
  useGlobalMasterKey: function useGlobalMasterKey(_ref13) {
489
415
  var _this12 = this;
490
-
491
416
  var assignedOrgId = _ref13.assignedOrgId;
492
417
  this.logger.info('kms: return to use global master key');
493
418
  return this.request({
@@ -498,21 +423,17 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
498
423
  requestId: _uuid.default.v4()
499
424
  }).then(function (res) {
500
425
  _this12.logger.info('kms: finish to return to global master key');
501
-
502
426
  return res;
503
427
  });
504
428
  },
505
429
  fetchKey: function fetchKey(_ref14) {
506
430
  var _this13 = this;
507
-
508
431
  var uri = _ref14.uri,
509
- onBehalfOf = _ref14.onBehalfOf;
510
-
432
+ onBehalfOf = _ref14.onBehalfOf;
511
433
  /* istanbul ignore if */
512
434
  if (!uri) {
513
435
  return _promise.default.reject(new Error('`options.uri` is required'));
514
436
  }
515
-
516
437
  this.logger.info('kms: fetching key');
517
438
  return this.request({
518
439
  method: 'retrieve',
@@ -521,11 +442,9 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
521
442
  onBehalfOf: onBehalfOf
522
443
  }).then(function (res) {
523
444
  _this13.logger.info('kms: fetched key');
524
-
525
445
  return _this13.asKey(res.key);
526
446
  });
527
447
  },
528
-
529
448
  /**
530
449
  * Pings the kms. Mostly for testing
531
450
  * @returns {Promise}
@@ -536,7 +455,6 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
536
455
  uri: '/ping'
537
456
  });
538
457
  },
539
-
540
458
  /**
541
459
  * Ensures a key obect is Key instance
542
460
  * @param {Object} key
@@ -548,7 +466,6 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
548
466
  return key;
549
467
  });
550
468
  },
551
-
552
469
  /**
553
470
  * Adds appropriate metadata to the KMS request
554
471
  * @param {Object} payload
@@ -557,18 +474,14 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
557
474
  */
558
475
  prepareRequest: function prepareRequest(payload, onBehalfOf) {
559
476
  var _this14 = this;
560
-
561
477
  var isECDHRequest = payload.method === 'create' && payload.uri.includes('/ecdhe');
562
478
  return _promise.default.resolve(isECDHRequest ? partialContexts.get(this) : this._getContext()).then(function (context) {
563
479
  _this14.logger.info("kms: wrapping ".concat(isECDHRequest ? 'ephemeral key' : 'kms', " request"));
564
-
565
480
  var req = new _nodeKms.Request(payload);
566
481
  var requestContext = context;
567
-
568
482
  if (onBehalfOf) {
569
483
  requestContext = _this14._contextOnBehalfOf(context, onBehalfOf);
570
484
  }
571
-
572
485
  return req.wrap(requestContext, {
573
486
  serverKey: isECDHRequest
574
487
  }).then(function () {
@@ -578,12 +491,10 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
578
491
  depth: null
579
492
  }));
580
493
  }
581
-
582
494
  return req;
583
495
  });
584
496
  });
585
497
  },
586
-
587
498
  /**
588
499
  * Accepts a kms message event, decrypts it, and passes it to the batcher
589
500
  * @param {Object} event
@@ -591,27 +502,29 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
591
502
  */
592
503
  processKmsMessageEvent: function processKmsMessageEvent(event) {
593
504
  var _this15 = this;
594
-
595
505
  this.logger.info('kms: received kms message');
596
506
  return _promise.default.all(event.encryption.kmsMessages.map(function (kmsMessage, index) {
597
507
  return _this15._isECDHEMessage(kmsMessage).then(function (isECDHMessage) {
598
508
  _this15.logger.info("kms: received ".concat(isECDHMessage ? 'ecdhe' : 'normal', " message"));
599
-
600
509
  var res = new _nodeKms.Response(kmsMessage);
601
- return _promise.default.resolve(isECDHMessage ? partialContexts.get(_this15) : contexts.get(_this15)) // eslint-disable-next-line max-nested-callbacks
510
+ return _promise.default.resolve(isECDHMessage ? partialContexts.get(_this15) : contexts.get(_this15))
511
+ // eslint-disable-next-line max-nested-callbacks
602
512
  .then(function (context) {
603
513
  return res.unwrap(context);
604
- }) // eslint-disable-next-line max-nested-callbacks
514
+ })
515
+ // eslint-disable-next-line max-nested-callbacks
605
516
  .then(function () {
606
517
  if (process.env.NODE_ENV !== 'production') {
607
518
  _this15.logger.info('kms: response payload', _util.default.inspect((0, _omit2.default)(JSON.parse((0, _stringify.default)(res)), 'wrapped'), {
608
519
  depth: null
609
520
  }));
610
521
  }
611
- }) // eslint-disable-next-line max-nested-callbacks
522
+ })
523
+ // eslint-disable-next-line max-nested-callbacks
612
524
  .then(function () {
613
525
  event.encryption.kmsMessages[index] = res;
614
- }) // eslint-disable-next-line max-nested-callbacks
526
+ })
527
+ // eslint-disable-next-line max-nested-callbacks
615
528
  .then(function () {
616
529
  return res;
617
530
  });
@@ -620,13 +533,11 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
620
533
  return _this15.batcher.processKmsMessageEvent(event);
621
534
  }).catch(function (reason) {
622
535
  _this15.logger.error('kms: decrypt failed', reason.stack);
623
-
624
536
  return _promise.default.reject(reason);
625
537
  }).then(function () {
626
538
  return event;
627
539
  });
628
540
  },
629
-
630
541
  /**
631
542
  * Decrypts a kms message
632
543
  * @param {Object} kmsMessage
@@ -640,7 +551,6 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
640
551
  return res.body;
641
552
  });
642
553
  },
643
-
644
554
  /**
645
555
  * Determines if the kms message is an ecdhe message or a normal message
646
556
  * @param {Object} kmsMessage
@@ -649,16 +559,13 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
649
559
  _isECDHEMessage: function _isECDHEMessage(kmsMessage) {
650
560
  return this._getKMSStaticPubKey().then(function (kmsStaticPubKey) {
651
561
  var fields = kmsMessage.split('.');
652
-
653
562
  if (fields.length !== 3) {
654
563
  return false;
655
564
  }
656
-
657
565
  var header = JSON.parse(_nodeJose.default.util.base64url.decode(fields[0]));
658
566
  return header.kid === kmsStaticPubKey.kid;
659
567
  });
660
568
  },
661
-
662
569
  /**
663
570
  * Sends a request to the kms
664
571
  * @param {Object} payload
@@ -669,83 +576,72 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
669
576
  */
670
577
  request: function request(payload) {
671
578
  var _this16 = this;
672
-
673
579
  var _ref15 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
674
- timeout = _ref15.timeout,
675
- onBehalfOf = _ref15.onBehalfOf;
580
+ timeout = _ref15.timeout,
581
+ onBehalfOf = _ref15.onBehalfOf;
582
+ timeout = timeout || this.config.kmsInitialTimeout;
676
583
 
677
- timeout = timeout || this.config.kmsInitialTimeout; // Note: this should only happen when we're using the async kms batcher;
584
+ // Note: this should only happen when we're using the async kms batcher;
678
585
  // once we implement the sync batcher, this'll need to be smarter.
679
-
680
586
  return this.webex.internal.mercury.connect().then(function () {
681
587
  return _this16.prepareRequest(payload, onBehalfOf);
682
588
  }).then(function (req) {
683
589
  req[_kmsBatcher.TIMEOUT_SYMBOL] = timeout;
684
590
  return _this16.batcher.request(req);
685
- }) // High complexity is due to attempt at test mode resiliency
591
+ })
592
+ // High complexity is due to attempt at test mode resiliency
686
593
  // eslint-disable-next-line complexity
687
594
  .catch(function (reason) {
688
595
  if (process.env.NODE_ENV === 'test' && (reason.status === 403 || reason.statusCode === 403) && reason.message.match(/Failed to resolve authorization token in KmsMessage request for user/)) {
689
596
  _this16.logger.warn('kms: rerequested key due to test-mode kms auth failure');
690
-
691
597
  return _this16.request(payload, {
692
598
  onBehalfOf: onBehalfOf
693
599
  });
694
- } // KMS Error. Notify the user
695
-
600
+ }
696
601
 
602
+ // KMS Error. Notify the user
697
603
  if (reason instanceof _kmsCertificateValidation.KMSError) {
698
604
  _this16.webex.trigger('client:InvalidRequestError');
699
-
700
605
  return _promise.default.reject(reason);
701
- } // Ideally, most or all of the code below would go in kms-batcher, but
606
+ }
607
+
608
+ // Ideally, most or all of the code below would go in kms-batcher, but
702
609
  // but batching needs at least one more round of refactoring for that to
703
610
  // work.
704
-
705
-
706
611
  if (!reason.statusCode && !reason.status) {
707
612
  /* istanbul ignore else */
708
613
  if (process.env.NODE_ENV !== 'production') {
709
614
  /* istanbul ignore next: reason.stack vs stack difficult to control in test */
710
615
  _this16.logger.info('kms: request error', reason.stack || reason);
711
616
  }
712
-
713
617
  consoleDebug("timeout ".concat(timeout));
714
618
  timeout *= 2;
715
-
716
619
  if (timeout >= _this16.config.ecdhMaxTimeout) {
717
620
  _this16.logger.info('kms: exceeded maximum KMS request retries');
718
-
719
621
  return _promise.default.reject(reason);
720
- } // Peek ahead to make sure we don't reset the timeout if the next timeout
721
- // will exceed the maximum timeout for renegotiating ECDH keys.
722
-
622
+ }
723
623
 
624
+ // Peek ahead to make sure we don't reset the timeout if the next timeout
625
+ // will exceed the maximum timeout for renegotiating ECDH keys.
724
626
  var nextTimeout = timeout * 2;
725
-
726
627
  if (timeout >= _this16.config.kmsMaxTimeout && nextTimeout < _this16.config.ecdhMaxTimeout) {
727
628
  _this16.logger.info('kms: exceeded maximum KMS request retries; negotiating new ecdh key');
728
- /* istanbul ignore else */
729
-
730
629
 
630
+ /* istanbul ignore else */
731
631
  if (process.env.NODE_ENV !== 'production') {
732
632
  _this16.logger.info('kms: timeout/maxtimeout', timeout, _this16.config.kmsMaxTimeout);
733
633
  }
734
-
735
634
  contexts.delete(_this16);
736
635
  timeout = 0;
737
636
  }
738
-
739
637
  return _this16.request(payload, {
740
638
  timeout: timeout,
741
639
  onBehalfOf: onBehalfOf
742
640
  });
743
641
  }
744
-
745
642
  return _promise.default.reject(reason);
746
643
  });
747
644
  },
748
-
749
645
  /**
750
646
  * @private
751
647
  * @returns {Promise<string>}
@@ -755,7 +651,6 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
755
651
  return token.access_token;
756
652
  });
757
653
  },
758
-
759
654
  /**
760
655
  * @private
761
656
  * @param {String} onBehalfOf create context on behalf of another user, undefined when this is not necessary
@@ -763,9 +658,7 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
763
658
  */
764
659
  _getContext: function _getContext() {
765
660
  var _this17 = this;
766
-
767
661
  var promise = contexts.get(this);
768
-
769
662
  if (!promise) {
770
663
  promise = this._prepareContext();
771
664
  contexts.set(this, promise);
@@ -776,17 +669,14 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
776
669
  }, expiresIn);
777
670
  });
778
671
  }
779
-
780
672
  return _promise.default.all([promise, this._getAuthorization()]).then(function (_ref16) {
781
673
  var _ref17 = (0, _slicedToArray2.default)(_ref16, 2),
782
- context = _ref17[0],
783
- authorization = _ref17[1];
784
-
674
+ context = _ref17[0],
675
+ authorization = _ref17[1];
785
676
  context.clientInfo.credential.bearer = authorization;
786
677
  return context;
787
678
  });
788
679
  },
789
-
790
680
  /**
791
681
  * @private
792
682
  * @returns {Promise<Object>}
@@ -798,16 +688,13 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
798
688
  return kmsCluster;
799
689
  });
800
690
  },
801
-
802
691
  /**
803
692
  * @private
804
693
  * @returns {Promise<Object>}
805
694
  */
806
695
  _getKMSDetails: function _getKMSDetails() {
807
696
  var _this18 = this;
808
-
809
697
  var details = kmsDetails.get(this);
810
-
811
698
  if (!details) {
812
699
  this.logger.info('kms: fetching KMS details');
813
700
  details = this.webex.request({
@@ -815,21 +702,17 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
815
702
  resource: "/kms/".concat(this.webex.internal.device.userId)
816
703
  }).then(function (res) {
817
704
  _this18.logger.info('kms: fetched KMS details');
818
-
819
705
  var body = res.body;
820
706
  body.rsaPublicKey = JSON.parse(body.rsaPublicKey);
821
707
  return body;
822
708
  }).catch(function (reason) {
823
709
  _this18.logger.error('kms: failed to fetch KMS details', reason);
824
-
825
710
  return _promise.default.reject(reason);
826
711
  });
827
712
  kmsDetails.set(this, details);
828
713
  }
829
-
830
714
  return details;
831
715
  },
832
-
833
716
  /**
834
717
  * @private
835
718
  * @returns {Promise<Object>}
@@ -841,21 +724,18 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
841
724
  return rsaPublicKey;
842
725
  });
843
726
  },
844
-
845
727
  /**
846
728
  * @private
847
729
  * @returns {Promise<Object>}
848
730
  */
849
731
  _prepareContext: function _prepareContext() {
850
732
  var _this19 = this;
851
-
852
733
  this.logger.info('kms: creating context');
853
734
  var context = new _nodeKms.Context();
854
735
  return _promise.default.all([this._getKMSStaticPubKey().then((0, _kmsCertificateValidation.default)(this.config.caroots)), this._getAuthorization()]).then(function (_ref20) {
855
736
  var _ref21 = (0, _slicedToArray2.default)(_ref20, 2),
856
- kmsStaticPubKey = _ref21[0],
857
- authorization = _ref21[1];
858
-
737
+ kmsStaticPubKey = _ref21[0],
738
+ authorization = _ref21[1];
859
739
  context.clientInfo = {
860
740
  clientId: _this19.webex.internal.device.url,
861
741
  credential: {
@@ -866,9 +746,7 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
866
746
  context.serverInfo = {
867
747
  key: kmsStaticPubKey
868
748
  };
869
-
870
749
  _this19.logger.info('kms: creating local ephemeral key');
871
-
872
750
  return context.createECDHKey();
873
751
  }).then(function (localECDHKey) {
874
752
  context.ephemeralKey = localECDHKey;
@@ -876,11 +754,9 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
876
754
  return _promise.default.all([localECDHKey.asKey(), _this19._getKMSCluster()]);
877
755
  }).then(function (_ref22) {
878
756
  var _ref23 = (0, _slicedToArray2.default)(_ref22, 2),
879
- localECDHKey = _ref23[0],
880
- cluster = _ref23[1];
881
-
757
+ localECDHKey = _ref23[0],
758
+ cluster = _ref23[1];
882
759
  _this19.logger.info('kms: submitting ephemeral key request');
883
-
884
760
  return _this19.request({
885
761
  uri: "".concat(cluster, "/ecdhe"),
886
762
  method: 'create',
@@ -888,22 +764,17 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
888
764
  });
889
765
  }).then(function (res) {
890
766
  _this19.logger.info('kms: deriving final ephemeral key');
891
-
892
767
  return context.deriveEphemeralKey(res.key);
893
768
  }).then(function (key) {
894
769
  context.ephemeralKey = key;
895
770
  partialContexts.delete(_this19);
896
-
897
771
  _this19.logger.info('kms: derived final ephemeral key');
898
-
899
772
  return context;
900
773
  }).catch(function (reason) {
901
774
  _this19.logger.error('kms: failed to negotiate ephemeral key', reason);
902
-
903
775
  return _promise.default.reject(reason);
904
776
  });
905
777
  },
906
-
907
778
  /**
908
779
  * KMS 'retrieve' requests can be made on behalf of another user. This is useful
909
780
  * for scenarios such as eDiscovery. i.e. Where an authorized compliance officer is
@@ -931,9 +802,8 @@ var KMS = _webexCore.WebexPlugin.extend((_dec = (0, _common.oneFlight)({
931
802
  context.ephemeralKey = originalContext.ephemeralKey;
932
803
  return context;
933
804
  },
934
- version: "3.0.0-beta.4"
805
+ version: "3.0.0-beta.400"
935
806
  }, ((0, _applyDecoratedDescriptor2.default)(_obj, "fetchKey", [_dec], (0, _getOwnPropertyDescriptor.default)(_obj, "fetchKey"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "_getContext", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "_getContext"), _obj)), _obj)));
936
-
937
807
  var _default = KMS;
938
808
  exports.default = _default;
939
809
  //# sourceMappingURL=kms.js.map