aws-sdk-resources 2.11.632 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/aws-sdk-resources.rb +1 -91
- metadata +14 -85
- data/lib/aws-sdk-resources/batch.rb +0 -143
- data/lib/aws-sdk-resources/builder.rb +0 -85
- data/lib/aws-sdk-resources/builder_sources.rb +0 -105
- data/lib/aws-sdk-resources/collection.rb +0 -107
- data/lib/aws-sdk-resources/definition.rb +0 -331
- data/lib/aws-sdk-resources/documenter.rb +0 -70
- data/lib/aws-sdk-resources/documenter/base_operation_documenter.rb +0 -279
- data/lib/aws-sdk-resources/documenter/data_operation_documenter.rb +0 -25
- data/lib/aws-sdk-resources/documenter/has_many_operation_documenter.rb +0 -69
- data/lib/aws-sdk-resources/documenter/has_operation_documenter.rb +0 -66
- data/lib/aws-sdk-resources/documenter/operation_documenter.rb +0 -20
- data/lib/aws-sdk-resources/documenter/resource_operation_documenter.rb +0 -53
- data/lib/aws-sdk-resources/documenter/waiter_operation_documenter.rb +0 -77
- data/lib/aws-sdk-resources/errors.rb +0 -15
- data/lib/aws-sdk-resources/operation_methods.rb +0 -83
- data/lib/aws-sdk-resources/operations.rb +0 -280
- data/lib/aws-sdk-resources/options.rb +0 -17
- data/lib/aws-sdk-resources/request.rb +0 -39
- data/lib/aws-sdk-resources/request_params.rb +0 -140
- data/lib/aws-sdk-resources/resource.rb +0 -243
- data/lib/aws-sdk-resources/services/ec2.rb +0 -21
- data/lib/aws-sdk-resources/services/ec2/instance.rb +0 -29
- data/lib/aws-sdk-resources/services/iam.rb +0 -19
- data/lib/aws-sdk-resources/services/s3.rb +0 -21
- data/lib/aws-sdk-resources/services/s3/bucket.rb +0 -131
- data/lib/aws-sdk-resources/services/s3/encryption.rb +0 -24
- data/lib/aws-sdk-resources/services/s3/encryption/client.rb +0 -386
- data/lib/aws-sdk-resources/services/s3/encryption/decrypt_handler.rb +0 -225
- data/lib/aws-sdk-resources/services/s3/encryption/default_cipher_provider.rb +0 -101
- data/lib/aws-sdk-resources/services/s3/encryption/default_key_provider.rb +0 -40
- data/lib/aws-sdk-resources/services/s3/encryption/encrypt_handler.rb +0 -61
- data/lib/aws-sdk-resources/services/s3/encryption/errors.rb +0 -15
- data/lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb +0 -58
- data/lib/aws-sdk-resources/services/s3/encryption/io_decrypter.rb +0 -37
- data/lib/aws-sdk-resources/services/s3/encryption/io_encrypter.rb +0 -71
- data/lib/aws-sdk-resources/services/s3/encryption/key_provider.rb +0 -31
- data/lib/aws-sdk-resources/services/s3/encryption/kms_cipher_provider.rb +0 -104
- data/lib/aws-sdk-resources/services/s3/encryption/materials.rb +0 -60
- data/lib/aws-sdk-resources/services/s3/encryption/utils.rb +0 -104
- data/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb +0 -561
- data/lib/aws-sdk-resources/services/s3/encryptionV2/decrypt_handler.rb +0 -214
- data/lib/aws-sdk-resources/services/s3/encryptionV2/default_cipher_provider.rb +0 -170
- data/lib/aws-sdk-resources/services/s3/encryptionV2/default_key_provider.rb +0 -40
- data/lib/aws-sdk-resources/services/s3/encryptionV2/encrypt_handler.rb +0 -69
- data/lib/aws-sdk-resources/services/s3/encryptionV2/errors.rb +0 -37
- data/lib/aws-sdk-resources/services/s3/encryptionV2/io_auth_decrypter.rb +0 -58
- data/lib/aws-sdk-resources/services/s3/encryptionV2/io_decrypter.rb +0 -37
- data/lib/aws-sdk-resources/services/s3/encryptionV2/io_encrypter.rb +0 -73
- data/lib/aws-sdk-resources/services/s3/encryptionV2/key_provider.rb +0 -31
- data/lib/aws-sdk-resources/services/s3/encryptionV2/kms_cipher_provider.rb +0 -169
- data/lib/aws-sdk-resources/services/s3/encryptionV2/materials.rb +0 -60
- data/lib/aws-sdk-resources/services/s3/encryptionV2/utils.rb +0 -103
- data/lib/aws-sdk-resources/services/s3/encryption_v2.rb +0 -24
- data/lib/aws-sdk-resources/services/s3/file_downloader.rb +0 -169
- data/lib/aws-sdk-resources/services/s3/file_part.rb +0 -75
- data/lib/aws-sdk-resources/services/s3/file_uploader.rb +0 -58
- data/lib/aws-sdk-resources/services/s3/multipart_file_uploader.rb +0 -187
- data/lib/aws-sdk-resources/services/s3/multipart_upload.rb +0 -42
- data/lib/aws-sdk-resources/services/s3/multipart_upload_error.rb +0 -16
- data/lib/aws-sdk-resources/services/s3/object.rb +0 -290
- data/lib/aws-sdk-resources/services/s3/object_copier.rb +0 -99
- data/lib/aws-sdk-resources/services/s3/object_multipart_copier.rb +0 -180
- data/lib/aws-sdk-resources/services/s3/object_summary.rb +0 -73
- data/lib/aws-sdk-resources/services/s3/presigned_post.rb +0 -651
- data/lib/aws-sdk-resources/services/sns.rb +0 -7
- data/lib/aws-sdk-resources/services/sns/message_verifier.rb +0 -171
- data/lib/aws-sdk-resources/services/sqs.rb +0 -7
- data/lib/aws-sdk-resources/services/sqs/queue_poller.rb +0 -521
- data/lib/aws-sdk-resources/source.rb +0 -39
@@ -1,225 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'base64'
|
4
|
-
|
5
|
-
module Aws
|
6
|
-
module S3
|
7
|
-
module Encryption
|
8
|
-
# @api private
|
9
|
-
class DecryptHandler < Seahorse::Client::Handler
|
10
|
-
@@warned_response_target_proc = false
|
11
|
-
|
12
|
-
V1_ENVELOPE_KEYS = %w(
|
13
|
-
x-amz-key
|
14
|
-
x-amz-iv
|
15
|
-
x-amz-matdesc
|
16
|
-
)
|
17
|
-
|
18
|
-
V2_ENVELOPE_KEYS = %w(
|
19
|
-
x-amz-key-v2
|
20
|
-
x-amz-iv
|
21
|
-
x-amz-cek-alg
|
22
|
-
x-amz-wrap-alg
|
23
|
-
x-amz-matdesc
|
24
|
-
)
|
25
|
-
|
26
|
-
V2_OPTIONAL_KEYS = %w(x-amz-tag-len)
|
27
|
-
|
28
|
-
POSSIBLE_ENVELOPE_KEYS = (V1_ENVELOPE_KEYS +
|
29
|
-
V2_ENVELOPE_KEYS + V2_OPTIONAL_KEYS).uniq
|
30
|
-
|
31
|
-
POSSIBLE_WRAPPING_FORMATS = %w(
|
32
|
-
AES/GCM
|
33
|
-
kms
|
34
|
-
kms+context
|
35
|
-
RSA-OAEP-SHA1
|
36
|
-
)
|
37
|
-
|
38
|
-
POSSIBLE_ENCRYPTION_FORMATS = %w(
|
39
|
-
AES/GCM/NoPadding
|
40
|
-
AES/CBC/PKCS5Padding
|
41
|
-
AES/CBC/PKCS7Padding
|
42
|
-
)
|
43
|
-
|
44
|
-
AUTH_REQUIRED_CEK_ALGS = %w(AES/GCM/NoPadding)
|
45
|
-
|
46
|
-
def call(context)
|
47
|
-
attach_http_event_listeners(context)
|
48
|
-
apply_cse_user_agent(context)
|
49
|
-
|
50
|
-
if context[:response_target].is_a?(Proc) && !@@warned_response_target_proc
|
51
|
-
@@warned_response_target_proc = true
|
52
|
-
warn(':response_target is a Proc, or a block was provided. ' \
|
53
|
-
'Read the entire object to the ' \
|
54
|
-
'end before you start using the decrypted data. This is to ' \
|
55
|
-
'verify that the object has not been modified since it ' \
|
56
|
-
'was encrypted.')
|
57
|
-
end
|
58
|
-
|
59
|
-
@handler.call(context)
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def attach_http_event_listeners(context)
|
65
|
-
|
66
|
-
context.http_response.on_headers(200) do
|
67
|
-
cipher, envelope = decryption_cipher(context)
|
68
|
-
decrypter = body_contains_auth_tag?(envelope) ?
|
69
|
-
authenticated_decrypter(context, cipher, envelope) :
|
70
|
-
IODecrypter.new(cipher, context.http_response.body)
|
71
|
-
context.http_response.body = decrypter
|
72
|
-
end
|
73
|
-
|
74
|
-
context.http_response.on_success(200) do
|
75
|
-
decrypter = context.http_response.body
|
76
|
-
decrypter.finalize
|
77
|
-
decrypter.io.rewind if decrypter.io.respond_to?(:rewind)
|
78
|
-
context.http_response.body = decrypter.io
|
79
|
-
end
|
80
|
-
|
81
|
-
context.http_response.on_error do
|
82
|
-
if context.http_response.body.respond_to?(:io)
|
83
|
-
context.http_response.body = context.http_response.body.io
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def decryption_cipher(context)
|
89
|
-
if (envelope = get_encryption_envelope(context))
|
90
|
-
cipher = context[:encryption][:cipher_provider]
|
91
|
-
.decryption_cipher(
|
92
|
-
envelope,
|
93
|
-
context[:encryption]
|
94
|
-
)
|
95
|
-
[cipher, envelope]
|
96
|
-
else
|
97
|
-
raise Errors::DecryptionError, "unable to locate encryption envelope"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def get_encryption_envelope(context)
|
102
|
-
if context[:encryption][:envelope_location] == :metadata
|
103
|
-
envelope_from_metadata(context) || envelope_from_instr_file(context)
|
104
|
-
else
|
105
|
-
envelope_from_instr_file(context) || envelope_from_metadata(context)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def envelope_from_metadata(context)
|
110
|
-
possible_envelope = {}
|
111
|
-
POSSIBLE_ENVELOPE_KEYS.each do |suffix|
|
112
|
-
if value = context.http_response.headers["x-amz-meta-#{suffix}"]
|
113
|
-
possible_envelope[suffix] = value
|
114
|
-
end
|
115
|
-
end
|
116
|
-
extract_envelope(possible_envelope)
|
117
|
-
end
|
118
|
-
|
119
|
-
def envelope_from_instr_file(context)
|
120
|
-
suffix = context[:encryption][:instruction_file_suffix]
|
121
|
-
possible_envelope = Json.load(context.client.get_object(
|
122
|
-
bucket: context.params[:bucket],
|
123
|
-
key: context.params[:key] + suffix
|
124
|
-
).body.read)
|
125
|
-
extract_envelope(possible_envelope)
|
126
|
-
rescue S3::Errors::ServiceError, Json::ParseError
|
127
|
-
nil
|
128
|
-
end
|
129
|
-
|
130
|
-
def extract_envelope(hash)
|
131
|
-
return nil unless hash
|
132
|
-
return v1_envelope(hash) if hash.key?('x-amz-key')
|
133
|
-
return v2_envelope(hash) if hash.key?('x-amz-key-v2')
|
134
|
-
if hash.keys.any? { |key| key.match(/^x-amz-key-(.+)$/) }
|
135
|
-
msg = "unsupported envelope encryption version #{$1}"
|
136
|
-
raise Errors::DecryptionError, msg
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def v1_envelope(envelope)
|
141
|
-
envelope
|
142
|
-
end
|
143
|
-
|
144
|
-
def v2_envelope(envelope)
|
145
|
-
unless POSSIBLE_ENCRYPTION_FORMATS.include? envelope['x-amz-cek-alg']
|
146
|
-
alg = envelope['x-amz-cek-alg'].inspect
|
147
|
-
msg = "unsupported content encrypting key (cek) format: #{alg}"
|
148
|
-
raise Errors::DecryptionError, msg
|
149
|
-
end
|
150
|
-
unless POSSIBLE_WRAPPING_FORMATS.include? envelope['x-amz-wrap-alg']
|
151
|
-
alg = envelope['x-amz-wrap-alg'].inspect
|
152
|
-
msg = "unsupported key wrapping algorithm: #{alg}"
|
153
|
-
raise Errors::DecryptionError, msg
|
154
|
-
end
|
155
|
-
unless (missing_keys = V2_ENVELOPE_KEYS - envelope.keys).empty?
|
156
|
-
msg = "incomplete v2 encryption envelope:\n"
|
157
|
-
msg += " missing: #{missing_keys.join(',')}\n"
|
158
|
-
raise Errors::DecryptionError, msg
|
159
|
-
end
|
160
|
-
envelope
|
161
|
-
end
|
162
|
-
|
163
|
-
# This method fetches the tag from the end of the object by
|
164
|
-
# making a GET Object w/range request. This auth tag is used
|
165
|
-
# to initialize the cipher, and the decrypter truncates the
|
166
|
-
# auth tag from the body when writing the final bytes.
|
167
|
-
def authenticated_decrypter(context, cipher, envelope)
|
168
|
-
if RUBY_VERSION.match(/1.9/)
|
169
|
-
raise "authenticated decryption not supported by OpenSSL in Ruby version ~> 1.9"
|
170
|
-
raise Aws::Errors::NonSupportedRubyVersionError, msg
|
171
|
-
end
|
172
|
-
http_resp = context.http_response
|
173
|
-
content_length = http_resp.headers['content-length'].to_i
|
174
|
-
auth_tag_length = auth_tag_length(envelope)
|
175
|
-
|
176
|
-
auth_tag = context.client.get_object(
|
177
|
-
bucket: context.params[:bucket],
|
178
|
-
key: context.params[:key],
|
179
|
-
range: "bytes=-#{auth_tag_length}"
|
180
|
-
).body.read
|
181
|
-
|
182
|
-
cipher.auth_tag = auth_tag
|
183
|
-
cipher.auth_data = ''
|
184
|
-
|
185
|
-
# The encrypted object contains both the cipher text
|
186
|
-
# plus a trailing auth tag.
|
187
|
-
IOAuthDecrypter.new(
|
188
|
-
io: http_resp.body,
|
189
|
-
encrypted_content_length: content_length - auth_tag_length,
|
190
|
-
cipher: cipher)
|
191
|
-
end
|
192
|
-
|
193
|
-
def body_contains_auth_tag?(envelope)
|
194
|
-
AUTH_REQUIRED_CEK_ALGS.include?(envelope['x-amz-cek-alg'])
|
195
|
-
end
|
196
|
-
|
197
|
-
# Determine the auth tag length from the algorithm
|
198
|
-
# Validate it against the value provided in the x-amz-tag-len
|
199
|
-
# Return the tag length in bytes
|
200
|
-
def auth_tag_length(envelope)
|
201
|
-
tag_length =
|
202
|
-
case envelope['x-amz-cek-alg']
|
203
|
-
when 'AES/GCM/NoPadding' then AES_GCM_TAG_LEN_BYTES
|
204
|
-
else
|
205
|
-
raise ArgumentError, 'Unsupported cek-alg: ' \
|
206
|
-
"#{envelope['x-amz-cek-alg']}"
|
207
|
-
end
|
208
|
-
if (tag_length * 8) != envelope['x-amz-tag-len'].to_i
|
209
|
-
raise Errors::DecryptionError, 'x-amz-tag-len does not match expected'
|
210
|
-
end
|
211
|
-
tag_length
|
212
|
-
end
|
213
|
-
|
214
|
-
def apply_cse_user_agent(context)
|
215
|
-
if context.config.user_agent_suffix.nil?
|
216
|
-
context.config.user_agent_suffix = EC_USER_AGENT
|
217
|
-
elsif !context.config.user_agent_suffix.include? EC_USER_AGENT
|
218
|
-
context.config.user_agent_suffix += " #{EC_USER_AGENT}"
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'base64'
|
4
|
-
|
5
|
-
module Aws
|
6
|
-
module S3
|
7
|
-
module Encryption
|
8
|
-
# @api private
|
9
|
-
class DefaultCipherProvider
|
10
|
-
|
11
|
-
def initialize(options = {})
|
12
|
-
@key_provider = options[:key_provider]
|
13
|
-
end
|
14
|
-
|
15
|
-
# @return [Array<Hash,Cipher>] Creates an returns a new encryption
|
16
|
-
# envelope and encryption cipher.
|
17
|
-
def encryption_cipher
|
18
|
-
cipher = Utils.aes_encryption_cipher(:CBC)
|
19
|
-
envelope = {
|
20
|
-
'x-amz-key' => encode64(encrypt(envelope_key(cipher))),
|
21
|
-
'x-amz-iv' => encode64(envelope_iv(cipher)),
|
22
|
-
'x-amz-matdesc' => materials_description,
|
23
|
-
}
|
24
|
-
[envelope, cipher]
|
25
|
-
end
|
26
|
-
|
27
|
-
# @return [Cipher] Given an encryption envelope, returns a
|
28
|
-
# decryption cipher.
|
29
|
-
def decryption_cipher(envelope, options = {})
|
30
|
-
master_key = @key_provider.key_for(envelope['x-amz-matdesc'])
|
31
|
-
if envelope.key? 'x-amz-key'
|
32
|
-
# Support for decryption of legacy objects
|
33
|
-
key = Utils.decrypt(master_key, decode64(envelope['x-amz-key']))
|
34
|
-
iv = decode64(envelope['x-amz-iv'])
|
35
|
-
Utils.aes_decryption_cipher(:CBC, key, iv)
|
36
|
-
else
|
37
|
-
if envelope['x-amz-cek-alg'] != 'AES/GCM/NoPadding'
|
38
|
-
raise ArgumentError, 'Unsupported cek-alg: ' \
|
39
|
-
"#{envelope['x-amz-cek-alg']}"
|
40
|
-
end
|
41
|
-
key =
|
42
|
-
case envelope['x-amz-wrap-alg']
|
43
|
-
when 'AES/GCM'
|
44
|
-
if master_key.is_a? OpenSSL::PKey::RSA
|
45
|
-
raise ArgumentError, 'Key mismatch - Client is configured' \
|
46
|
-
' with an RSA key and the x-amz-wrap-alg is AES/GCM.'
|
47
|
-
end
|
48
|
-
Utils.decrypt_aes_gcm(master_key,
|
49
|
-
decode64(envelope['x-amz-key-v2']),
|
50
|
-
envelope['x-amz-cek-alg'])
|
51
|
-
when 'RSA-OAEP-SHA1'
|
52
|
-
unless master_key.is_a? OpenSSL::PKey::RSA
|
53
|
-
raise ArgumentError, 'Key mismatch - Client is configured' \
|
54
|
-
' with an AES key and the x-amz-wrap-alg is RSA-OAEP-SHA1.'
|
55
|
-
end
|
56
|
-
key, cek_alg = Utils.decrypt_rsa(master_key, decode64(envelope['x-amz-key-v2']))
|
57
|
-
raise Errors::DecryptionError unless cek_alg == envelope['x-amz-cek-alg']
|
58
|
-
key
|
59
|
-
when 'kms+context'
|
60
|
-
raise ArgumentError, 'Key mismatch - Client is configured' \
|
61
|
-
' with a user provided key and the x-amz-wrap-alg is' \
|
62
|
-
' kms+context. Please configure the client with the' \
|
63
|
-
' required kms_key_id'
|
64
|
-
else
|
65
|
-
raise ArgumentError, 'Unsupported wrap-alg: ' \
|
66
|
-
"#{envelope['x-amz-wrap-alg']}"
|
67
|
-
end
|
68
|
-
iv = decode64(envelope['x-amz-iv'])
|
69
|
-
Utils.aes_decryption_cipher(:GCM, key, iv)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def envelope_key(cipher)
|
76
|
-
cipher.key = cipher.random_key
|
77
|
-
end
|
78
|
-
|
79
|
-
def envelope_iv(cipher)
|
80
|
-
cipher.iv = cipher.random_iv
|
81
|
-
end
|
82
|
-
|
83
|
-
def encrypt(data)
|
84
|
-
Utils.encrypt(@key_provider.encryption_materials.key, data)
|
85
|
-
end
|
86
|
-
|
87
|
-
def materials_description
|
88
|
-
@key_provider.encryption_materials.description
|
89
|
-
end
|
90
|
-
|
91
|
-
def encode64(str)
|
92
|
-
Base64.encode64(str).split("\n") * ""
|
93
|
-
end
|
94
|
-
|
95
|
-
def decode64(str)
|
96
|
-
Base64.decode64(str)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Aws
|
4
|
-
module S3
|
5
|
-
module Encryption
|
6
|
-
|
7
|
-
# The default key provider is constructed with a single key
|
8
|
-
# that is used for both encryption and decryption, ignoring
|
9
|
-
# the possible per-object envelope encryption materials description.
|
10
|
-
# @api private
|
11
|
-
class DefaultKeyProvider
|
12
|
-
|
13
|
-
include KeyProvider
|
14
|
-
|
15
|
-
# @option options [required, OpenSSL::PKey::RSA, String] :encryption_key
|
16
|
-
# The master key to use for encrypting objects.
|
17
|
-
# @option options [String<JSON>] :materials_description ('{}')
|
18
|
-
# A description of the encryption key.
|
19
|
-
def initialize(options = {})
|
20
|
-
@encryption_materials = Materials.new(
|
21
|
-
key: options[:encryption_key],
|
22
|
-
description: options[:materials_description] || '{}'
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
# @return [Materials]
|
27
|
-
def encryption_materials
|
28
|
-
@encryption_materials
|
29
|
-
end
|
30
|
-
|
31
|
-
# @param [String<JSON>] materials_description
|
32
|
-
# @return Returns the key given in the constructor.
|
33
|
-
def key_for(materials_description)
|
34
|
-
@encryption_materials.key
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'base64'
|
4
|
-
|
5
|
-
module Aws
|
6
|
-
module S3
|
7
|
-
module Encryption
|
8
|
-
# @api private
|
9
|
-
class EncryptHandler < Seahorse::Client::Handler
|
10
|
-
|
11
|
-
def call(context)
|
12
|
-
envelope, cipher = context[:encryption][:cipher_provider].encryption_cipher
|
13
|
-
apply_encryption_envelope(context, envelope, cipher)
|
14
|
-
apply_encryption_cipher(context, cipher)
|
15
|
-
apply_cse_user_agent(context)
|
16
|
-
@handler.call(context)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def apply_encryption_envelope(context, envelope, cipher)
|
22
|
-
context[:encryption][:cipher] = cipher
|
23
|
-
if context[:encryption][:envelope_location] == :metadata
|
24
|
-
context.params[:metadata] ||= {}
|
25
|
-
context.params[:metadata].update(envelope)
|
26
|
-
else # :instruction_file
|
27
|
-
suffix = context[:encryption][:instruction_file_suffix]
|
28
|
-
context.client.put_object(
|
29
|
-
bucket: context.params[:bucket],
|
30
|
-
key: context.params[:key] + suffix,
|
31
|
-
body: Json.dump(envelope)
|
32
|
-
)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def apply_encryption_cipher(context, cipher)
|
37
|
-
io = context.params[:body] || ''
|
38
|
-
io = StringIO.new(io) if String === io
|
39
|
-
context.params[:body] = IOEncrypter.new(cipher, io)
|
40
|
-
context.params[:metadata] ||= {}
|
41
|
-
context.params[:metadata]['x-amz-unencrypted-content-length'] = io.size
|
42
|
-
if context.params.delete(:content_md5)
|
43
|
-
warn('Setting content_md5 on client side encrypted objects is deprecated')
|
44
|
-
end
|
45
|
-
context.http_response.on_headers do
|
46
|
-
context.params[:body].close
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def apply_cse_user_agent(context)
|
51
|
-
if context.config.user_agent_suffix.nil?
|
52
|
-
context.config.user_agent_suffix = EC_USER_AGENT
|
53
|
-
elsif !context.config.user_agent_suffix.include? EC_USER_AGENT
|
54
|
-
context.config.user_agent_suffix += " #{EC_USER_AGENT}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Aws
|
4
|
-
module S3
|
5
|
-
module Encryption
|
6
|
-
# @api private
|
7
|
-
class IOAuthDecrypter
|
8
|
-
|
9
|
-
# @option options [required, IO#write] :io
|
10
|
-
# An IO-like object that responds to {#write}.
|
11
|
-
# @option options [required, Integer] :encrypted_content_length
|
12
|
-
# The number of bytes to decrypt from the `:io` object.
|
13
|
-
# This should be the total size of `:io` minus the length of
|
14
|
-
# the cipher auth tag.
|
15
|
-
# @option options [required, OpenSSL::Cipher] :cipher An initialized
|
16
|
-
# cipher that can be used to decrypt the bytes as they are
|
17
|
-
# written to the `:io` object. The cipher should already have
|
18
|
-
# its `#auth_tag` set.
|
19
|
-
def initialize(options = {})
|
20
|
-
@decrypter = IODecrypter.new(options[:cipher], options[:io])
|
21
|
-
@max_bytes = options[:encrypted_content_length]
|
22
|
-
@bytes_written = 0
|
23
|
-
end
|
24
|
-
|
25
|
-
def write(chunk)
|
26
|
-
chunk = truncate_chunk(chunk)
|
27
|
-
if chunk.bytesize > 0
|
28
|
-
@bytes_written += chunk.bytesize
|
29
|
-
@decrypter.write(chunk)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def finalize
|
34
|
-
@decrypter.finalize
|
35
|
-
end
|
36
|
-
|
37
|
-
def io
|
38
|
-
@decrypter.io
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def truncate_chunk(chunk)
|
44
|
-
if chunk.bytesize + @bytes_written <= @max_bytes
|
45
|
-
chunk
|
46
|
-
elsif @bytes_written < @max_bytes
|
47
|
-
chunk[0..(@max_bytes - @bytes_written - 1)]
|
48
|
-
else
|
49
|
-
# If the tag was sent over after the full body has been read,
|
50
|
-
# we don't want to accidentally append it.
|
51
|
-
""
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|