From cc9784a7ed8af436bad9d033b22347c0285acc0c Mon Sep 17 00:00:00 2001 From: Maxwell Krohn Date: Sat, 6 Aug 2016 16:16:14 -0400 Subject: [PATCH] don't harass to unlock a paper key that's already unlocked (#3761) * don't harass to unlock a paper key that's already unlocked * check for nil keys --- go/service/rekey_ui_handler.go | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/go/service/rekey_ui_handler.go b/go/service/rekey_ui_handler.go index 736977ce4052..7125ff5212f7 100644 --- a/go/service/rekey_ui_handler.go +++ b/go/service/rekey_ui_handler.go @@ -111,11 +111,18 @@ func (r *RekeyUIHandler) rekeyNeeded(ctx context.Context, item gregor.Item) (err return r.startUpdater(ctx, problemSet, item.Metadata().MsgID()) } -func keySolvesProblemTLF(key libkb.GenericKey, tlf keybase1.ProblemTLF) bool { - ourKid := key.GetKID() - for _, kid := range tlf.Solution_kids { - if kid.Equal(ourKid) { - return true +func keysSolveProblemTLF(keys []libkb.GenericKey, tlf keybase1.ProblemTLF) bool { + var ourKIDs []keybase1.KID + for _, key := range keys { + if key != nil { + ourKIDs = append(ourKIDs, key.GetKID()) + } + } + for _, theirKID := range tlf.Solution_kids { + for _, ourKID := range ourKIDs { + if ourKID.Equal(theirKID) { + return true + } } } return false @@ -135,14 +142,25 @@ func currentDeviceSolvesProblemSet(g *libkb.GlobalContext, ps keybase1.ProblemSe return ret } - key, err := me.GetDeviceSubkey() + var paperKey libkb.GenericKey + deviceKey, err := me.GetDeviceSubkey() if err != nil { g.Log.Info("| Problem getting device subkey: %s\n", err) return ret } + err = g.LoginState().Account(func(a *libkb.Account) { + paperKey = a.GetUnlockedPaperEncKey() + }, "currentDeviceSolvesProblemSet") + + // We can continue though, so no need to error out + if err != nil { + g.Log.Info("| Error getting paper key: %s\n", err) + err = nil + } + for _, tlf := range ps.Tlfs { - if !keySolvesProblemTLF(key, tlf) { + if !keysSolveProblemTLF([]libkb.GenericKey{deviceKey, paperKey}, tlf) { g.Log.Debug("| Doesn't solve problem TLF: %s (%s)\n", tlf.Tlf.Name, tlf.Tlf.Id) return ret }