func (e *SaltpackSenderIdentify) identifySender(ctx *Context) (err error) { defer e.G().Trace("SaltpackDecrypt::identifySender", func() error { return err })() var lin bool var uid keybase1.UID if lin, uid, err = IsLoggedIn(e, ctx); err == nil && lin && uid.Equal(e.res.Uid) { e.G().Log.Debug("| Sender is self") e.res.SenderType = keybase1.SaltpackSenderType_SELF return nil } iarg := keybase1.Identify2Arg{ Uid: e.res.Uid, UseDelegateUI: !e.arg.interactive, AlwaysBlock: e.arg.interactive, ForceRemoteCheck: e.arg.forceRemoteCheck, NoErrorOnTrackFailure: true, Reason: e.arg.reason, UserAssertion: e.arg.userAssertion, } eng := NewIdentify2WithUID(e.G(), &iarg) if err = RunEngine(eng, ctx); err != nil { return err } switch eng.getTrackType() { case identify2NoTrack: e.res.SenderType = keybase1.SaltpackSenderType_NOT_TRACKED case identify2TrackOK: e.res.SenderType = keybase1.SaltpackSenderType_TRACKING_OK default: e.res.SenderType = keybase1.SaltpackSenderType_TRACKING_BROKE } return nil }
func (sc *SigChain) LoadFromServer(t *MerkleTriple, selfUID keybase1.UID) (dirtyTail *MerkleTriple, err error) { low := sc.GetLastLoadedSeqno() sc.loadedFromLinkOne = (low == Seqno(0) || low == Seqno(-1)) sc.G().Log.Debug("+ Load SigChain from server (uid=%s, low=%d)", sc.uid, low) defer func() { sc.G().Log.Debug("- Loaded SigChain -> %s", ErrToOk(err)) }() res, err := G.API.Get(APIArg{ Endpoint: "sig/get", NeedSession: false, Args: HTTPArgs{ "uid": UIDArg(sc.uid), "low": I{int(low)}, }, }) if err != nil { return } v := res.Body.AtKey("sigs") var lim int if lim, err = v.Len(); err != nil { return } foundTail := false sc.G().Log.Debug("| Got back %d new entries", lim) var links []*ChainLink var tail *ChainLink for i := 0; i < lim; i++ { var link *ChainLink if link, err = ImportLinkFromServer(sc.G(), sc, v.AtIndex(i), selfUID); err != nil { return } if link.GetSeqno() <= low { continue } if selfUID.Equal(link.GetUID()) { sc.G().Log.Debug("| Setting isOwnNewLinkFromServer=true for seqno %d", link.GetSeqno()) link.isOwnNewLinkFromServer = true } links = append(links, link) if !foundTail && t != nil { if foundTail, err = link.checkAgainstMerkleTree(t); err != nil { return } } tail = link } if t != nil && !foundTail { err = NewServerChainError("Failed to reach (%s, %d) in server response", t.LinkID, int(t.Seqno)) return } if tail != nil { dirtyTail = tail.ToMerkleTriple() // If we've stored a `last` and it's less than the one // we just loaded, then nuke it. if sc.localChainTail != nil && sc.localChainTail.Less(*dirtyTail) { sc.G().Log.Debug("| Clear cached last (%d < %d)", sc.localChainTail.Seqno, dirtyTail.Seqno) sc.localChainTail = nil sc.localCki = nil } } sc.chainLinks = append(sc.chainLinks, links...) return }