aws-sdk-s3 1.136.0 → 1.208.0

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 (119) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +452 -1
  3. data/VERSION +1 -1
  4. data/lib/aws-sdk-s3/access_grants_credentials.rb +57 -0
  5. data/lib/aws-sdk-s3/access_grants_credentials_provider.rb +250 -0
  6. data/lib/aws-sdk-s3/bucket.rb +728 -145
  7. data/lib/aws-sdk-s3/bucket_acl.rb +19 -18
  8. data/lib/aws-sdk-s3/bucket_cors.rb +22 -21
  9. data/lib/aws-sdk-s3/bucket_lifecycle.rb +23 -18
  10. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +76 -19
  11. data/lib/aws-sdk-s3/bucket_logging.rb +21 -14
  12. data/lib/aws-sdk-s3/bucket_notification.rb +6 -6
  13. data/lib/aws-sdk-s3/bucket_policy.rb +65 -20
  14. data/lib/aws-sdk-s3/bucket_region_cache.rb +9 -5
  15. data/lib/aws-sdk-s3/bucket_request_payment.rb +15 -15
  16. data/lib/aws-sdk-s3/bucket_tagging.rb +19 -19
  17. data/lib/aws-sdk-s3/bucket_versioning.rb +74 -41
  18. data/lib/aws-sdk-s3/bucket_website.rb +19 -19
  19. data/lib/aws-sdk-s3/client.rb +9951 -3365
  20. data/lib/aws-sdk-s3/client_api.rb +758 -164
  21. data/lib/aws-sdk-s3/customizations/bucket.rb +1 -1
  22. data/lib/aws-sdk-s3/customizations/errors.rb +15 -2
  23. data/lib/aws-sdk-s3/customizations/object.rb +87 -91
  24. data/lib/aws-sdk-s3/customizations/object_summary.rb +5 -0
  25. data/lib/aws-sdk-s3/customizations/object_version.rb +13 -0
  26. data/lib/aws-sdk-s3/customizations.rb +28 -31
  27. data/lib/aws-sdk-s3/default_executor.rb +103 -0
  28. data/lib/aws-sdk-s3/encryption/client.rb +4 -4
  29. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +2 -0
  30. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +2 -0
  31. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +4 -2
  32. data/lib/aws-sdk-s3/encryptionV2/client.rb +100 -25
  33. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +7 -162
  34. data/lib/aws-sdk-s3/encryptionV2/decryption.rb +205 -0
  35. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +17 -0
  36. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +2 -0
  37. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +2 -0
  38. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +10 -2
  39. data/lib/aws-sdk-s3/encryptionV2/utils.rb +5 -0
  40. data/lib/aws-sdk-s3/encryptionV3/client.rb +885 -0
  41. data/lib/aws-sdk-s3/encryptionV3/decrypt_handler.rb +98 -0
  42. data/lib/aws-sdk-s3/encryptionV3/decryption.rb +244 -0
  43. data/lib/aws-sdk-s3/encryptionV3/default_cipher_provider.rb +159 -0
  44. data/lib/aws-sdk-s3/encryptionV3/default_key_provider.rb +35 -0
  45. data/lib/aws-sdk-s3/encryptionV3/encrypt_handler.rb +98 -0
  46. data/lib/aws-sdk-s3/encryptionV3/errors.rb +47 -0
  47. data/lib/aws-sdk-s3/encryptionV3/io_auth_decrypter.rb +60 -0
  48. data/lib/aws-sdk-s3/encryptionV3/io_decrypter.rb +35 -0
  49. data/lib/aws-sdk-s3/encryptionV3/io_encrypter.rb +84 -0
  50. data/lib/aws-sdk-s3/encryptionV3/key_provider.rb +28 -0
  51. data/lib/aws-sdk-s3/encryptionV3/kms_cipher_provider.rb +159 -0
  52. data/lib/aws-sdk-s3/encryptionV3/materials.rb +58 -0
  53. data/lib/aws-sdk-s3/encryptionV3/utils.rb +321 -0
  54. data/lib/aws-sdk-s3/encryption_v2.rb +1 -0
  55. data/lib/aws-sdk-s3/encryption_v3.rb +24 -0
  56. data/lib/aws-sdk-s3/endpoint_parameters.rb +65 -30
  57. data/lib/aws-sdk-s3/endpoint_provider.rb +604 -227
  58. data/lib/aws-sdk-s3/endpoints.rb +655 -1261
  59. data/lib/aws-sdk-s3/errors.rb +58 -0
  60. data/lib/aws-sdk-s3/express_credentials.rb +55 -0
  61. data/lib/aws-sdk-s3/express_credentials_provider.rb +59 -0
  62. data/lib/aws-sdk-s3/file_downloader.rb +192 -147
  63. data/lib/aws-sdk-s3/file_uploader.rb +10 -14
  64. data/lib/aws-sdk-s3/legacy_signer.rb +2 -1
  65. data/lib/aws-sdk-s3/multipart_download_error.rb +8 -0
  66. data/lib/aws-sdk-s3/multipart_file_uploader.rb +106 -103
  67. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +99 -109
  68. data/lib/aws-sdk-s3/multipart_upload.rb +185 -38
  69. data/lib/aws-sdk-s3/multipart_upload_error.rb +3 -4
  70. data/lib/aws-sdk-s3/multipart_upload_part.rb +205 -68
  71. data/lib/aws-sdk-s3/object.rb +2052 -315
  72. data/lib/aws-sdk-s3/object_acl.rb +46 -28
  73. data/lib/aws-sdk-s3/object_copier.rb +1 -1
  74. data/lib/aws-sdk-s3/object_multipart_copier.rb +12 -9
  75. data/lib/aws-sdk-s3/object_summary.rb +1778 -262
  76. data/lib/aws-sdk-s3/object_version.rb +400 -68
  77. data/lib/aws-sdk-s3/plugins/access_grants.rb +178 -0
  78. data/lib/aws-sdk-s3/plugins/checksum_algorithm.rb +31 -0
  79. data/lib/aws-sdk-s3/plugins/endpoints.rb +32 -208
  80. data/lib/aws-sdk-s3/plugins/express_session_auth.rb +88 -0
  81. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +55 -18
  82. data/lib/aws-sdk-s3/plugins/location_constraint.rb +3 -1
  83. data/lib/aws-sdk-s3/plugins/md5s.rb +10 -70
  84. data/lib/aws-sdk-s3/plugins/s3_signer.rb +7 -2
  85. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +5 -7
  86. data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -1
  87. data/lib/aws-sdk-s3/presigner.rb +9 -7
  88. data/lib/aws-sdk-s3/resource.rb +127 -22
  89. data/lib/aws-sdk-s3/transfer_manager.rb +303 -0
  90. data/lib/aws-sdk-s3/types.rb +8065 -1783
  91. data/lib/aws-sdk-s3.rb +35 -31
  92. data/sig/bucket.rbs +231 -0
  93. data/sig/bucket_acl.rbs +78 -0
  94. data/sig/bucket_cors.rbs +69 -0
  95. data/sig/bucket_lifecycle.rbs +88 -0
  96. data/sig/bucket_lifecycle_configuration.rbs +115 -0
  97. data/sig/bucket_logging.rbs +76 -0
  98. data/sig/bucket_notification.rbs +114 -0
  99. data/sig/bucket_policy.rbs +59 -0
  100. data/sig/bucket_request_payment.rbs +54 -0
  101. data/sig/bucket_tagging.rbs +65 -0
  102. data/sig/bucket_versioning.rbs +77 -0
  103. data/sig/bucket_website.rbs +93 -0
  104. data/sig/client.rbs +2612 -0
  105. data/sig/customizations/bucket.rbs +19 -0
  106. data/sig/customizations/object.rbs +38 -0
  107. data/sig/customizations/object_summary.rbs +35 -0
  108. data/sig/errors.rbs +44 -0
  109. data/sig/multipart_upload.rbs +120 -0
  110. data/sig/multipart_upload_part.rbs +109 -0
  111. data/sig/object.rbs +464 -0
  112. data/sig/object_acl.rbs +86 -0
  113. data/sig/object_summary.rbs +347 -0
  114. data/sig/object_version.rbs +143 -0
  115. data/sig/resource.rbs +141 -0
  116. data/sig/types.rbs +2899 -0
  117. data/sig/waiters.rbs +95 -0
  118. metadata +61 -12
  119. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +0 -31
@@ -0,0 +1,321 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl'
4
+
5
+ module Aws
6
+ module S3
7
+ module EncryptionV3
8
+ # @api private
9
+ module Utils
10
+ class << self
11
+ ##= ../specification/s3-encryption/client.md#encryption-algorithm
12
+ ##% The S3EC MUST validate that the configured encryption algorithm is not legacy.
13
+ def validate_cek(content_encryption_schema)
14
+ ##= ../specification/s3-encryption/data-format/content-metadata.md#algorithm-suite-and-message-format-version-compatibility
15
+ ##% Objects encrypted with ALG_AES_256_GCM_HKDF_SHA512_COMMIT_KEY MUST use the V3 message format version only.
16
+ return '115' if content_encryption_schema.nil?
17
+
18
+ case content_encryption_schema
19
+ when :alg_aes_256_gcm_hkdf_sha512_commit_key
20
+ '115'
21
+ else
22
+ ##= ../specification/s3-encryption/encryption.md#alg-aes-256-ctr-iv16-tag16-no-kdf
23
+ ##% Attempts to encrypt using AES-CTR MUST fail.
24
+ ##= ../specification/s3-encryption/encryption.md#alg-aes-256-ctr-hkdf-sha512-commit-key
25
+ ##% Attempts to encrypt using key committing AES-CTR MUST fail.
26
+ ##= ../specification/s3-encryption/client.md#encryption-algorithm
27
+ ##% If the configured encryption algorithm is legacy, then the S3EC MUST throw an exception.
28
+ ##= ../specification/s3-encryption/client.md#key-commitment
29
+ ##% If the configured Encryption Algorithm is incompatible with the key commitment policy, then it MUST throw an exception.
30
+ raise ArgumentError, "Unsupported content_encryption_schema: #{content_encryption_schema}"
31
+ end
32
+ end
33
+
34
+ def encrypt_aes_gcm(key, data, auth_data)
35
+ cipher = aes_encryption_cipher(:GCM, key)
36
+ cipher.iv = (iv = cipher.random_iv)
37
+ cipher.auth_data = auth_data
38
+
39
+ iv + cipher.update(data) + cipher.final + cipher.auth_tag
40
+ end
41
+
42
+ def encrypt_rsa(key, data, auth_data)
43
+ # Plaintext must be KeyLengthInBytes (1 Byte) + DataKey + AuthData
44
+ buf = [data.bytesize] + data.unpack('C*') + auth_data.unpack('C*')
45
+ key.public_encrypt(buf.pack('C*'), OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
46
+ end
47
+
48
+ def decrypt_aes_gcm(key, data, auth_data)
49
+ # data is iv (12B) + key + tag (16B)
50
+ buf = data.unpack('C*')
51
+ iv = buf[0, 12].pack('C*') # iv will always be 12 bytes
52
+ tag = buf[-16, 16].pack('C*') # tag is 16 bytes
53
+ enc_key = buf[12, buf.size - (12 + 16)].pack('C*')
54
+ cipher = aes_cipher(:decrypt, :GCM, key, iv)
55
+ cipher.auth_tag = tag
56
+ cipher.auth_data = auth_data
57
+ cipher.update(enc_key) + cipher.final
58
+ end
59
+
60
+ # returns the decrypted data + auth_data
61
+ def decrypt_rsa(key, enc_data)
62
+ # Plaintext must be KeyLengthInBytes (1 Byte) + DataKey + AuthData
63
+ buf = key.private_decrypt(enc_data, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING).unpack('C*')
64
+ key_length = buf[0]
65
+ data = buf[1, key_length].pack('C*')
66
+ auth_data = buf[key_length + 1, buf.length - key_length].pack('C*')
67
+ [data, auth_data]
68
+ end
69
+
70
+ # @param [String] block_mode "CBC" or "ECB"
71
+ # @param [OpenSSL::PKey::RSA, String, nil] key
72
+ # @param [String, nil] iv The initialization vector
73
+ def aes_encryption_cipher(block_mode, key = nil, iv = nil)
74
+ aes_cipher(:encrypt, block_mode, key, iv)
75
+ end
76
+
77
+ # @param [String] block_mode "CBC" or "ECB"
78
+ # @param [OpenSSL::PKey::RSA, String, nil] key
79
+ # @param [String, nil] iv The initialization vector
80
+ def aes_decryption_cipher(block_mode, key = nil, iv = nil)
81
+ aes_cipher(:decrypt, block_mode, key, iv)
82
+ end
83
+
84
+ # @param [String] mode "encrypt" or "decrypt"
85
+ # @param [String] block_mode "CBC" or "ECB"
86
+ # @param [OpenSSL::PKey::RSA, String, nil] key
87
+ # @param [String, nil] iv The initialization vector
88
+ def aes_cipher(mode, block_mode, key, iv)
89
+ cipher =
90
+ if key
91
+ OpenSSL::Cipher.new("aes-#{cipher_size(key)}-#{block_mode.downcase}")
92
+ else
93
+ OpenSSL::Cipher.new("aes-256-#{block_mode.downcase}")
94
+ end
95
+ cipher.send(mode) # encrypt or decrypt
96
+ cipher.key = key if key
97
+ cipher.iv = iv if iv
98
+ cipher
99
+ end
100
+
101
+ # @param [String] key
102
+ # @return [Integer]
103
+ # @raise ArgumentError
104
+ def cipher_size(key)
105
+ key.bytesize * 8
106
+ end
107
+
108
+ # There is only 1 supported algorithm suite at this time
109
+ ENCRYPTION_KEY_INFO = ([0x00, 0x73].pack('C*') + 'DERIVEKEY'.encode('UTF-8')).freeze
110
+ COMMITMENT_KEY_INFO = ([0x00, 0x73].pack('C*') + 'COMMITKEY'.encode('UTF-8')).freeze
111
+
112
+ SHA512_DIGEST = OpenSSL::Digest::SHA512.new.freeze
113
+ V3_IV_BYTES = ("\x01" * 12).freeze
114
+ ALGO_ID = [0x00, 0x73].pack('C*').freeze
115
+
116
+ def generate_alg_aes_256_gcm_hkdf_sha512_commit_key_cipher(data_key)
117
+ ##= ../specification/s3-encryption/encryption.md#content-encryption
118
+ ##% The client MUST generate an IV or Message ID using the length of the IV or Message ID defined in the algorithm suite.
119
+ message_id = Utils.generate_message_id
120
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
121
+ ##% - The salt MUST be the Message ID with the length defined in the algorithm suite.
122
+ commitment_key = Utils.derive_commitment_key(data_key, message_id)
123
+ cipher = alg_aes_256_gcm_hkdf_sha512_commit_key_cipher(:encrypt, data_key, message_id)
124
+
125
+ [
126
+ cipher,
127
+ ##= ../specification/s3-encryption/encryption.md#content-encryption
128
+ ##% The generated IV or Message ID MUST be set or returned from the encryption process such that it can be included in the content metadata.
129
+ message_id,
130
+ ##= ../specification/s3-encryption/encryption.md#alg-aes-256-gcm-hkdf-sha512-commit-key
131
+ ##% The derived key commitment value MUST be set or returned from the encryption process such that it can be included in the content metadata.
132
+ commitment_key
133
+ ]
134
+ end
135
+
136
+ def derive_alg_aes_256_gcm_hkdf_sha512_commit_key_cipher(data_key, message_id, stored_commitment_key)
137
+ raise Errors::DecryptionError, 'Data key length does not match algorithm suite' unless data_key.length == 32
138
+
139
+ raise Errors::DecryptionError, 'Message id length does not match algorithm suite' unless message_id.length == 28
140
+
141
+ unless stored_commitment_key.length == 28
142
+ raise Errors::DecryptionError, 'Commitment key length does not match algorithm suite'
143
+ end
144
+
145
+ ##= ../specification/s3-encryption/decryption.md#decrypting-with-commitment
146
+ ##= type=implication
147
+ ##% When using an algorithm suite which supports key commitment,
148
+ ##% the verification of the derived key commitment value MUST be done in constant time.
149
+ unless timing_safe_equal?(
150
+ ##= ../specification/s3-encryption/decryption.md#decrypting-with-commitment
151
+ ##% When using an algorithm suite which supports key commitment,
152
+ ##% the client MUST verify that the [derived key commitment](./key-derivation.md#hkdf-operation) contains the same bytes
153
+ ##% as the stored key commitment retrieved from the stored object's metadata.
154
+ Utils.derive_commitment_key(data_key, message_id),
155
+ stored_commitment_key
156
+ )
157
+ ##= ../specification/s3-encryption/decryption.md#decrypting-with-commitment
158
+ ##% When using an algorithm suite which supports key commitment,
159
+ ##% the client MUST throw an exception when the derived key commitment value and stored key commitment value do not match.
160
+ raise Errors::DecryptionError, 'Commitment key verification failed'
161
+ end
162
+
163
+ ##= ../specification/s3-encryption/decryption.md#decrypting-with-commitment
164
+ ##% When using an algorithm suite which supports key commitment,
165
+ ##% the client MUST verify the key commitment values match before deriving the [derived encryption key](./key-derivation.md#hkdf-operation).
166
+
167
+ alg_aes_256_gcm_hkdf_sha512_commit_key_cipher(:decrypt, data_key, message_id)
168
+ end
169
+
170
+ def alg_aes_256_gcm_hkdf_sha512_commit_key_cipher(mode, data_key, message_id)
171
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
172
+ ##% The client MUST initialize the cipher, or call an AES-GCM encryption API, with the derived encryption key, an IV containing only bytes with the value 0x01,
173
+ ##% and the tag length defined in the Algorithm Suite when encrypting or decrypting with ALG_AES_256_GCM_HKDF_SHA512_COMMIT_KEY.
174
+ cipher = Utils.aes_cipher(
175
+ mode,
176
+ :GCM,
177
+ ##= ../specification/s3-encryption/encryption.md#alg-aes-256-gcm-hkdf-sha512-commit-key
178
+ ##% The client MUST use HKDF to derive the key commitment value and the derived encrypting key as described in [Key Derivation](key-derivation.md).
179
+ Utils.derive_encryption_key(data_key, message_id),
180
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
181
+ ##% When encrypting or decrypting with ALG_AES_256_GCM_HKDF_SHA512_COMMIT_KEY,
182
+ ##% the IV used in the AES-GCM content encryption/decryption MUST consist entirely of bytes with the value 0x01.
183
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
184
+ ##% The IV's total length MUST match the IV length defined by the algorithm suite.
185
+ V3_IV_BYTES
186
+ ) #OpenSSL::Cipher.new("aes-256-gcm")
187
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
188
+ ##% The client MUST set the AAD to the Algorithm Suite ID represented as bytes.
189
+ cipher.auth_data = ALGO_ID # auth_data must be set after key and iv
190
+ cipher
191
+ end
192
+
193
+ def generate_data_key
194
+ OpenSSL::Random.random_bytes(32)
195
+ end
196
+
197
+ def generate_message_id
198
+ ##= ../specification/s3-encryption/encryption.md#cipher-initialization
199
+ ##= type=exception
200
+ ##= reason=This would be a new runtime error that happens randomly.
201
+ ##% The client SHOULD validate that the generated IV or Message ID is not zeros.
202
+
203
+ ##= ../specification/s3-encryption/encryption.md#content-encryption
204
+ ##% The client MUST generate an IV or Message ID using the length of the IV or Message ID defined in the algorithm suite.
205
+ OpenSSL::Random.random_bytes(28)
206
+ end
207
+
208
+ def derive_encryption_key(data_key, message_id)
209
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
210
+ ##% - The DEK input pseudorandom key MUST be the output from the extract step.
211
+ hkdf(
212
+ data_key,
213
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
214
+ ##% - The salt MUST be the Message ID with the length defined in the algorithm suite.
215
+ message_id,
216
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
217
+ ##% - The input info MUST be a concatenation of the algorithm suite ID as bytes followed by the string DERIVEKEY as UTF8 encoded bytes.
218
+ ENCRYPTION_KEY_INFO,
219
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
220
+ ##% - The length of the output keying material MUST equal the encryption key length specified by the algorithm suite encryption settings.
221
+ 32
222
+ )
223
+ end
224
+
225
+ def derive_commitment_key(data_key, message_id)
226
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
227
+ ##% - The CK input pseudorandom key MUST be the output from the extract step.
228
+ hkdf(
229
+ data_key,
230
+ message_id,
231
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
232
+ ##% - The input info MUST be a concatenation of the algorithm suite ID as bytes followed by the string COMMITKEY as UTF8 encoded bytes.
233
+ COMMITMENT_KEY_INFO,
234
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
235
+ ##% - The length of the output keying material MUST equal the commit key length specified by the supported algorithm suites.
236
+ 28
237
+ )
238
+ end
239
+
240
+ ONE_BYTE = [1].pack('C').freeze
241
+ # assert: the following function is equivalent to `OpenSSL::KDF.hkdf` for all desired_length <= 64
242
+ # see spec: 'produces identical output to native hkdf for random inputs (property-based test)'
243
+ def hkdf_fallback(input_key_material, salt, info, desired_length)
244
+ # Extract from RFC 5869
245
+ # PRK = HMAC-Hash(salt, IKM)
246
+ prk = OpenSSL::HMAC.digest(SHA512_DIGEST, salt, input_key_material)
247
+
248
+ # Expand from RFC 5869
249
+ # N = ceil(L/HashLen)
250
+ # T = T(1) | T(2) | T(3) | ... | T(N)
251
+ # OKM = first L octets of T
252
+ #
253
+ # where:
254
+ # T(0) = empty string (zero length)
255
+ # T(1) = HMAC-Hash(PRK, T(0) | info | 0x01)
256
+ # T(2) = HMAC-Hash(PRK, T(1) | info | 0x02)
257
+ # T(3) = HMAC-Hash(PRK, T(2) | info | 0x03)
258
+ #
259
+ # L == desired_length
260
+ # HashLen == 64 (because SHA512_DIGEST is fixed)
261
+ # N = ceil(desired_length/64)
262
+ # The only supported suites have desired_length less than 64
263
+ # This will result in a single iteration of the expand loop.
264
+ # This check verifies that it is safe to do not do a loop
265
+ raise Errors::DecryptionError, "Unsupported length: #{desired_length}" if desired_length > 64
266
+
267
+ # assert N == 1
268
+ #
269
+ # For a single iteration of the loop we then get:
270
+ # OKM = first L of T(0) | T(1)
271
+ # ==
272
+ # (T(0) + T(1))[0, desired_length]
273
+ # == {assert T(0) == ''}
274
+ # ('' + HMAC-Hash(PRK, '' + info + 0x01))[0, desired_length]
275
+ # == HMAC-Hash(PRK, info + 0x01)[0, desired_length]
276
+ # == {assert ONE_BYTE == 0x01}
277
+ # HMAC-Hash(PRK, info + ONE_BYTE)[0, desired_length]
278
+ # ==
279
+ OpenSSL::HMAC.digest(SHA512_DIGEST, prk, info + ONE_BYTE)[0, desired_length]
280
+ end
281
+
282
+ if defined?(OpenSSL::KDF) && OpenSSL::KDF.respond_to?(:hkdf)
283
+ def hkdf(input_key_material, salt, info, desired_length)
284
+ OpenSSL::KDF.hkdf(
285
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
286
+ ##% - The input keying material MUST be the plaintext data key (PDK) generated by the key provider.
287
+ input_key_material,
288
+ salt: salt,
289
+ info: info,
290
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
291
+ ##% - The length of the input keying material MUST equal the key derivation input length specified by the algorithm suite commit key derivation setting.
292
+ length: desired_length,
293
+ ##= ../specification/s3-encryption/key-derivation.md#hkdf-operation
294
+ ##% - The hash function MUST be specified by the algorithm suite commitment settings.
295
+ hash: SHA512_DIGEST
296
+ )
297
+ end
298
+ else
299
+ # This is done so that we can test hkdf_fallback when we have `OpenSSL::KDF.hkdf`
300
+ alias hkdf hkdf_fallback
301
+ end
302
+
303
+ if defined?(OpenSSL) && OpenSSL.respond_to?(:secure_compare)
304
+ def timing_safe_equal?(a, b)
305
+ OpenSSL.secure_compare(a, b)
306
+ end
307
+ else
308
+ def timing_safe_equal?(a, b)
309
+ return false unless a.bytesize == b.bytesize
310
+
311
+ l = a.unpack('C*')
312
+ r = 0
313
+ b.each_byte { |byte| r |= byte ^ l.shift }
314
+ r.zero?
315
+ end
316
+ end
317
+ end
318
+ end
319
+ end
320
+ end
321
+ end
@@ -1,4 +1,5 @@
1
1
  require 'aws-sdk-s3/encryptionV2/client'
2
+ require 'aws-sdk-s3/encryptionV2/decryption'
2
3
  require 'aws-sdk-s3/encryptionV2/decrypt_handler'
3
4
  require 'aws-sdk-s3/encryptionV2/default_cipher_provider'
4
5
  require 'aws-sdk-s3/encryptionV2/encrypt_handler'
@@ -0,0 +1,24 @@
1
+ require 'aws-sdk-s3/encryptionV3/client'
2
+ require 'aws-sdk-s3/encryptionV3/decryption'
3
+ require 'aws-sdk-s3/encryptionV3/decrypt_handler'
4
+ require 'aws-sdk-s3/encryptionV3/default_cipher_provider'
5
+ require 'aws-sdk-s3/encryptionV3/encrypt_handler'
6
+ require 'aws-sdk-s3/encryptionV3/errors'
7
+ require 'aws-sdk-s3/encryptionV3/io_encrypter'
8
+ require 'aws-sdk-s3/encryptionV3/io_decrypter'
9
+ require 'aws-sdk-s3/encryptionV3/io_auth_decrypter'
10
+ require 'aws-sdk-s3/encryptionV3/key_provider'
11
+ require 'aws-sdk-s3/encryptionV3/kms_cipher_provider'
12
+ require 'aws-sdk-s3/encryptionV3/materials'
13
+ require 'aws-sdk-s3/encryptionV3/utils'
14
+ require 'aws-sdk-s3/encryptionV3/default_key_provider'
15
+
16
+ module Aws
17
+ module S3
18
+ module EncryptionV3
19
+ AES_GCM_TAG_LEN_BYTES = 16
20
+ EC_USER_AGENT = 'S3CryptoV3'
21
+ end
22
+ end
23
+ end
24
+
@@ -13,62 +13,87 @@ module Aws::S3
13
13
  # @!attribute bucket
14
14
  # The S3 bucket used to send the request. This is an optional parameter that will be set automatically for operations that are scoped to an S3 bucket.
15
15
  #
16
- # @return [String]
16
+ # @return [string]
17
17
  #
18
18
  # @!attribute region
19
19
  # The AWS region used to dispatch the request.
20
20
  #
21
- # @return [String]
21
+ # @return [string]
22
22
  #
23
23
  # @!attribute use_fips
24
24
  # When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.
25
25
  #
26
- # @return [Boolean]
26
+ # @return [boolean]
27
27
  #
28
28
  # @!attribute use_dual_stack
29
29
  # When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
30
30
  #
31
- # @return [Boolean]
31
+ # @return [boolean]
32
32
  #
33
33
  # @!attribute endpoint
34
34
  # Override the endpoint used to send this request
35
35
  #
36
- # @return [String]
36
+ # @return [string]
37
37
  #
38
38
  # @!attribute force_path_style
39
39
  # When true, force a path-style endpoint to be used where the bucket name is part of the path.
40
40
  #
41
- # @return [Boolean]
41
+ # @return [boolean]
42
42
  #
43
43
  # @!attribute accelerate
44
44
  # When true, use S3 Accelerate. NOTE: Not all regions support S3 accelerate.
45
45
  #
46
- # @return [Boolean]
46
+ # @return [boolean]
47
47
  #
48
48
  # @!attribute use_global_endpoint
49
49
  # Whether the global endpoint should be used, rather then the regional endpoint for us-east-1.
50
50
  #
51
- # @return [Boolean]
51
+ # @return [boolean]
52
52
  #
53
53
  # @!attribute use_object_lambda_endpoint
54
54
  # Internal parameter to use object lambda endpoint for an operation (eg: WriteGetObjectResponse)
55
55
  #
56
- # @return [Boolean]
56
+ # @return [boolean]
57
+ #
58
+ # @!attribute key
59
+ # The S3 Key used to send the request. This is an optional parameter that will be set automatically for operations that are scoped to an S3 Key.
60
+ #
61
+ # @return [string]
62
+ #
63
+ # @!attribute prefix
64
+ # The S3 Prefix used to send the request. This is an optional parameter that will be set automatically for operations that are scoped to an S3 Prefix.
65
+ #
66
+ # @return [string]
67
+ #
68
+ # @!attribute copy_source
69
+ # The Copy Source used for Copy Object request. This is an optional parameter that will be set automatically for operations that are scoped to Copy Source.
70
+ #
71
+ # @return [string]
57
72
  #
58
73
  # @!attribute disable_access_points
59
74
  # Internal parameter to disable Access Point Buckets
60
75
  #
61
- # @return [Boolean]
76
+ # @return [boolean]
62
77
  #
63
78
  # @!attribute disable_multi_region_access_points
64
79
  # Whether multi-region access points (MRAP) should be disabled.
65
80
  #
66
- # @return [Boolean]
81
+ # @return [boolean]
67
82
  #
68
83
  # @!attribute use_arn_region
69
84
  # When an Access Point ARN is provided and this flag is enabled, the SDK MUST use the ARN&#39;s region when constructing the endpoint instead of the client&#39;s configured region.
70
85
  #
71
- # @return [Boolean]
86
+ # @return [boolean]
87
+ #
88
+ # @!attribute use_s3_express_control_endpoint
89
+ # Internal parameter to indicate whether S3Express operation should use control plane, (ex. CreateBucket)
90
+ #
91
+ # @return [boolean]
92
+ #
93
+ # @!attribute disable_s3_express_session_auth
94
+ # Parameter to indicate whether S3Express session auth should be disabled
95
+ #
96
+ # @return [boolean]
72
97
  #
73
98
  EndpointParameters = Struct.new(
74
99
  :bucket,
@@ -80,9 +105,14 @@ module Aws::S3
80
105
  :accelerate,
81
106
  :use_global_endpoint,
82
107
  :use_object_lambda_endpoint,
108
+ :key,
109
+ :prefix,
110
+ :copy_source,
83
111
  :disable_access_points,
84
112
  :disable_multi_region_access_points,
85
113
  :use_arn_region,
114
+ :use_s3_express_control_endpoint,
115
+ :disable_s3_express_session_auth,
86
116
  ) do
87
117
  include Aws::Structure
88
118
 
@@ -98,9 +128,14 @@ module Aws::S3
98
128
  'Accelerate' => :accelerate,
99
129
  'UseGlobalEndpoint' => :use_global_endpoint,
100
130
  'UseObjectLambdaEndpoint' => :use_object_lambda_endpoint,
131
+ 'Key' => :key,
132
+ 'Prefix' => :prefix,
133
+ 'CopySource' => :copy_source,
101
134
  'DisableAccessPoints' => :disable_access_points,
102
135
  'DisableMultiRegionAccessPoints' => :disable_multi_region_access_points,
103
136
  'UseArnRegion' => :use_arn_region,
137
+ 'UseS3ExpressControlEndpoint' => :use_s3_express_control_endpoint,
138
+ 'DisableS3ExpressSessionAuth' => :disable_s3_express_session_auth,
104
139
  }.freeze
105
140
  end
106
141
 
@@ -109,38 +144,38 @@ module Aws::S3
109
144
  self[:region] = options[:region]
110
145
  self[:use_fips] = options[:use_fips]
111
146
  self[:use_fips] = false if self[:use_fips].nil?
112
- if self[:use_fips].nil?
113
- raise ArgumentError, "Missing required EndpointParameter: :use_fips"
114
- end
115
147
  self[:use_dual_stack] = options[:use_dual_stack]
116
148
  self[:use_dual_stack] = false if self[:use_dual_stack].nil?
117
- if self[:use_dual_stack].nil?
118
- raise ArgumentError, "Missing required EndpointParameter: :use_dual_stack"
119
- end
120
149
  self[:endpoint] = options[:endpoint]
121
150
  self[:force_path_style] = options[:force_path_style]
122
151
  self[:force_path_style] = false if self[:force_path_style].nil?
123
- if self[:force_path_style].nil?
124
- raise ArgumentError, "Missing required EndpointParameter: :force_path_style"
125
- end
126
152
  self[:accelerate] = options[:accelerate]
127
153
  self[:accelerate] = false if self[:accelerate].nil?
128
- if self[:accelerate].nil?
129
- raise ArgumentError, "Missing required EndpointParameter: :accelerate"
130
- end
131
154
  self[:use_global_endpoint] = options[:use_global_endpoint]
132
155
  self[:use_global_endpoint] = false if self[:use_global_endpoint].nil?
133
- if self[:use_global_endpoint].nil?
134
- raise ArgumentError, "Missing required EndpointParameter: :use_global_endpoint"
135
- end
136
156
  self[:use_object_lambda_endpoint] = options[:use_object_lambda_endpoint]
157
+ self[:key] = options[:key]
158
+ self[:prefix] = options[:prefix]
159
+ self[:copy_source] = options[:copy_source]
137
160
  self[:disable_access_points] = options[:disable_access_points]
138
161
  self[:disable_multi_region_access_points] = options[:disable_multi_region_access_points]
139
162
  self[:disable_multi_region_access_points] = false if self[:disable_multi_region_access_points].nil?
140
- if self[:disable_multi_region_access_points].nil?
141
- raise ArgumentError, "Missing required EndpointParameter: :disable_multi_region_access_points"
142
- end
143
163
  self[:use_arn_region] = options[:use_arn_region]
164
+ self[:use_s3_express_control_endpoint] = options[:use_s3_express_control_endpoint]
165
+ self[:disable_s3_express_session_auth] = options[:disable_s3_express_session_auth]
166
+ end
167
+
168
+ def self.create(config, options={})
169
+ new({
170
+ region: config.region,
171
+ use_fips: config.use_fips_endpoint,
172
+ endpoint: (config.endpoint.to_s unless config.regional_endpoint),
173
+ force_path_style: config.force_path_style,
174
+ use_global_endpoint: config.s3_us_east_1_regional_endpoint == 'legacy',
175
+ disable_multi_region_access_points: config.s3_disable_multiregion_access_points,
176
+ use_arn_region: config.s3_use_arn_region,
177
+ disable_s3_express_session_auth: config.disable_s3_express_session_auth,
178
+ }.merge(options))
144
179
  end
145
180
  end
146
181
  end