@webex/internal-plugin-encryption 2.59.3-next.1 → 2.59.4
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 +19 -20
- 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/src/kms-errors.js
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {Exception} from '@webex/common';
|
|
6
|
-
import {WebexHttpError} from '@webex/webex-core';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Error class for KMS errors
|
|
10
|
-
*/
|
|
11
|
-
export class KmsError extends Exception {
|
|
12
|
-
static defaultMessage =
|
|
13
|
-
'An unknown error occurred while communicating with the kms. This implies we received an error response without a body.';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {HttpResponse} body
|
|
17
|
-
* @returns {string}
|
|
18
|
-
*/
|
|
19
|
-
parse(body) {
|
|
20
|
-
body = body.body || body;
|
|
21
|
-
|
|
22
|
-
Object.defineProperties(this, {
|
|
23
|
-
body: {
|
|
24
|
-
enumerable: false,
|
|
25
|
-
value: body,
|
|
26
|
-
},
|
|
27
|
-
reason: {
|
|
28
|
-
enumerable: false,
|
|
29
|
-
value: body.reason,
|
|
30
|
-
},
|
|
31
|
-
requestId: {
|
|
32
|
-
enumerable: false,
|
|
33
|
-
value: body.requestId,
|
|
34
|
-
},
|
|
35
|
-
status: {
|
|
36
|
-
enumerable: false,
|
|
37
|
-
value: body.status,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
let message = typeof body === 'string' ? body : body.reason;
|
|
42
|
-
|
|
43
|
-
if (!message) {
|
|
44
|
-
message = this.constructor.defaultMessage;
|
|
45
|
-
}
|
|
46
|
-
if (body.status) {
|
|
47
|
-
message += `\nKMS_RESPONSE_STATUS: ${body.status}`;
|
|
48
|
-
}
|
|
49
|
-
if (body.requestId) {
|
|
50
|
-
message += `\nKMS_REQUEST_ID: ${body.requestId}`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (body.statusCode) {
|
|
54
|
-
message += `\nKMS_STATUS_CODE: ${body.statusCode}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (body.errorCode) {
|
|
58
|
-
message += `\nKMS_ErrorCode: ${body.errorCode}`;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return message;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Thrown when an expected KMSResponse is not received in a timely manner
|
|
67
|
-
*/
|
|
68
|
-
export class KmsTimeoutError extends KmsError {
|
|
69
|
-
/**
|
|
70
|
-
* @param {KmsRequest} options.request
|
|
71
|
-
* @param {KmsRequest} options.timeout
|
|
72
|
-
* @returns {string}
|
|
73
|
-
*/
|
|
74
|
-
parse({request = {}, timeout} = {}) {
|
|
75
|
-
let message = `The KMS did not respond within ${
|
|
76
|
-
timeout ? `${timeout} milliseconds` : 'a timely fashion'
|
|
77
|
-
}`;
|
|
78
|
-
|
|
79
|
-
if (request) {
|
|
80
|
-
if (request.method && request.uri) {
|
|
81
|
-
message += `\nKMS_REQUEST: ${request.method} ${request.uri}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (request.requestId) {
|
|
85
|
-
message += `\nKMS_REQUEST_ID: ${request.requestId}`;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return message;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Emitted when a REST request includes an encrypter error
|
|
95
|
-
*/
|
|
96
|
-
export class DryError extends WebexHttpError {
|
|
97
|
-
static defaultMessage = 'An unknown error was received from a service that proxies to the KMS';
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @param {WebexHttpError} reason
|
|
101
|
-
* @returns {string}
|
|
102
|
-
*/
|
|
103
|
-
parse(reason) {
|
|
104
|
-
Reflect.apply(WebexHttpError.prototype.parse, this, [reason._res]);
|
|
105
|
-
const body = reason._res.body.message;
|
|
106
|
-
|
|
107
|
-
let message = body.reason || body;
|
|
108
|
-
|
|
109
|
-
if (!message) {
|
|
110
|
-
message = this.constructor.defaultMessage;
|
|
111
|
-
}
|
|
112
|
-
if (this.options.url) {
|
|
113
|
-
message += `\n${this.options.method} ${this.options.url}`;
|
|
114
|
-
} else if (this.options.uri) {
|
|
115
|
-
message += `\n${this.options.method} ${this.options.uri}`;
|
|
116
|
-
} else {
|
|
117
|
-
message += `\n${this.options.method} ${this.options.service.toUpperCase()}/${
|
|
118
|
-
this.options.resource
|
|
119
|
-
}`;
|
|
120
|
-
}
|
|
121
|
-
message += `\nWEBEX_TRACKING_ID: ${this.options.headers.trackingid}`;
|
|
122
|
-
|
|
123
|
-
if (body.status) {
|
|
124
|
-
message += `\nKMS_RESPONSE_STATUS: ${body.status}`;
|
|
125
|
-
}
|
|
126
|
-
if (body.requestId) {
|
|
127
|
-
message += `\nKMS_REQUEST_ID: ${body.requestId}`;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
Object.defineProperties(this, {
|
|
131
|
-
reason: {
|
|
132
|
-
enumerable: false,
|
|
133
|
-
value: body.reason,
|
|
134
|
-
},
|
|
135
|
-
requestId: {
|
|
136
|
-
enumerable: false,
|
|
137
|
-
value: body.requestId,
|
|
138
|
-
},
|
|
139
|
-
status: {
|
|
140
|
-
enumerable: false,
|
|
141
|
-
value: body.status,
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
return message;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {Exception} from '@webex/common';
|
|
6
|
+
import {WebexHttpError} from '@webex/webex-core';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Error class for KMS errors
|
|
10
|
+
*/
|
|
11
|
+
export class KmsError extends Exception {
|
|
12
|
+
static defaultMessage =
|
|
13
|
+
'An unknown error occurred while communicating with the kms. This implies we received an error response without a body.';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {HttpResponse} body
|
|
17
|
+
* @returns {string}
|
|
18
|
+
*/
|
|
19
|
+
parse(body) {
|
|
20
|
+
body = body.body || body;
|
|
21
|
+
|
|
22
|
+
Object.defineProperties(this, {
|
|
23
|
+
body: {
|
|
24
|
+
enumerable: false,
|
|
25
|
+
value: body,
|
|
26
|
+
},
|
|
27
|
+
reason: {
|
|
28
|
+
enumerable: false,
|
|
29
|
+
value: body.reason,
|
|
30
|
+
},
|
|
31
|
+
requestId: {
|
|
32
|
+
enumerable: false,
|
|
33
|
+
value: body.requestId,
|
|
34
|
+
},
|
|
35
|
+
status: {
|
|
36
|
+
enumerable: false,
|
|
37
|
+
value: body.status,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
let message = typeof body === 'string' ? body : body.reason;
|
|
42
|
+
|
|
43
|
+
if (!message) {
|
|
44
|
+
message = this.constructor.defaultMessage;
|
|
45
|
+
}
|
|
46
|
+
if (body.status) {
|
|
47
|
+
message += `\nKMS_RESPONSE_STATUS: ${body.status}`;
|
|
48
|
+
}
|
|
49
|
+
if (body.requestId) {
|
|
50
|
+
message += `\nKMS_REQUEST_ID: ${body.requestId}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (body.statusCode) {
|
|
54
|
+
message += `\nKMS_STATUS_CODE: ${body.statusCode}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (body.errorCode) {
|
|
58
|
+
message += `\nKMS_ErrorCode: ${body.errorCode}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return message;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Thrown when an expected KMSResponse is not received in a timely manner
|
|
67
|
+
*/
|
|
68
|
+
export class KmsTimeoutError extends KmsError {
|
|
69
|
+
/**
|
|
70
|
+
* @param {KmsRequest} options.request
|
|
71
|
+
* @param {KmsRequest} options.timeout
|
|
72
|
+
* @returns {string}
|
|
73
|
+
*/
|
|
74
|
+
parse({request = {}, timeout} = {}) {
|
|
75
|
+
let message = `The KMS did not respond within ${
|
|
76
|
+
timeout ? `${timeout} milliseconds` : 'a timely fashion'
|
|
77
|
+
}`;
|
|
78
|
+
|
|
79
|
+
if (request) {
|
|
80
|
+
if (request.method && request.uri) {
|
|
81
|
+
message += `\nKMS_REQUEST: ${request.method} ${request.uri}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (request.requestId) {
|
|
85
|
+
message += `\nKMS_REQUEST_ID: ${request.requestId}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return message;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Emitted when a REST request includes an encrypter error
|
|
95
|
+
*/
|
|
96
|
+
export class DryError extends WebexHttpError {
|
|
97
|
+
static defaultMessage = 'An unknown error was received from a service that proxies to the KMS';
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {WebexHttpError} reason
|
|
101
|
+
* @returns {string}
|
|
102
|
+
*/
|
|
103
|
+
parse(reason) {
|
|
104
|
+
Reflect.apply(WebexHttpError.prototype.parse, this, [reason._res]);
|
|
105
|
+
const body = reason._res.body.message;
|
|
106
|
+
|
|
107
|
+
let message = body.reason || body;
|
|
108
|
+
|
|
109
|
+
if (!message) {
|
|
110
|
+
message = this.constructor.defaultMessage;
|
|
111
|
+
}
|
|
112
|
+
if (this.options.url) {
|
|
113
|
+
message += `\n${this.options.method} ${this.options.url}`;
|
|
114
|
+
} else if (this.options.uri) {
|
|
115
|
+
message += `\n${this.options.method} ${this.options.uri}`;
|
|
116
|
+
} else {
|
|
117
|
+
message += `\n${this.options.method} ${this.options.service.toUpperCase()}/${
|
|
118
|
+
this.options.resource
|
|
119
|
+
}`;
|
|
120
|
+
}
|
|
121
|
+
message += `\nWEBEX_TRACKING_ID: ${this.options.headers.trackingid}`;
|
|
122
|
+
|
|
123
|
+
if (body.status) {
|
|
124
|
+
message += `\nKMS_RESPONSE_STATUS: ${body.status}`;
|
|
125
|
+
}
|
|
126
|
+
if (body.requestId) {
|
|
127
|
+
message += `\nKMS_REQUEST_ID: ${body.requestId}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
Object.defineProperties(this, {
|
|
131
|
+
reason: {
|
|
132
|
+
enumerable: false,
|
|
133
|
+
value: body.reason,
|
|
134
|
+
},
|
|
135
|
+
requestId: {
|
|
136
|
+
enumerable: false,
|
|
137
|
+
value: body.requestId,
|
|
138
|
+
},
|
|
139
|
+
status: {
|
|
140
|
+
enumerable: false,
|
|
141
|
+
value: body.status,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return message;
|
|
146
|
+
}
|
|
147
|
+
}
|