Author

Topic: What happens when you unlock the wallet? (Read 141 times)

staff
Activity: 3458
Merit: 6793
Just writing some code
September 26, 2021, 06:56:47 PM
#4
When you unlock the wallet, the password is used to decrypt the key actually used to encrypt the private keys. That decryption key is stored in the wallet as vMasterKey. It will remain there in memory (and thus the wallet is unlocked) until CWallet::Lock is called to remove it from memory and thus lock the wallet.

When you use the walletpassphrase RPC, a timer thread will be scheduled to run after the given timeout. That thread will just call CWallet::Lock and lock the wallet.

The GUI doesn't need a timer like the RPC does because it can ask for the passphrase when needed, and lock the wallet when it is done with what it is doing. So it does not have a timeout in the same way the RPC does. Rather each action that needs the wallet to be unlocked for it to succeed will create a WalletModel::UnlockContext object, which in doing so, will spawn the AskPassphraseDialog to get your passphrase. That sets CWallet::vMasterKey thereby unlocking your wallet. The UnlockContext object has a destructor which calls CWallet::Lock so when it is destroyed, the wallet is locked. The object is destroyed when it goes out of scope, i.e. when the action being performed that needed the wallet to be unlocked is completed.
member
Activity: 124
Merit: 11
September 26, 2021, 10:36:22 AM
#3
This has everything you need to know about wallet encryption: github.com/bitcoin/bitcoin/blob/6b8a5ab622e5c9386c872036646bf94da983b190/doc/README

Unfortunately it doesn't answer about what GUI do when you unlock the wallet.

I use the walletpassphrase to see if I still can remember my password and I don't want to transact, so im curious about what goes on when the GUI unlocks it when making a transaction.
If you need to do that, you can set a timeout of '1' second so your passphrase wont stay in your RAM for too long.

You also could use command walletlock if you accidentally use default unlock duration and being extremely careful.

It should be somewhere on the code. Im trying to find things related to transactions on the qt folder source where it it's related to the passphrase being used:

https://github.com/bitcoin/bitcoin/blob/master/src/qt/askpassphrasedialog.h
https://github.com/bitcoin/bitcoin/blob/master/src/qt/askpassphrasedialog.cpp

I think this only relates to the actual window but not what happens with the passphrase. There's also this:

https://github.com/bitcoin/bitcoin/blob/master/src/interfaces/wallet.h

Code:
    //! Encrypt wallet.
    virtual bool encryptWallet(const SecureString& wallet_passphrase) = 0;

    //! Return whether wallet is encrypted.
    virtual bool isCrypted() = 0;

    //! Lock wallet.
    virtual bool lock() = 0;

    //! Unlock wallet.
    virtual bool unlock(const SecureString& wallet_passphrase) = 0;

    //! Return whether wallet is locked.
    virtual bool isLocked() = 0;

    //! Change wallet passphrase.
    virtual bool changeWalletPassphrase(const SecureString& old_wallet_passphrase,
        const SecureString& new_wallet_passphrase) = 0;

I can't find what the "default timeout" would be.

legendary
Activity: 2534
Merit: 6080
Self-proclaimed Genius
September 24, 2021, 12:07:44 AM
#2
This has everything you need to know about wallet encryption: github.com/bitcoin/bitcoin/blob/6b8a5ab622e5c9386c872036646bf94da983b190/doc/README

I use the walletpassphrase to see if I still can remember my password and I don't want to transact, so im curious about what goes on when the GUI unlocks it when making a transaction.
If you need to do that, you can set a timeout of '1' second so your passphrase master key wont stay in your RAM for too long.
member
Activity: 124
Merit: 11
September 23, 2021, 09:21:53 PM
#1
Specifically, what goes on when you get prompted by the GUI to enter your password in order to make a transaction?

Does the code run the default walletpassphrase command line with the default 60 seconds or something else happens?

I use the walletpassphrase to see if I still can remember my password and I don't want to transact, so im curious about what goes on when the GUI unlocks it when making a transaction.
Jump to: