aws-sdk-s3 1.48.0 → 1.113.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +888 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -0
  5. data/lib/aws-sdk-s3/arn/access_point_arn.rb +69 -0
  6. data/lib/aws-sdk-s3/arn/multi_region_access_point_arn.rb +68 -0
  7. data/lib/aws-sdk-s3/arn/object_lambda_arn.rb +69 -0
  8. data/lib/aws-sdk-s3/arn/outpost_access_point_arn.rb +74 -0
  9. data/lib/aws-sdk-s3/bucket.rb +375 -82
  10. data/lib/aws-sdk-s3/bucket_acl.rb +55 -15
  11. data/lib/aws-sdk-s3/bucket_cors.rb +67 -14
  12. data/lib/aws-sdk-s3/bucket_lifecycle.rb +54 -16
  13. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +56 -16
  14. data/lib/aws-sdk-s3/bucket_logging.rb +52 -13
  15. data/lib/aws-sdk-s3/bucket_notification.rb +43 -17
  16. data/lib/aws-sdk-s3/bucket_policy.rb +51 -13
  17. data/lib/aws-sdk-s3/bucket_region_cache.rb +2 -0
  18. data/lib/aws-sdk-s3/bucket_request_payment.rb +51 -12
  19. data/lib/aws-sdk-s3/bucket_tagging.rb +59 -14
  20. data/lib/aws-sdk-s3/bucket_versioning.rb +118 -12
  21. data/lib/aws-sdk-s3/bucket_website.rb +66 -17
  22. data/lib/aws-sdk-s3/client.rb +8973 -740
  23. data/lib/aws-sdk-s3/client_api.rb +778 -2
  24. data/lib/aws-sdk-s3/customizations/bucket.rb +59 -16
  25. data/lib/aws-sdk-s3/customizations/multipart_upload.rb +2 -0
  26. data/lib/aws-sdk-s3/customizations/object.rb +200 -62
  27. data/lib/aws-sdk-s3/customizations/object_summary.rb +5 -0
  28. data/lib/aws-sdk-s3/customizations/types/list_object_versions_output.rb +2 -0
  29. data/lib/aws-sdk-s3/customizations.rb +4 -1
  30. data/lib/aws-sdk-s3/encryption/client.rb +22 -5
  31. data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +71 -29
  32. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +43 -5
  33. data/lib/aws-sdk-s3/encryption/default_key_provider.rb +2 -0
  34. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +13 -2
  35. data/lib/aws-sdk-s3/encryption/errors.rb +2 -0
  36. data/lib/aws-sdk-s3/encryption/io_auth_decrypter.rb +2 -0
  37. data/lib/aws-sdk-s3/encryption/io_decrypter.rb +11 -3
  38. data/lib/aws-sdk-s3/encryption/io_encrypter.rb +2 -0
  39. data/lib/aws-sdk-s3/encryption/key_provider.rb +2 -0
  40. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +34 -3
  41. data/lib/aws-sdk-s3/encryption/materials.rb +8 -6
  42. data/lib/aws-sdk-s3/encryption/utils.rb +25 -0
  43. data/lib/aws-sdk-s3/encryption.rb +4 -0
  44. data/lib/aws-sdk-s3/encryptionV2/client.rb +566 -0
  45. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +222 -0
  46. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +170 -0
  47. data/lib/aws-sdk-s3/encryptionV2/default_key_provider.rb +40 -0
  48. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +65 -0
  49. data/lib/aws-sdk-s3/encryptionV2/errors.rb +37 -0
  50. data/lib/aws-sdk-s3/encryptionV2/io_auth_decrypter.rb +58 -0
  51. data/lib/aws-sdk-s3/encryptionV2/io_decrypter.rb +37 -0
  52. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +73 -0
  53. data/lib/aws-sdk-s3/encryptionV2/key_provider.rb +31 -0
  54. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +169 -0
  55. data/lib/aws-sdk-s3/encryptionV2/materials.rb +60 -0
  56. data/lib/aws-sdk-s3/encryptionV2/utils.rb +103 -0
  57. data/lib/aws-sdk-s3/encryption_v2.rb +23 -0
  58. data/lib/aws-sdk-s3/errors.rb +123 -1
  59. data/lib/aws-sdk-s3/event_streams.rb +8 -1
  60. data/lib/aws-sdk-s3/file_downloader.rb +17 -10
  61. data/lib/aws-sdk-s3/file_part.rb +11 -6
  62. data/lib/aws-sdk-s3/file_uploader.rb +33 -14
  63. data/lib/aws-sdk-s3/legacy_signer.rb +17 -25
  64. data/lib/aws-sdk-s3/multipart_file_uploader.rb +78 -19
  65. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +18 -7
  66. data/lib/aws-sdk-s3/multipart_upload.rb +178 -29
  67. data/lib/aws-sdk-s3/multipart_upload_error.rb +2 -0
  68. data/lib/aws-sdk-s3/multipart_upload_part.rb +233 -42
  69. data/lib/aws-sdk-s3/object.rb +846 -179
  70. data/lib/aws-sdk-s3/object_acl.rb +79 -21
  71. data/lib/aws-sdk-s3/object_copier.rb +2 -0
  72. data/lib/aws-sdk-s3/object_multipart_copier.rb +2 -0
  73. data/lib/aws-sdk-s3/object_summary.rb +611 -162
  74. data/lib/aws-sdk-s3/object_version.rb +162 -71
  75. data/lib/aws-sdk-s3/plugins/accelerate.rb +38 -38
  76. data/lib/aws-sdk-s3/plugins/arn.rb +254 -0
  77. data/lib/aws-sdk-s3/plugins/bucket_dns.rb +8 -8
  78. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +25 -3
  79. data/lib/aws-sdk-s3/plugins/dualstack.rb +38 -33
  80. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +4 -4
  81. data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +3 -1
  82. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +11 -3
  83. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +73 -0
  84. data/lib/aws-sdk-s3/plugins/location_constraint.rb +2 -0
  85. data/lib/aws-sdk-s3/plugins/md5s.rb +34 -30
  86. data/lib/aws-sdk-s3/plugins/object_lambda_endpoint.rb +25 -0
  87. data/lib/aws-sdk-s3/plugins/redirects.rb +2 -0
  88. data/lib/aws-sdk-s3/plugins/s3_host_id.rb +2 -0
  89. data/lib/aws-sdk-s3/plugins/s3_signer.rb +89 -36
  90. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +31 -0
  91. data/lib/aws-sdk-s3/plugins/sse_cpk.rb +3 -1
  92. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +118 -0
  93. data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -0
  94. data/lib/aws-sdk-s3/presigned_post.rb +110 -51
  95. data/lib/aws-sdk-s3/presigner.rb +133 -45
  96. data/lib/aws-sdk-s3/resource.rb +43 -7
  97. data/lib/aws-sdk-s3/types.rb +8437 -1132
  98. data/lib/aws-sdk-s3/waiters.rb +67 -1
  99. data/lib/aws-sdk-s3.rb +12 -6
  100. metadata +37 -12
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+ require 'tempfile'
5
+
6
+ module Aws
7
+ module S3
8
+ module EncryptionV2
9
+
10
+ # Provides an IO wrapper encrypting a stream of data.
11
+ # @api private
12
+ class IOEncrypter
13
+
14
+ # @api private
15
+ ONE_MEGABYTE = 1024 * 1024
16
+
17
+ def initialize(cipher, io)
18
+ @encrypted = io.size <= ONE_MEGABYTE ?
19
+ encrypt_to_stringio(cipher, io.read) :
20
+ encrypt_to_tempfile(cipher, io)
21
+ @size = @encrypted.size
22
+ end
23
+
24
+ # @return [Integer]
25
+ attr_reader :size
26
+
27
+ def read(bytes = nil, output_buffer = nil)
28
+ if @encrypted.is_a?(Tempfile) && @encrypted.closed?
29
+ @encrypted.open
30
+ @encrypted.binmode
31
+ end
32
+ @encrypted.read(bytes, output_buffer)
33
+ end
34
+
35
+ def rewind
36
+ @encrypted.rewind
37
+ end
38
+
39
+ # @api private
40
+ def close
41
+ @encrypted.close if @encrypted.is_a?(Tempfile)
42
+ end
43
+
44
+ private
45
+
46
+ def encrypt_to_stringio(cipher, plain_text)
47
+ if plain_text.empty?
48
+ StringIO.new(cipher.final + cipher.auth_tag)
49
+ else
50
+ StringIO.new(cipher.update(plain_text) + cipher.final + cipher.auth_tag)
51
+ end
52
+ end
53
+
54
+ def encrypt_to_tempfile(cipher, io)
55
+ encrypted = Tempfile.new(self.object_id.to_s)
56
+ encrypted.binmode
57
+ while chunk = io.read(ONE_MEGABYTE, read_buffer ||= String.new)
58
+ if cipher.method(:update).arity == 1
59
+ encrypted.write(cipher.update(chunk))
60
+ else
61
+ encrypted.write(cipher.update(chunk, cipher_buffer ||= String.new))
62
+ end
63
+ end
64
+ encrypted.write(cipher.final)
65
+ encrypted.write(cipher.auth_tag)
66
+ encrypted.rewind
67
+ encrypted
68
+ end
69
+
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ module EncryptionV2
6
+
7
+ # This module defines the interface required for a {Client#key_provider}.
8
+ # A key provider is any object that:
9
+ #
10
+ # * Responds to {#encryption_materials} with an {Materials} object.
11
+ #
12
+ # * Responds to {#key_for}, receiving a JSON document String,
13
+ # returning an encryption key. The returned encryption key
14
+ # must be one of:
15
+ #
16
+ # * `OpenSSL::PKey::RSA` - for asymmetric encryption
17
+ # * `String` - 32, 24, or 16 bytes long, for symmetric encryption
18
+ #
19
+ module KeyProvider
20
+
21
+ # @return [Materials]
22
+ def encryption_materials; end
23
+
24
+ # @param [String<JSON>] materials_description
25
+ # @return [OpenSSL::PKey::RSA, String] encryption_key
26
+ def key_for(materials_description); end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,169 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+
5
+ module Aws
6
+ module S3
7
+ module EncryptionV2
8
+ # @api private
9
+ class KmsCipherProvider
10
+
11
+ def initialize(options = {})
12
+ @kms_key_id = validate_kms_key(options[:kms_key_id])
13
+ @kms_client = options[:kms_client]
14
+ @key_wrap_schema = validate_key_wrap(
15
+ options[:key_wrap_schema]
16
+ )
17
+ @content_encryption_schema = validate_cek(
18
+ options[:content_encryption_schema]
19
+ )
20
+ end
21
+
22
+ # @return [Array<Hash,Cipher>] Creates and returns a new encryption
23
+ # envelope and encryption cipher.
24
+ def encryption_cipher(options = {})
25
+ validate_key_for_encryption
26
+ encryption_context = build_encryption_context(@content_encryption_schema, options)
27
+ key_data = @kms_client.generate_data_key(
28
+ key_id: @kms_key_id,
29
+ encryption_context: encryption_context,
30
+ key_spec: 'AES_256'
31
+ )
32
+ cipher = Utils.aes_encryption_cipher(:GCM)
33
+ cipher.key = key_data.plaintext
34
+ envelope = {
35
+ 'x-amz-key-v2' => encode64(key_data.ciphertext_blob),
36
+ 'x-amz-iv' => encode64(cipher.iv = cipher.random_iv),
37
+ 'x-amz-cek-alg' => @content_encryption_schema,
38
+ 'x-amz-tag-len' => (AES_GCM_TAG_LEN_BYTES * 8).to_s,
39
+ 'x-amz-wrap-alg' => @key_wrap_schema,
40
+ 'x-amz-matdesc' => Json.dump(encryption_context)
41
+ }
42
+ cipher.auth_data = '' # auth_data must be set after key and iv
43
+ [envelope, cipher]
44
+ end
45
+
46
+ # @return [Cipher] Given an encryption envelope, returns a
47
+ # decryption cipher.
48
+ def decryption_cipher(envelope, options = {})
49
+ encryption_context = Json.load(envelope['x-amz-matdesc'])
50
+ cek_alg = envelope['x-amz-cek-alg']
51
+
52
+ case envelope['x-amz-wrap-alg']
53
+ when 'kms'
54
+ unless options[:security_profile] == :v2_and_legacy
55
+ raise Errors::LegacyDecryptionError
56
+ end
57
+ when 'kms+context'
58
+ if cek_alg != encryption_context['aws:x-amz-cek-alg']
59
+ raise Errors::CEKAlgMismatchError
60
+ end
61
+
62
+ if encryption_context != build_encryption_context(cek_alg, options)
63
+ raise Errors::DecryptionError, 'Value of encryption context from'\
64
+ ' envelope does not match the provided encryption context'
65
+ end
66
+ when 'AES/GCM'
67
+ raise ArgumentError, 'Key mismatch - Client is configured' \
68
+ ' with a KMS key and the x-amz-wrap-alg is AES/GCM.'
69
+ when 'RSA-OAEP-SHA1'
70
+ raise ArgumentError, 'Key mismatch - Client is configured' \
71
+ ' with a KMS key and the x-amz-wrap-alg is RSA-OAEP-SHA1.'
72
+ else
73
+ raise ArgumentError, 'Unsupported wrap-alg: ' \
74
+ "#{envelope['x-amz-wrap-alg']}"
75
+ end
76
+
77
+ any_cmk_mode = false || options[:kms_allow_decrypt_with_any_cmk]
78
+ decrypt_options = {
79
+ ciphertext_blob: decode64(envelope['x-amz-key-v2']),
80
+ encryption_context: encryption_context
81
+ }
82
+ unless any_cmk_mode
83
+ decrypt_options[:key_id] = @kms_key_id
84
+ end
85
+
86
+ key = @kms_client.decrypt(decrypt_options).plaintext
87
+ iv = decode64(envelope['x-amz-iv'])
88
+ block_mode =
89
+ case cek_alg
90
+ when 'AES/CBC/PKCS5Padding'
91
+ :CBC
92
+ when 'AES/CBC/PKCS7Padding'
93
+ :CBC
94
+ when 'AES/GCM/NoPadding'
95
+ :GCM
96
+ else
97
+ type = envelope['x-amz-cek-alg'].inspect
98
+ msg = "unsupported content encrypting key (cek) format: #{type}"
99
+ raise Errors::DecryptionError, msg
100
+ end
101
+ Utils.aes_decryption_cipher(block_mode, key, iv)
102
+ end
103
+
104
+ private
105
+
106
+ def validate_key_wrap(key_wrap_schema)
107
+ case key_wrap_schema
108
+ when :kms_context then 'kms+context'
109
+ else
110
+ raise ArgumentError, "Unsupported key_wrap_schema: #{key_wrap_schema}"
111
+ end
112
+ end
113
+
114
+ def validate_cek(content_encryption_schema)
115
+ case content_encryption_schema
116
+ when :aes_gcm_no_padding
117
+ "AES/GCM/NoPadding"
118
+ else
119
+ raise ArgumentError, "Unsupported content_encryption_schema: #{content_encryption_schema}"
120
+ end
121
+ end
122
+
123
+ def validate_kms_key(kms_key_id)
124
+ if kms_key_id.nil? || kms_key_id.length.zero?
125
+ raise ArgumentError, 'KMS CMK ID was not specified. ' \
126
+ 'Please specify a CMK ID, ' \
127
+ 'or set kms_key_id: :kms_allow_decrypt_with_any_cmk to use ' \
128
+ 'any valid CMK from the object.'
129
+ end
130
+
131
+ if kms_key_id.is_a?(Symbol) && kms_key_id != :kms_allow_decrypt_with_any_cmk
132
+ raise ArgumentError, 'kms_key_id must be a valid KMS CMK or be ' \
133
+ 'set to :kms_allow_decrypt_with_any_cmk'
134
+ end
135
+ kms_key_id
136
+ end
137
+
138
+ def build_encryption_context(cek_alg, options = {})
139
+ kms_context = (options[:kms_encryption_context] || {})
140
+ .each_with_object({}) { |(k, v), h| h[k.to_s] = v }
141
+ if kms_context.include? 'aws:x-amz-cek-alg'
142
+ raise ArgumentError, 'Conflict in reserved KMS Encryption Context ' \
143
+ 'key aws:x-amz-cek-alg. This value is reserved for the S3 ' \
144
+ 'Encryption Client and cannot be set by the user.'
145
+ end
146
+ {
147
+ 'aws:x-amz-cek-alg' => cek_alg
148
+ }.merge(kms_context)
149
+ end
150
+
151
+ def encode64(str)
152
+ Base64.encode64(str).split("\n") * ""
153
+ end
154
+
155
+ def decode64(str)
156
+ Base64.decode64(str)
157
+ end
158
+
159
+ def validate_key_for_encryption
160
+ if @kms_key_id == :kms_allow_decrypt_with_any_cmk
161
+ raise ArgumentError, 'Unable to encrypt/write objects with '\
162
+ 'kms_key_id = :kms_allow_decrypt_with_any_cmk. Provide ' \
163
+ 'a valid kms_key_id on client construction.'
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+
5
+ module Aws
6
+ module S3
7
+ module EncryptionV2
8
+ class Materials
9
+
10
+ # @option options [required, OpenSSL::PKey::RSA, String] :key
11
+ # The master key to use for encrypting/decrypting all objects.
12
+ #
13
+ # @option options [String<JSON>] :description ('{}')
14
+ # The encryption materials description. This is must be
15
+ # a JSON document string.
16
+ #
17
+ def initialize(options = {})
18
+ @key = validate_key(options[:key])
19
+ @description = validate_desc(options[:description])
20
+ end
21
+
22
+ # @return [OpenSSL::PKey::RSA, String]
23
+ attr_reader :key
24
+
25
+ # @return [String<JSON>]
26
+ attr_reader :description
27
+
28
+ private
29
+
30
+ def validate_key(key)
31
+ case key
32
+ when OpenSSL::PKey::RSA then key
33
+ when String
34
+ if [32, 24, 16].include?(key.bytesize)
35
+ key
36
+ else
37
+ msg = 'invalid key, symmetric key required to be 16, 24, or '\
38
+ '32 bytes in length, saw length ' + key.bytesize.to_s
39
+ raise ArgumentError, msg
40
+ end
41
+ else
42
+ msg = 'invalid encryption key, expected an OpenSSL::PKey::RSA key '\
43
+ '(for asymmetric encryption) or a String (for symmetric '\
44
+ 'encryption).'
45
+ raise ArgumentError, msg
46
+ end
47
+ end
48
+
49
+ def validate_desc(description)
50
+ Json.load(description)
51
+ description
52
+ rescue Json::ParseError, EncodingError
53
+ msg = 'expected description to be a valid JSON document string'
54
+ raise ArgumentError, msg
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl'
4
+
5
+ module Aws
6
+ module S3
7
+ module EncryptionV2
8
+ # @api private
9
+ module Utils
10
+
11
+ class << self
12
+
13
+ def encrypt_aes_gcm(key, data, auth_data)
14
+ cipher = aes_encryption_cipher(:GCM, key)
15
+ cipher.iv = (iv = cipher.random_iv)
16
+ cipher.auth_data = auth_data
17
+
18
+ iv + cipher.update(data) + cipher.final + cipher.auth_tag
19
+ end
20
+
21
+ def encrypt_rsa(key, data, auth_data)
22
+ # Plaintext must be KeyLengthInBytes (1 Byte) + DataKey + AuthData
23
+ buf = [data.bytesize] + data.unpack('C*') + auth_data.unpack('C*')
24
+ key.public_encrypt(buf.pack('C*'), OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
25
+ end
26
+
27
+ def decrypt(key, data)
28
+ begin
29
+ case key
30
+ when OpenSSL::PKey::RSA # asymmetric decryption
31
+ key.private_decrypt(data)
32
+ when String # symmetric Decryption
33
+ cipher = aes_cipher(:decrypt, :ECB, key, nil)
34
+ cipher.update(data) + cipher.final
35
+ end
36
+ rescue OpenSSL::Cipher::CipherError
37
+ msg = 'decryption failed, possible incorrect key'
38
+ raise Errors::DecryptionError, msg
39
+ end
40
+ end
41
+
42
+ def decrypt_aes_gcm(key, data, auth_data)
43
+ # data is iv (12B) + key + tag (16B)
44
+ buf = data.unpack('C*')
45
+ iv = buf[0,12].pack('C*') # iv will always be 12 bytes
46
+ tag = buf[-16, 16].pack('C*') # tag is 16 bytes
47
+ enc_key = buf[12, buf.size - (12+16)].pack('C*')
48
+ cipher = aes_cipher(:decrypt, :GCM, key, iv)
49
+ cipher.auth_tag = tag
50
+ cipher.auth_data = auth_data
51
+ cipher.update(enc_key) + cipher.final
52
+ end
53
+
54
+ # returns the decrypted data + auth_data
55
+ def decrypt_rsa(key, enc_data)
56
+ # Plaintext must be KeyLengthInBytes (1 Byte) + DataKey + AuthData
57
+ buf = key.private_decrypt(enc_data, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING).unpack('C*')
58
+ key_length = buf[0]
59
+ data = buf[1, key_length].pack('C*')
60
+ auth_data = buf[key_length+1, buf.length - key_length].pack('C*')
61
+ [data, auth_data]
62
+ end
63
+
64
+ # @param [String] block_mode "CBC" or "ECB"
65
+ # @param [OpenSSL::PKey::RSA, String, nil] key
66
+ # @param [String, nil] iv The initialization vector
67
+ def aes_encryption_cipher(block_mode, key = nil, iv = nil)
68
+ aes_cipher(:encrypt, block_mode, key, iv)
69
+ end
70
+
71
+ # @param [String] block_mode "CBC" or "ECB"
72
+ # @param [OpenSSL::PKey::RSA, String, nil] key
73
+ # @param [String, nil] iv The initialization vector
74
+ def aes_decryption_cipher(block_mode, key = nil, iv = nil)
75
+ aes_cipher(:decrypt, block_mode, key, iv)
76
+ end
77
+
78
+ # @param [String] mode "encrypt" or "decrypt"
79
+ # @param [String] block_mode "CBC" or "ECB"
80
+ # @param [OpenSSL::PKey::RSA, String, nil] key
81
+ # @param [String, nil] iv The initialization vector
82
+ def aes_cipher(mode, block_mode, key, iv)
83
+ cipher = key ?
84
+ OpenSSL::Cipher.new("aes-#{cipher_size(key)}-#{block_mode.downcase}") :
85
+ OpenSSL::Cipher.new("aes-256-#{block_mode.downcase}")
86
+ cipher.send(mode) # encrypt or decrypt
87
+ cipher.key = key if key
88
+ cipher.iv = iv if iv
89
+ cipher
90
+ end
91
+
92
+ # @param [String] key
93
+ # @return [Integer]
94
+ # @raise ArgumentError
95
+ def cipher_size(key)
96
+ key.bytesize * 8
97
+ end
98
+
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,23 @@
1
+ require 'aws-sdk-s3/encryptionV2/client'
2
+ require 'aws-sdk-s3/encryptionV2/decrypt_handler'
3
+ require 'aws-sdk-s3/encryptionV2/default_cipher_provider'
4
+ require 'aws-sdk-s3/encryptionV2/encrypt_handler'
5
+ require 'aws-sdk-s3/encryptionV2/errors'
6
+ require 'aws-sdk-s3/encryptionV2/io_encrypter'
7
+ require 'aws-sdk-s3/encryptionV2/io_decrypter'
8
+ require 'aws-sdk-s3/encryptionV2/io_auth_decrypter'
9
+ require 'aws-sdk-s3/encryptionV2/key_provider'
10
+ require 'aws-sdk-s3/encryptionV2/kms_cipher_provider'
11
+ require 'aws-sdk-s3/encryptionV2/materials'
12
+ require 'aws-sdk-s3/encryptionV2/utils'
13
+ require 'aws-sdk-s3/encryptionV2/default_key_provider'
14
+
15
+ module Aws
16
+ module S3
17
+ module EncryptionV2
18
+ AES_GCM_TAG_LEN_BYTES = 16
19
+ EC_USER_AGENT = 'S3CryptoV2'
20
+ end
21
+ end
22
+ end
23
+
@@ -1,14 +1,136 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # WARNING ABOUT GENERATED CODE
2
4
  #
3
5
  # This file is generated. See the contributing guide for more information:
4
- # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
6
+ # https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
5
7
  #
6
8
  # WARNING ABOUT GENERATED CODE
7
9
 
8
10
  module Aws::S3
11
+
12
+ # When S3 returns an error response, the Ruby SDK constructs and raises an error.
13
+ # These errors all extend Aws::S3::Errors::ServiceError < {Aws::Errors::ServiceError}
14
+ #
15
+ # You can rescue all S3 errors using ServiceError:
16
+ #
17
+ # begin
18
+ # # do stuff
19
+ # rescue Aws::S3::Errors::ServiceError
20
+ # # rescues all S3 API errors
21
+ # end
22
+ #
23
+ #
24
+ # ## Request Context
25
+ # ServiceError objects have a {Aws::Errors::ServiceError#context #context} method that returns
26
+ # information about the request that generated the error.
27
+ # See {Seahorse::Client::RequestContext} for more information.
28
+ #
29
+ # ## Error Classes
30
+ # * {BucketAlreadyExists}
31
+ # * {BucketAlreadyOwnedByYou}
32
+ # * {InvalidObjectState}
33
+ # * {NoSuchBucket}
34
+ # * {NoSuchKey}
35
+ # * {NoSuchUpload}
36
+ # * {ObjectAlreadyInActiveTierError}
37
+ # * {ObjectNotInActiveTierError}
38
+ #
39
+ # Additionally, error classes are dynamically generated for service errors based on the error code
40
+ # if they are not defined above.
9
41
  module Errors
10
42
 
11
43
  extend Aws::Errors::DynamicErrors
12
44
 
45
+ class BucketAlreadyExists < ServiceError
46
+
47
+ # @param [Seahorse::Client::RequestContext] context
48
+ # @param [String] message
49
+ # @param [Aws::S3::Types::BucketAlreadyExists] data
50
+ def initialize(context, message, data = Aws::EmptyStructure.new)
51
+ super(context, message, data)
52
+ end
53
+ end
54
+
55
+ class BucketAlreadyOwnedByYou < ServiceError
56
+
57
+ # @param [Seahorse::Client::RequestContext] context
58
+ # @param [String] message
59
+ # @param [Aws::S3::Types::BucketAlreadyOwnedByYou] data
60
+ def initialize(context, message, data = Aws::EmptyStructure.new)
61
+ super(context, message, data)
62
+ end
63
+ end
64
+
65
+ class InvalidObjectState < ServiceError
66
+
67
+ # @param [Seahorse::Client::RequestContext] context
68
+ # @param [String] message
69
+ # @param [Aws::S3::Types::InvalidObjectState] data
70
+ def initialize(context, message, data = Aws::EmptyStructure.new)
71
+ super(context, message, data)
72
+ end
73
+
74
+ # @return [String]
75
+ def storage_class
76
+ @data[:storage_class]
77
+ end
78
+
79
+ # @return [String]
80
+ def access_tier
81
+ @data[:access_tier]
82
+ end
83
+ end
84
+
85
+ class NoSuchBucket < ServiceError
86
+
87
+ # @param [Seahorse::Client::RequestContext] context
88
+ # @param [String] message
89
+ # @param [Aws::S3::Types::NoSuchBucket] data
90
+ def initialize(context, message, data = Aws::EmptyStructure.new)
91
+ super(context, message, data)
92
+ end
93
+ end
94
+
95
+ class NoSuchKey < ServiceError
96
+
97
+ # @param [Seahorse::Client::RequestContext] context
98
+ # @param [String] message
99
+ # @param [Aws::S3::Types::NoSuchKey] data
100
+ def initialize(context, message, data = Aws::EmptyStructure.new)
101
+ super(context, message, data)
102
+ end
103
+ end
104
+
105
+ class NoSuchUpload < ServiceError
106
+
107
+ # @param [Seahorse::Client::RequestContext] context
108
+ # @param [String] message
109
+ # @param [Aws::S3::Types::NoSuchUpload] data
110
+ def initialize(context, message, data = Aws::EmptyStructure.new)
111
+ super(context, message, data)
112
+ end
113
+ end
114
+
115
+ class ObjectAlreadyInActiveTierError < ServiceError
116
+
117
+ # @param [Seahorse::Client::RequestContext] context
118
+ # @param [String] message
119
+ # @param [Aws::S3::Types::ObjectAlreadyInActiveTierError] data
120
+ def initialize(context, message, data = Aws::EmptyStructure.new)
121
+ super(context, message, data)
122
+ end
123
+ end
124
+
125
+ class ObjectNotInActiveTierError < ServiceError
126
+
127
+ # @param [Seahorse::Client::RequestContext] context
128
+ # @param [String] message
129
+ # @param [Aws::S3::Types::ObjectNotInActiveTierError] data
130
+ def initialize(context, message, data = Aws::EmptyStructure.new)
131
+ super(context, message, data)
132
+ end
133
+ end
134
+
13
135
  end
14
136
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # WARNING ABOUT GENERATED CODE
2
4
  #
3
5
  # This file is generated. See the contributing guide for more information:
4
- # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
6
+ # https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
5
7
  #
6
8
  # WARNING ABOUT GENERATED CODE
7
9
 
@@ -41,6 +43,10 @@ module Aws::S3
41
43
  @event_emitter.on(:initial_response, block) if block_given?
42
44
  end
43
45
 
46
+ def on_unknown_event(&block)
47
+ @event_emitter.on(:unknown_event, block) if block_given?
48
+ end
49
+
44
50
  def on_event(&block)
45
51
  on_records_event(&block)
46
52
  on_stats_event(&block)
@@ -49,6 +55,7 @@ module Aws::S3
49
55
  on_end_event(&block)
50
56
  on_error_event(&block)
51
57
  on_initial_response_event(&block)
58
+ on_unknown_event(&block)
52
59
  end
53
60
 
54
61
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  require 'thread'
3
5
  require 'set'
@@ -21,7 +23,7 @@ module Aws
21
23
 
22
24
  def download(destination, options = {})
23
25
  @path = destination
24
- @mode = options[:mode] || "auto"
26
+ @mode = options[:mode] || 'auto'
25
27
  @thread_count = options[:thread_count] || THREAD_COUNT
26
28
  @chunk_size = options[:chunk_size]
27
29
  @params = {
@@ -31,19 +33,19 @@ module Aws
31
33
  @params[:version_id] = options[:version_id] if options[:version_id]
32
34
 
33
35
  case @mode
34
- when "auto" then multipart_download
35
- when "single_request" then single_request
36
- when "get_range"
36
+ when 'auto' then multipart_download
37
+ when 'single_request' then single_request
38
+ when 'get_range'
37
39
  if @chunk_size
38
40
  resp = @client.head_object(@params)
39
41
  multithreaded_get_by_ranges(construct_chunks(resp.content_length))
40
42
  else
41
- msg = "In :get_range mode, :chunk_size must be provided"
43
+ msg = 'In :get_range mode, :chunk_size must be provided'
42
44
  raise ArgumentError, msg
43
45
  end
44
46
  else
45
47
  msg = "Invalid mode #{@mode} provided, "\
46
- "mode should be :single_request, :get_range or :auto"
48
+ 'mode should be :single_request, :get_range or :auto'
47
49
  raise ArgumentError, msg
48
50
  end
49
51
  end
@@ -92,7 +94,12 @@ module Aws
92
94
  if @chunk_size && @chunk_size > file_size
93
95
  raise ArgumentError, ":chunk_size shouldn't exceed total file size."
94
96
  else
95
- @chunk_size || [(file_size.to_f / MAX_PARTS).ceil, MIN_CHUNK_SIZE].max.to_i
97
+ chunk_size = @chunk_size || [
98
+ (file_size.to_f / MAX_PARTS).ceil,
99
+ MIN_CHUNK_SIZE
100
+ ].max.to_i
101
+ chunk_size -= 1 if file_size % chunk_size == 1
102
+ chunk_size
96
103
  end
97
104
  end
98
105
 
@@ -125,9 +132,9 @@ module Aws
125
132
  end
126
133
 
127
134
  def write(resp)
128
- range, _ = resp.content_range.split(" ").last.split("/")
129
- head, _ = range.split("-").map {|s| s.to_i}
130
- IO.write(@path, resp.body.read, head)
135
+ range, _ = resp.content_range.split(' ').last.split('/')
136
+ head, _ = range.split('-').map {|s| s.to_i}
137
+ File.write(@path, resp.body.read, head)
131
138
  end
132
139
 
133
140
  def single_request