Skip to content
This repository was archived by the owner on Apr 22, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions source/aws-ruby-sdk/encryption_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,18 @@ def decrypt(data:, iv:, key:)

cipher.update(data[0..-17]) + cipher.final
end

def encrypt(data:, iv:, key:)
cipher = OpenSSL::Cipher.new('aes-256-gcm')
cipher.encrypt
cipher.iv = iv
cipher.key = key
cipher.auth_data = ''

encrypted = cipher.update(data) + cipher.final
tag = cipher.auth_tag # produces 16 bytes tag by default

encrypted + tag
end
end
end
20 changes: 11 additions & 9 deletions source/proof_document_mock/spec/proof_document_mock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,17 @@
let(:selfie_image_url) { 'http://example.com/bar3' }

before do
stub_request(:get, front_image_url).to_return(
body: encrypt(data: applicant_pii.to_json, key: encryption_key, iv: front_image_iv),
)
stub_request(:get, back_image_url).to_return(
body: encrypt(data: applicant_pii.to_json, key: encryption_key, iv: back_image_iv),
)
stub_request(:get, selfie_image_url).to_return(
body: encrypt(data: applicant_pii.to_json, key: encryption_key, iv: selfie_image_iv),
)
encryption_helper = IdentityIdpFunctions::EncryptionHelper.new

stub_request(:get, front_image_url).to_return(body: encryption_helper.encrypt(
data: applicant_pii.to_json, key: encryption_key, iv: front_image_iv,
))
stub_request(:get, back_image_url).to_return(body: encryption_helper.encrypt(
data: applicant_pii.to_json, key: encryption_key, iv: back_image_iv,
))
stub_request(:get, selfie_image_url).to_return(body: encryption_helper.encrypt(
data: applicant_pii.to_json, key: encryption_key, iv: selfie_image_iv,
))
end

it 'still downloads and decrypts the content' do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/encryption_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let(:plaintext) { 'the quick brown fox jumps over the lazy dog' }

it 'decrypts data' do
encrypted = encrypt(data: plaintext, iv: iv, key: key)
encrypted = encryption_helper.encrypt(data: plaintext, iv: iv, key: key)

expect(encryption_helper.decrypt(data: encrypted, iv: iv, key: key)).to eq(plaintext)
end
Expand Down
17 changes: 3 additions & 14 deletions spec/support/encryption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ def encrypt_and_stub_s3(body:, url:, iv:, key:)
prefix = URI(url).path.gsub(%r{^/}, '')

@responses ||= {}
@responses[prefix] = encrypt(data: body, iv: iv, key: key)
@responses[prefix] = IdentityIdpFunctions::EncryptionHelper.new.encrypt(
data: body, iv: iv, key: key,
)

Aws.config[:s3] = {
stub_responses: {
Expand All @@ -12,16 +14,3 @@ def encrypt_and_stub_s3(body:, url:, iv:, key:)
},
}
end

def encrypt(data:, iv:, key:)
cipher = OpenSSL::Cipher.new('aes-256-gcm')
cipher.encrypt
cipher.iv = iv
cipher.key = key
cipher.auth_data = ''

encrypted = cipher.update(data) + cipher.final
tag = cipher.auth_tag # produces 16 bytes tag by default

encrypted + tag
end