Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

[AD-270] Check keyfile for unknown keys on startup #299

Merged

Conversation

Haskell-mouse
Copy link
Contributor

@Haskell-mouse Haskell-mouse commented Sep 4, 2018

YT issue: https://issues.serokell.io/issue/AD-270

Checklist:

Description:

It's possible that key file has more secret keys than there are wallets in wallet DB. Btw, the opposite is impossible.

So - now unknown keys are deleted on startup.

Copy link
Member

@gromakovsky gromakovsky left a comment

Choose a reason for hiding this comment

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

Looks good. Rejecting only because it conflicts with #288 and I'd like to merge that PR ASAP. Will approve after #288 is merged (hopefully tomorrow) and conflicts are resolved.

ariadne/cardano/src/Ariadne/Wallet/Backend.hs Outdated Show resolved Hide resolved
Copy link
Contributor

@artemohanjanyan artemohanjanyan left a comment

Choose a reason for hiding this comment

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

Otherwise, looks sensible

ariadne/cardano/src/Ariadne/MainTemplate.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/Wallet/Backend/KeyStorage.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/Wallet/Backend/KeyStorage.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/Wallet/Backend/KeyStorage.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/Wallet/Backend/KeyStorage.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/Wallet/Backend/KeyStorage.hs Outdated Show resolved Hide resolved
@gromakovsky
Copy link
Member

I suddenly realized that this solution is dangerous. If user somehow passes wrong path to wallet-db, all secret keys will be deleted and it may cause loss of funds. I see two options:

  1. Use some heuristics to decide whether to delete secret keys (e. g. if set of keys is similar to set of wallets).
  2. Insert into wallet DB first and delete from keyfile first. Then on startup we'll have to delete stuff from wallet DB, which is less dangerous.

Both options don't sound very good :/
I'll get back to it tomorrow.

@Haskell-mouse
Copy link
Contributor Author

Maybe we shoud just check for empty wallet-db on startup and ask user about correctness of wallet-db path in case of empty wallet-db and non-empty keyfile ?
Another option is creating backup of keyfile in case of deletion of keys on startup.

@gromakovsky
Copy link
Member

This is the thread where we discussed how to proceed with the issue: https://serokell.slack.com/archives/C9B1DAMDJ/p1536319212000100

@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch from 8c37986 to f8012ab Compare October 22, 2018 01:20
@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch 3 times, most recently from 8aa0ca1 to cb45051 Compare October 22, 2018 17:05
Copy link
Member

@gromakovsky gromakovsky left a comment

Choose a reason for hiding this comment

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

I haven't reviewed whole PR yet, but there already are some things which need to be changed. Will make another round of review later.
Next time you make a PR, please check that CI passes a bit later (when it finishes), currently there are some warnings and it fails.

stack-to-nix.yaml Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/MainTemplate.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/MainTemplate.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/MainTemplate.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/Wallet/Backend/KeyStorage.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/MainTemplate.hs Outdated Show resolved Hide resolved
@Haskell-mouse
Copy link
Contributor Author

It is really strange (i am talking about CI), because i have "-Werror" option enabled in generated ".cabal" file an have no warnings. Will fix now.

@gromakovsky
Copy link
Member

If you are using make dev or something similar, keep in mind that it passes -Wwarn to GHC.

@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch 2 times, most recently from ce005c6 to 1492c22 Compare October 24, 2018 02:09
@Haskell-mouse
Copy link
Contributor Author

updated PR

@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch from 1492c22 to eb59171 Compare October 25, 2018 01:53
ariadne/cardano/src/Ariadne/Wallet/Backend/KeyStorage.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/Wallet/Backend/KeyStorage.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/Wallet/Face.hs Outdated Show resolved Hide resolved
ariadne/core/src/Ariadne/UIConfig.hs Outdated Show resolved Hide resolved
ariadne/core/src/Ariadne/UIConfig.hs Outdated Show resolved Hide resolved
@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch 3 times, most recently from dcdd264 to 702b754 Compare November 5, 2018 17:48
@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch from 3eea9c6 to 0ffdd4b Compare November 8, 2018 12:58
@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch from f38ebb8 to 81b4579 Compare November 12, 2018 17:59
Copy link
Contributor

@artemohanjanyan artemohanjanyan left a comment

Choose a reason for hiding this comment

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

I'll review the rest of the code a bit later. Couple of comments for now and this bug I noticed. Steps to reproduce:

  1. Launch Ariadne.
  2. new-wallet name: "A" no-confirm: true
  3. Close Ariadne.
  4. Open Ariadne.
  5. Remove previously created wallet "A".
  6. Close Ariadne.
  7. Open Ariadne and behold some weird wallet and unknown keys dialog.

ariadne/cardano/src/Ariadne/Wallet/Backend.hs Outdated Show resolved Hide resolved
ariadne/cardano/src/Ariadne/Wallet/Backend.hs Outdated Show resolved Hide resolved
ariadne/core/src/Ariadne/UIConfig.hs Outdated Show resolved Hide resolved
@Haskell-mouse
Copy link
Contributor Author

@artemohanjanyan
Can't reproduce the bug, tried it few times and have no that new weird wallet (

@@ -192,10 +192,11 @@ deleteHdWallet pw rootId = do
Keystore.delete (WalletIdHdSeq rootId) (pw ^. walletKeystore)
return $ Right ()

removeKeysFromKeyStore :: PassiveWallet
removeKeysFromKeystore
:: PassiveWallet
Copy link
Member

Choose a reason for hiding this comment

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

Now indentation looks very weird.

Copy link
Member

Choose a reason for hiding this comment

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

Why was it marked as resolved? It's 1-space indentation here. It's not allowed.

Copy link
Contributor Author

@Haskell-mouse Haskell-mouse Nov 25, 2018

Choose a reason for hiding this comment

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

It was marked as resolved because it is resolved. I made the same indentation as in other functions in the module. Here you see the old version before the last commit. Look

Copy link
Member

Choose a reason for hiding this comment

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

Hm, strange, I was pretty sure I was looking at the latest version last time I saw it. Ok then.

@dniku dniku changed the title [AD-270]Now keyfile is checked for unknown keys on startup [AD-270] Now keyfile is checked for unknown keys on startup Nov 19, 2018
@dniku dniku changed the title [AD-270] Now keyfile is checked for unknown keys on startup [AD-270] Check keyfile for unknown keys on startup Nov 19, 2018
@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch 4 times, most recently from 705f519 to dc53c2c Compare November 22, 2018 11:18
@gromakovsky
Copy link
Member

There's a new conflict, btw.

@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch from dc53c2c to cfdf857 Compare November 23, 2018 08:30
@Haskell-mouse
Copy link
Contributor Author

Resolved

QWidget.adjustSize delete
_ -> pass


Copy link
Member

Choose a reason for hiding this comment

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

Extra newline.

@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch 2 times, most recently from ee01271 to 937633a Compare November 25, 2018 05:25
ariadne/cardano/src/Ariadne/MainTemplate.hs Show resolved Hide resolved
ariadne/cardano/src/Ariadne/Wallet/Backend/KeyStorage.hs Outdated Show resolved Hide resolved
import Ariadne.Wallet.Cardano.Kernel.DB.AcidState (DB, dbHdWallets, defDB)
import Ariadne.Wallet.Cardano.Kernel.DB.Resolved (ResolvedBlock)
import Ariadne.Wallet.Cardano.Kernel.Keystore (Keystore)

import qualified Ariadne.Wallet.Cardano.Kernel.Keystore as Keystore (lookup)
Copy link
Member

Choose a reason for hiding this comment

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

Why was this import moved?

ui/qt-lib/src/Ariadne/UI/Qt/Widgets/Dialogs/Delete.hs Outdated Show resolved Hide resolved
@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch from bd5e4c8 to 9f7d683 Compare November 30, 2018 09:29
Copy link
Member

@gromakovsky gromakovsky left a comment

Choose a reason for hiding this comment

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

Ok. @artemohanjanyan please take a look.

Copy link
Contributor

@artemohanjanyan artemohanjanyan left a comment

Choose a reason for hiding this comment

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

I also suspect that some text is not entirely correct according to English, but I'm not sure.


rmBrokenWalletsIntroMkMessage :: Text
rmBrokenWalletsIntroMkMessage = "There are wallets without corresponding secret key \
\in keyfile.\n Without secret keys you can do almost nothing with such wallets. \
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that

Suggested change
\in keyfile.\n Without secret keys you can do almost nothing with such wallets. \
\in keyfile. Without secret keys you can do almost nothing with such wallets. \

is better, but 🤷‍♂️

Problem: Keyfile may contain unknown keys (from deleted wallets for example)
         Also sometimes we may have wallets without corresponding keys
         in keyfile (user can delete keys by hands).

Solution: Now keyfile is checked for unknown keys on startup
          and user is asked if he wants to delete them.

          Also wallets are checked for existence of
          corresponding secret keys in keyfile. User will be
          asked if he wants to delete broken wallets
          (without secret key).

          Also added small chages to qt and vty UI - made text on deletion
          widget dependent on deleting item
          (and delete confirmation widget is used to ask user,
          with changed text on widget,
          and added new type of deleting item - unknownKeys and brokenWallets).
@Haskell-mouse Haskell-mouse force-pushed the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch from 9f7d683 to 6caec98 Compare December 13, 2018 18:31
@Haskell-mouse Haskell-mouse merged commit 6caec98 into master Dec 13, 2018
@serokell-bot serokell-bot deleted the Haskell-mouse/ad270-Delete-useless-secret-keys-on-start branch December 13, 2018 21:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants