Skip to content
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
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def fix_broken_personal_key_url

flash[:info] = t('account.personal_key.needs_new')

pii_unlocked = user_session[:decrypted_pii].present?
pii_unlocked = Pii::Cacher.new(current_user, user_session).exists_in_session?

if pii_unlocked
cacher = Pii::Cacher.new(current_user, user_session)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/idv/gpo_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def non_address_pii
end

def pii_to_h
JSON.parse(user_session[:decrypted_pii])
JSON.parse(
Pii::Cacher.new(current_user, user_session).fetch_string,
)
end

def resolution_success(hash)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/idv/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def destroy
analytics.track_event(Analytics::IDV_START_OVER, **location_params)
user_session['idv/doc_auth'] = {}
idv_session.clear
user_session.delete(:decrypted_pii)
Pii::Cacher.new(current_user, user_session).delete
redirect_to idv_url
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/openid_connect/authorization_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def store_request
def pii_requested_but_locked?
sp_session && sp_session_ial > 1 &&
UserDecorator.new(current_user).identity_verified? &&
user_session[:decrypted_pii].blank?
!Pii::Cacher.new(current_user, user_session).exists_in_session?
end

def track_events
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/saml_idp_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def profile_or_identity_needs_verification_or_decryption?
end

def identity_needs_decryption?
UserDecorator.new(current_user).identity_verified? && user_session[:decrypted_pii].blank?
UserDecorator.new(current_user).identity_verified? &&
!Pii::Cacher.new(current_user, user_session).exists_in_session?
end

def capture_analytics
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/sign_up/completions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def track_completion_event(last_page)
end

def pii
JSON.parse(user_session.fetch('decrypted_pii', '{}')).symbolize_keys
pii_string = Pii::Cacher.new(current_user, user_session).fetch_string
JSON.parse(pii_string || '{}', symbolize_names: true)
end
end
end
3 changes: 2 additions & 1 deletion app/controllers/users/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def update
private

def capture_password_if_pii_requested_but_locked
return unless current_user.decorate.identity_verified? && user_session[:decrypted_pii].blank?
return unless current_user.decorate.identity_verified? &&
!Pii::Cacher.new(current_user, user_session).exists_in_session?
user_session[:stored_location] = request.url
redirect_to capture_password_url
end
Expand Down
19 changes: 16 additions & 3 deletions app/services/pii/cacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@ def save(user_password, profile = user.active_profile)
end

def fetch
decrypted_pii = user_session[:decrypted_pii]
return unless decrypted_pii
Pii::Attributes.new_from_json(decrypted_pii)
pii_string = fetch_string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking of using this same tooling to handle the PII that is moving through the proofing flow? I'm curious what that looks like if so.

May be an irrelevant question in an FSMv2 world where we store the unverified PII on the client. But I suspect we'll want the changes to reduce KMS calls in place before we get there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, yeah. It kind of requires a more central way to manage which FSMv2 can hopefully bring.

We do know the top-level keys that are used (idv/doc_auth and idv), but one of those is probably accessed during each proofing step anyway? It may be easier to encrypt/decrypt those in their entirety during the proofing process.

return nil unless pii_string

Pii::Attributes.new_from_json(pii_string)
end

def fetch_string
user_session[:decrypted_pii]
end

def exists_in_session?
fetch_string.present?
end

def delete
user_session.delete(:decrypted_pii)
end

private
Expand Down
3 changes: 2 additions & 1 deletion app/services/pii/session_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def initialize(session_uuid)

def load
session = session_accessor.load
Pii::Attributes.new_from_json(session.dig('warden.user.user.session', :decrypted_pii))

Pii::Cacher.new(nil, session.dig('warden.user.user.session')).fetch
end

# @api private
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/saml_idp_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def name_id_version(format_urn)
zipcode: '12345',
)
end
let(:pii_json) { pii.present? ? pii.to_json : nil }
let(:this_authn_request) do
ial2_authnrequest = saml_authn_request_url(
overrides: {
Expand Down Expand Up @@ -481,7 +482,7 @@ def name_id_version(format_urn)
)
allow(subject).to receive(:attribute_asserter) { asserter }

controller.user_session[:decrypted_pii] = pii
controller.user_session[:decrypted_pii] = pii_json
end

it 'calls AttributeAsserter#build' do
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/users/passwords_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
end

it 'renders form if PII is decrypted' do
controller.user_session[:decrypted_pii] = pii
controller.user_session[:decrypted_pii] = pii.to_json

get :edit

Expand Down