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

[wallet]Store encrypted local signing key #1188

Merged
merged 2 commits into from
Oct 4, 2019

Conversation

ashishb
Copy link
Contributor

@ashishb ashishb commented Oct 2, 2019

Description

Store encrypted local signing key, the encryption password is coming
from the Android Keystore.

Tested

Unit test

$ node_modules/.bin/jest src/web3/saga.test.ts

Manual test

  1. Set DEFAULT_SYNC_MODE=-1 in packages/mobile/.env
  2. packages/mobile $ yarn run dev. Log in verify that you can send money.
  3. Check the contents of the file /data/data/$APP_ID/files/private_key_for_<address>.txt are encrypted hex-encoded key 8672a59c5d55302a5d64288084137303f5cd431abbff3d1edeca4b1c9f8266c41148d712c99d26b52165a6426b048ab1710c6311154c66e75e071386538c7a0091a920d1167d729a8916ad646099adfd

Related issues

Backwards compatibility

Not backward compatible but this code path was added yesterday (Oct 1) and is still behind a flag. So, it is not an issue.

@ashishb ashishb force-pushed the ashishb/web3_local_signing_encrypt_password branch from 8409590 to 989dd42 Compare October 2, 2019 20:20
@codecov
Copy link

codecov bot commented Oct 2, 2019

Codecov Report

Merging #1188 into master will decrease coverage by 0.06%.
The diff coverage is 34.78%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1188      +/-   ##
=========================================
- Coverage   66.16%   66.1%   -0.07%     
=========================================
  Files         261     261              
  Lines        7599    7618      +19     
  Branches      508     440      -68     
=========================================
+ Hits         5028    5036       +8     
- Misses       2474    2487      +13     
+ Partials       97      95       -2
Flag Coverage Δ
#mobile 66.1% <34.78%> (-0.07%) ⬇️
Impacted Files Coverage Δ
packages/mobile/src/web3/saga.ts 50.31% <34.78%> (-1.1%) ⬇️
packages/mobile/src/utils/formatting.ts 89.74% <0%> (ø) ⬆️
packages/mobile/src/identity/reducer.ts 41.66% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a23aef3...7429a06. Read the comment docs.

packages/mobile/src/web3/saga.ts Outdated Show resolved Hide resolved
packages/mobile/src/web3/saga.ts Outdated Show resolved Hide resolved
packages/mobile/src/web3/saga.ts Show resolved Hide resolved
@@ -230,8 +235,34 @@ export async function readPrivateKeyFromLocalDisk(
): Promise<string> {
const filePath = getPrivateKeyFilePath(account)
Logger.debug('readPrivateKeyFromLocalDisk', `Reading private key from ${filePath}`)
// TODO(ashishb): Read and decrypt private key instead
return RNFS.readFile(getPrivateKeyFilePath(account))
const hexEncodedEncryptedData: string = await RNFS.readFile(filePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, these explicit typings (varName: type) aren't necessary unless the function/object your calling is missing a type, which usually shouldnt be the case

Copy link
Contributor Author

@ashishb ashishb Oct 3, 2019

Choose a reason for hiding this comment

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

It is not necessary, but I find it helpful when there is a mix going on.

const hexEncodedEncryptedData: string = await RNFS.readFile(filePath)
const encryptedDataBuffer: Buffer = new Buffer(hexEncodedEncryptedData, 'hex')
const privateKey: string = getDecryptedData(encryptedDataBuffer, encryptionPassword)

Copy link
Contributor

@annakaz annakaz left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Logger.debug('savePrivateKeyToLocalDisk', `Writing private key to ${filePath}`)
// TODO(ashishb): Store encrypted private key instead
await RNFS.writeFile(getPrivateKeyFilePath(account), privateKey)
const plainTextData = privateKey
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why not skip the variable assignment and just pass privateKey into the function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getEncryptedData(privateKey, encryptionPassword) felt a bit confusing to read.

// TODO(ashishb): Read and decrypt private key instead
return RNFS.readFile(getPrivateKeyFilePath(account))
const hexEncodedEncryptedData: string = await RNFS.readFile(filePath)
const encryptedDataBuffer: Buffer = new Buffer(hexEncodedEncryptedData, 'hex')
Copy link
Contributor

Choose a reason for hiding this comment

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

@jmrossy On the other hand, I find this explicit typing to help with readability in cases that switch between strings/buffers/etc
Some linting rules will prevent explicit typing for common types like numbers, strings (ex: https://palantir.github.io/tslint/rules/no-inferrable-types/) but in the case of less common types I find the explicit typing helpful

Store encrypted local signing key, the encryption password is coming
from the Android keystore.
@ashishb ashishb force-pushed the ashishb/web3_local_signing_encrypt_password branch from 83f5cf3 to 6b587f4 Compare October 3, 2019 19:50
@ashishb ashishb added the automerge Have PR merge automatically when checks pass label Oct 4, 2019
@ashishb ashishb merged commit 13f353a into master Oct 4, 2019
@ashishb ashishb deleted the ashishb/web3_local_signing_encrypt_password branch October 4, 2019 18:47
aaronmgdr added a commit that referenced this pull request Oct 8, 2019
* master: (35 commits)
  [Wallet] Fix top of emojis cut off in the activity feed (#1243)
  Adding a contract to store minimum required client version (#1081)
  Revert "Feature #909 proxy delegatecall (#1152)" (#1241)
  Use ContractKit to get addresses for Blockchain API (#1175)
  Feature #909 proxy delegatecall (#1152)
  Fix Faucet done message (#1217)
  Updated SETUP.md with new yarn process (#1224)
  Adding `increaseAllowance` and `decreaseAllowance` methods (#1196)
  extracting function signatures (#1061)
  Fix integration hardcode (#1208)
  Fixing flaky governance test (#1155)
  Restore CI branch (#1223)
  [wallet] e2e back to green (#1210)
  [Wallet] Implement new import wallet flow designs (#1209)
  [Wallet] Fix disable conditions for butons on Enter Invite screen (#1214)
  [protocol] Rename infrastructureFraction to proposerFraction (#1174)
  [ck] Proper promise treatment to avoid UnhandledPromises (#1219)
  [ck] Transform StableToken parameters from fixidity format (#1218)
  [wallet]Store encrypted local signing key (#1188)
  2019-10-03 alfajores deployment (#1200)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Have PR merge automatically when checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Users SBAT to store encrypted key for local signing
4 participants