Skip to content

Commit

Permalink
fix: gnoNativeService: In RotatePassword, call Lock() after getSigner (
Browse files Browse the repository at this point in the history
…#190)

In gnoNativeService, `RotatePassword` calls `Lock` at the beginning of
the function, then [calls
`getSigner`](https://github.com/gnolang/gnonative/blob/cdd7bcbfc3b932396e3c469f65859b772d35d44a/service/api.go#L285)
. But `getSigner` [calls
`RLock`](https://github.com/gnolang/gnonative/blob/cdd7bcbfc3b932396e3c469f65859b772d35d44a/service/service.go#L193)
which blocks, and `RotatePassword` never returns. (The effect is that
Gnokey Mobile hangs during "Change Master Password".) This PR changes
`RotatePassword` to call `Lock` after the loop which calls `getSigner`.

This was tested by doing `make npm.pack` and installing it locally in
Gnokey Mobile.

Signed-off-by: Jeff Thompson <[email protected]>
  • Loading branch information
jefft0 authored Oct 23, 2024
1 parent cdd7bcb commit 53473b6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions service/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,6 @@ func (s *gnoNativeService) SetPassword(ctx context.Context, req *connect.Request
}

func (s *gnoNativeService) RotatePassword(ctx context.Context, req *connect.Request[api_gen.RotatePasswordRequest]) (*connect.Response[api_gen.RotatePasswordResponse], error) {
s.lock.Lock()
defer s.lock.Unlock()

// Get all the signers, before trying to update the password.
var signers = make([]*gnoclient.SignerFromKeybase, len(req.Msg.Addresses))
for i := range len(req.Msg.Addresses) {
Expand All @@ -287,6 +284,8 @@ func (s *gnoNativeService) RotatePassword(ctx context.Context, req *connect.Requ
}
}

s.lock.Lock()
defer s.lock.Unlock()
getNewPassword := func() (string, error) { return req.Msg.NewPassword, nil }
for i := range len(req.Msg.Addresses) {
if err := s.keybase.Rotate(signers[i].Account, signers[i].Password, getNewPassword); err != nil {
Expand Down

0 comments on commit 53473b6

Please sign in to comment.