Skip to content

periodically refresh keys from EKM #841

@tomholub

Description

@tomholub

part of #275

Each time the app starts, if clientConfiguration.usesKeyManager is true, the app should refetch keys from EKM and update the local ones. The fetch should be in the background, not holding up the app during startup. Thrown network errors can be ignored but not other types of errors (which should show error modal on whichever screen will load next)

The update mechanism should be similar to what we do for updating received public keys:

  • for each received key, check if we have that key in storage, by primary fingerprint
  • if we don't have the key in storage, add it
  • if we do, check if the received key is more recent than the local key, by dateLastModified
  • if received key is newer, replace stored key with the received one
  • else if it's same or older, leave the stored key as is

HOWEVER, these being private keys, we have to ensure to encrypt them with pass phrase before storing. If the pass phrase (for any of the existing keys already in storage) is already available, then we use the same pass phrase to encrypt each key that we are updating, and then store encrypted.

If the pass phrase is not available at that moment, then we display a pass phrase prompt (for iOS this would be just a modal) with Enter pass phrase to keep your account keys up to date. There would be an ok and cancel button, and cancel would do nothing, meaning next time the app restarts, they should see the same.

Ui tests can be written for this as follows:

test 1: app auto updates keys from EKM during startup with a pass phrase prompt

  • // stage 1 - setup
  • set up mock FES and EKM
    • FES should have FORBID_STORING_PASS_PHRASE
    • EKM should have any one key returned
  • set up the app
  • go to app settings -> keys and observe which key it has
  • // stage 2 - prompt appears / wrong pass phrase rejected / cancel
  • change EKM mock to start returning one more key
  • restart the app
  • observe that it shows EKM pass phrase prompt. Enter wrong pass phrase in the prompt. Observe it gets rejected / prompt remains.
  • cancel the prompt. check settings -> keys and observe it stayed the same
  • // stage 3 - new key gets added
  • restart the app.
  • enter the correct pass phrase. Observe that a toast message shows up with Account keys updated
  • go to settings -> keys and observe that it updated the keys
  • // stage 4 - modified key gets updated, removed key does not get removed
  • change EKM mock to start returning an updated version of one of the existing keys. Stop returning the other key
  • restart app, enter pass phrase into prompt, observe Account keys updated
  • go to settings -> keys. Observe that no key was removed, and then updated key was updated
  • // stage 5 - older version of key does not get updated
  • change EKM mock to start returning only the older version of that modified key again
  • restart app
  • observe no prompt shows
  • go to settings -> keys. Observe keys remain the same as in stage 4.
  • success

test 2: app auto updates keys from EKM during startup without pass phrase prompt

  • // stage 1 - setup
  • set up mock FES and EKM
    • FES should NOT have FORBID_STORING_PASS_PHRASE
    • EKM should have any one key returned
  • set up the app
  • go to app settings -> keys and observe which key it has
  • // stage 2 - keys get autoupdated
  • change EKM mock to start returning one more key
  • restart the app
  • observe that a toast message shows up with Account keys updated
  • go to settings -> keys and observe that a key was added
  • // stage 3 - nothing to update
  • restart the app
  • observe that no toast shows during startup
  • go to settings -> keys and see they are unchanged

test 3: EKM key update errors handled gracefully

  • // stage 1 - setup
  • set up mock FES and EKM, with one key returned by EKM
  • set up the app
  • go to app settings -> keys and observe which key it has
  • // stage 2 - EKM down
  • change EKM mock to start returning error 500
  • restart the app
  • observe that no modal shows during startup. Go to app settings -> keys, notice keys stayed the same
  • // stage 3 - error shown to user
  • change EKM mock to start returning a broken key (for example, only return the first half of the armored key text)
  • restart the app
  • observe that the app shows a modal during startup Could not update keys from EKM due to error: and followed by whatever error happened.
  • tap close on the modal and observe that inbox loads normally
  • go to app settings -> keys and observe they stayed the same

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions