Skip to content

Commit ee19046

Browse files
HuiSFAllanZhengYP
andauthored
fix(storage): custom client base64 encoded SSE-C headers (#11567)
* fix(storage): custom client base64 encoded SSE-C headers * Lower md5-js version to control bundle sizes (tslib) * Update bunlde size limit * Add todo removing SSECustomerKeyMD5 from public interface --------- Co-authored-by: AllanZhengYP <zheallan@amazon.com>
1 parent 523c941 commit ee19046

29 files changed

+218
-50
lines changed

packages/core/src/clients/internal/composeServiceApi.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export const composeServiceApi = <
1616
HttpResponse,
1717
TransferHandlerOptions
1818
>,
19-
serializer: (input: Input, endpoint: Endpoint) => HttpRequest,
19+
serializer: (
20+
input: Input,
21+
endpoint: Endpoint
22+
) => Promise<HttpRequest> | HttpRequest,
2023
deserializer: (output: HttpResponse) => Promise<Output>,
2124
defaultConfig: DefaultConfig
2225
) => {
@@ -40,7 +43,7 @@ export const composeServiceApi = <
4043
// Unlike AWS SDK clients, a serializer should NOT populate the `host` or `content-length` headers.
4144
// Both of these headers are prohibited per Spec(https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name).
4245
// They will be populated automatically by browser, or node-fetch polyfill.
43-
const request = serializer(input, endpoint);
46+
const request = await serializer(input, endpoint);
4447
const response = await transferHandler(request, {
4548
...resolvedConfig,
4649
});

packages/notifications/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"name": "Notifications (with Analytics)",
7272
"path": "./lib-esm/index.js",
7373
"import": "{ Amplify, Notifications, Analytics }",
74-
"limit": "29.9 kB"
74+
"limit": "29.902 kB"
7575
}
7676
]
7777
}

packages/storage/__tests__/AwsClients/S3/cases/completeMultipartUpload.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { completeMultipartUpload } from '../../../../src/AwsClients/S3';
5+
import { toBase64 } from '../../../../src/AwsClients/S3/utils';
56
import { ApiFunctionalTestCase } from '../../testUtils/types';
67
import {
78
defaultConfig,
@@ -44,8 +45,9 @@ const completeMultipartUploadHappyCase: ApiFunctionalTestCase<
4445
method: 'POST',
4546
headers: expect.objectContaining({
4647
'x-amz-server-side-encryption-customer-algorithm': 'SSECustomerAlgorithm',
47-
'x-amz-server-side-encryption-customer-key': 'SSECustomerKey',
48-
'x-amz-server-side-encryption-customer-key-md5': 'SSECustomerKeyMD5',
48+
'x-amz-server-side-encryption-customer-key': toBase64('SSECustomerKey'),
49+
'x-amz-server-side-encryption-customer-key-md5':
50+
'u2yTVQWmqQ+XbBDNNmwr4Q==',
4951
'content-type': 'application/xml',
5052
}),
5153
body:

packages/storage/__tests__/AwsClients/S3/cases/copyObject.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { copyObject } from '../../../../src/AwsClients/S3';
5+
import { toBase64 } from '../../../../src/AwsClients/S3/utils';
56
import { ApiFunctionalTestCase } from '../../testUtils/types';
67
import {
78
defaultConfig,
@@ -24,7 +25,7 @@ const copyObjectHappyCase: ApiFunctionalTestCase<typeof copyObject> = [
2425
ACL: 'acl',
2526
ServerSideEncryption: 'serverSideEncryption',
2627
SSECustomerAlgorithm: 'sseCustomerAlgorithm',
27-
SSECustomerKey: 'sseCustomerKey',
28+
SSECustomerKey: 'SSECustomerKey',
2829
SSECustomerKeyMD5: 'sseCustomerKeyMD5',
2930
SSEKMSKeyId: 'sseKMSKeyId',
3031
},
@@ -40,8 +41,9 @@ const copyObjectHappyCase: ApiFunctionalTestCase<typeof copyObject> = [
4041
'x-amz-acl': 'acl',
4142
'x-amz-server-side-encryption': 'serverSideEncryption',
4243
'x-amz-server-side-encryption-customer-algorithm': 'sseCustomerAlgorithm',
43-
'x-amz-server-side-encryption-customer-key': 'sseCustomerKey',
44-
'x-amz-server-side-encryption-customer-key-md5': 'sseCustomerKeyMD5',
44+
'x-amz-server-side-encryption-customer-key': toBase64('SSECustomerKey'),
45+
'x-amz-server-side-encryption-customer-key-md5':
46+
'u2yTVQWmqQ+XbBDNNmwr4Q==',
4547
'x-amz-server-side-encryption-aws-kms-key-id': 'sseKMSKeyId',
4648
}),
4749
}),

packages/storage/__tests__/AwsClients/S3/cases/getObject.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { getObject } from '../../../../src/AwsClients/S3';
5+
import { toBase64 } from '../../../../src/AwsClients/S3/utils';
56
import { ApiFunctionalTestCase } from '../../testUtils/types';
67
import {
78
defaultConfig,
@@ -83,8 +84,9 @@ const getObjectHappyCase: ApiFunctionalTestCase<typeof getObject> = [
8384
authorization: expect.stringContaining('Signature'),
8485
host: 'bucket.s3.us-east-1.amazonaws.com',
8586
'x-amz-server-side-encryption-customer-algorithm': 'SSECustomerAlgorithm',
86-
'x-amz-server-side-encryption-customer-key': 'SSECustomerKey',
87-
'x-amz-server-side-encryption-customer-key-md5': 'SSECustomerKeyMD5',
87+
'x-amz-server-side-encryption-customer-key': toBase64('SSECustomerKey'),
88+
'x-amz-server-side-encryption-customer-key-md5':
89+
'u2yTVQWmqQ+XbBDNNmwr4Q==',
8890
'x-amz-content-sha256': EMPTY_SHA256,
8991
'x-amz-date': expect.stringMatching(/^\d{8}T\d{6}Z/),
9092
'x-amz-user-agent': expect.stringContaining('aws-amplify'),

packages/storage/__tests__/AwsClients/S3/cases/headObject.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { headObject } from '../../../../src/AwsClients/S3';
5+
import { toBase64 } from '../../../../src/AwsClients/S3/utils';
56
import { ApiFunctionalTestCase } from '../../testUtils/types';
67
import {
78
defaultConfig,
@@ -19,7 +20,7 @@ const headObjectHappyCase: ApiFunctionalTestCase<typeof headObject> = [
1920
Bucket: 'bucket',
2021
Key: 'key',
2122
SSECustomerAlgorithm: 'sseCustomerAlgorithm',
22-
SSECustomerKey: 'sseCustomerKey',
23+
SSECustomerKey: 'SSECustomerKey',
2324
SSECustomerKeyMD5: 'sseCustomerKeyMD5',
2425
},
2526
expect.objectContaining({
@@ -29,8 +30,9 @@ const headObjectHappyCase: ApiFunctionalTestCase<typeof headObject> = [
2930
method: 'HEAD',
3031
headers: expect.objectContaining({
3132
'x-amz-server-side-encryption-customer-algorithm': 'sseCustomerAlgorithm',
32-
'x-amz-server-side-encryption-customer-key': 'sseCustomerKey',
33-
'x-amz-server-side-encryption-customer-key-md5': 'sseCustomerKeyMD5',
33+
'x-amz-server-side-encryption-customer-key': toBase64('SSECustomerKey'),
34+
'x-amz-server-side-encryption-customer-key-md5':
35+
'u2yTVQWmqQ+XbBDNNmwr4Q==',
3436
}),
3537
}),
3638
{

packages/storage/__tests__/AwsClients/S3/cases/putObject.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { putObject } from '../../../../src/AwsClients/S3';
5+
import { toBase64 } from '../../../../src/AwsClients/S3/utils';
56
import { ApiFunctionalTestCase } from '../../testUtils/types';
67
import {
78
defaultConfig,
@@ -33,8 +34,8 @@ export const putObjectRequest = {
3334
export const expectedPutObjectRequestHeaders = {
3435
'x-amz-server-side-encryption': 'ServerSideEncryption',
3536
'x-amz-server-side-encryption-customer-algorithm': 'SSECustomerAlgorithm',
36-
'x-amz-server-side-encryption-customer-key': 'SSECustomerKey',
37-
'x-amz-server-side-encryption-customer-key-md5': 'SSECustomerKeyMD5',
37+
'x-amz-server-side-encryption-customer-key': toBase64('SSECustomerKey'),
38+
'x-amz-server-side-encryption-customer-key-md5': 'u2yTVQWmqQ+XbBDNNmwr4Q==',
3839
'x-amz-server-side-encryption-aws-kms-key-id': 'SSEKMSKeyId',
3940
'x-amz-acl': 'public-read',
4041
'cache-control': 'CacheControl',

packages/storage/__tests__/AwsClients/S3/cases/uploadPart.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { uploadPart } from '../../../../src/AwsClients/S3';
5+
import { toBase64 } from '../../../../src/AwsClients/S3/utils';
56
import { ApiFunctionalTestCase } from '../../testUtils/types';
67
import {
78
defaultConfig,
@@ -32,8 +33,9 @@ const uploadPartHappyCase: ApiFunctionalTestCase<typeof uploadPart> = [
3233
method: 'PUT',
3334
headers: expect.objectContaining({
3435
'x-amz-server-side-encryption-customer-algorithm': 'SSECustomerAlgorithm',
35-
'x-amz-server-side-encryption-customer-key': 'SSECustomerKey',
36-
'x-amz-server-side-encryption-customer-key-md5': 'SSECustomerKeyMD5',
36+
'x-amz-server-side-encryption-customer-key': toBase64('SSECustomerKey'),
37+
'x-amz-server-side-encryption-customer-key-md5':
38+
'u2yTVQWmqQ+XbBDNNmwr4Q==',
3739
'content-type': 'application/octet-stream', // required by RN Android if body exists
3840
}),
3941
body: 'body',
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { toBase64 } from '../../../src/AwsClients/S3/runtime/base64/index.browser';
5+
6+
import { TextEncoder, TextDecoder } from 'util';
7+
import { toBase64TestCases } from './cases';
8+
9+
Object.assign(global, { TextDecoder, TextEncoder });
10+
11+
describe('base64 until for browser', () => {
12+
describe('toBase64()', () => {
13+
for (let { input, expected } of toBase64TestCases) {
14+
it(`it should base64 encode ${input}`, () => {
15+
expect(toBase64(input)).toStrictEqual(expected);
16+
});
17+
}
18+
});
19+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { toBase64 } from '../../../src/AwsClients/S3/runtime/base64/index.native';
5+
import { toBase64TestCases } from './cases';
6+
7+
describe('base64 until for browser', () => {
8+
describe('toBase64()', () => {
9+
for (let { input, expected } of toBase64TestCases) {
10+
it(`it should base64 encode ${input}`, () => {
11+
expect(toBase64(input)).toStrictEqual(expected);
12+
});
13+
}
14+
});
15+
});

0 commit comments

Comments
 (0)