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

[WIP] ABW-1674: Import export profile as file with encryption #670

Merged
merged 76 commits into from
Aug 25, 2023

Conversation

CyonAlexRDX
Copy link
Contributor

@CyonAlexRDX CyonAlexRDX commented Aug 16, 2023

Jira ticket: ABW-1674

All exported files are JSON files, if profile snapshot is plaintext, it is just the JSON encoding of the snapshot saved as a .json file, if encryption is used then this json file is saved:

{
   "version": 1,
    "encryptionScheme":
    {
        "version": 1,
        "description": "AESGCM-256"
    },
    "encryptedSnapshot": "deadbeef.....",
    "keyDerivationScheme":
    {
        "version": 1,
        "description": "HKDFSHA256-with-UTF8-encoding-of-password-no-salt-no-info"
    }
}

The Swift model looks like this:

public struct EncryptedProfileSnapshot: Codable {
        public let version: Version

	/// Encrypted JSON encoding of a `ProfileSnapshot`
	public let encryptedSnapshot: HexCodable

	/// The KDF algorithm which was used to derive the encryption key from the user provided password.
	public let keyDerivationScheme: KeyDerivationScheme

	/// The encryption algorithm which was used to produce `encryptedSnapshot` with the encryption key
	/// derived using the `keyDerivationScheme`.
	public let encryptionScheme: EncryptionScheme
}

We are versioning KDF and encryption!! And that has been encapsulated in full by the types KeyDerivationScheme and EncryptionScheme, which when coded contains a version and a description property. Only version is used during decryption, but the description is useful nonetheless.

N.B.
The KDF and encryption used for profile snapshot is/will NOT be the same for SecurityQuestionsFactorSource!!! Which will use a much more complicated scheme (which should also be versioned...).

Example

Here follows to examples of file based manually exported profiles, one encrypted and one plaintext. Both are identical (once the encrypted have been decrypted...). Below is the mnemonics for them:

Mnemonics

  • Main mnemonic:
glimpse excite strike buyer error toss sleep oil menu more define album oyster target imitate possible vanish muffin current stove bench increase asset depart
  • Olympia 12 word mnemonic:
gentle hawk winner rain embrace erosion call update photo frost fatal wrestle
  • Olympia 18 word mnemonic:
smile entry satisfy shed margin rubber disorder hungry foot error ribbon cradle aim round october blind lab spend

Encrypted

The encryption password is

apabanan

File

(apparently I cannot upload JSON files to Github - wtf... so uploading them to Slack)
See encrypted file here on Slack

Plaintext

(apparently I cannot upload JSON files to Github - wtf... so uploading them to Slack)

See plaintext Profile file here on Slack

Pro-Tip: For DEBUG build under Advanced Mode in Import Mnemonic screen you can copy paste the mnemoncs...

Video

Updated video/demo from Wednesday 23rd of August: https://rdxworks.slack.com/archives/C031A0V1A1W/p1692798080432219

PR submission checklist

  • I have tested account to account transfer flow and have confirmed that it works

@CyonAlexRDX CyonAlexRDX added the DO NOT MERGE Merging is blocked or prohibited due to missing specs or other higher priority PRs label Aug 16, 2023
@CyonAlexRDX CyonAlexRDX changed the title [WIP ]ABW-1674: Import export profile as file w encryption [WIP] ABW-1674: Import export profile as file with encryption Aug 21, 2023
func path(
for store: StoreOf<RestoreProfileFromBackupCoordinator.Path>
) -> some SwiftUI.View {
SwitchStore(store) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to use the newer version of SwitchStore, where you get a reference to state in the closure, and you can switch on that. Still need to use CaseLet in the cases, but it still forces exhaustivity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice! I migrated ALL SwitchStores to this, see: 59c1a4a
@GhenadieVP ping ^^

Copy link
Contributor

Choose a reason for hiding this comment

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

Great work. Should probably test the Relayed one, I don't fully trust the Relay magic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested all relayed ( TransferAccountList and DappInteractionFlow) and they worked.

Copy link
Contributor

@kugel3 kugel3 left a comment

Choose a reason for hiding this comment

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

A work of art, only style comments.

then: { ChooseReceivingAccount.View(store: $0) }
)
SwitchStore(store.relay()) { state in

Copy link
Contributor

Choose a reason for hiding this comment

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

Extra space

@CyonAlexRDX CyonAlexRDX merged commit e9b1ccd into main Aug 25, 2023
5 checks passed
@CyonAlexRDX CyonAlexRDX deleted the ABW-1674_import_export_profile_as_file_w_encryption branch August 25, 2023 11:57
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants