Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Encrypting necessary local storage data #286

Merged
merged 6 commits into from
Jul 29, 2022
Merged

Conversation

blakecduncan
Copy link
Contributor

@blakecduncan blakecduncan commented Jul 26, 2022

What is this PR doing?

Adding a local cell collection that encrypts the values before persisting to local storage

How can these changes be manually tested?

Yes this was tested. There should be no functional UX changes to the app.

Does this PR resolve or contribute to any issues?

277

Checklist

  • I have manually tested these changes
  • Post a link to the PR in the group chat

Guidelines

  • If your PR is not ready, mark it as a draft
  • The resolve conversation button is for reviewers, not authors
    • (But add a 'done' comment or similar)

@github-actions github-actions bot added the extension Browser extension related label Jul 26, 2022
@blakecduncan blakecduncan marked this pull request as draft July 26, 2022 09:33

// TODO: Store users key that is generated from the password in memory so we
// don't keep a copy of the password
const PASSWORD = 'TEMP_PASSWORD';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought for a first PR it would be good to just get the encryption working. I figure as a separate PR I'll store the pass key in memory.

If anyone has any recommendations on how I should do that, let me know. I know that metamask uses obs-store to keep the password in memory.

Copy link
Contributor

Choose a reason for hiding this comment

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

works for now 👍🏼

@@ -32,7 +35,7 @@ function QuillStorageCells(storage: CellCollection) {
completed: false,
}),
),
keyring: storage.Cell(
keyring: encryptedStorage.Cell(
Copy link
Contributor Author

@blakecduncan blakecduncan Jul 26, 2022

Choose a reason for hiding this comment

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

This was the cleanest way I could think of to allow both encrypted and decrypted storage. If anyone has alternative ideas let me know.

This approach allows us to only encrypt specific cells. So for example, we can keep the preferences decrypted

Copy link
Contributor

Choose a reason for hiding this comment

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

This is perfect! I was wishing for exactly the same setup. Just change the storage type and your collection is good to go.


const payload = JSON.parse(readResult);
const { salt } = payload;
const passwordKey = await encryptor.keyFromPassword(PASSWORD, salt);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This key from password part will be moved somewhere else once we are keeping the key in memory

@blakecduncan blakecduncan self-assigned this Jul 26, 2022
@blakecduncan blakecduncan marked this pull request as ready for review July 26, 2022 10:08
@blakecduncan blakecduncan changed the title First attempt at encrypting the local storage Encrypting necessary local storage data Jul 26, 2022
Copy link
Contributor

@kautukkundan kautukkundan left a comment

Choose a reason for hiding this comment

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

The changes are good! Exactly what I was hoping for. Left some minor comments related to grouping of similar items.

@@ -32,7 +35,7 @@ function QuillStorageCells(storage: CellCollection) {
completed: false,
}),
),
keyring: storage.Cell(
keyring: encryptedStorage.Cell(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is perfect! I was wishing for exactly the same setup. Just change the storage type and your collection is good to go.

@@ -19,7 +19,10 @@ import { QuillTransaction } from './types/Rpc';
// fields that always have concrete values incrementally without breaking
// existing clients.

function QuillStorageCells(storage: CellCollection) {
function QuillStorageCells(
storage: CellCollection,
Copy link
Contributor

Choose a reason for hiding this comment

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

lets make this change to be more explicit about the storage type

- storage
+ standardStorage

A few more places within the file

Comment on lines 55 to 59
public storage: CellCollection,
public encryptedStorage: CellCollection,
public currencyConversionConfig: CurrencyConversionConfig,
) {
this.cells = QuillStorageCells(storage);
this.cells = QuillStorageCells(storage, encryptedStorage);
Copy link
Contributor

@kautukkundan kautukkundan Jul 26, 2022

Choose a reason for hiding this comment

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

considering storage and encryptedStorage are types of the same entity, we can group these and pass as an object instead of 2 different constructor arguments

lets create a new type

export type StorageConfig = {
  standardStorage: CellCollection;
  encryptedStorage: CellCollection;
};

and modify the constructor to accept a single storage object

public storage: StorageConfig,

and access standardStorage and encryptedStorage separately

- this.cells = QuillStorageCells(storage, encryptedStorage);
+ this.cells = QuillStorageCells(storage.standardStorage, storage.encryptedStorage);

@@ -19,7 +19,10 @@ import { QuillTransaction } from './types/Rpc';
// fields that always have concrete values incrementally without breaking
// existing clients.

function QuillStorageCells(storage: CellCollection) {
function QuillStorageCells(
Copy link
Contributor

@kautukkundan kautukkundan Jul 26, 2022

Choose a reason for hiding this comment

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

the separate arguments are fine here since this function only handles storage 👍🏼

Comment on lines 73 to 74
storage: CellCollection,
encryptedStorage: CellCollection,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same changes as QuillController's constructor can be made here by importing the StorageConfig type since both arguments are part of same entity.

Comment on lines 18 to 19
extensionLocalCellCollection,
encryptedLocalCellCollection,
Copy link
Contributor

Choose a reason for hiding this comment

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

this would be converted to a single object as per changes mentioned above.


// TODO: Store users key that is generated from the password in memory so we
// don't keep a copy of the password
const PASSWORD = 'TEMP_PASSWORD';
Copy link
Contributor

Choose a reason for hiding this comment

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

works for now 👍🏼

Copy link
Contributor

@kautukkundan kautukkundan left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏼

@blakecduncan blakecduncan merged commit 04af3ae into main Jul 29, 2022
@blakecduncan blakecduncan deleted the encrypt-local-storage branch July 29, 2022 09:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extension Browser extension related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants