Skip to content

Commit

Permalink
check for password when running buyer
Browse files Browse the repository at this point in the history
  • Loading branch information
vctt94 authored and jrick committed Feb 4, 2021
1 parent b00d794 commit 73ef730
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
3 changes: 1 addition & 2 deletions internal/rpc/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1411,8 +1411,6 @@ func (s *walletServer) ChangePassphrase(ctx context.Context, req *pb.ChangePassp
func (s *walletServer) SignTransaction(ctx context.Context, req *pb.SignTransactionRequest) (
*pb.SignTransactionResponse, error) {

defer zero(req.Passphrase)

var tx wire.MsgTx
err := tx.Deserialize(bytes.NewReader(req.SerializedTransaction))
if err != nil {
Expand All @@ -1424,6 +1422,7 @@ func (s *walletServer) SignTransaction(ctx context.Context, req *pb.SignTransact
lock := make(chan time.Time, 1)
defer func() {
lock <- time.Time{} // send matters, not the value
zero(req.Passphrase)
}()
err = s.wallet.Unlock(ctx, req.Passphrase, lock)
if err != nil {
Expand Down
22 changes: 13 additions & 9 deletions ticketbuyer/tb.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ func New(w *wallet.Wallet) *TB {
// ever becomes incorrect due to a wallet passphrase change, Run exits with an
// errors.Passphrase error.
func (tb *TB) Run(ctx context.Context, passphrase []byte) error {
err := tb.wallet.Unlock(ctx, passphrase, nil)
if err != nil {
return err
if len(passphrase) > 0 {
err := tb.wallet.Unlock(ctx, passphrase, nil)
if err != nil {
return err
}
}

c := tb.wallet.NtfnServer.MainTipChangedNotifications()
Expand Down Expand Up @@ -211,12 +213,14 @@ func (tb *TB) buy(ctx context.Context, passphrase []byte, tip *wire.BlockHeader,
return err
}

// Ensure wallet is unlocked with the current passphrase. If the passphase
// is changed, the Run exits and TB must be restarted with the new
// passphrase.
err = w.Unlock(ctx, passphrase, nil)
if err != nil {
return err
if len(passphrase) > 0 {
// Ensure wallet is unlocked with the current passphrase. If the passphase
// is changed, the Run exits and TB must be restarted with the new
// passphrase.
err = w.Unlock(ctx, passphrase, nil)
if err != nil {
return err
}
}

// Read config
Expand Down

0 comments on commit 73ef730

Please sign in to comment.