Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tear down scaffolding for migrating to sessions w/ KMS contexts #2790

Merged
merged 5 commits into from
Mar 14, 2019
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
10 changes: 1 addition & 9 deletions app/services/encryption/encryptors/session_encryptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SessionEncryptor

def encrypt(plaintext)
aes_ciphertext = AesEncryptor.new.encrypt(plaintext, aes_encryption_key)
kms_ciphertext = encrypt_with_kms(aes_ciphertext)
kms_ciphertext = KmsClient.new.encrypt(aes_ciphertext, 'context' => 'session-encryption')
encode(kms_ciphertext)
end

Expand All @@ -18,14 +18,6 @@ def decrypt(ciphertext)

private

def encrypt_with_kms(ciphertext)
if FeatureManagement.use_kms_context_for_sessions?
KmsClient.new.encrypt(ciphertext, 'context' => 'session-encryption')
else
ContextlessKmsClient.new.encrypt(ciphertext)
end
end

def aes_encryptor
AesEncryptor.new
end
Expand Down
3 changes: 0 additions & 3 deletions config/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ development:
twilio_record_voice: 'true'
use_dashboard_service_providers: 'true'
use_kms: 'false'
use_kms_context_for_sessions: 'false'
usps_confirmation_max_days: '10'
enable_load_testing_mode: 'false'
usps_download_sftp_directory: '/undeliverable'
Expand Down Expand Up @@ -323,7 +322,6 @@ production:
twilio_record_voice: 'false'
twilio_verify_api_key: 'change-me'
use_kms: 'true'
use_kms_context_for_sessions: 'false'
usps_confirmation_max_days: '30'
enable_load_testing_mode: 'false'
usps_download_sftp_directory:
Expand Down Expand Up @@ -443,7 +441,6 @@ test:
twilio_record_voice: 'true'
twilio_verify_api_key: 'secret'
use_kms: 'false'
use_kms_context_for_sessions: 'true'
usps_confirmation_max_days: '10'
enable_load_testing_mode: 'false'
usps_download_sftp_directory: '/undeliverable'
Expand Down
4 changes: 0 additions & 4 deletions lib/feature_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,4 @@ def self.backup_codes_enabled?
def self.send_new_device_sms?
Figaro.env.send_new_device_sms == 'true'
end

def self.use_kms_context_for_sessions?
Figaro.env.use_kms_context_for_sessions == 'true'
end
end
36 changes: 8 additions & 28 deletions spec/services/encryption/encryptors/session_encryptor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,14 @@
expect(ciphertext).to eq(expected_ciphertext)
end

context 'when use_kms_context_for_sessions is true' do
before do
allow(FeatureManagement).to receive(:use_kms_context_for_sessions?).and_return(true)
end

it 'sets an encryption context' do
client = instance_double(Encryption::KmsClient)
expect(client).to receive(:encrypt).with(
instance_of(String), 'context' => 'session-encryption'
).and_return('kms_ciphertext')
allow(Encryption::KmsClient).to receive(:new).and_return(client)

subject.encrypt(plaintext)
end
end

context 'when use_kms_context_for_sessions is false' do
before do
allow(FeatureManagement).to receive(:use_kms_context_for_sessions?).and_return(false)
end

it 'does not set an encryption context' do
client = instance_double(Encryption::ContextlessKmsClient)
expect(client).to receive(:encrypt).with(instance_of(String)).and_return('kms_ciphertext')
allow(Encryption::ContextlessKmsClient).to receive(:new).and_return(client)

subject.encrypt(plaintext)
end
it 'sets an encryption context' do
client = instance_double(Encryption::KmsClient)
expect(client).to receive(:encrypt).with(
instance_of(String), 'context' => 'session-encryption'
).and_return('kms_ciphertext')
allow(Encryption::KmsClient).to receive(:new).and_return(client)

subject.encrypt(plaintext)
end
end

Expand Down