Skip to content

Commit 2d74e6e

Browse files
committed
Add support for session mode
1 parent 30e9a18 commit 2d74e6e

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

Diff for: source/s3_request_messages.c

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const struct aws_byte_cursor g_s3_create_multipart_upload_excluded_headers[] = {
2727
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-checksum-sha1"),
2828
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-checksum-sha256"),
2929
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("if-none-match"),
30+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-create-session-mode"),
3031
};
3132

3233
const size_t g_s3_create_multipart_upload_excluded_headers_count =
@@ -62,6 +63,7 @@ const struct aws_byte_cursor g_s3_upload_part_excluded_headers[] = {
6263
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-checksum-sha1"),
6364
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-checksum-sha256"),
6465
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("if-none-match"),
66+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-create-session-mode"),
6567
};
6668

6769
const size_t g_s3_upload_part_excluded_headers_count = AWS_ARRAY_SIZE(g_s3_upload_part_excluded_headers);
@@ -96,6 +98,7 @@ const struct aws_byte_cursor g_s3_complete_multipart_upload_excluded_headers[] =
9698
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-copy-source"),
9799
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-copy-source-range"),
98100
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-mp-object-size"),
101+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-create-session-mode"),
99102
};
100103

101104
const size_t g_s3_complete_multipart_upload_excluded_headers_count =
@@ -131,6 +134,7 @@ const struct aws_byte_cursor g_s3_complete_multipart_upload_with_checksum_exclud
131134
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-copy-source-range"),
132135
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-sdk-checksum-algorithm"),
133136
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-mp-object-size"),
137+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-create-session-mode"),
134138
};
135139

136140
const struct aws_byte_cursor g_s3_list_parts_excluded_headers[] = {
@@ -162,6 +166,7 @@ const struct aws_byte_cursor g_s3_list_parts_excluded_headers[] = {
162166
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-object-lock-legal-hold"),
163167
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-copy-source"),
164168
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-copy-source-range"),
169+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-create-session-mode"),
165170
};
166171

167172
const size_t g_s3_list_parts_excluded_headers_count = AWS_ARRAY_SIZE(g_s3_list_parts_excluded_headers);
@@ -192,6 +197,7 @@ const struct aws_byte_cursor g_s3_list_parts_with_checksum_excluded_headers[] =
192197
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-object-lock-legal-hold"),
193198
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-copy-source"),
194199
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-copy-source-range"),
200+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-create-session-mode"),
195201
};
196202

197203
const size_t g_s3_list_parts_with_checksum_excluded_headers_count =
@@ -227,9 +233,11 @@ const struct aws_byte_cursor g_s3_abort_multipart_upload_excluded_headers[] = {
227233
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-copy-source"),
228234
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-copy-source-range"),
229235
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("if-none-match"),
236+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-create-session-mode"),
230237
};
231238

232239
const struct aws_byte_cursor g_s3_create_session_allowed_headers[] = {
240+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-create-session-mode"),
233241
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption"),
234242
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-aws-kms-key-id"),
235243
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-context"),

Diff for: source/s3express_credentials_provider.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,14 @@ struct aws_string *aws_encode_s3express_hash_key_new(
486486
struct aws_byte_cursor host_value,
487487
struct aws_http_headers *headers) {
488488

489-
struct aws_byte_buf combined_hash_buf;
489+
struct aws_byte_buf combined_buf;
490490

491491
/* 1. Combine access_key and secret_access_key into one buffer */
492492
struct aws_byte_cursor access_key = aws_credentials_get_access_key_id(original_credentials);
493493
struct aws_byte_cursor secret_access_key = aws_credentials_get_secret_access_key(original_credentials);
494-
aws_byte_buf_init(&combined_hash_buf, allocator, access_key.len + secret_access_key.len);
495-
aws_byte_buf_write_from_whole_cursor(&combined_hash_buf, access_key);
496-
aws_byte_buf_write_from_whole_cursor(&combined_hash_buf, secret_access_key);
494+
aws_byte_buf_init(&combined_buf, allocator, access_key.len + secret_access_key.len);
495+
aws_byte_buf_write_from_whole_cursor(&combined_buf, access_key);
496+
aws_byte_buf_write_from_whole_cursor(&combined_buf, secret_access_key);
497497

498498
/* Write the allowed headers into hash */
499499
if (headers != NULL) {
@@ -503,19 +503,19 @@ struct aws_string *aws_encode_s3express_hash_key_new(
503503
struct aws_byte_cursor header_name = g_s3_create_session_allowed_headers[header_index];
504504
struct aws_byte_cursor header_value;
505505
if (aws_http_headers_get(headers, header_name, &header_value) == AWS_OP_SUCCESS && header_value.len > 0) {
506-
aws_byte_buf_write_from_whole_cursor(&combined_hash_buf, comma);
507-
aws_byte_buf_write_from_whole_cursor(&combined_hash_buf, header_name);
508-
aws_byte_buf_write_from_whole_cursor(&combined_hash_buf, collon);
509-
aws_byte_buf_write_from_whole_cursor(&combined_hash_buf, header_value);
506+
aws_byte_buf_append_dynamic(&combined_buf, &comma);
507+
aws_byte_buf_append_dynamic(&combined_buf, &header_name);
508+
aws_byte_buf_append_dynamic(&combined_buf, &collon);
509+
aws_byte_buf_append_dynamic(&combined_buf, &header_value);
510510
}
511511
}
512512
}
513513

514514
/* 2. Get sha256 digest from the combined key */
515-
struct aws_byte_cursor combine_key = aws_byte_cursor_from_buf(&combined_hash_buf);
515+
struct aws_byte_cursor combined_cursor = aws_byte_cursor_from_buf(&combined_buf);
516516
struct aws_byte_buf digest_buf;
517517
aws_byte_buf_init(&digest_buf, allocator, AWS_SHA256_LEN);
518-
aws_sha256_compute(allocator, &combine_key, &digest_buf, 0);
518+
aws_sha256_compute(allocator, &combined_cursor, &digest_buf, 0);
519519

520520
/* 3. Encode the result to be [host_value][hash_of_credentials] */
521521
struct aws_byte_buf result_buffer;
@@ -526,7 +526,7 @@ struct aws_string *aws_encode_s3express_hash_key_new(
526526

527527
/* Clean up */
528528
aws_byte_buf_clean_up(&result_buffer);
529-
aws_byte_buf_clean_up(&combined_hash_buf);
529+
aws_byte_buf_clean_up(&combined_buf);
530530
aws_byte_buf_clean_up(&digest_buf);
531531

532532
return result;

Diff for: tests/s3_s3express_client_test.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -717,14 +717,16 @@ TEST_CASE(s3express_client_copy_object_multipart) {
717717
}
718718

719719
/**
720-
* Test hash of the express cache key
720+
* Test hash of the express cache key
721721
*/
722722
TEST_CASE(s3express_hash_key_test) {
723723
(void)ctx;
724724

725725
struct aws_string *access_key = aws_string_new_from_c_str(allocator, "AccessKey");
726726
struct aws_string *secret_access_key = aws_string_new_from_c_str(allocator, "SecretAccessKey");
727727
struct aws_http_headers *headers = aws_http_headers_new(allocator);
728+
aws_http_headers_add(
729+
headers, aws_byte_cursor_from_c_str("x-amz-create-session-mode"), aws_byte_cursor_from_c_str("ReadOnly"));
728730
aws_http_headers_add(
729731
headers, aws_byte_cursor_from_c_str("x-amz-server-side-encryption"), aws_byte_cursor_from_c_str("aws:kms"));
730732
aws_http_headers_add(
@@ -740,20 +742,22 @@ TEST_CASE(s3express_hash_key_test) {
740742
aws_byte_cursor_from_c_str("x-amz-server-side-encryption-bucket-key-enabled"),
741743
aws_byte_cursor_from_c_str("true"));
742744
aws_http_headers_add(
743-
headers, aws_byte_cursor_from_c_str("header-not-allowed"), aws_byte_cursor_from_c_str("should-be-ignored"));
745+
headers,
746+
aws_byte_cursor_from_c_str("header-not-in-allow-list"),
747+
aws_byte_cursor_from_c_str("should-be-ignored"));
744748

745749
struct aws_credentials *creds =
746750
aws_credentials_new_from_string(allocator, access_key, secret_access_key, NULL, UINT64_MAX);
747751

748752
struct aws_string *hash_key =
749-
aws_encode_s3express_hash_key_new(allocator, creds, aws_byte_cursor_from_c_str("host"), headers);
753+
aws_encode_s3express_hash_key_new(allocator, creds, aws_byte_cursor_from_c_str(""), headers);
750754
struct aws_byte_cursor hash_cursor = aws_byte_cursor_from_string(hash_key);
751755

752756
struct aws_byte_buf encoded_buf;
753-
aws_byte_buf_init(&encoded_buf, allocator, 100);
757+
aws_byte_buf_init(&encoded_buf, allocator, 200);
754758
aws_hex_encode_append_dynamic(&hash_cursor, &encoded_buf);
755759

756-
char *expected_encoded_key = "686f737498ae6a365790707488b3e85402c9eddf422dc39f096e15eaba0d7cdd45f57ad2";
760+
char *expected_encoded_key = "cabfefee4365e075646ba8928ed9f757481d1062ffcb0a3afe5b9c428dd45800";
757761
ASSERT_BIN_ARRAYS_EQUALS(expected_encoded_key, strlen(expected_encoded_key), encoded_buf.buffer, encoded_buf.len);
758762

759763
aws_byte_buf_clean_up(&encoded_buf);

0 commit comments

Comments
 (0)