Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tear down scaffolding for migrating to sessions w/ KMS contexts
Browse files Browse the repository at this point in the history
**Why**: After #2787 is deployed, we won't be using contextless KMS for
session encryption anymore.

This should not be merged until after #2787 is deployed to production
and the feature flags have been adjusted to have the new instances write
sessions encrypted with KMS contexts.
jmhooper committed Feb 27, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 5f1a887 commit 5694284
Showing 4 changed files with 9 additions and 44 deletions.
10 changes: 1 addition & 9 deletions app/services/encryption/encryptors/session_encryptor.rb
Original file line number Diff line number Diff line change
@@ -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

@@ -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
3 changes: 0 additions & 3 deletions config/application.yml.example
Original file line number Diff line number Diff line change
@@ -204,7 +204,6 @@ development:
twilio_record_voice: 'true'
use_dashboard_service_providers: 'true'
use_kms: 'false'
use_kms_context_for_sessions: 'false'
use_kms_contexts: 'false'
usps_confirmation_max_days: '10'
enable_load_testing_mode: 'false'
@@ -319,7 +318,6 @@ production:
twilio_record_voice: 'false'
twilio_verify_api_key: 'change-me'
use_kms: 'true'
use_kms_context_for_sessions: 'false'
use_kms_contexts: 'false'
usps_confirmation_max_days: '30'
enable_load_testing_mode: 'false'
@@ -438,7 +436,6 @@ test:
twilio_record_voice: 'true'
twilio_verify_api_key: 'secret'
use_kms: 'false'
use_kms_context_for_sessions: 'true'
use_kms_contexts: 'true'
usps_confirmation_max_days: '10'
enable_load_testing_mode: 'false'
4 changes: 0 additions & 4 deletions lib/feature_management.rb
Original file line number Diff line number Diff line change
@@ -109,8 +109,4 @@ def self.use_kms_contexts?
def self.write_2lkms_passwords?
Figaro.env.write_2lkms_passwords == '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
@@ -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

0 comments on commit 5694284

Please sign in to comment.