@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.
- package/.eslintrc.js +6 -6
- package/README.md +42 -42
- package/babel.config.js +3 -3
- package/dist/config.js +21 -21
- package/dist/config.js.map +1 -1
- package/dist/encryption.js +57 -57
- package/dist/encryption.js.map +1 -1
- package/dist/ensure-buffer.browser.js +7 -7
- package/dist/ensure-buffer.browser.js.map +1 -1
- package/dist/ensure-buffer.js +7 -7
- package/dist/ensure-buffer.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/kms-batcher.js +38 -38
- package/dist/kms-batcher.js.map +1 -1
- package/dist/kms-certificate-validation.js +50 -50
- package/dist/kms-certificate-validation.js.map +1 -1
- package/dist/kms-dry-error-interceptor.js +15 -15
- package/dist/kms-dry-error-interceptor.js.map +1 -1
- package/dist/kms-errors.js +16 -16
- package/dist/kms-errors.js.map +1 -1
- package/dist/kms.js +171 -171
- package/dist/kms.js.map +1 -1
- package/jest.config.js +3 -3
- package/package.json +20 -19
- package/process +1 -1
- package/src/config.js +50 -50
- package/src/encryption.js +257 -257
- package/src/ensure-buffer.browser.js +37 -37
- package/src/ensure-buffer.js +20 -20
- package/src/index.js +159 -159
- package/src/kms-batcher.js +158 -158
- package/src/kms-certificate-validation.js +232 -232
- package/src/kms-dry-error-interceptor.js +65 -65
- package/src/kms-errors.js +147 -147
- package/src/kms.js +848 -848
- package/test/integration/spec/encryption.js +448 -448
- package/test/integration/spec/kms.js +800 -800
- package/test/integration/spec/payload-transfom.js +97 -97
- package/test/unit/spec/encryption.js +82 -82
- package/test/unit/spec/kms-certificate-validation.js +165 -165
- package/test/unit/spec/kms.js +103 -103
package/.eslintrc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const config = {
|
|
2
|
-
root: true,
|
|
3
|
-
extends: ['@webex/eslint-config-legacy'],
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
module.exports = config;
|
|
1
|
+
const config = {
|
|
2
|
+
root: true,
|
|
3
|
+
extends: ['@webex/eslint-config-legacy'],
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
module.exports = config;
|
package/README.md
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
# @webex/internal-plugin-encryption
|
|
2
|
-
|
|
3
|
-
[](https://github.com/RichardLitt/standard-readme)
|
|
4
|
-
|
|
5
|
-
> Plugin for the Encryption and KMS services
|
|
6
|
-
|
|
7
|
-
This is an internal Cisco Webex plugin. As such, it does not strictly adhere to semantic versioning. Use at your own risk. If you're not working on one of our first party clients, please look at our [developer api](https://developer.webex.com/) and stick to our public plugins.
|
|
8
|
-
|
|
9
|
-
- [Install](#install)
|
|
10
|
-
- [Usage](#usage)
|
|
11
|
-
- [Contribute](#contribute)
|
|
12
|
-
- [Maintainers](#maintainers)
|
|
13
|
-
- [License](#license)
|
|
14
|
-
|
|
15
|
-
## Install
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install --save @webex/internal-plugin-encryption
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
|
|
23
|
-
```js
|
|
24
|
-
import '@webex/internal-plugin-encryption';
|
|
25
|
-
|
|
26
|
-
import WebexCore from '@webex/webex-core';
|
|
27
|
-
|
|
28
|
-
const webex = new WebexCore();
|
|
29
|
-
webex.internal.encryption.WHATEVER;
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Maintainers
|
|
33
|
-
|
|
34
|
-
This package is maintained by [Cisco Webex for Developers](https://developer.webex.com/).
|
|
35
|
-
|
|
36
|
-
## Contribute
|
|
37
|
-
|
|
38
|
-
Pull requests welcome. Please see [CONTRIBUTING.md](https://github.com/webex/webex-js-sdk/blob/master/CONTRIBUTING.md) for more details.
|
|
39
|
-
|
|
40
|
-
## License
|
|
41
|
-
|
|
42
|
-
© 2016-2020 Cisco and/or its affiliates. All Rights Reserved.
|
|
1
|
+
# @webex/internal-plugin-encryption
|
|
2
|
+
|
|
3
|
+
[](https://github.com/RichardLitt/standard-readme)
|
|
4
|
+
|
|
5
|
+
> Plugin for the Encryption and KMS services
|
|
6
|
+
|
|
7
|
+
This is an internal Cisco Webex plugin. As such, it does not strictly adhere to semantic versioning. Use at your own risk. If you're not working on one of our first party clients, please look at our [developer api](https://developer.webex.com/) and stick to our public plugins.
|
|
8
|
+
|
|
9
|
+
- [Install](#install)
|
|
10
|
+
- [Usage](#usage)
|
|
11
|
+
- [Contribute](#contribute)
|
|
12
|
+
- [Maintainers](#maintainers)
|
|
13
|
+
- [License](#license)
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install --save @webex/internal-plugin-encryption
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import '@webex/internal-plugin-encryption';
|
|
25
|
+
|
|
26
|
+
import WebexCore from '@webex/webex-core';
|
|
27
|
+
|
|
28
|
+
const webex = new WebexCore();
|
|
29
|
+
webex.internal.encryption.WHATEVER;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Maintainers
|
|
33
|
+
|
|
34
|
+
This package is maintained by [Cisco Webex for Developers](https://developer.webex.com/).
|
|
35
|
+
|
|
36
|
+
## Contribute
|
|
37
|
+
|
|
38
|
+
Pull requests welcome. Please see [CONTRIBUTING.md](https://github.com/webex/webex-js-sdk/blob/master/CONTRIBUTING.md) for more details.
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
© 2016-2020 Cisco and/or its affiliates. All Rights Reserved.
|
package/babel.config.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const babelConfigLegacy = require('@webex/babel-config-legacy');
|
|
2
|
-
|
|
3
|
-
module.exports = babelConfigLegacy;
|
|
1
|
+
const babelConfigLegacy = require('@webex/babel-config-legacy');
|
|
2
|
+
|
|
3
|
+
module.exports = babelConfigLegacy;
|
package/dist/config.js
CHANGED
|
@@ -5,8 +5,8 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
/*!
|
|
9
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
8
|
+
/*!
|
|
9
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
10
10
|
*/
|
|
11
11
|
var _default = {
|
|
12
12
|
encryption: {
|
|
@@ -15,35 +15,35 @@ var _default = {
|
|
|
15
15
|
contentAlg: 'A256GCM',
|
|
16
16
|
protect: '*'
|
|
17
17
|
},
|
|
18
|
-
/**
|
|
19
|
-
* Initial timeout before contacting KMS with a new request
|
|
20
|
-
* @type {Number}
|
|
18
|
+
/**
|
|
19
|
+
* Initial timeout before contacting KMS with a new request
|
|
20
|
+
* @type {Number}
|
|
21
21
|
*/
|
|
22
22
|
kmsInitialTimeout: 6000,
|
|
23
|
-
/**
|
|
24
|
-
* Maximum timeout before negotiating a new ECDH key
|
|
25
|
-
* and contacting KMS with a new request
|
|
26
|
-
* @type {Number}
|
|
23
|
+
/**
|
|
24
|
+
* Maximum timeout before negotiating a new ECDH key
|
|
25
|
+
* and contacting KMS with a new request
|
|
26
|
+
* @type {Number}
|
|
27
27
|
*/
|
|
28
28
|
kmsMaxTimeout: 32000,
|
|
29
|
-
/**
|
|
30
|
-
* Maximum timeout after negotiating several ECDH keys
|
|
31
|
-
* @type {Number}
|
|
29
|
+
/**
|
|
30
|
+
* Maximum timeout after negotiating several ECDH keys
|
|
31
|
+
* @type {Number}
|
|
32
32
|
*/
|
|
33
33
|
ecdhMaxTimeout: 32000 * 3,
|
|
34
|
-
/**
|
|
35
|
-
* Debounce wait before sending a kms request
|
|
36
|
-
* @type {Number}
|
|
34
|
+
/**
|
|
35
|
+
* Debounce wait before sending a kms request
|
|
36
|
+
* @type {Number}
|
|
37
37
|
*/
|
|
38
38
|
batcherWait: 50,
|
|
39
|
-
/**
|
|
40
|
-
* Maximum queue size before sending a kms request
|
|
41
|
-
* @type {Number}
|
|
39
|
+
/**
|
|
40
|
+
* Maximum queue size before sending a kms request
|
|
41
|
+
* @type {Number}
|
|
42
42
|
*/
|
|
43
43
|
batcherMaxCalls: 50,
|
|
44
|
-
/**
|
|
45
|
-
* Debounce max wait before sending a kms metric
|
|
46
|
-
* @type {Number}
|
|
44
|
+
/**
|
|
45
|
+
* Debounce max wait before sending a kms metric
|
|
46
|
+
* @type {Number}
|
|
47
47
|
*/
|
|
48
48
|
batcherMaxWait: 150
|
|
49
49
|
}
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_default","encryption","joseOptions","compact","contentAlg","protect","kmsInitialTimeout","kmsMaxTimeout","ecdhMaxTimeout","batcherWait","batcherMaxCalls","batcherMaxWait","exports","default"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport default {\n encryption: {\n joseOptions: {\n compact: true,\n contentAlg: 'A256GCM',\n protect: '*',\n },\n\n /**\n * Initial timeout before contacting KMS with a new request\n * @type {Number}\n */\n kmsInitialTimeout: 6000,\n\n /**\n * Maximum timeout before negotiating a new ECDH key\n * and contacting KMS with a new request\n * @type {Number}\n */\n kmsMaxTimeout: 32000,\n\n /**\n * Maximum timeout after negotiating several ECDH keys\n * @type {Number}\n */\n ecdhMaxTimeout: 32000 * 3,\n\n /**\n * Debounce wait before sending a kms request\n * @type {Number}\n */\n batcherWait: 50,\n\n /**\n * Maximum queue size before sending a kms request\n * @type {Number}\n */\n batcherMaxCalls: 50,\n\n /**\n * Debounce max wait before sending a kms metric\n * @type {Number}\n */\n batcherMaxWait: 150,\n },\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAFA,IAAAA,QAAA,GAIe;EACbC,UAAU,EAAE;IACVC,WAAW,EAAE;MACXC,OAAO,EAAE,IAAI;MACbC,UAAU,EAAE,SAAS;MACrBC,OAAO,EAAE;IACX,CAAC;IAED;AACJ;AACA;AACA;IACIC,iBAAiB,EAAE,IAAI;IAEvB;AACJ;AACA;AACA;AACA;IACIC,aAAa,EAAE,KAAK;IAEpB;AACJ;AACA;AACA;IACIC,cAAc,EAAE,KAAK,GAAG,CAAC;IAEzB;AACJ;AACA;AACA;IACIC,WAAW,EAAE,EAAE;IAEf;AACJ;AACA;AACA;IACIC,eAAe,EAAE,EAAE;IAEnB;AACJ;AACA;AACA;IACIC,cAAc,EAAE;EAClB;AACF,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAb,QAAA"}
|
|
1
|
+
{"version":3,"names":["_default","encryption","joseOptions","compact","contentAlg","protect","kmsInitialTimeout","kmsMaxTimeout","ecdhMaxTimeout","batcherWait","batcherMaxCalls","batcherMaxWait","exports","default"],"sources":["config.js"],"sourcesContent":["/*!\r\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\r\n */\r\n\r\nexport default {\r\n encryption: {\r\n joseOptions: {\r\n compact: true,\r\n contentAlg: 'A256GCM',\r\n protect: '*',\r\n },\r\n\r\n /**\r\n * Initial timeout before contacting KMS with a new request\r\n * @type {Number}\r\n */\r\n kmsInitialTimeout: 6000,\r\n\r\n /**\r\n * Maximum timeout before negotiating a new ECDH key\r\n * and contacting KMS with a new request\r\n * @type {Number}\r\n */\r\n kmsMaxTimeout: 32000,\r\n\r\n /**\r\n * Maximum timeout after negotiating several ECDH keys\r\n * @type {Number}\r\n */\r\n ecdhMaxTimeout: 32000 * 3,\r\n\r\n /**\r\n * Debounce wait before sending a kms request\r\n * @type {Number}\r\n */\r\n batcherWait: 50,\r\n\r\n /**\r\n * Maximum queue size before sending a kms request\r\n * @type {Number}\r\n */\r\n batcherMaxCalls: 50,\r\n\r\n /**\r\n * Debounce max wait before sending a kms metric\r\n * @type {Number}\r\n */\r\n batcherMaxWait: 150,\r\n },\r\n};\r\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAFA,IAAAA,QAAA,GAIe;EACbC,UAAU,EAAE;IACVC,WAAW,EAAE;MACXC,OAAO,EAAE,IAAI;MACbC,UAAU,EAAE,SAAS;MACrBC,OAAO,EAAE;IACX,CAAC;IAED;AACJ;AACA;AACA;IACIC,iBAAiB,EAAE,IAAI;IAEvB;AACJ;AACA;AACA;AACA;IACIC,aAAa,EAAE,KAAK;IAEpB;AACJ;AACA;AACA;IACIC,cAAc,EAAE,KAAK,GAAG,CAAC;IAEzB;AACJ;AACA;AACA;IACIC,WAAW,EAAE,EAAE;IAEf;AACJ;AACA;AACA;IACIC,eAAe,EAAE,EAAE;IAEnB;AACJ;AACA;AACA;IACIC,cAAc,EAAE;EAClB;AACF,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAb,QAAA"}
|
package/dist/encryption.js
CHANGED
|
@@ -41,28 +41,28 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
41
41
|
return scr.decrypt(b);
|
|
42
42
|
});
|
|
43
43
|
},
|
|
44
|
-
/**
|
|
45
|
-
* Decrypt a SCR (Secure Content Resource) using the supplied key uri.
|
|
46
|
-
*
|
|
47
|
-
* @param {string} key - The uri of a key stored in KMS
|
|
48
|
-
* @param {Object} cipherScr - An encrypted SCR
|
|
49
|
-
* @param {Object} options
|
|
50
|
-
* @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role
|
|
51
|
-
* @returns {Object} Decrypted SCR
|
|
44
|
+
/**
|
|
45
|
+
* Decrypt a SCR (Secure Content Resource) using the supplied key uri.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} key - The uri of a key stored in KMS
|
|
48
|
+
* @param {Object} cipherScr - An encrypted SCR
|
|
49
|
+
* @param {Object} options
|
|
50
|
+
* @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role
|
|
51
|
+
* @returns {Object} Decrypted SCR
|
|
52
52
|
*/
|
|
53
53
|
decryptScr: function decryptScr(key, cipherScr, options) {
|
|
54
54
|
return this.getKey(key, options).then(function (k) {
|
|
55
55
|
return _nodeScr.default.fromJWE(k.jwk, cipherScr);
|
|
56
56
|
});
|
|
57
57
|
},
|
|
58
|
-
/**
|
|
59
|
-
* Decrypt text using the supplied key uri.
|
|
60
|
-
*
|
|
61
|
-
* @param {string} key - The uri of a key stored in KMS
|
|
62
|
-
* @param {string} ciphertext - Encrypted text
|
|
63
|
-
* @param {Object} options
|
|
64
|
-
* @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role
|
|
65
|
-
* @returns {string} Decrypted plaintext
|
|
58
|
+
/**
|
|
59
|
+
* Decrypt text using the supplied key uri.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} key - The uri of a key stored in KMS
|
|
62
|
+
* @param {string} ciphertext - Encrypted text
|
|
63
|
+
* @param {Object} options
|
|
64
|
+
* @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role
|
|
65
|
+
* @returns {string} Decrypted plaintext
|
|
66
66
|
*/
|
|
67
67
|
decryptText: function decryptText(key, ciphertext, options) {
|
|
68
68
|
return this.getKey(key, options).then(function (k) {
|
|
@@ -71,12 +71,12 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
73
|
},
|
|
74
|
-
/**
|
|
75
|
-
* Validate and initiate a Download request for requested file
|
|
76
|
-
*
|
|
77
|
-
* @param {Object} scr - Plaintext
|
|
78
|
-
* @param {Object} options - optional parameters to download a file
|
|
79
|
-
* @returns {promise}
|
|
74
|
+
/**
|
|
75
|
+
* Validate and initiate a Download request for requested file
|
|
76
|
+
*
|
|
77
|
+
* @param {Object} scr - Plaintext
|
|
78
|
+
* @param {Object} options - optional parameters to download a file
|
|
79
|
+
* @returns {promise}
|
|
80
80
|
*/
|
|
81
81
|
download: function download(scr, options) {
|
|
82
82
|
var _this = this;
|
|
@@ -101,12 +101,12 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
101
101
|
(0, _common.proxyEvents)(shunt, promise);
|
|
102
102
|
return promise;
|
|
103
103
|
},
|
|
104
|
-
/**
|
|
105
|
-
* Fetch Download URL for the requested file
|
|
106
|
-
*
|
|
107
|
-
* @param {Object} scr - Plaintext
|
|
108
|
-
* @param {Object} options - optional parameters to download a file
|
|
109
|
-
* @returns {promise} url of the downloadable file
|
|
104
|
+
/**
|
|
105
|
+
* Fetch Download URL for the requested file
|
|
106
|
+
*
|
|
107
|
+
* @param {Object} scr - Plaintext
|
|
108
|
+
* @param {Object} options - optional parameters to download a file
|
|
109
|
+
* @returns {promise} url of the downloadable file
|
|
110
110
|
*/
|
|
111
111
|
_fetchDownloadUrl: function _fetchDownloadUrl(scr, options) {
|
|
112
112
|
var _this2 = this;
|
|
@@ -154,14 +154,14 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
154
154
|
});
|
|
155
155
|
});
|
|
156
156
|
},
|
|
157
|
-
/**
|
|
158
|
-
* Encrypt a SCR (Secure Content Resource) using the supplied key uri.
|
|
159
|
-
*
|
|
160
|
-
* @param {string} key - The uri of a key stored in KMS
|
|
161
|
-
* @param {Object} scr - Plaintext
|
|
162
|
-
* @param {Object} options
|
|
163
|
-
* @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role
|
|
164
|
-
* @returns {string} Encrypted SCR
|
|
157
|
+
/**
|
|
158
|
+
* Encrypt a SCR (Secure Content Resource) using the supplied key uri.
|
|
159
|
+
*
|
|
160
|
+
* @param {string} key - The uri of a key stored in KMS
|
|
161
|
+
* @param {Object} scr - Plaintext
|
|
162
|
+
* @param {Object} options
|
|
163
|
+
* @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role
|
|
164
|
+
* @returns {string} Encrypted SCR
|
|
165
165
|
*/
|
|
166
166
|
encryptScr: function encryptScr(key, scr, options) {
|
|
167
167
|
/* istanbul ignore if */
|
|
@@ -172,14 +172,14 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
172
172
|
return scr.toJWE(k.jwk);
|
|
173
173
|
});
|
|
174
174
|
},
|
|
175
|
-
/**
|
|
176
|
-
* Encrypt plaintext using the supplied key uri.
|
|
177
|
-
*
|
|
178
|
-
* @param {string} key - The uri of a key stored in KMS
|
|
179
|
-
* @param {string} plaintext
|
|
180
|
-
* @param {Object} options
|
|
181
|
-
* @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role
|
|
182
|
-
* @returns {string} Encrypted text
|
|
175
|
+
/**
|
|
176
|
+
* Encrypt plaintext using the supplied key uri.
|
|
177
|
+
*
|
|
178
|
+
* @param {string} key - The uri of a key stored in KMS
|
|
179
|
+
* @param {string} plaintext
|
|
180
|
+
* @param {Object} options
|
|
181
|
+
* @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role
|
|
182
|
+
* @returns {string} Encrypted text
|
|
183
183
|
*/
|
|
184
184
|
encryptText: function encryptText(key, plaintext, options) {
|
|
185
185
|
var _this3 = this;
|
|
@@ -193,13 +193,13 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
193
193
|
}).final(plaintext, 'utf8');
|
|
194
194
|
});
|
|
195
195
|
},
|
|
196
|
-
/**
|
|
197
|
-
* Fetch the key associated with the supplied KMS uri.
|
|
198
|
-
*
|
|
199
|
-
* @param {string} uri - The uri of a key stored in KMS
|
|
200
|
-
* @param {Object} options
|
|
201
|
-
* @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role
|
|
202
|
-
* @returns {string} Key
|
|
196
|
+
/**
|
|
197
|
+
* Fetch the key associated with the supplied KMS uri.
|
|
198
|
+
*
|
|
199
|
+
* @param {string} uri - The uri of a key stored in KMS
|
|
200
|
+
* @param {Object} options
|
|
201
|
+
* @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role
|
|
202
|
+
* @returns {string} Key
|
|
203
203
|
*/
|
|
204
204
|
getKey: function getKey(uri) {
|
|
205
205
|
var _this4 = this;
|
|
@@ -225,14 +225,14 @@ var Encryption = _webexCore.WebexPlugin.extend({
|
|
|
225
225
|
}));
|
|
226
226
|
});
|
|
227
227
|
},
|
|
228
|
-
version: "2.59.
|
|
228
|
+
version: "2.59.0"
|
|
229
229
|
});
|
|
230
230
|
|
|
231
|
-
/**
|
|
232
|
-
* JSON.stringify replacer that ensures private key data is serialized.
|
|
233
|
-
* @param {string} k
|
|
234
|
-
* @param {mixed} v
|
|
235
|
-
* @returns {mixed}
|
|
231
|
+
/**
|
|
232
|
+
* JSON.stringify replacer that ensures private key data is serialized.
|
|
233
|
+
* @param {string} k
|
|
234
|
+
* @param {mixed} v
|
|
235
|
+
* @returns {mixed}
|
|
236
236
|
*/
|
|
237
237
|
function replacer(k, v) {
|
|
238
238
|
if (k === 'jwk') {
|
package/dist/encryption.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_events","require","_url","_interopRequireDefault","_webexCore","_common","_nodeJose","_nodeScr","_ensureBuffer","_kms","ownKeys","object","enumerableOnly","keys","_Object$keys","_Object$getOwnPropertySymbols","symbols","filter","sym","_Object$getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","Object","forEach","key","_defineProperty2","default","_Object$getOwnPropertyDescriptors","_Object$defineProperties","_Object$defineProperty","Encryption","WebexPlugin","extend","children","kms","KMS","namespace","processKmsMessageEvent","event","decryptBinary","scr","buffer","ensureBuffer","then","b","byteLength","_promise","reject","Error","decrypt","decryptScr","cipherScr","options","getKey","k","SCR","fromJWE","jwk","decryptText","ciphertext","jose","JWE","createDecrypt","result","plaintext","toString","download","_this","loc","shunt","EventEmitter","promise","_fetchDownloadUrl","uri","method","responseType","ret","request","transferEvents","res","body","proxyEvents","_this2","logger","info","process","env","NODE_ENV","includes","resolve","inputBody","endpoints","endpointUrl","url","parse","protocol","pathname","format","allow","params","warn","encryptBinary","file","create","encrypt","cdata","encryptScr","toJWE","encryptText","_this3","createEncrypt","config","joseOptions","header","alg","reference","final","_this4","_ref","undefined","onBehalfOf","asKey","storageKey","concat","unboundedStorage","get","keyString","JSON","keyObject","catch","fetchKey","tap","put","_stringify","replacer","version","v","json","toJSON","_default","exports"],"sources":["encryption.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {EventEmitter} from 'events';\nimport url from 'url';\n\nimport {WebexPlugin} from '@webex/webex-core';\nimport {proxyEvents, tap, transferEvents} from '@webex/common';\nimport jose from 'node-jose';\nimport SCR from 'node-scr';\n\nimport ensureBuffer from './ensure-buffer';\nimport KMS from './kms';\n\nconst Encryption = WebexPlugin.extend({\n children: {\n kms: KMS,\n },\n\n namespace: 'Encryption',\n\n processKmsMessageEvent(event) {\n return this.kms.processKmsMessageEvent(event);\n },\n\n decryptBinary(scr, buffer) {\n return ensureBuffer(buffer).then((b) => {\n /* istanbul ignore if */\n if (buffer.length === 0 || buffer.byteLength === 0) {\n return Promise.reject(new Error('Attempted to decrypt zero-length buffer'));\n }\n\n return scr.decrypt(b);\n });\n },\n\n /**\n * Decrypt a SCR (Secure Content Resource) using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {Object} cipherScr - An encrypted SCR\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {Object} Decrypted SCR\n */\n decryptScr(key, cipherScr, options) {\n return this.getKey(key, options).then((k) => SCR.fromJWE(k.jwk, cipherScr));\n },\n\n /**\n * Decrypt text using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {string} ciphertext - Encrypted text\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Decrypted plaintext\n */\n decryptText(key, ciphertext, options) {\n return this.getKey(key, options).then((k) =>\n jose.JWE.createDecrypt(k.jwk)\n .decrypt(ciphertext)\n .then((result) => result.plaintext.toString())\n );\n },\n\n /**\n * Validate and initiate a Download request for requested file\n *\n * @param {Object} scr - Plaintext\n * @param {Object} options - optional parameters to download a file\n * @returns {promise}\n */\n download(scr, options) {\n /* istanbul ignore if */\n if (!scr.loc) {\n return Promise.reject(new Error('`scr.loc` is required'));\n }\n\n const shunt = new EventEmitter();\n const promise = this._fetchDownloadUrl(scr, options)\n .then((uri) => {\n // eslint-disable-next-line no-shadow\n const options = {\n method: 'GET',\n uri,\n responseType: 'buffer',\n };\n\n const ret = this.request(options);\n\n transferEvents('progress', options.download, shunt);\n\n return ret;\n })\n .then((res) => this.decryptBinary(scr, res.body));\n\n proxyEvents(shunt, promise);\n\n return promise;\n },\n\n /**\n * Fetch Download URL for the requested file\n *\n * @param {Object} scr - Plaintext\n * @param {Object} options - optional parameters to download a file\n * @returns {promise} url of the downloadable file\n */\n _fetchDownloadUrl(scr, options) {\n this.logger.info('encryption: retrieving download url for encrypted file');\n\n if (process.env.NODE_ENV !== 'production' && scr.loc.includes('localhost')) {\n this.logger.info(\n 'encryption: bypassing webex files because this looks to be a test file on localhost'\n );\n\n return Promise.resolve(scr.loc);\n }\n\n const inputBody = {\n endpoints: [scr.loc],\n };\n const endpointUrl = url.parse(scr.loc);\n\n // hardcode the url to use 'https' and the file service '/v1/download/endpoints' api\n endpointUrl.protocol = 'https';\n endpointUrl.pathname = '/v1/download/endpoints';\n\n return this.request({\n method: 'POST',\n uri: url.format(endpointUrl),\n body: options\n ? {\n ...inputBody,\n allow: options.params.allow,\n }\n : inputBody,\n }).then((res) => {\n // eslint-disable-next-line no-shadow\n const url = res.body.endpoints[scr.loc];\n\n if (!url) {\n this.logger.warn(\n 'encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly'\n );\n\n return scr.loc;\n }\n this.logger.info('encryption: retrieved download url for encrypted file');\n\n return url;\n });\n },\n\n encryptBinary(file) {\n return ensureBuffer(file).then((buffer) =>\n SCR.create().then((scr) =>\n scr\n .encrypt(buffer)\n .then(ensureBuffer)\n // eslint-disable-next-line max-nested-callbacks\n .then((cdata) => ({scr, cdata}))\n )\n );\n },\n\n /**\n * Encrypt a SCR (Secure Content Resource) using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {Object} scr - Plaintext\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Encrypted SCR\n */\n encryptScr(key, scr, options) {\n /* istanbul ignore if */\n if (!scr.loc) {\n return Promise.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));\n }\n\n return this.getKey(key, options).then((k) => scr.toJWE(k.jwk));\n },\n\n /**\n * Encrypt plaintext using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {string} plaintext\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Encrypted text\n */\n encryptText(key, plaintext, options) {\n return this.getKey(key, options).then((k) =>\n jose.JWE.createEncrypt(this.config.joseOptions, {\n key: k.jwk,\n header: {\n alg: 'dir',\n },\n reference: null,\n }).final(plaintext, 'utf8')\n );\n },\n\n /**\n * Fetch the key associated with the supplied KMS uri.\n *\n * @param {string} uri - The uri of a key stored in KMS\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Key\n */\n getKey(uri, {onBehalfOf} = {}) {\n if (uri.jwk) {\n return this.kms.asKey(uri);\n }\n\n let storageKey = uri;\n\n if (onBehalfOf) {\n storageKey += `/onBehalfOf/${onBehalfOf}`;\n }\n\n return this.unboundedStorage\n .get(storageKey)\n .then((keyString) => JSON.parse(keyString))\n .then((keyObject) => this.kms.asKey(keyObject))\n .catch(() =>\n this.kms\n .fetchKey({uri, onBehalfOf})\n .then(tap((key) => this.unboundedStorage.put(storageKey, JSON.stringify(key, replacer))))\n );\n },\n});\n\n/**\n * JSON.stringify replacer that ensures private key data is serialized.\n * @param {string} k\n * @param {mixed} v\n * @returns {mixed}\n */\nfunction replacer(k, v) {\n if (k === 'jwk') {\n // note: this[k] and v may be different representations of the same value\n // eslint-disable-next-line no-invalid-this\n const json = this[k].toJSON(true);\n\n return json;\n }\n\n return v;\n}\n\nexport default Encryption;\n"],"mappings":";;;;;;;;;;;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,QAAA,GAAAJ,sBAAA,CAAAF,OAAA;AAEA,IAAAO,aAAA,GAAAL,sBAAA,CAAAF,OAAA;AACA,IAAAQ,IAAA,GAAAN,sBAAA,CAAAF,OAAA;AAAwB,SAAAS,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,YAAA,CAAAH,MAAA,OAAAI,6BAAA,QAAAC,OAAA,GAAAD,6BAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAC,gCAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,YAAAH,IAAA;AAAA,SAA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MAAA,OAAKC,IAAI,CAACjC,KAAK,CAACgC,SAAS,CAAC;IAAA,EAAC,CAC1CnF,IAAI,CAAC,UAACqF,SAAS;MAAA,OAAKX,MAAI,CAACnF,GAAG,CAACuF,KAAK,CAACO,SAAS,CAAC;IAAA,EAAC,CAC9CC,KAAK,CAAC;MAAA,OACLZ,MAAI,CAACnF,GAAG,CACLgG,QAAQ,CAAC;QAACzD,GAAG,EAAHA,GAAG;QAAE+C,UAAU,EAAVA;MAAU,CAAC,CAAC,CAC3B7E,IAAI,CAAC,IAAAwF,WAAG,EAAC,UAAC3G,GAAG;QAAA,OAAK6F,MAAI,CAACO,gBAAgB,CAACQ,GAAG,CAACV,UAAU,EAAE,IAAAW,UAAA,CAAA3G,OAAA,EAAeF,GAAG,EAAE8G,QAAQ,CAAC,CAAC;MAAA,EAAC,CAAC;IAAA,EAC5F;EACL,CAAC;EAAAC,OAAA;AACH,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,SAASD,QAAQA,CAAChF,CAAC,EAAEkF,CAAC,EAAE;EACtB,IAAIlF,CAAC,KAAK,KAAK,EAAE;IACf;IACA;IACA,IAAMmF,IAAI,GAAG,IAAI,CAACnF,CAAC,CAAC,CAACoF,MAAM,CAAC,IAAI,CAAC;IAEjC,OAAOD,IAAI;EACb;EAEA,OAAOD,CAAC;AACV;AAAC,IAAAG,QAAA,GAEc7G,UAAU;AAAA8G,OAAA,CAAAlH,OAAA,GAAAiH,QAAA"}
|
|
1
|
+
{"version":3,"names":["_events","require","_url","_interopRequireDefault","_webexCore","_common","_nodeJose","_nodeScr","_ensureBuffer","_kms","ownKeys","object","enumerableOnly","keys","_Object$keys","_Object$getOwnPropertySymbols","symbols","filter","sym","_Object$getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","Object","forEach","key","_defineProperty2","default","_Object$getOwnPropertyDescriptors","_Object$defineProperties","_Object$defineProperty","Encryption","WebexPlugin","extend","children","kms","KMS","namespace","processKmsMessageEvent","event","decryptBinary","scr","buffer","ensureBuffer","then","b","byteLength","_promise","reject","Error","decrypt","decryptScr","cipherScr","options","getKey","k","SCR","fromJWE","jwk","decryptText","ciphertext","jose","JWE","createDecrypt","result","plaintext","toString","download","_this","loc","shunt","EventEmitter","promise","_fetchDownloadUrl","uri","method","responseType","ret","request","transferEvents","res","body","proxyEvents","_this2","logger","info","process","env","NODE_ENV","includes","resolve","inputBody","endpoints","endpointUrl","url","parse","protocol","pathname","format","allow","params","warn","encryptBinary","file","create","encrypt","cdata","encryptScr","toJWE","encryptText","_this3","createEncrypt","config","joseOptions","header","alg","reference","final","_this4","_ref","undefined","onBehalfOf","asKey","storageKey","concat","unboundedStorage","get","keyString","JSON","keyObject","catch","fetchKey","tap","put","_stringify","replacer","version","v","json","toJSON","_default","exports"],"sources":["encryption.js"],"sourcesContent":["/*!\r\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\r\n */\r\n\r\nimport {EventEmitter} from 'events';\r\nimport url from 'url';\r\n\r\nimport {WebexPlugin} from '@webex/webex-core';\r\nimport {proxyEvents, tap, transferEvents} from '@webex/common';\r\nimport jose from 'node-jose';\r\nimport SCR from 'node-scr';\r\n\r\nimport ensureBuffer from './ensure-buffer';\r\nimport KMS from './kms';\r\n\r\nconst Encryption = WebexPlugin.extend({\r\n children: {\r\n kms: KMS,\r\n },\r\n\r\n namespace: 'Encryption',\r\n\r\n processKmsMessageEvent(event) {\r\n return this.kms.processKmsMessageEvent(event);\r\n },\r\n\r\n decryptBinary(scr, buffer) {\r\n return ensureBuffer(buffer).then((b) => {\r\n /* istanbul ignore if */\r\n if (buffer.length === 0 || buffer.byteLength === 0) {\r\n return Promise.reject(new Error('Attempted to decrypt zero-length buffer'));\r\n }\r\n\r\n return scr.decrypt(b);\r\n });\r\n },\r\n\r\n /**\r\n * Decrypt a SCR (Secure Content Resource) using the supplied key uri.\r\n *\r\n * @param {string} key - The uri of a key stored in KMS\r\n * @param {Object} cipherScr - An encrypted SCR\r\n * @param {Object} options\r\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\r\n * @returns {Object} Decrypted SCR\r\n */\r\n decryptScr(key, cipherScr, options) {\r\n return this.getKey(key, options).then((k) => SCR.fromJWE(k.jwk, cipherScr));\r\n },\r\n\r\n /**\r\n * Decrypt text using the supplied key uri.\r\n *\r\n * @param {string} key - The uri of a key stored in KMS\r\n * @param {string} ciphertext - Encrypted text\r\n * @param {Object} options\r\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\r\n * @returns {string} Decrypted plaintext\r\n */\r\n decryptText(key, ciphertext, options) {\r\n return this.getKey(key, options).then((k) =>\r\n jose.JWE.createDecrypt(k.jwk)\r\n .decrypt(ciphertext)\r\n .then((result) => result.plaintext.toString())\r\n );\r\n },\r\n\r\n /**\r\n * Validate and initiate a Download request for requested file\r\n *\r\n * @param {Object} scr - Plaintext\r\n * @param {Object} options - optional parameters to download a file\r\n * @returns {promise}\r\n */\r\n download(scr, options) {\r\n /* istanbul ignore if */\r\n if (!scr.loc) {\r\n return Promise.reject(new Error('`scr.loc` is required'));\r\n }\r\n\r\n const shunt = new EventEmitter();\r\n const promise = this._fetchDownloadUrl(scr, options)\r\n .then((uri) => {\r\n // eslint-disable-next-line no-shadow\r\n const options = {\r\n method: 'GET',\r\n uri,\r\n responseType: 'buffer',\r\n };\r\n\r\n const ret = this.request(options);\r\n\r\n transferEvents('progress', options.download, shunt);\r\n\r\n return ret;\r\n })\r\n .then((res) => this.decryptBinary(scr, res.body));\r\n\r\n proxyEvents(shunt, promise);\r\n\r\n return promise;\r\n },\r\n\r\n /**\r\n * Fetch Download URL for the requested file\r\n *\r\n * @param {Object} scr - Plaintext\r\n * @param {Object} options - optional parameters to download a file\r\n * @returns {promise} url of the downloadable file\r\n */\r\n _fetchDownloadUrl(scr, options) {\r\n this.logger.info('encryption: retrieving download url for encrypted file');\r\n\r\n if (process.env.NODE_ENV !== 'production' && scr.loc.includes('localhost')) {\r\n this.logger.info(\r\n 'encryption: bypassing webex files because this looks to be a test file on localhost'\r\n );\r\n\r\n return Promise.resolve(scr.loc);\r\n }\r\n\r\n const inputBody = {\r\n endpoints: [scr.loc],\r\n };\r\n const endpointUrl = url.parse(scr.loc);\r\n\r\n // hardcode the url to use 'https' and the file service '/v1/download/endpoints' api\r\n endpointUrl.protocol = 'https';\r\n endpointUrl.pathname = '/v1/download/endpoints';\r\n\r\n return this.request({\r\n method: 'POST',\r\n uri: url.format(endpointUrl),\r\n body: options\r\n ? {\r\n ...inputBody,\r\n allow: options.params.allow,\r\n }\r\n : inputBody,\r\n }).then((res) => {\r\n // eslint-disable-next-line no-shadow\r\n const url = res.body.endpoints[scr.loc];\r\n\r\n if (!url) {\r\n this.logger.warn(\r\n 'encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly'\r\n );\r\n\r\n return scr.loc;\r\n }\r\n this.logger.info('encryption: retrieved download url for encrypted file');\r\n\r\n return url;\r\n });\r\n },\r\n\r\n encryptBinary(file) {\r\n return ensureBuffer(file).then((buffer) =>\r\n SCR.create().then((scr) =>\r\n scr\r\n .encrypt(buffer)\r\n .then(ensureBuffer)\r\n // eslint-disable-next-line max-nested-callbacks\r\n .then((cdata) => ({scr, cdata}))\r\n )\r\n );\r\n },\r\n\r\n /**\r\n * Encrypt a SCR (Secure Content Resource) using the supplied key uri.\r\n *\r\n * @param {string} key - The uri of a key stored in KMS\r\n * @param {Object} scr - Plaintext\r\n * @param {Object} options\r\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\r\n * @returns {string} Encrypted SCR\r\n */\r\n encryptScr(key, scr, options) {\r\n /* istanbul ignore if */\r\n if (!scr.loc) {\r\n return Promise.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));\r\n }\r\n\r\n return this.getKey(key, options).then((k) => scr.toJWE(k.jwk));\r\n },\r\n\r\n /**\r\n * Encrypt plaintext using the supplied key uri.\r\n *\r\n * @param {string} key - The uri of a key stored in KMS\r\n * @param {string} plaintext\r\n * @param {Object} options\r\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\r\n * @returns {string} Encrypted text\r\n */\r\n encryptText(key, plaintext, options) {\r\n return this.getKey(key, options).then((k) =>\r\n jose.JWE.createEncrypt(this.config.joseOptions, {\r\n key: k.jwk,\r\n header: {\r\n alg: 'dir',\r\n },\r\n reference: null,\r\n }).final(plaintext, 'utf8')\r\n );\r\n },\r\n\r\n /**\r\n * Fetch the key associated with the supplied KMS uri.\r\n *\r\n * @param {string} uri - The uri of a key stored in KMS\r\n * @param {Object} options\r\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\r\n * @returns {string} Key\r\n */\r\n getKey(uri, {onBehalfOf} = {}) {\r\n if (uri.jwk) {\r\n return this.kms.asKey(uri);\r\n }\r\n\r\n let storageKey = uri;\r\n\r\n if (onBehalfOf) {\r\n storageKey += `/onBehalfOf/${onBehalfOf}`;\r\n }\r\n\r\n return this.unboundedStorage\r\n .get(storageKey)\r\n .then((keyString) => JSON.parse(keyString))\r\n .then((keyObject) => this.kms.asKey(keyObject))\r\n .catch(() =>\r\n this.kms\r\n .fetchKey({uri, onBehalfOf})\r\n .then(tap((key) => this.unboundedStorage.put(storageKey, JSON.stringify(key, replacer))))\r\n );\r\n },\r\n});\r\n\r\n/**\r\n * JSON.stringify replacer that ensures private key data is serialized.\r\n * @param {string} k\r\n * @param {mixed} v\r\n * @returns {mixed}\r\n */\r\nfunction replacer(k, v) {\r\n if (k === 'jwk') {\r\n // note: this[k] and v may be different representations of the same value\r\n // eslint-disable-next-line no-invalid-this\r\n const json = this[k].toJSON(true);\r\n\r\n return json;\r\n }\r\n\r\n return v;\r\n}\r\n\r\nexport default Encryption;\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IAAA,EAC5F;EACL,CAAC;EAAAC,OAAA;AACH,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,SAASD,QAAQA,CAAChF,CAAC,EAAEkF,CAAC,EAAE;EACtB,IAAIlF,CAAC,KAAK,KAAK,EAAE;IACf;IACA;IACA,IAAMmF,IAAI,GAAG,IAAI,CAACnF,CAAC,CAAC,CAACoF,MAAM,CAAC,IAAI,CAAC;IAEjC,OAAOD,IAAI;EACb;EAEA,OAAOD,CAAC;AACV;AAAC,IAAAG,QAAA,GAEc7G,UAAU;AAAA8G,OAAA,CAAAlH,OAAA,GAAAiH,QAAA"}
|
|
@@ -7,17 +7,17 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = ensureBuffer;
|
|
9
9
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
10
|
-
/*!
|
|
11
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
10
|
+
/*!
|
|
11
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
/* eslint-env: browser */
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Ensures the provider buffer is, indeed, an ArrayBuffer; converts File and
|
|
18
|
-
* Blob objects to ArrayBuffers.
|
|
19
|
-
* @param {mixed} buffer
|
|
20
|
-
* @returns {Promise<ArrayBuffer>}
|
|
16
|
+
/**
|
|
17
|
+
* Ensures the provider buffer is, indeed, an ArrayBuffer; converts File and
|
|
18
|
+
* Blob objects to ArrayBuffers.
|
|
19
|
+
* @param {mixed} buffer
|
|
20
|
+
* @returns {Promise<ArrayBuffer>}
|
|
21
21
|
*/
|
|
22
22
|
function ensureBuffer(buffer) {
|
|
23
23
|
if (buffer instanceof ArrayBuffer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ensureBuffer","buffer","ArrayBuffer","_promise","default","resolve","toArrayBuffer","reject","fr","FileReader","onload","Uint8Array","result","onerror","readAsArrayBuffer"],"sources":["ensure-buffer.browser.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env: browser */\n\n/**\n * Ensures the provider buffer is, indeed, an ArrayBuffer; converts File and\n * Blob objects to ArrayBuffers.\n * @param {mixed} buffer\n * @returns {Promise<ArrayBuffer>}\n */\nexport default function ensureBuffer(buffer) {\n if (buffer instanceof ArrayBuffer) {\n return Promise.resolve(buffer);\n }\n\n if (buffer.toArrayBuffer) {\n return Promise.resolve(buffer.toArrayBuffer());\n }\n\n if (buffer.buffer) {\n return Promise.resolve(buffer.buffer);\n }\n\n return new Promise((resolve, reject) => {\n const fr = new FileReader();\n\n fr.onload = function onload() {\n resolve(new Uint8Array(this.result));\n };\n\n fr.onerror = reject;\n\n fr.readAsArrayBuffer(buffer);\n });\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAYA,CAACC,MAAM,EAAE;EAC3C,IAAIA,MAAM,YAAYC,WAAW,EAAE;IACjC,OAAOC,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAAC;EAChC;EAEA,IAAIA,MAAM,CAACK,aAAa,EAAE;IACxB,OAAOH,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAACK,aAAa,EAAE,CAAC;EAChD;EAEA,IAAIL,MAAM,CAACA,MAAM,EAAE;IACjB,OAAOE,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAACA,MAAM,CAAC;EACvC;EAEA,OAAO,IAAAE,QAAA,CAAAC,OAAA,CAAY,UAACC,OAAO,EAAEE,MAAM,EAAK;IACtC,IAAMC,EAAE,GAAG,IAAIC,UAAU,EAAE;IAE3BD,EAAE,CAACE,MAAM,GAAG,SAASA,MAAMA,CAAA,EAAG;MAC5BL,OAAO,CAAC,IAAIM,UAAU,CAAC,IAAI,CAACC,MAAM,CAAC,CAAC;IACtC,CAAC;IAEDJ,EAAE,CAACK,OAAO,GAAGN,MAAM;IAEnBC,EAAE,CAACM,iBAAiB,CAACb,MAAM,CAAC;EAC9B,CAAC,CAAC;AACJ"}
|
|
1
|
+
{"version":3,"names":["ensureBuffer","buffer","ArrayBuffer","_promise","default","resolve","toArrayBuffer","reject","fr","FileReader","onload","Uint8Array","result","onerror","readAsArrayBuffer"],"sources":["ensure-buffer.browser.js"],"sourcesContent":["/*!\r\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\r\n */\r\n\r\n/* eslint-env: browser */\r\n\r\n/**\r\n * Ensures the provider buffer is, indeed, an ArrayBuffer; converts File and\r\n * Blob objects to ArrayBuffers.\r\n * @param {mixed} buffer\r\n * @returns {Promise<ArrayBuffer>}\r\n */\r\nexport default function ensureBuffer(buffer) {\r\n if (buffer instanceof ArrayBuffer) {\r\n return Promise.resolve(buffer);\r\n }\r\n\r\n if (buffer.toArrayBuffer) {\r\n return Promise.resolve(buffer.toArrayBuffer());\r\n }\r\n\r\n if (buffer.buffer) {\r\n return Promise.resolve(buffer.buffer);\r\n }\r\n\r\n return new Promise((resolve, reject) => {\r\n const fr = new FileReader();\r\n\r\n fr.onload = function onload() {\r\n resolve(new Uint8Array(this.result));\r\n };\r\n\r\n fr.onerror = reject;\r\n\r\n fr.readAsArrayBuffer(buffer);\r\n });\r\n}\r\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAYA,CAACC,MAAM,EAAE;EAC3C,IAAIA,MAAM,YAAYC,WAAW,EAAE;IACjC,OAAOC,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAAC;EAChC;EAEA,IAAIA,MAAM,CAACK,aAAa,EAAE;IACxB,OAAOH,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAACK,aAAa,EAAE,CAAC;EAChD;EAEA,IAAIL,MAAM,CAACA,MAAM,EAAE;IACjB,OAAOE,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACJ,MAAM,CAACA,MAAM,CAAC;EACvC;EAEA,OAAO,IAAAE,QAAA,CAAAC,OAAA,CAAY,UAACC,OAAO,EAAEE,MAAM,EAAK;IACtC,IAAMC,EAAE,GAAG,IAAIC,UAAU,EAAE;IAE3BD,EAAE,CAACE,MAAM,GAAG,SAASA,MAAMA,CAAA,EAAG;MAC5BL,OAAO,CAAC,IAAIM,UAAU,CAAC,IAAI,CAACC,MAAM,CAAC,CAAC;IACtC,CAAC;IAEDJ,EAAE,CAACK,OAAO,GAAGN,MAAM;IAEnBC,EAAE,CAACM,iBAAiB,CAACb,MAAM,CAAC;EAC9B,CAAC,CAAC;AACJ"}
|
package/dist/ensure-buffer.js
CHANGED
|
@@ -8,15 +8,15 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.default = ensureBuffer;
|
|
9
9
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
10
10
|
var _common = require("@webex/common");
|
|
11
|
-
/*!
|
|
12
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
11
|
+
/*!
|
|
12
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be
|
|
17
|
-
* byte-arrays instead of proper Buffer objects.
|
|
18
|
-
* @param {mixed} buffer
|
|
19
|
-
* @returns {Promise<Buffer>}
|
|
15
|
+
/**
|
|
16
|
+
* Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be
|
|
17
|
+
* byte-arrays instead of proper Buffer objects.
|
|
18
|
+
* @param {mixed} buffer
|
|
19
|
+
* @returns {Promise<Buffer>}
|
|
20
20
|
*/
|
|
21
21
|
function ensureBuffer(buffer) {
|
|
22
22
|
/* istanbul ignore if */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_common","require","ensureBuffer","buffer","isBuffer","_promise","default","reject","Error","resolve"],"sources":["ensure-buffer.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {isBuffer} from '@webex/common';\n\n/**\n * Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be\n * byte-arrays instead of proper Buffer objects.\n * @param {mixed} buffer\n * @returns {Promise<Buffer>}\n */\nexport default function ensureBuffer(buffer) {\n /* istanbul ignore if */\n if (!isBuffer(buffer)) {\n return Promise.reject(new Error('`buffer` must be a buffer'));\n }\n\n return Promise.resolve(buffer);\n}\n"],"mappings":";;;;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,YAAYA,CAACC,MAAM,EAAE;EAC3C;EACA,IAAI,CAAC,IAAAC,gBAAQ,EAACD,MAAM,CAAC,EAAE;IACrB,OAAOE,QAAA,CAAAC,OAAA,CAAQC,MAAM,CAAC,IAAIC,KAAK,CAAC,2BAA2B,CAAC,CAAC;EAC/D;EAEA,OAAOH,QAAA,CAAAC,OAAA,CAAQG,OAAO,CAACN,MAAM,CAAC;AAChC"}
|
|
1
|
+
{"version":3,"names":["_common","require","ensureBuffer","buffer","isBuffer","_promise","default","reject","Error","resolve"],"sources":["ensure-buffer.js"],"sourcesContent":["/*!\r\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\r\n */\r\n\r\nimport {isBuffer} from '@webex/common';\r\n\r\n/**\r\n * Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be\r\n * byte-arrays instead of proper Buffer objects.\r\n * @param {mixed} buffer\r\n * @returns {Promise<Buffer>}\r\n */\r\nexport default function ensureBuffer(buffer) {\r\n /* istanbul ignore if */\r\n if (!isBuffer(buffer)) {\r\n return Promise.reject(new Error('`buffer` must be a buffer'));\r\n }\r\n\r\n return Promise.resolve(buffer);\r\n}\r\n"],"mappings":";;;;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,YAAYA,CAACC,MAAM,EAAE;EAC3C;EACA,IAAI,CAAC,IAAAC,gBAAQ,EAACD,MAAM,CAAC,EAAE;IACrB,OAAOE,QAAA,CAAAC,OAAA,CAAQC,MAAM,CAAC,IAAIC,KAAK,CAAC,2BAA2B,CAAC,CAAC;EAC/D;EAEA,OAAOH,QAAA,CAAAC,OAAA,CAAQG,OAAO,CAACN,MAAM,CAAC;AAChC"}
|
package/dist/index.js
CHANGED
|
@@ -41,8 +41,8 @@ var _config = _interopRequireDefault(require("./config"));
|
|
|
41
41
|
var _kmsErrors = require("./kms-errors");
|
|
42
42
|
var _kmsDryErrorInterceptor = _interopRequireDefault(require("./kms-dry-error-interceptor"));
|
|
43
43
|
var _kms = _interopRequireDefault(require("./kms"));
|
|
44
|
-
/*!
|
|
45
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
44
|
+
/*!
|
|
45
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
48
|
// Note: There's a bug where if bind gets replayed because of a timeout in which
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require","_webexCore","_encryption","_interopRequireDefault","_config","_kmsErrors","_kmsDryErrorInterceptor","_kms","interceptors","process","env","NODE_ENV","KmsDryErrorInterceptor","create","registerInternalPlugin","Encryption","payloadTransformer","predicates","name","direction","test","ctx","options","_has2","default","_promise","resolve","_isObject2","body","kmsMessage","keyUris","length","resourceUri","includes","uri","extract","response","_isString2","reason","Boolean","errorCode","transforms","fn","object","webex","internal","encryption","kms","prepareRequest","then","req","wrapped","decryptKmsMessage","promises","errors","map","error","description","desc","push","message","all","reject","DryError","config"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n// Note: There's a bug where if bind gets replayed because of a timeout in which\n// the original request eventually completed, there'll be an error indicating\n// the key can't be bound (because it already has been). This could be mitigated\n// by using Promise.race to resolve replays (as more requests get enqueue for a\n// specific action, accept whichever one completes first).\n\nimport '@webex/internal-plugin-device';\n\nimport '@webex/internal-plugin-mercury';\n\nimport {registerInternalPlugin} from '@webex/webex-core';\nimport {has, isObject, isString} from 'lodash';\n\nimport Encryption from './encryption';\nimport config from './config';\nimport {DryError} from './kms-errors';\n\nimport KmsDryErrorInterceptor from './kms-dry-error-interceptor';\n\nlet interceptors;\n\nif (process.env.NODE_ENV === 'test') {\n interceptors = {\n KmsDryErrorInterceptor: KmsDryErrorInterceptor.create,\n };\n}\n\nregisterInternalPlugin('encryption', Encryption, {\n payloadTransformer: {\n predicates: [\n {\n name: 'encryptKmsMessage',\n direction: 'outbound',\n // I don't see any practical way to reduce complexity here.\n // eslint-disable-next-line complexity\n test(ctx, options) {\n if (!has(options, 'body.kmsMessage')) {\n return Promise.resolve(false);\n }\n\n if (!isObject(options.body.kmsMessage)) {\n return Promise.resolve(false);\n }\n\n // If this is a template for a kms message, assume another transform\n // will fill it in later. This is a bit of a leaky abstraction, but the\n // alternative is building a complex rules engine for controlling\n // ordering of transforms\n if (options.body.kmsMessage.keyUris && options.body.kmsMessage.keyUris.length === 0) {\n return Promise.resolve(false);\n }\n if (\n options.body.kmsMessage.resourceUri &&\n (options.body.kmsMessage.resourceUri.includes('<KRO>') ||\n options.body.kmsMessage.resourceUri.includes('<KEYURL>'))\n ) {\n return Promise.resolve(false);\n }\n if (\n options.body.kmsMessage.uri &&\n (options.body.kmsMessage.uri.includes('<KRO>') ||\n options.body.kmsMessage.uri.includes('<KEYURL>'))\n ) {\n return Promise.resolve(false);\n }\n\n return Promise.resolve(true);\n },\n extract(options) {\n return Promise.resolve(options.body);\n },\n },\n {\n name: 'decryptKmsMessage',\n direction: 'inbound',\n test(ctx, response) {\n return Promise.resolve(\n has(response, 'body.kmsMessage') && isString(response.body.kmsMessage)\n );\n },\n extract(response) {\n return Promise.resolve(response.body);\n },\n },\n {\n name: 'decryptErrorResponse',\n direction: 'inbound',\n test(ctx, reason) {\n return Promise.resolve(Boolean(reason.body && reason.body.errorCode === 1900000));\n },\n extract(reason) {\n return Promise.resolve(reason);\n },\n },\n ],\n transforms: [\n {\n name: 'encryptKmsMessage',\n fn(ctx, object) {\n if (!object) {\n return Promise.resolve();\n }\n\n if (!object.kmsMessage) {\n return Promise.resolve();\n }\n\n if (isString(object.kmsMessage)) {\n return Promise.resolve();\n }\n\n return ctx.webex.internal.encryption.kms.prepareRequest(object.kmsMessage).then((req) => {\n object.kmsMessage = req.wrapped;\n });\n },\n },\n {\n name: 'decryptKmsMessage',\n fn(ctx, object) {\n return ctx.webex.internal.encryption.kms\n .decryptKmsMessage(object.kmsMessage)\n .then((kmsMessage) => {\n object.kmsMessage = kmsMessage;\n });\n },\n },\n {\n name: 'decryptErrorResponse',\n fn(ctx, reason) {\n const promises = reason.body.errors.map((error) =>\n ctx.webex.internal.encryption.kms.decryptKmsMessage(error.description).then((desc) => {\n error.description = desc;\n })\n );\n\n promises.push(\n ctx.webex.internal.encryption.kms\n .decryptKmsMessage(reason.body.message)\n .then((kmsMessage) => {\n reason.body.message = kmsMessage;\n })\n );\n\n return Promise.all(promises).then(() => Promise.reject(new DryError(reason)));\n },\n },\n ],\n },\n interceptors,\n config,\n});\n\nexport {default} from './encryption';\nexport {default as KMS} from './kms';\nexport {KmsError, DryError} from './kms-errors';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUAA,OAAA;AAEAA,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAGA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH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;UACpBc,MAAM,CAACd,UAAU,GAAGA,UAAU;QAChC,CAAC,CAAC;MACN;IACF,CAAC,EACD;MACEX,IAAI,EAAE,sBAAsB;MAC5BwB,EAAE,WAAAA,GAACrB,GAAG,EAAEiB,MAAM,EAAE;QACd,IAAMe,QAAQ,GAAGf,MAAM,CAACV,IAAI,CAAC0B,MAAM,CAACC,GAAG,CAAC,UAACC,KAAK;UAAA,OAC5CnC,GAAG,CAACuB,KAAK,CAACC,QAAQ,CAACC,UAAU,CAACC,GAAG,CAACK,iBAAiB,CAACI,KAAK,CAACC,WAAW,CAAC,CAACR,IAAI,CAAC,UAACS,IAAI,EAAK;YACpFF,KAAK,CAACC,WAAW,GAAGC,IAAI;UAC1B,CAAC,CAAC;QAAA,EACH;QAEDL,QAAQ,CAACM,IAAI,CACXtC,GAAG,CAACuB,KAAK,CAACC,QAAQ,CAACC,UAAU,CAACC,GAAG,CAC9BK,iBAAiB,CAACd,MAAM,CAACV,IAAI,CAACgC,OAAO,CAAC,CACtCX,IAAI,CAAC,UAACpB,UAAU,EAAK;UACpBS,MAAM,CAACV,IAAI,CAACgC,OAAO,GAAG/B,UAAU;QAClC,CAAC,CAAC,CACL;QAED,OAAOJ,QAAA,CAAAD,OAAA,CAAQqC,GAAG,CAACR,QAAQ,CAAC,CAACJ,IAAI,CAAC;UAAA,OAAMxB,QAAA,CAAAD,OAAA,CAAQsC,MAAM,CAAC,IAAIC,mBAAQ,CAACzB,MAAM,CAAC,CAAC;QAAA,EAAC;MAC/E;IACF,CAAC;EAEL,CAAC;EACD9B,YAAY,EAAZA,YAAY;EACZwD,MAAM,EAANA;AACF,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"names":["require","_webexCore","_encryption","_interopRequireDefault","_config","_kmsErrors","_kmsDryErrorInterceptor","_kms","interceptors","process","env","NODE_ENV","KmsDryErrorInterceptor","create","registerInternalPlugin","Encryption","payloadTransformer","predicates","name","direction","test","ctx","options","_has2","default","_promise","resolve","_isObject2","body","kmsMessage","keyUris","length","resourceUri","includes","uri","extract","response","_isString2","reason","Boolean","errorCode","transforms","fn","object","webex","internal","encryption","kms","prepareRequest","then","req","wrapped","decryptKmsMessage","promises","errors","map","error","description","desc","push","message","all","reject","DryError","config"],"sources":["index.js"],"sourcesContent":["/*!\r\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\r\n */\r\n\r\n// Note: There's a bug where if bind gets replayed because of a timeout in which\r\n// the original request eventually completed, there'll be an error indicating\r\n// the key can't be bound (because it already has been). This could be mitigated\r\n// by using Promise.race to resolve replays (as more requests get enqueue for a\r\n// specific action, accept whichever one completes first).\r\n\r\nimport '@webex/internal-plugin-device';\r\n\r\nimport '@webex/internal-plugin-mercury';\r\n\r\nimport {registerInternalPlugin} from '@webex/webex-core';\r\nimport {has, isObject, isString} from 'lodash';\r\n\r\nimport Encryption from './encryption';\r\nimport config from './config';\r\nimport {DryError} from './kms-errors';\r\n\r\nimport KmsDryErrorInterceptor from './kms-dry-error-interceptor';\r\n\r\nlet interceptors;\r\n\r\nif (process.env.NODE_ENV === 'test') {\r\n interceptors = {\r\n KmsDryErrorInterceptor: KmsDryErrorInterceptor.create,\r\n };\r\n}\r\n\r\nregisterInternalPlugin('encryption', Encryption, {\r\n payloadTransformer: {\r\n predicates: [\r\n {\r\n name: 'encryptKmsMessage',\r\n direction: 'outbound',\r\n // I don't see any practical way to reduce complexity here.\r\n // eslint-disable-next-line complexity\r\n test(ctx, options) {\r\n if (!has(options, 'body.kmsMessage')) {\r\n return Promise.resolve(false);\r\n }\r\n\r\n if (!isObject(options.body.kmsMessage)) {\r\n return Promise.resolve(false);\r\n }\r\n\r\n // If this is a template for a kms message, assume another transform\r\n // will fill it in later. This is a bit of a leaky abstraction, but the\r\n // alternative is building a complex rules engine for controlling\r\n // ordering of transforms\r\n if (options.body.kmsMessage.keyUris && options.body.kmsMessage.keyUris.length === 0) {\r\n return Promise.resolve(false);\r\n }\r\n if (\r\n options.body.kmsMessage.resourceUri &&\r\n (options.body.kmsMessage.resourceUri.includes('<KRO>') ||\r\n options.body.kmsMessage.resourceUri.includes('<KEYURL>'))\r\n ) {\r\n return Promise.resolve(false);\r\n }\r\n if (\r\n options.body.kmsMessage.uri &&\r\n (options.body.kmsMessage.uri.includes('<KRO>') ||\r\n options.body.kmsMessage.uri.includes('<KEYURL>'))\r\n ) {\r\n return Promise.resolve(false);\r\n }\r\n\r\n return Promise.resolve(true);\r\n },\r\n extract(options) {\r\n return Promise.resolve(options.body);\r\n },\r\n },\r\n {\r\n name: 'decryptKmsMessage',\r\n direction: 'inbound',\r\n test(ctx, response) {\r\n return Promise.resolve(\r\n has(response, 'body.kmsMessage') && isString(response.body.kmsMessage)\r\n );\r\n },\r\n extract(response) {\r\n return Promise.resolve(response.body);\r\n },\r\n },\r\n {\r\n name: 'decryptErrorResponse',\r\n direction: 'inbound',\r\n test(ctx, reason) {\r\n return Promise.resolve(Boolean(reason.body && reason.body.errorCode === 1900000));\r\n },\r\n extract(reason) {\r\n return Promise.resolve(reason);\r\n },\r\n },\r\n ],\r\n transforms: [\r\n {\r\n name: 'encryptKmsMessage',\r\n fn(ctx, object) {\r\n if (!object) {\r\n return Promise.resolve();\r\n }\r\n\r\n if (!object.kmsMessage) {\r\n return Promise.resolve();\r\n }\r\n\r\n if (isString(object.kmsMessage)) {\r\n return Promise.resolve();\r\n }\r\n\r\n return ctx.webex.internal.encryption.kms.prepareRequest(object.kmsMessage).then((req) => {\r\n object.kmsMessage = req.wrapped;\r\n });\r\n },\r\n },\r\n {\r\n name: 'decryptKmsMessage',\r\n fn(ctx, object) {\r\n return ctx.webex.internal.encryption.kms\r\n .decryptKmsMessage(object.kmsMessage)\r\n .then((kmsMessage) => {\r\n object.kmsMessage = kmsMessage;\r\n });\r\n },\r\n },\r\n {\r\n name: 'decryptErrorResponse',\r\n fn(ctx, reason) {\r\n const promises = reason.body.errors.map((error) =>\r\n ctx.webex.internal.encryption.kms.decryptKmsMessage(error.description).then((desc) => {\r\n error.description = desc;\r\n })\r\n );\r\n\r\n promises.push(\r\n ctx.webex.internal.encryption.kms\r\n .decryptKmsMessage(reason.body.message)\r\n .then((kmsMessage) => {\r\n reason.body.message = kmsMessage;\r\n })\r\n );\r\n\r\n return Promise.all(promises).then(() => Promise.reject(new DryError(reason)));\r\n },\r\n },\r\n ],\r\n },\r\n interceptors,\r\n config,\r\n});\r\n\r\nexport {default} from './encryption';\r\nexport {default as KMS} from './kms';\r\nexport {KmsError, DryError} from './kms-errors';\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUAA,OAAA;AAEAA,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAGA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAEA,IAAAM,uBAAA,GAAAH,sBAAA,CAAAH,OAAA;AAwIA,IAAAO,IAAA,GAAAJ,sBAAA,CAAAH,OAAA;AA7JA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAeA,IAAIQ,YAAY;AAEhB,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,EAAE;EACnCH,YAAY,GAAG;IACbI,sBAAsB,EAAEA,+BAAsB,CAACC;EACjD,CAAC;AACH;AAEA,IAAAC,iCAAsB,EAAC,YAAY,EAAEC,mBAAU,EAAE;EAC/CC,kBAAkB,EAAE;IAClBC,UAAU,EAAE,CACV;MACEC,IAAI,EAAE,mBAAmB;MACzBC,SAAS,EAAE,UAAU;MACrB;MACA;MACAC,IAAI,WAAAA,KAACC,GAAG,EAAEC,OAAO,EAAE;QACjB,IAAI,CAAC,IAAAC,KAAA,CAAAC,OAAA,EAAIF,OAAO,EAAE,iBAAiB,CAAC,EAAE;UACpC,OAAOG,QAAA,CAAAD,OAAA,CAAQE,OAAO,CAAC,KAAK,CAAC;QAC/B;QAEA,IAAI,CAAC,IAAAC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