@webex/internal-plugin-encryption 2.59.1 → 2.59.3-next.1

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/.eslintrc.js +6 -6
  2. package/README.md +42 -42
  3. package/babel.config.js +3 -3
  4. package/dist/config.js +21 -21
  5. package/dist/config.js.map +1 -1
  6. package/dist/encryption.js +57 -57
  7. package/dist/encryption.js.map +1 -1
  8. package/dist/ensure-buffer.browser.js +7 -7
  9. package/dist/ensure-buffer.browser.js.map +1 -1
  10. package/dist/ensure-buffer.js +7 -7
  11. package/dist/ensure-buffer.js.map +1 -1
  12. package/dist/index.js +2 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/kms-batcher.js +38 -38
  15. package/dist/kms-batcher.js.map +1 -1
  16. package/dist/kms-certificate-validation.js +50 -50
  17. package/dist/kms-certificate-validation.js.map +1 -1
  18. package/dist/kms-dry-error-interceptor.js +15 -15
  19. package/dist/kms-dry-error-interceptor.js.map +1 -1
  20. package/dist/kms-errors.js +16 -16
  21. package/dist/kms-errors.js.map +1 -1
  22. package/dist/kms.js +171 -171
  23. package/dist/kms.js.map +1 -1
  24. package/jest.config.js +3 -3
  25. package/package.json +20 -19
  26. package/process +1 -1
  27. package/src/config.js +50 -50
  28. package/src/encryption.js +257 -257
  29. package/src/ensure-buffer.browser.js +37 -37
  30. package/src/ensure-buffer.js +20 -20
  31. package/src/index.js +159 -159
  32. package/src/kms-batcher.js +158 -158
  33. package/src/kms-certificate-validation.js +232 -232
  34. package/src/kms-dry-error-interceptor.js +65 -65
  35. package/src/kms-errors.js +147 -147
  36. package/src/kms.js +848 -848
  37. package/test/integration/spec/encryption.js +448 -448
  38. package/test/integration/spec/kms.js +800 -800
  39. package/test/integration/spec/payload-transfom.js +97 -97
  40. package/test/unit/spec/encryption.js +82 -82
  41. package/test/unit/spec/kms-certificate-validation.js +165 -165
  42. package/test/unit/spec/kms.js +103 -103
@@ -11,22 +11,22 @@ var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/pr
11
11
  var _commonTimers = require("@webex/common-timers");
12
12
  var _webexCore = require("@webex/webex-core");
13
13
  var _kmsErrors = require("./kms-errors");
14
- /*!
15
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
14
+ /*!
15
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
16
16
  */
17
17
 
18
18
  var TIMEOUT_SYMBOL = (0, _symbol.default)('TIMEOUT_SYMBOL');
19
19
 
20
- /**
21
- * @class
20
+ /**
21
+ * @class
22
22
  */
23
23
  exports.TIMEOUT_SYMBOL = TIMEOUT_SYMBOL;
24
24
  var KmsBatcher = _webexCore.Batcher.extend({
25
25
  namespace: 'Encryption',
26
- /**
27
- * Accepts a kmsMessage event and passes its contents to acceptItem
28
- * @param {Object} event
29
- * @returns {Promise}
26
+ /**
27
+ * Accepts a kmsMessage event and passes its contents to acceptItem
28
+ * @param {Object} event
29
+ * @returns {Promise}
30
30
  */
31
31
  processKmsMessageEvent: function processKmsMessageEvent(event) {
32
32
  var _this = this;
@@ -41,10 +41,10 @@ var KmsBatcher = _webexCore.Batcher.extend({
41
41
  });
42
42
  }));
43
43
  },
44
- /**
45
- * Attaches a timeout to the given KMS message
46
- * @param {Object} item
47
- * @returns {Promise<Object>}
44
+ /**
45
+ * Attaches a timeout to the given KMS message
46
+ * @param {Object} item
47
+ * @returns {Promise<Object>}
48
48
  */
49
49
  prepareItem: function prepareItem(item) {
50
50
  var _this2 = this;
@@ -74,10 +74,10 @@ var KmsBatcher = _webexCore.Batcher.extend({
74
74
  return item;
75
75
  });
76
76
  },
77
- /**
78
- * Attaches the final bits of cluster info to the payload
79
- * @param {Array} queue
80
- * @returns {Promise<Array>}
77
+ /**
78
+ * Attaches the final bits of cluster info to the payload
79
+ * @param {Array} queue
80
+ * @returns {Promise<Array>}
81
81
  */
82
82
  prepareRequest: function prepareRequest(queue) {
83
83
  return this.webex.internal.encryption.kms._getKMSCluster().then(function (cluster) {
@@ -89,9 +89,9 @@ var KmsBatcher = _webexCore.Batcher.extend({
89
89
  };
90
90
  });
91
91
  },
92
- /**
93
- * @param {Object} payload
94
- * @returns {Promise<HttpResponseObject>}
92
+ /**
93
+ * @param {Object} payload
94
+ * @returns {Promise<HttpResponseObject>}
95
95
  */
96
96
  submitHttpRequest: function submitHttpRequest(payload) {
97
97
  this.logger.info('kms: batched-request-length', payload.kmsMessages.length);
@@ -102,49 +102,49 @@ var KmsBatcher = _webexCore.Batcher.extend({
102
102
  body: payload
103
103
  });
104
104
  },
105
- /**
106
- * Does nothing; the http response doesn't carry our response data
107
- * @returns {Promise}
105
+ /**
106
+ * Does nothing; the http response doesn't carry our response data
107
+ * @returns {Promise}
108
108
  */
109
109
  handleHttpSuccess: function handleHttpSuccess() {
110
110
  return _promise.default.resolve();
111
111
  },
112
- /**
113
- * @param {Object} item
114
- * @returns {Promise<boolean>}
112
+ /**
113
+ * @param {Object} item
114
+ * @returns {Promise<boolean>}
115
115
  */
116
116
  didItemFail: function didItemFail(item) {
117
117
  return _promise.default.resolve(item.status >= 400);
118
118
  },
119
- /**
120
- * @param {Object} item
121
- * @returns {Promise}
119
+ /**
120
+ * @param {Object} item
121
+ * @returns {Promise}
122
122
  */
123
123
  handleItemSuccess: function handleItemSuccess(item) {
124
124
  return this.getDeferredForResponse(item).then(function (defer) {
125
125
  defer.resolve(item.body);
126
126
  });
127
127
  },
128
- /**
129
- * @param {Object} item
130
- * @param {KmsError} [reason]
131
- * @returns {Promise}
128
+ /**
129
+ * @param {Object} item
130
+ * @param {KmsError} [reason]
131
+ * @returns {Promise}
132
132
  */
133
133
  handleItemFailure: function handleItemFailure(item, reason) {
134
134
  return this.getDeferredForResponse(item).then(function (defer) {
135
135
  defer.reject(reason || new _kmsErrors.KmsError(item.body));
136
136
  });
137
137
  },
138
- /**
139
- * @param {Object} item
140
- * @returns {Promise}
138
+ /**
139
+ * @param {Object} item
140
+ * @returns {Promise}
141
141
  */
142
142
  fingerprintRequest: function fingerprintRequest(item) {
143
143
  return _promise.default.resolve(item.requestId);
144
144
  },
145
- /**
146
- * @param {Object} item
147
- * @returns {Promise}
145
+ /**
146
+ * @param {Object} item
147
+ * @returns {Promise}
148
148
  */
149
149
  fingerprintResponse: function fingerprintResponse(item) {
150
150
  return _promise.default.resolve(item.requestId);
@@ -1 +1 @@
1
- {"version":3,"names":["_commonTimers","require","_webexCore","_kmsErrors","TIMEOUT_SYMBOL","_symbol","default","exports","KmsBatcher","Batcher","extend","namespace","processKmsMessageEvent","event","_this","logger","info","_promise","all","encryption","kmsMessages","map","kmsMessage","resolve","process","env","NODE_ENV","body","acceptItem","prepareItem","item","_this2","getDeferredForRequest","then","defer","timeout","Error","timer","safeSetTimeout","warn","concat","requestId","handleItemFailure","KmsTimeoutError","request","promise","clearTimeout","catch","prepareRequest","queue","webex","internal","kms","_getKMSCluster","cluster","destination","req","wrapped","submitHttpRequest","payload","length","method","service","resource","handleHttpSuccess","didItemFail","status","handleItemSuccess","getDeferredForResponse","reason","reject","KmsError","fingerprintRequest","fingerprintResponse","_default"],"sources":["kms-batcher.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {safeSetTimeout} from '@webex/common-timers';\nimport {Batcher} from '@webex/webex-core';\n\nimport {KmsError, KmsTimeoutError} from './kms-errors';\n\nexport const TIMEOUT_SYMBOL = Symbol('TIMEOUT_SYMBOL');\n\n/**\n * @class\n */\nconst KmsBatcher = Batcher.extend({\n namespace: 'Encryption',\n\n /**\n * Accepts a kmsMessage event and passes its contents to acceptItem\n * @param {Object} event\n * @returns {Promise}\n */\n processKmsMessageEvent(event) {\n this.logger.info('kms-batcher: received kms message');\n\n return Promise.all(\n event.encryption.kmsMessages.map(\n (kmsMessage) =>\n new Promise((resolve) => {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n this.logger.info('kms-batcher:', kmsMessage.body);\n }\n\n resolve(this.acceptItem(kmsMessage));\n })\n )\n );\n },\n\n /**\n * Attaches a timeout to the given KMS message\n * @param {Object} item\n * @returns {Promise<Object>}\n */\n prepareItem(item) {\n return this.getDeferredForRequest(item).then((defer) => {\n const timeout = item[TIMEOUT_SYMBOL];\n\n /* istanbul ignore if */\n if (!timeout) {\n throw new Error('timeout is required');\n }\n\n const timer = safeSetTimeout(() => {\n this.logger.warn(\n `kms: request timed out; request id: ${item.requestId}; timeout: ${timeout}`\n );\n this.handleItemFailure(\n item,\n new KmsTimeoutError({\n timeout,\n request: item,\n })\n );\n }, timeout);\n\n // Reminder: reassign `promise` is not a viable means of inserting into\n // the Promise chain\n defer.promise.then(() => clearTimeout(timer));\n defer.promise.catch(() => clearTimeout(timer));\n\n return item;\n });\n },\n\n /**\n * Attaches the final bits of cluster info to the payload\n * @param {Array} queue\n * @returns {Promise<Array>}\n */\n prepareRequest(queue) {\n return this.webex.internal.encryption.kms._getKMSCluster().then((cluster) => ({\n destination: cluster,\n kmsMessages: queue.map((req) => req.wrapped),\n }));\n },\n\n /**\n * @param {Object} payload\n * @returns {Promise<HttpResponseObject>}\n */\n submitHttpRequest(payload) {\n this.logger.info('kms: batched-request-length', payload.kmsMessages.length);\n\n return this.webex.request({\n method: 'POST',\n service: 'encryption',\n resource: '/kms/messages',\n body: payload,\n });\n },\n\n /**\n * Does nothing; the http response doesn't carry our response data\n * @returns {Promise}\n */\n handleHttpSuccess() {\n return Promise.resolve();\n },\n\n /**\n * @param {Object} item\n * @returns {Promise<boolean>}\n */\n didItemFail(item) {\n return Promise.resolve(item.status >= 400);\n },\n\n /**\n * @param {Object} item\n * @returns {Promise}\n */\n handleItemSuccess(item) {\n return this.getDeferredForResponse(item).then((defer) => {\n defer.resolve(item.body);\n });\n },\n\n /**\n * @param {Object} item\n * @param {KmsError} [reason]\n * @returns {Promise}\n */\n handleItemFailure(item, reason) {\n return this.getDeferredForResponse(item).then((defer) => {\n defer.reject(reason || new KmsError(item.body));\n });\n },\n\n /**\n * @param {Object} item\n * @returns {Promise}\n */\n fingerprintRequest(item) {\n return Promise.resolve(item.requestId);\n },\n\n /**\n * @param {Object} item\n * @returns {Promise}\n */\n fingerprintResponse(item) {\n return Promise.resolve(item.requestId);\n },\n});\n\nexport default KmsBatcher;\n"],"mappings":";;;;;;;;;;AAIA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAPA;AACA;AACA;;AAOO,IAAMG,cAAc,GAAG,IAAAC,OAAA,CAAAC,OAAA,EAAO,gBAAgB,CAAC;;AAEtD;AACA;AACA;AAFAC,OAAA,CAAAH,cAAA,GAAAA,cAAA;AAGA,IAAMI,UAAU,GAAGC,kBAAO,CAACC,MAAM,CAAC;EAChCC,SAAS,EAAE,YAAY;EAEvB;AACF;AACA;AACA;AACA;EACEC,sBAAsB,WAAAA,uBAACC,KAAK,EAAE;IAAA,IAAAC,KAAA;IAC5B,IAAI,CAACC,MAAM,CAACC,IAAI,CAAC,mCAAmC,CAAC;IAErD,OAAOC,QAAA,CAAAX,OAAA,CAAQY,GAAG,CAChBL,KAAK,CAACM,UAAU,CAACC,WAAW,CAACC,GAAG,CAC9B,UAACC,UAAU;MAAA,OACT,IAAAL,QAAA,CAAAX,OAAA,CAAY,UAACiB,OAAO,EAAK;QACvB;QACA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;UACzCZ,KAAI,CAACC,MAAM,CAACC,IAAI,CAAC,cAAc,EAAEM,UAAU,CAACK,IAAI,CAAC;QACnD;QAEAJ,OAAO,CAACT,KAAI,CAACc,UAAU,CAACN,UAAU,CAAC,CAAC;MACtC,CAAC,CAAC;IAAA,EACL,CACF;EACH,CAAC;EAED;AACF;AACA;AACA;AACA;EACEO,WAAW,WAAAA,YAACC,IAAI,EAAE;IAAA,IAAAC,MAAA;IAChB,OAAO,IAAI,CAACC,qBAAqB,CAACF,IAAI,CAAC,C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B,WAAAA,oBAAC3C,IAAI,EAAE;IACxB,OAAOb,QAAA,CAAAX,OAAA,CAAQiB,OAAO,CAACO,IAAI,CAACW,SAAS,CAAC;EACxC;AACF,CAAC,CAAC;AAAC,IAAAiC,QAAA,GAEYlE,UAAU;AAAAD,OAAA,CAAAD,OAAA,GAAAoE,QAAA"}
1
+ {"version":3,"names":["_commonTimers","require","_webexCore","_kmsErrors","TIMEOUT_SYMBOL","_symbol","default","exports","KmsBatcher","Batcher","extend","namespace","processKmsMessageEvent","event","_this","logger","info","_promise","all","encryption","kmsMessages","map","kmsMessage","resolve","process","env","NODE_ENV","body","acceptItem","prepareItem","item","_this2","getDeferredForRequest","then","defer","timeout","Error","timer","safeSetTimeout","warn","concat","requestId","handleItemFailure","KmsTimeoutError","request","promise","clearTimeout","catch","prepareRequest","queue","webex","internal","kms","_getKMSCluster","cluster","destination","req","wrapped","submitHttpRequest","payload","length","method","service","resource","handleHttpSuccess","didItemFail","status","handleItemSuccess","getDeferredForResponse","reason","reject","KmsError","fingerprintRequest","fingerprintResponse","_default"],"sources":["kms-batcher.js"],"sourcesContent":["/*!\r\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\r\n */\r\n\r\nimport {safeSetTimeout} from '@webex/common-timers';\r\nimport {Batcher} from '@webex/webex-core';\r\n\r\nimport {KmsError, KmsTimeoutError} from './kms-errors';\r\n\r\nexport const TIMEOUT_SYMBOL = Symbol('TIMEOUT_SYMBOL');\r\n\r\n/**\r\n * @class\r\n */\r\nconst KmsBatcher = Batcher.extend({\r\n namespace: 'Encryption',\r\n\r\n /**\r\n * Accepts a kmsMessage event and passes its contents to acceptItem\r\n * @param {Object} event\r\n * @returns {Promise}\r\n */\r\n processKmsMessageEvent(event) {\r\n this.logger.info('kms-batcher: received kms message');\r\n\r\n return Promise.all(\r\n event.encryption.kmsMessages.map(\r\n (kmsMessage) =>\r\n new Promise((resolve) => {\r\n /* istanbul ignore else */\r\n if (process.env.NODE_ENV !== 'production') {\r\n this.logger.info('kms-batcher:', kmsMessage.body);\r\n }\r\n\r\n resolve(this.acceptItem(kmsMessage));\r\n })\r\n )\r\n );\r\n },\r\n\r\n /**\r\n * Attaches a timeout to the given KMS message\r\n * @param {Object} item\r\n * @returns {Promise<Object>}\r\n */\r\n prepareItem(item) {\r\n return this.getDeferredForRequest(item).then((defer) => {\r\n const timeout = item[TIMEOUT_SYMBOL];\r\n\r\n /* istanbul ignore if */\r\n if (!timeout) {\r\n throw new Error('timeout is required');\r\n }\r\n\r\n const timer = safeSetTimeout(() => {\r\n this.logger.warn(\r\n `kms: request timed out; request id: ${item.requestId}; timeout: ${timeout}`\r\n );\r\n this.handleItemFailure(\r\n item,\r\n new KmsTimeoutError({\r\n timeout,\r\n request: item,\r\n })\r\n );\r\n }, timeout);\r\n\r\n // Reminder: reassign `promise` is not a viable means of inserting into\r\n // the Promise chain\r\n defer.promise.then(() => clearTimeout(timer));\r\n defer.promise.catch(() => clearTimeout(timer));\r\n\r\n return item;\r\n });\r\n },\r\n\r\n /**\r\n * Attaches the final bits of cluster info to the payload\r\n * @param {Array} queue\r\n * @returns {Promise<Array>}\r\n */\r\n prepareRequest(queue) {\r\n return this.webex.internal.encryption.kms._getKMSCluster().then((cluster) => ({\r\n destination: cluster,\r\n kmsMessages: queue.map((req) => req.wrapped),\r\n }));\r\n },\r\n\r\n /**\r\n * @param {Object} payload\r\n * @returns {Promise<HttpResponseObject>}\r\n */\r\n submitHttpRequest(payload) {\r\n this.logger.info('kms: batched-request-length', payload.kmsMessages.length);\r\n\r\n return this.webex.request({\r\n method: 'POST',\r\n service: 'encryption',\r\n resource: '/kms/messages',\r\n body: payload,\r\n });\r\n },\r\n\r\n /**\r\n * Does nothing; the http response doesn't carry our response data\r\n * @returns {Promise}\r\n */\r\n handleHttpSuccess() {\r\n return Promise.resolve();\r\n },\r\n\r\n /**\r\n * @param {Object} item\r\n * @returns {Promise<boolean>}\r\n */\r\n didItemFail(item) {\r\n return Promise.resolve(item.status >= 400);\r\n },\r\n\r\n /**\r\n * @param {Object} item\r\n * @returns {Promise}\r\n */\r\n handleItemSuccess(item) {\r\n return this.getDeferredForResponse(item).then((defer) => {\r\n defer.resolve(item.body);\r\n });\r\n },\r\n\r\n /**\r\n * @param {Object} item\r\n * @param {KmsError} [reason]\r\n * @returns {Promise}\r\n */\r\n handleItemFailure(item, reason) {\r\n return this.getDeferredForResponse(item).then((defer) => {\r\n defer.reject(reason || new KmsError(item.body));\r\n });\r\n },\r\n\r\n /**\r\n * @param {Object} item\r\n * @returns {Promise}\r\n */\r\n fingerprintRequest(item) {\r\n return Promise.resolve(item.requestId);\r\n },\r\n\r\n /**\r\n * @param {Object} item\r\n * @returns {Promise}\r\n */\r\n fingerprintResponse(item) {\r\n return Promise.resolve(item.requestId);\r\n },\r\n});\r\n\r\nexport default KmsBatcher;\r\n"],"mappings":";;;;;;;;;;AAIA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAPA;AACA;AACA;;AAOO,IAAMG,cAAc,GAAG,IAAAC,OAAA,CAAAC,OAAA,EAAO,gBAAgB,CAAC;;AAEtD;AACA;AACA;AAFAC,OAAA,CAAAH,cAAA,GAAAA,cAAA;AAGA,IAAMI,UAAU,GAAGC,kBAAO,CAACC,MAAM,CAAC;EAChCC,SAAS,EAAE,YAAY;EAEvB;AACF;AACA;AACA;AACA;EACEC,sBAAsB,WAAAA,uBAACC,KAAK,EAAE;IAAA,IAAAC,KAAA;IAC5B,IAAI,CAACC,MAAM,CAACC,IAAI,CAAC,mCAAmC,CAAC;IAErD,OAAOC,QAAA,CAAAX,OAAA,CAAQY,GAAG,CAChBL,KAAK,CAACM,UAAU,CAACC,WAAW,CAACC,GAAG,CAC9B,UAACC,UAAU;MAAA,OACT,IAAAL,QAAA,CAAAX,OAAA,CAAY,UAACiB,OAAO,EAAK;QACvB;QACA,IAAIC,OAAO,CAACC,GAAG,CAACC,QA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,CAACG,IAAI,CAAC,UAACC,KAAK,EAAK;MACvDA,KAAK,CAACoC,MAAM,CAACD,MAAM,IAAI,IAAIE,mBAAQ,CAACzC,IAAI,CAACH,IAAI,CAAC,CAAC;IACjD,CAAC,CAAC;EACJ,CAAC;EAED;AACF;AACA;AACA;EACE6C,kBAAkB,WAAAA,mBAAC1C,IAAI,EAAE;IACvB,OAAOb,QAAA,CAAAX,OAAA,CAAQiB,OAAO,CAACO,IAAI,CAACW,SAAS,CAAC;EACxC,CAAC;EAED;AACF;AACA;AACA;EACEgC,mBAAmB,WAAAA,oBAAC3C,IAAI,EAAE;IACxB,OAAOb,QAAA,CAAAX,OAAA,CAAQiB,OAAO,CAACO,IAAI,CAACW,SAAS,CAAC;EACxC;AACF,CAAC,CAAC;AAAC,IAAAiC,QAAA,GAEYlE,UAAU;AAAAD,OAAA,CAAAD,OAAA,GAAAoE,QAAA"}
@@ -42,16 +42,16 @@ var VALID_KID_PROTOCOL = 'kms:';
42
42
  var X509_COMMON_NAME_KEY = '2.5.4.3';
43
43
  var X509_SUBJECT_ALT_NAME_KEY = '2.5.29.17';
44
44
 
45
- /**
46
- * Customize Error so the SDK knows to quit retrying and notify
47
- * the user
45
+ /**
46
+ * Customize Error so the SDK knows to quit retrying and notify
47
+ * the user
48
48
  */
49
49
  var KMSError = /*#__PURE__*/function (_Error) {
50
50
  (0, _inherits2.default)(KMSError, _Error);
51
51
  var _super = _createSuper(KMSError);
52
- /**
53
- * add kmsError field to notify
54
- * @param {string} message
52
+ /**
53
+ * add kmsError field to notify
54
+ * @param {string} message
55
55
  */
56
56
  function KMSError(message) {
57
57
  var _this;
@@ -67,10 +67,10 @@ var throwError = function throwError(err) {
67
67
  throw new KMSError("INVALID KMS: ".concat(err));
68
68
  };
69
69
 
70
- /**
71
- * Converts the PEM string to a pkijs certificate object
72
- * @param {string} pem PEM representation of a certificate
73
- * @returns {Certificate} pkijs object of the certificate
70
+ /**
71
+ * Converts the PEM string to a pkijs certificate object
72
+ * @param {string} pem PEM representation of a certificate
73
+ * @returns {Certificate} pkijs object of the certificate
74
74
  */
75
75
  var decodeCert = function decodeCert(pem) {
76
76
  if (typeof pem !== 'string') {
@@ -84,12 +84,12 @@ var decodeCert = function decodeCert(pem) {
84
84
  });
85
85
  };
86
86
 
87
- /**
88
- * Validate the 'kty' property of the KMS credentials
89
- * @param {Object} JWT KMS credentials
90
- * @param {string} JWT.kty type of certificate
91
- * @throws {KMSError} if kty is not a valid type
92
- * @returns {void}
87
+ /**
88
+ * Validate the 'kty' property of the KMS credentials
89
+ * @param {Object} JWT KMS credentials
90
+ * @param {string} JWT.kty type of certificate
91
+ * @throws {KMSError} if kty is not a valid type
92
+ * @returns {void}
93
93
  */
94
94
  var validateKtyHeader = function validateKtyHeader(_ref) {
95
95
  var kty = _ref.kty;
@@ -107,15 +107,15 @@ var validateKidHeader = function validateKidHeader(_ref2) {
107
107
  }
108
108
  };
109
109
 
110
- /**
111
- * Checks the first certificate matches the 'kid' in the JWT.
112
- * It first checks the Subject Alternative Name then it checks
113
- * the Common Name
114
- * @param {Certificate} certificate represents the KMS
115
- * @param {Object} JWT KMS credentials
116
- * @param {string} JWT.kid the uri of the KMS
117
- * @throws {KMSError} if unable to validate certificate against KMS credentials
118
- * @returns {void}
110
+ /**
111
+ * Checks the first certificate matches the 'kid' in the JWT.
112
+ * It first checks the Subject Alternative Name then it checks
113
+ * the Common Name
114
+ * @param {Certificate} certificate represents the KMS
115
+ * @param {Object} JWT KMS credentials
116
+ * @param {string} JWT.kid the uri of the KMS
117
+ * @throws {KMSError} if unable to validate certificate against KMS credentials
118
+ * @returns {void}
119
119
  */
120
120
  var validateCommonName = function validateCommonName(_ref3, _ref4) {
121
121
  var _ref5 = (0, _slicedToArray2.default)(_ref3, 1),
@@ -186,15 +186,15 @@ var validateCommonName = function validateCommonName(_ref3, _ref4) {
186
186
  }
187
187
  };
188
188
 
189
- /**
190
- * Validate the first KMS certificate against the information
191
- * provided in the JWT
192
- * @param {Certificate} certificate first certificate the identifies the KMS
193
- * @param {Object} JWT credentials of the KMS
194
- * @param {string} JWT.e Public exponent of the first certificate
195
- * @param {string} KWT.n Modulus of the first certificate
196
- * @throws {KMSError} if e or n doesn't match the first certificate
197
- * @returns {void}
189
+ /**
190
+ * Validate the first KMS certificate against the information
191
+ * provided in the JWT
192
+ * @param {Certificate} certificate first certificate the identifies the KMS
193
+ * @param {Object} JWT credentials of the KMS
194
+ * @param {string} JWT.e Public exponent of the first certificate
195
+ * @param {string} KWT.n Modulus of the first certificate
196
+ * @throws {KMSError} if e or n doesn't match the first certificate
197
+ * @returns {void}
198
198
  */
199
199
  var validatePublicCertificate = function validatePublicCertificate(_ref6, _ref7) {
200
200
  var _ref8 = (0, _slicedToArray2.default)(_ref6, 1),
@@ -217,13 +217,13 @@ var validatePublicCertificate = function validatePublicCertificate(_ref6, _ref7)
217
217
  }
218
218
  };
219
219
 
220
- /**
221
- * Validates the list of certificates against the CAs provided
222
- * @param {certificate[]} certificates list of certificates provided
223
- * by the KMS to certify itself
224
- * @param {string[]} [caroots=[]] list of Certificate Authorities used to
225
- * validate the KMS's certificates
226
- * @returns {Promise} rejects if unable to validate the certificates
220
+ /**
221
+ * Validates the list of certificates against the CAs provided
222
+ * @param {certificate[]} certificates list of certificates provided
223
+ * by the KMS to certify itself
224
+ * @param {string[]} [caroots=[]] list of Certificate Authorities used to
225
+ * validate the KMS's certificates
226
+ * @returns {Promise} rejects if unable to validate the certificates
227
227
  */
228
228
  var validateCertificatesSignature = function validateCertificatesSignature(certificates) {
229
229
  var caroots = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
@@ -241,15 +241,15 @@ var validateCertificatesSignature = function validateCertificatesSignature(certi
241
241
  });
242
242
  };
243
243
 
244
- /**
245
- * Validates the information provided by the KMS. This is a curried function.
246
- * The first function takes the caroots param and returns a second function.
247
- * The second function takes the credentials of the KMS and validates it
248
- * @param {string[]} caroots PEM encoded certificates that will be used
249
- * as Certificate Authorities
250
- * @param {Object} jwt Object containing the fields necessary to
251
- * validate the KMS
252
- * @returns {Promise} when resolved will return the jwt
244
+ /**
245
+ * Validates the information provided by the KMS. This is a curried function.
246
+ * The first function takes the caroots param and returns a second function.
247
+ * The second function takes the credentials of the KMS and validates it
248
+ * @param {string[]} caroots PEM encoded certificates that will be used
249
+ * as Certificate Authorities
250
+ * @param {Object} jwt Object containing the fields necessary to
251
+ * validate the KMS
252
+ * @returns {Promise} when resolved will return the jwt
253
253
  */
254
254
  var validateKMS = function validateKMS(caroots) {
255
255
  return function () {
@@ -1 +1 @@
1
- {"version":3,"names":["_url","require","_validUrl","_asn1js","_pkijs","_nodeJose","_interopRequireDefault","_isomorphicWebcrypto","_safeBuffer","_createForOfIteratorHelper","o","allowArrayLike","it","_Symbol","_Symbol$iterator","_Array$isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","_Array$from","test","arr","len","arr2","Array","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf2","default","result","NewTarget","_Reflect$construct","arguments","apply","_possibleConstructorReturn2","Reflect","sham","Proxy","Boolean","valueOf","setEngine","crypto","CryptoEngine","subtle","VALID_KTY","VALID_KID_PROTOCOL","X509_COMMON_NAME_KEY","X509_SUBJECT_ALT_NAME_KEY","KMSError","_Error","_inherits2","_super","message","_this","_classCallCheck2","kmsError","_createClass2","_wrapNativeSuper2","Error","exports","throwError","concat","decodeCert","pem","der","Buffer","from","ber","Uint8Array","buffer","asn1","fromBER","Certificate","schema","validateKtyHeader","_ref","kty","validateKidHeader","_ref2","kid","isUri","parseUrl","protocol","validateCommonName","_ref3","_ref4","_ref5","_slicedToArray2","certificate","kidHostname","hostname","validationSuccessful","extensions","_iterator","_step","extension","extnID","altNames","parsedValue","_iterator2","_step2","entry","san","subjectAttributes","subject","typesAndValues","_iterator3","_step3","attribute","type","commonName","valueBlock","validatePublicCertificate","_ref6","_ref7","_ref8","publicExponent","modulus","encode","jose","util","base64url","publicKey","subjectPublicKeyInfo","subjectPublicKey","asn1PublicCert","valueHex","publicCert","RSAPublicKey","publicExponentHex","modulusHex","validateCertificatesSignature","certificates","caroots","undefined","certificateEngine","CertificateChainValidationEngine","trustedCerts","map","certs","verify","then","_ref9","resultCode","resultMessage","validateKMS","jwt","_promise","resolve","_isArray2","x5c","promise","_default"],"sources":["kms-certificate-validation.js"],"sourcesContent":["import {parse as parseUrl} from 'url';\n\nimport {isUri} from 'valid-url';\nimport {fromBER} from 'asn1js';\nimport {\n Certificate,\n RSAPublicKey,\n CertificateChainValidationEngine,\n CryptoEngine,\n setEngine,\n} from 'pkijs';\nimport {isArray} from 'lodash';\nimport jose from 'node-jose';\nimport crypto from 'isomorphic-webcrypto';\nimport {Buffer} from 'safe-buffer';\n\nsetEngine(\n 'newEngine',\n crypto,\n new CryptoEngine({\n name: '',\n crypto,\n subtle: crypto.subtle,\n })\n);\n\nconst VALID_KTY = 'RSA';\nconst VALID_KID_PROTOCOL = 'kms:';\n\nconst X509_COMMON_NAME_KEY = '2.5.4.3';\n\nconst X509_SUBJECT_ALT_NAME_KEY = '2.5.29.17';\n\n/**\n * Customize Error so the SDK knows to quit retrying and notify\n * the user\n */\nexport class KMSError extends Error {\n /**\n * add kmsError field to notify\n * @param {string} message\n */\n constructor(message) {\n super(message);\n this.kmsError = true;\n }\n}\n\nconst throwError = (err) => {\n throw new KMSError(`INVALID KMS: ${err}`);\n};\n\n/**\n * Converts the PEM string to a pkijs certificate object\n * @param {string} pem PEM representation of a certificate\n * @returns {Certificate} pkijs object of the certificate\n */\nconst decodeCert = (pem) => {\n if (typeof pem !== 'string') {\n throwError('certificate needs to be a string');\n }\n\n const der = Buffer.from(pem, 'base64');\n const ber = new Uint8Array(der).buffer;\n\n const asn1 = fromBER(ber);\n\n return new Certificate({schema: asn1.result});\n};\n\n/**\n * Validate the 'kty' property of the KMS credentials\n * @param {Object} JWT KMS credentials\n * @param {string} JWT.kty type of certificate\n * @throws {KMSError} if kty is not a valid type\n * @returns {void}\n */\nconst validateKtyHeader = ({kty}) => {\n if (kty !== VALID_KTY) {\n throwError(`'kty' header must be '${VALID_KTY}'`);\n }\n};\n\nconst validateKidHeader = ({kid}) => {\n if (!isUri(kid)) {\n throwError(\"'kid' is not a valid URI\");\n }\n\n if (parseUrl(kid).protocol !== VALID_KID_PROTOCOL) {\n throwError(`'kid' protocol must be '${VALID_KID_PROTOCOL}'`);\n }\n};\n\n/**\n * Checks the first certificate matches the 'kid' in the JWT.\n * It first checks the Subject Alternative Name then it checks\n * the Common Name\n * @param {Certificate} certificate represents the KMS\n * @param {Object} JWT KMS credentials\n * @param {string} JWT.kid the uri of the KMS\n * @throws {KMSError} if unable to validate certificate against KMS credentials\n * @returns {void}\n */\nconst validateCommonName = ([certificate], {kid}) => {\n const kidHostname = parseUrl(kid).hostname;\n let validationSuccessful = false;\n\n if (certificate.extensions) {\n // Subject Alt Names are in here\n for (const extension of certificate.extensions) {\n if (extension.extnID === X509_SUBJECT_ALT_NAME_KEY) {\n const {altNames} = extension.parsedValue;\n\n for (const entry of altNames) {\n const san = entry.value;\n\n validationSuccessful = san === kidHostname;\n if (validationSuccessful) {\n break;\n }\n }\n\n if (validationSuccessful) {\n break;\n }\n }\n }\n }\n\n if (!validationSuccessful) {\n // Didn't match kid in the Subject Alt Names, checking the Common Name\n const subjectAttributes = certificate.subject.typesAndValues;\n\n for (const attribute of subjectAttributes) {\n if (attribute.type === X509_COMMON_NAME_KEY) {\n const commonName = attribute.value.valueBlock.value;\n\n validationSuccessful = commonName === kidHostname;\n if (validationSuccessful) {\n break;\n }\n }\n }\n }\n\n if (!validationSuccessful) {\n throwError(\"hostname of the 1st certificate does not match 'kid'\");\n }\n};\n\n/**\n * Validate the first KMS certificate against the information\n * provided in the JWT\n * @param {Certificate} certificate first certificate the identifies the KMS\n * @param {Object} JWT credentials of the KMS\n * @param {string} JWT.e Public exponent of the first certificate\n * @param {string} KWT.n Modulus of the first certificate\n * @throws {KMSError} if e or n doesn't match the first certificate\n * @returns {void}\n */\nconst validatePublicCertificate = ([certificate], {e: publicExponent, n: modulus}) => {\n const {encode} = jose.util.base64url;\n\n const publicKey = certificate.subjectPublicKeyInfo.subjectPublicKey;\n const asn1PublicCert = fromBER(publicKey.valueBlock.valueHex);\n const publicCert = new RSAPublicKey({schema: asn1PublicCert.result});\n const publicExponentHex = publicCert.publicExponent.valueBlock.valueHex;\n const modulusHex = publicCert.modulus.valueBlock.valueHex;\n\n if (publicExponent !== encode(publicExponentHex)) {\n throwError('Public exponent is invalid');\n }\n if (modulus !== encode(modulusHex)) {\n throwError('Modulus is invalid');\n }\n};\n\n/**\n * Validates the list of certificates against the CAs provided\n * @param {certificate[]} certificates list of certificates provided\n * by the KMS to certify itself\n * @param {string[]} [caroots=[]] list of Certificate Authorities used to\n * validate the KMS's certificates\n * @returns {Promise} rejects if unable to validate the certificates\n */\nconst validateCertificatesSignature = (certificates, caroots = []) => {\n const certificateEngine = new CertificateChainValidationEngine({\n trustedCerts: caroots.map(decodeCert),\n certs: certificates,\n });\n\n return certificateEngine.verify().then(({result, resultCode, resultMessage}) => {\n if (!result) {\n throwError(`Certificate Validation failed [${resultCode}]: ${resultMessage}`);\n }\n });\n};\n\n/**\n * Validates the information provided by the KMS. This is a curried function.\n * The first function takes the caroots param and returns a second function.\n * The second function takes the credentials of the KMS and validates it\n * @param {string[]} caroots PEM encoded certificates that will be used\n * as Certificate Authorities\n * @param {Object} jwt Object containing the fields necessary to\n * validate the KMS\n * @returns {Promise} when resolved will return the jwt\n */\nconst validateKMS =\n (caroots) =>\n (jwt = {}) =>\n Promise.resolve().then(() => {\n validateKtyHeader(jwt);\n validateKidHeader(jwt);\n\n if (!(isArray(jwt.x5c) && jwt.x5c.length > 0)) {\n throwError('JWK does not contain a list of certificates');\n }\n const certificates = jwt.x5c.map(decodeCert);\n\n validateCommonName(certificates, jwt);\n validatePublicCertificate(certificates, jwt);\n\n // Skip validating signatures if no CA roots were provided\n const promise = caroots\n ? validateCertificatesSignature(certificates, caroots)\n : Promise.resolve();\n\n return promise.then(() => jwt);\n });\n\nexport default validateKMS;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAQA,IAAAI,SAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,oBAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAAmC,SAAAQ,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,OAAA,oBAAAH,CAAA,CAAAI,gBAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,cAAA,CAAAL,CAAA,MAAAE,EAAA,GAAAI,2BAAA,CAAAN,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAO,MAAA,qBAAAL,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAM,CAAA,UAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,QAAAH,CAAA,IAAAR,CAAA,CAAAO,MAAA,WAAAK,IAAA,mBAAAA,IAAA,SAAAC,KAAA,EAAAb,CAAA,CAAAQ,CAAA,UAAAM,CAAA,WAAAA,EAAAC,EAAA,UAAAA,EAAA,KAAAC,CAAA,EAAAP,CAAA,gBAAAQ,SAAA,iJAAAC,gBAAA,SAAAC,MAAA,UAAAC,GAAA,WAAAV,CAAA,WAAAA,EAAA,IAAAR,EAAA,GAAAA,EAAA,CAAAmB,IAAA,CAAArB,CAAA,MAAAW,CAAA,WAAAA,EAAA,QAAAW,IAAA,GAAApB,EAAA,CAAAqB,IAAA,IAAAL,gBAAA,GAAAI,IAAA,CAAA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AAa,EAAG;IAC/E;EACF,CAAC,CAAC;AACJ,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,WAAW,GACf,SADIA,WAAWA,CACdZ,OAAO;EAAA,OACR;IAAA,IAACa,GAAG,GAAAlH,SAAA,CAAA5C,MAAA,QAAA4C,SAAA,QAAAsG,SAAA,GAAAtG,SAAA,MAAG,CAAC,CAAC;IAAA,OACPmH,QAAA,CAAAvH,OAAA,CAAQwH,OAAO,EAAE,CAACP,IAAI,CAAC,YAAM;MAC3BnE,iBAAiB,CAACwE,GAAG,CAAC;MACtBrE,iBAAiB,CAACqE,GAAG,CAAC;MAEtB,IAAI,EAAE,IAAAG,SAAA,CAAAzH,OAAA,EAAQsH,GAAG,CAACI,GAAG,CAAC,IAAIJ,GAAG,CAACI,GAAG,CAAClK,MAAM,GAAG,CAAC,CAAC,EAAE;QAC7CwE,UAAU,CAAC,6CAA6C,CAAC;MAC3D;MACA,IAAMwE,YAAY,GAAGc,GAAG,CAACI,GAAG,CAACZ,GAAG,CAAC5E,UAAU,CAAC;MAE5CqB,kBAAkB,CAACiD,YAAY,EAAEc,GAAG,CAAC;MACrClC,yBAAyB,CAACoB,YAAY,EAAEc,GAAG,CAAC;;MAE5C;MACA,IAAMK,OAAO,GAAGlB,OAAO,GACnBF,6BAA6B,CAACC,YAAY,EAAEC,OAAO,CAAC,GACpDc,QAAA,CAAAvH,OAAA,CAAQwH,OAAO,EAAE;MAErB,OAAOG,OAAO,CAACV,IAAI,CAAC;QAAA,OAAMK,GAAG;MAAA,EAAC;IAChC,CAAC,CAAC;EAAA;AAAA;AAAC,IAAAM,QAAA,GAEQP,WAAW;AAAAtF,OAAA,CAAA/B,OAAA,GAAA4H,QAAA"}
1
+ {"version":3,"names":["_url","require","_validUrl","_asn1js","_pkijs","_nodeJose","_interopRequireDefault","_isomorphicWebcrypto","_safeBuffer","_createForOfIteratorHelper","o","allowArrayLike","it","_Symbol","_Symbol$iterator","_Array$isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","_Array$from","test","arr","len","arr2","Array","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf2","default","result","NewTarget","_Reflect$construct","arguments","apply","_possibleConstructorReturn2","Reflect","sham","Proxy","Boolean","valueOf","setEngine","crypto","CryptoEngine","subtle","VALID_KTY","VALID_KID_PROTOCOL","X509_COMMON_NAME_KEY","X509_SUBJECT_ALT_NAME_KEY","KMSError","_Error","_inherits2","_super","message","_this","_classCallCheck2","kmsError","_createClass2","_wrapNativeSuper2","Error","exports","throwError","concat","decodeCert","pem","der","Buffer","from","ber","Uint8Array","buffer","asn1","fromBER","Certificate","schema","validateKtyHeader","_ref","kty","validateKidHeader","_ref2","kid","isUri","parseUrl","protocol","validateCommonName","_ref3","_ref4","_ref5","_slicedToArray2","certificate","kidHostname","hostname","validationSuccessful","extensions","_iterator","_step","extension","extnID","altNames","parsedValue","_iterator2","_step2","entry","san","subjectAttributes","subject","typesAndValues","_iterator3","_step3","attribute","type","commonName","valueBlock","validatePublicCertificate","_ref6","_ref7","_ref8","publicExponent","modulus","encode","jose","util","base64url","publicKey","subjectPublicKeyInfo","subjectPublicKey","asn1PublicCert","valueHex","publicCert","RSAPublicKey","publicExponentHex","modulusHex","validateCertificatesSignature","certificates","caroots","undefined","certificateEngine","CertificateChainValidationEngine","trustedCerts","map","certs","verify","then","_ref9","resultCode","resultMessage","validateKMS","jwt","_promise","resolve","_isArray2","x5c","promise","_default"],"sources":["kms-certificate-validation.js"],"sourcesContent":["import {parse as parseUrl} from 'url';\r\n\r\nimport {isUri} from 'valid-url';\r\nimport {fromBER} from 'asn1js';\r\nimport {\r\n Certificate,\r\n RSAPublicKey,\r\n CertificateChainValidationEngine,\r\n CryptoEngine,\r\n setEngine,\r\n} from 'pkijs';\r\nimport {isArray} from 'lodash';\r\nimport jose from 'node-jose';\r\nimport crypto from 'isomorphic-webcrypto';\r\nimport {Buffer} from 'safe-buffer';\r\n\r\nsetEngine(\r\n 'newEngine',\r\n crypto,\r\n new CryptoEngine({\r\n name: '',\r\n crypto,\r\n subtle: crypto.subtle,\r\n })\r\n);\r\n\r\nconst VALID_KTY = 'RSA';\r\nconst VALID_KID_PROTOCOL = 'kms:';\r\n\r\nconst X509_COMMON_NAME_KEY = '2.5.4.3';\r\n\r\nconst X509_SUBJECT_ALT_NAME_KEY = '2.5.29.17';\r\n\r\n/**\r\n * Customize Error so the SDK knows to quit retrying and notify\r\n * the user\r\n */\r\nexport class KMSError extends Error {\r\n /**\r\n * add kmsError field to notify\r\n * @param {string} message\r\n */\r\n constructor(message) {\r\n super(message);\r\n this.kmsError = true;\r\n }\r\n}\r\n\r\nconst throwError = (err) => {\r\n throw new KMSError(`INVALID KMS: ${err}`);\r\n};\r\n\r\n/**\r\n * Converts the PEM string to a pkijs certificate object\r\n * @param {string} pem PEM representation of a certificate\r\n * @returns {Certificate} pkijs object of the certificate\r\n */\r\nconst decodeCert = (pem) => {\r\n if (typeof pem !== 'string') {\r\n throwError('certificate needs to be a string');\r\n }\r\n\r\n const der = Buffer.from(pem, 'base64');\r\n const ber = new Uint8Array(der).buffer;\r\n\r\n const asn1 = fromBER(ber);\r\n\r\n return new Certificate({schema: asn1.result});\r\n};\r\n\r\n/**\r\n * Validate the 'kty' property of the KMS credentials\r\n * @param {Object} JWT KMS credentials\r\n * @param {string} JWT.kty type of certificate\r\n * @throws {KMSError} if kty is not a valid type\r\n * @returns {void}\r\n */\r\nconst validateKtyHeader = ({kty}) => {\r\n if (kty !== VALID_KTY) {\r\n throwError(`'kty' header must be '${VALID_KTY}'`);\r\n }\r\n};\r\n\r\nconst validateKidHeader = ({kid}) => {\r\n if (!isUri(kid)) {\r\n throwError(\"'kid' is not a valid URI\");\r\n }\r\n\r\n if (parseUrl(kid).protocol !== VALID_KID_PROTOCOL) {\r\n throwError(`'kid' protocol must be '${VALID_KID_PROTOCOL}'`);\r\n }\r\n};\r\n\r\n/**\r\n * Checks the first certificate matches the 'kid' in the JWT.\r\n * It first checks the Subject Alternative Name then it checks\r\n * the Common Name\r\n * @param {Certificate} certificate represents the KMS\r\n * @param {Object} JWT KMS credentials\r\n * @param {string} JWT.kid the uri of the KMS\r\n * @throws {KMSError} if unable to validate certificate against KMS credentials\r\n * @returns {void}\r\n */\r\nconst validateCommonName = ([certificate], {kid}) => {\r\n const kidHostname = parseUrl(kid).hostname;\r\n let validationSuccessful = false;\r\n\r\n if (certificate.extensions) {\r\n // Subject Alt Names are in here\r\n for (const extension of certificate.extensions) {\r\n if (extension.extnID === X509_SUBJECT_ALT_NAME_KEY) {\r\n const {altNames} = extension.parsedValue;\r\n\r\n for (const entry of altNames) {\r\n const san = entry.value;\r\n\r\n validationSuccessful = san === kidHostname;\r\n if (validationSuccessful) {\r\n break;\r\n }\r\n }\r\n\r\n if (validationSuccessful) {\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (!validationSuccessful) {\r\n // Didn't match kid in the Subject Alt Names, checking the Common Name\r\n const subjectAttributes = certificate.subject.typesAndValues;\r\n\r\n for (const attribute of subjectAttributes) {\r\n if (attribute.type === X509_COMMON_NAME_KEY) {\r\n const commonName = attribute.value.valueBlock.value;\r\n\r\n validationSuccessful = commonName === kidHostname;\r\n if (validationSuccessful) {\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (!validationSuccessful) {\r\n throwError(\"hostname of the 1st certificate does not match 'kid'\");\r\n }\r\n};\r\n\r\n/**\r\n * Validate the first KMS certificate against the information\r\n * provided in the JWT\r\n * @param {Certificate} certificate first certificate the identifies the KMS\r\n * @param {Object} JWT credentials of the KMS\r\n * @param {string} JWT.e Public exponent of the first certificate\r\n * @param {string} KWT.n Modulus of the first certificate\r\n * @throws {KMSError} if e or n doesn't match the first certificate\r\n * @returns {void}\r\n */\r\nconst validatePublicCertificate = ([certificate], {e: publicExponent, n: modulus}) => {\r\n const {encode} = jose.util.base64url;\r\n\r\n const publicKey = certificate.subjectPublicKeyInfo.subjectPublicKey;\r\n const asn1PublicCert = fromBER(publicKey.valueBlock.valueHex);\r\n const publicCert = new RSAPublicKey({schema: asn1PublicCert.result});\r\n const publicExponentHex = publicCert.publicExponent.valueBlock.valueHex;\r\n const modulusHex = publicCert.modulus.valueBlock.valueHex;\r\n\r\n if (publicExponent !== encode(publicExponentHex)) {\r\n throwError('Public exponent is invalid');\r\n }\r\n if (modulus !== encode(modulusHex)) {\r\n throwError('Modulus is invalid');\r\n }\r\n};\r\n\r\n/**\r\n * Validates the list of certificates against the CAs provided\r\n * @param {certificate[]} certificates list of certificates provided\r\n * by the KMS to certify itself\r\n * @param {string[]} [caroots=[]] list of Certificate Authorities used to\r\n * validate the KMS's certificates\r\n * @returns {Promise} rejects if unable to validate the certificates\r\n */\r\nconst validateCertificatesSignature = (certificates, caroots = []) => {\r\n const certificateEngine = new CertificateChainValidationEngine({\r\n trustedCerts: caroots.map(decodeCert),\r\n certs: certificates,\r\n });\r\n\r\n return certificateEngine.verify().then(({result, resultCode, resultMessage}) => {\r\n if (!result) {\r\n throwError(`Certificate Validation failed [${resultCode}]: ${resultMessage}`);\r\n }\r\n });\r\n};\r\n\r\n/**\r\n * Validates the information provided by the KMS. This is a curried function.\r\n * The first function takes the caroots param and returns a second function.\r\n * The second function takes the credentials of the KMS and validates it\r\n * @param {string[]} caroots PEM encoded certificates that will be used\r\n * as Certificate Authorities\r\n * @param {Object} jwt Object containing the fields necessary to\r\n * validate the KMS\r\n * @returns {Promise} when resolved will return the jwt\r\n */\r\nconst validateKMS =\r\n (caroots) =>\r\n (jwt = {}) =>\r\n Promise.resolve().then(() => {\r\n validateKtyHeader(jwt);\r\n validateKidHeader(jwt);\r\n\r\n if (!(isArray(jwt.x5c) && jwt.x5c.length > 0)) {\r\n throwError('JWK does not contain a list of certificates');\r\n }\r\n const certificates = jwt.x5c.map(decodeCert);\r\n\r\n validateCommonName(certificates, jwt);\r\n validatePublicCertificate(certificates, jwt);\r\n\r\n // Skip validating signatures if no CA roots were provided\r\n const promise = caroots\r\n ? validateCertificatesSignature(certificates, caroots)\r\n : Promise.resolve();\r\n\r\n return promise.then(() => jwt);\r\n });\r\n\r\nexport default validateKMS;\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAQA,IAAAI,SAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,oBAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAAmC,SAAAQ,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,OAAA,oBAAAH,CAAA,CAAAI,gBAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,cAAA,CAAAL,CAAA,MAAAE,EAAA,GAAAI,2BAAA,CAAAN,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAO,MAAA,qBAAAL,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAM,CAAA,UAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,QAAAH,CAAA,IAAAR,CAAA,CAAAO,MAAA,WAAAK,IAAA,mBAAAA,IAAA,SAAAC,KAAA,EAAAb,CAAA,CAAAQ,CAAA,UAAAM,CAAA,WAAAA,EAAAC,EAAA,UAAAA,EAAA,KAAAC,CAAA,EAAAP,CAAA,gBAAAQ,SAAA,iJAAAC,gBAAA,SAAAC,MAAA,UAAAC,GAAA,WAAAV,CAAA,WAAAA,EAAA,IAAAR,EAAA,GAAAA,EAAA,CAAAmB,IAAA,CAAArB,CAAA,MAAAW,CAAA,WAAAA,EAAA,QAA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18
18
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
19
19
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
- /**
21
- * Interceptor (only to be used in test mode) intended to replay requests that
22
- * fail as a result of the test-user incompatibility in KMS.
23
- * @class
20
+ /**
21
+ * Interceptor (only to be used in test mode) intended to replay requests that
22
+ * fail as a result of the test-user incompatibility in KMS.
23
+ * @class
24
24
  */
25
25
  var KmsDryErrorInterceptor = /*#__PURE__*/function (_Interceptor) {
26
26
  (0, _inherits2.default)(KmsDryErrorInterceptor, _Interceptor);
@@ -32,10 +32,10 @@ var KmsDryErrorInterceptor = /*#__PURE__*/function (_Interceptor) {
32
32
  (0, _createClass2.default)(KmsDryErrorInterceptor, [{
33
33
  key: "onResponseError",
34
34
  value:
35
- /**
36
- * @param {Object} options
37
- * @param {Exception} reason
38
- * @returns {Promise}
35
+ /**
36
+ * @param {Object} options
37
+ * @param {Exception} reason
38
+ * @returns {Promise}
39
39
  */
40
40
  function onResponseError(options, reason) {
41
41
  if (reason instanceof _kmsErrors.DryError && reason.message.match(/Failed to resolve authorization token in KmsMessage request for user/)) {
@@ -46,11 +46,11 @@ var KmsDryErrorInterceptor = /*#__PURE__*/function (_Interceptor) {
46
46
  return _promise.default.reject(reason);
47
47
  }
48
48
 
49
- /**
50
- * Replays the request
51
- * @param {Object} options
52
- * @param {DryError} reason
53
- * @returns {Object}
49
+ /**
50
+ * Replays the request
51
+ * @param {Object} options
52
+ * @param {DryError} reason
53
+ * @returns {Object}
54
54
  */
55
55
  }, {
56
56
  key: "replay",
@@ -70,8 +70,8 @@ var KmsDryErrorInterceptor = /*#__PURE__*/function (_Interceptor) {
70
70
  }], [{
71
71
  key: "create",
72
72
  value:
73
- /**
74
- * @returns {KmsDryErrorInterceptor}
73
+ /**
74
+ * @returns {KmsDryErrorInterceptor}
75
75
  */
76
76
  function create() {
77
77
  return new KmsDryErrorInterceptor({
@@ -1 +1 @@
1
- {"version":3,"names":["_httpCore","require","_kmsErrors","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf2","default","result","NewTarget","constructor","_Reflect$construct","arguments","apply","_possibleConstructorReturn2","Reflect","sham","Proxy","Boolean","prototype","valueOf","call","e","KmsDryErrorInterceptor","_Interceptor","_inherits2","_super","_classCallCheck2","_createClass2","key","value","onResponseError","options","reason","DryError","message","match","webex","logger","error","replay","_promise","reject","replayCount","config","maxAuthenticationReplays","concat","info","request","create","Interceptor","exports"],"sources":["kms-dry-error-interceptor.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {Interceptor} from '@webex/http-core';\n\nimport {DryError} from './kms-errors';\n/**\n * Interceptor (only to be used in test mode) intended to replay requests that\n * fail as a result of the test-user incompatibility in KMS.\n * @class\n */\nexport default class KmsDryErrorInterceptor extends Interceptor {\n /**\n * @returns {KmsDryErrorInterceptor}\n */\n static create() {\n return new KmsDryErrorInterceptor({webex: this});\n }\n\n /**\n * @param {Object} options\n * @param {Exception} reason\n * @returns {Promise}\n */\n onResponseError(options, reason) {\n if (\n reason instanceof DryError &&\n reason.message.match(/Failed to resolve authorization token in KmsMessage request for user/)\n ) {\n this.webex.logger.error('DRY Request Failed due to kms/test-user flakiness');\n this.webex.logger.error(reason);\n\n return this.replay(options, reason);\n }\n\n return Promise.reject(reason);\n }\n\n /**\n * Replays the request\n * @param {Object} options\n * @param {DryError} reason\n * @returns {Object}\n */\n replay(options, reason) {\n if (options.replayCount) {\n options.replayCount += 1;\n } else {\n options.replayCount = 1;\n }\n\n if (options.replayCount > this.webex.config.maxAuthenticationReplays) {\n this.webex.logger.error(\n `kms: failed after ${this.webex.config.maxAuthenticationReplays} replay attempts`\n );\n\n return Promise.reject(reason);\n }\n\n this.webex.logger.info(`kms: replaying request ${options.replayCount} time`);\n\n return this.webex.request(options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAIA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAAsC,SAAAE,aAAAC,OAAA,QAAAC,yBAAA,GAAAC,yBAAA,oBAAAC,qBAAA,QAAAC,KAAA,OAAAC,gBAAA,CAAAC,OAAA,EAAAN,OAAA,GAAAO,MAAA,MAAAN,yBAAA,QAAAO,SAAA,OAAAH,gBAAA,CAAAC,OAAA,QAAAG,WAAA,EAAAF,MAAA,GAAAG,kBAAA,CAAAN,KAAA,EAAAO,SAAA,EAAAH,SAAA,YAAAD,MAAA,GAAAH,KAAA,CAAAQ,KAAA,OAAAD,SAAA,gBAAAE,2BAAA,CAAAP,OAAA,QAAAC,MAAA;AAAA,SAAAL,0BAAA,eAAAY,OAAA,qBAAAJ,kBAAA,oBAAAA,kBAAA,CAAAK,IAAA,2BAAAC,KAAA,oCAAAC,OAAA,CAAAC,SAAA,CAAAC,OAAA,CAAAC,IAAA,CAAAV,kBAAA,CAAAO,OAAA,8CAAAI,CAAA;AACtC;AACA;AACA;AACA;AACA;AAJA,IAKqBC,sBAAsB,0BAAAC,YAAA;EAAA,IAAAC,UAAA,CAAAlB,OAAA,EAAAgB,sBAAA,EAAAC,YAAA;EAAA,IAAAE,MAAA,GAAA1B,YAAA,CAAAuB,sBAAA;EAAA,SAAAA,uBAAA;IAAA,IAAAI,gBAAA,CAAApB,OAAA,QAAAgB,sBAAA;IAAA,OAAAG,MAAA,CAAAb,KAAA,OAAAD,SAAA;EAAA;EAAA,IAAAgB,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AAA;IAlDD;AACF;AACA;IACE,SAAAmB,OAAA,EAAgB;MACd,OAAO,IAAI1B,sBAAsB,CAAC;QAACc,KAAK,EAAE;MAAI,CAAC,CAAC;IAClD;EAAC;EAAA,OAAAd,sBAAA;AAAA,EANiD2B,qBAAW;AAAAC,OAAA,CAAA5C,OAAA,GAAAgB,sBAAA"}
1
+ {"version":3,"names":["_httpCore","require","_kmsErrors","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf2","default","result","NewTarget","constructor","_Reflect$construct","arguments","apply","_possibleConstructorReturn2","Reflect","sham","Proxy","Boolean","prototype","valueOf","call","e","KmsDryErrorInterceptor","_Interceptor","_inherits2","_super","_classCallCheck2","_createClass2","key","value","onResponseError","options","reason","DryError","message","match","webex","logger","error","replay","_promise","reject","replayCount","config","maxAuthenticationReplays","concat","info","request","create","Interceptor","exports"],"sources":["kms-dry-error-interceptor.js"],"sourcesContent":["/*!\r\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\r\n */\r\n\r\nimport {Interceptor} from '@webex/http-core';\r\n\r\nimport {DryError} from './kms-errors';\r\n/**\r\n * Interceptor (only to be used in test mode) intended to replay requests that\r\n * fail as a result of the test-user incompatibility in KMS.\r\n * @class\r\n */\r\nexport default class KmsDryErrorInterceptor extends Interceptor {\r\n /**\r\n * @returns {KmsDryErrorInterceptor}\r\n */\r\n static create() {\r\n return new KmsDryErrorInterceptor({webex: this});\r\n }\r\n\r\n /**\r\n * @param {Object} options\r\n * @param {Exception} reason\r\n * @returns {Promise}\r\n */\r\n onResponseError(options, reason) {\r\n if (\r\n reason instanceof DryError &&\r\n reason.message.match(/Failed to resolve authorization token in KmsMessage request for user/)\r\n ) {\r\n this.webex.logger.error('DRY Request Failed due to kms/test-user flakiness');\r\n this.webex.logger.error(reason);\r\n\r\n return this.replay(options, reason);\r\n }\r\n\r\n return Promise.reject(reason);\r\n }\r\n\r\n /**\r\n * Replays the request\r\n * @param {Object} options\r\n * @param {DryError} reason\r\n * @returns {Object}\r\n */\r\n replay(options, reason) {\r\n if (options.replayCount) {\r\n options.replayCount += 1;\r\n } else {\r\n options.replayCount = 1;\r\n }\r\n\r\n if (options.replayCount > this.webex.config.maxAuthenticationReplays) {\r\n this.webex.logger.error(\r\n `kms: failed after ${this.webex.config.maxAuthenticationReplays} replay attempts`\r\n );\r\n\r\n return Promise.reject(reason);\r\n }\r\n\r\n this.webex.logger.info(`kms: replaying request ${options.replayCount} time`);\r\n\r\n return this.webex.request(options);\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;AAIA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAAsC,SAAAE,aAAAC,OAAA,QAAAC,yBAAA,GAAAC,yBAAA,oBAAAC,qBAAA,QAAAC,KAAA,OAAAC,gBAAA,CAAAC,OAAA,EAAAN,OAAA,GAAAO,MAAA,MAAAN,yBAAA,QAAAO,SAAA,OAAAH,gBAAA,CAAAC,OAAA,QAAAG,WAAA,EAAAF,MAAA,GAAAG,kBAAA,CAAAN,KAAA,EAAAO,SAAA,EAAAH,SAAA,YAAAD,MAAA,GAAAH,KAAA,CAAAQ,KAAA,OAAAD,SAAA,gBAAAE,2BAAA,CAAAP,OAAA,QAAAC,MAAA;AAAA,SAAAL,0BAAA,eAAAY,OAAA,qBAAAJ,kBAAA,oBAAAA,kBAAA,CAAAK,IAAA,2BAAAC,KAAA,oCAAAC,OAAA,CAAAC,SAAA,CAAAC,OAAA,CAAAC,IAAA,CAAAV,kBAAA,CAAAO,OAAA,8CAAAI,CAAA;AACtC;AACA;AACA;AACA;AACA;AAJA,IAKqBC,sBAAsB,0BAAAC,YAAA;EAAA,IAAAC,UAAA,CAAAlB,OAAA,EAAAgB,sBAAA,EAAAC,YAAA;EAAA,IAAAE,MAAA,GAAA1B,YAAA,CAAAuB,sBAAA;EAAA,SAAAA,uBAAA;IAAA,IAAAI,gBAAA,CAAApB,OA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O,IAAI,CAACN,KAAK,CAACW,OAAO,CAAChB,OAAO,CAAC;IACpC;EAAC;IAAAH,GAAA;IAAAC,KAAA;IAlDD;AACF;AACA;IACE,SAAAmB,OAAA,EAAgB;MACd,OAAO,IAAI1B,sBAAsB,CAAC;QAACc,KAAK,EAAE;MAAI,CAAC,CAAC;IAClD;EAAC;EAAA,OAAAd,sBAAA;AAAA,EANiD2B,qBAAW;AAAAC,OAAA,CAAA5C,OAAA,GAAAgB,sBAAA"}
@@ -19,8 +19,8 @@ var _common = require("@webex/common");
19
19
  var _webexCore = require("@webex/webex-core");
20
20
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
21
21
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
22
- /**
23
- * Error class for KMS errors
22
+ /**
23
+ * Error class for KMS errors
24
24
  */
25
25
  var KmsError = /*#__PURE__*/function (_Exception) {
26
26
  (0, _inherits2.default)(KmsError, _Exception);
@@ -32,9 +32,9 @@ var KmsError = /*#__PURE__*/function (_Exception) {
32
32
  (0, _createClass2.default)(KmsError, [{
33
33
  key: "parse",
34
34
  value:
35
- /**
36
- * @param {HttpResponse} body
37
- * @returns {string}
35
+ /**
36
+ * @param {HttpResponse} body
37
+ * @returns {string}
38
38
  */
39
39
  function parse(body) {
40
40
  body = body.body || body;
@@ -77,8 +77,8 @@ var KmsError = /*#__PURE__*/function (_Exception) {
77
77
  }]);
78
78
  return KmsError;
79
79
  }(_common.Exception);
80
- /**
81
- * Thrown when an expected KMSResponse is not received in a timely manner
80
+ /**
81
+ * Thrown when an expected KMSResponse is not received in a timely manner
82
82
  */
83
83
  exports.KmsError = KmsError;
84
84
  (0, _defineProperty2.default)(KmsError, "defaultMessage", 'An unknown error occurred while communicating with the kms. This implies we received an error response without a body.');
@@ -92,10 +92,10 @@ var KmsTimeoutError = /*#__PURE__*/function (_KmsError) {
92
92
  (0, _createClass2.default)(KmsTimeoutError, [{
93
93
  key: "parse",
94
94
  value:
95
- /**
96
- * @param {KmsRequest} options.request
97
- * @param {KmsRequest} options.timeout
98
- * @returns {string}
95
+ /**
96
+ * @param {KmsRequest} options.request
97
+ * @param {KmsRequest} options.timeout
98
+ * @returns {string}
99
99
  */
100
100
  function parse() {
101
101
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
@@ -116,8 +116,8 @@ var KmsTimeoutError = /*#__PURE__*/function (_KmsError) {
116
116
  }]);
117
117
  return KmsTimeoutError;
118
118
  }(KmsError);
119
- /**
120
- * Emitted when a REST request includes an encrypter error
119
+ /**
120
+ * Emitted when a REST request includes an encrypter error
121
121
  */
122
122
  exports.KmsTimeoutError = KmsTimeoutError;
123
123
  var DryError = /*#__PURE__*/function (_WebexHttpError) {
@@ -130,9 +130,9 @@ var DryError = /*#__PURE__*/function (_WebexHttpError) {
130
130
  (0, _createClass2.default)(DryError, [{
131
131
  key: "parse",
132
132
  value:
133
- /**
134
- * @param {WebexHttpError} reason
135
- * @returns {string}
133
+ /**
134
+ * @param {WebexHttpError} reason
135
+ * @returns {string}
136
136
  */
137
137
  function parse(reason) {
138
138
  (0, _apply.default)(_webexCore.WebexHttpError.prototype.parse, this, [reason._res]);