// Delegate marks the given ComputedKeyInfos object that the given kid is now // delegated, as of time tm, in sigid, as signed by signingKid, etc. func (cki *ComputedKeyInfos) Delegate(kid keybase1.KID, tm *KeybaseTime, sigid keybase1.SigID, signingKid, parentKID keybase1.KID, pgpHash string, isSibkey bool, ctime, etime time.Time) (err error) { G.Log.Debug("ComputeKeyInfos::Delegate To %s with %s at sig %s", kid.String(), signingKid, sigid.ToDisplayString(true)) info, found := cki.Infos[kid] if !found { newInfo := NewComputedKeyInfo(false, false, KeyUncancelled, ctime.Unix(), etime.Unix(), pgpHash) newInfo.DelegatedAt = tm info = &newInfo cki.Infos[kid] = info } else { info.Status = KeyUncancelled info.CTime = ctime.Unix() info.ETime = etime.Unix() } info.Delegations[sigid] = signingKid info.Sibkey = isSibkey cki.Sigs[sigid] = info // If it's a subkey, make a pointer from it to its parent, // and also from its parent to it. if parentKID.Exists() { info.Parent = parentKID if parent, found := cki.Infos[parentKID]; found { parent.Subkey = kid } } return }
func (l *SigChainLoader) LoadLinksFromStorage() (err error) { var curr LinkID var links []*ChainLink var mt *MerkleTriple goodKey := true uid := l.user.GetUID() l.G().Log.Debug("+ SigChainLoader.LoadFromStorage(%s)", uid) defer func() { l.G().Log.Debug("- SigChainLoader.LoadFromStorage(%s) -> %s", uid, ErrToOk(err)) }() if mt, err = l.LoadLastLinkIDFromStorage(); err != nil || mt == nil { l.G().Log.Debug("| Failed to load last link ID") if err == nil { l.G().Log.Debug("| no error loading last link ID from storage") } if mt == nil { l.G().Log.Debug("| mt (MerkleTriple) nil result from load last link ID from storage") } return err } // Load whatever the last fingerprint was in the chain if we're not loading // allKeys. We have to load something... Note that we don't use l.fp // here (as we used to) since if the user used to have chainlinks, and then // removed their key, we still want to load their last chainlinks. var loadKID keybase1.KID curr = mt.LinkID var link *ChainLink suid := l.selfUID() for curr != nil && goodKey { l.G().VDL.Log(VLog1, "| loading link; curr=%s", curr) if link, err = ImportLinkFromStorage(curr, suid, l.G()); err != nil { return } kid2 := link.ToEldestKID() if loadKID.IsNil() { loadKID = kid2 l.G().Log.Debug("| Setting loadKID=%s", kid2) } else if !l.allKeys && loadKID.Exists() && !loadKID.Equal(kid2) { goodKey = false l.G().Log.Debug("| Stop loading at KID=%s (!= KID=%s)", loadKID, kid2) } if goodKey { links = append(links, link) curr = link.GetPrev() } } reverse(links) l.G().Log.Debug("| Loaded %d links", len(links)) l.links = links return }
// GetSibkeyForDevice gets the current per-device key for the given Device. Will // return nil if one isn't found, and set err for a real error. The sibkey should // be a signing key, not an encryption key of course. func (ckf *ComputedKeyFamily) GetSibkeyForDevice(did keybase1.DeviceID) (key GenericKey, err error) { var kid keybase1.KID kid, err = ckf.getSibkeyKidForDevice(did) if kid.Exists() { key, _, err = ckf.FindActiveSibkey(kid) } return }
func (k SKBKeyringFile) SearchWithComputedKeyFamily(ckf *ComputedKeyFamily, ska SecretKeyArg) []*SKB { var kid keybase1.KID G.Log.Debug("+ SKBKeyringFile.SearchWithComputedKeyFamily") defer func() { var res string if kid.Exists() { res = kid.String() } else { res = "<nil>" } G.Log.Debug("- SKBKeyringFile.SearchWithComputedKeyFamily -> %s\n", res) }() G.Log.Debug("| Searching %d possible blocks", len(k.Blocks)) var blocks []*SKB for i := len(k.Blocks) - 1; i >= 0; i-- { G.Log.Debug("| trying key index# -> %d", i) if key, err := k.Blocks[i].GetPubKey(); err == nil && key != nil { kid = key.GetKID() active := ckf.GetKeyRole(kid) G.Log.Debug("| Checking KID: %s -> %d", kid, int(active)) if !ska.KeyType.nonDeviceKeyMatches(key) { G.Log.Debug("| Skipped, doesn't match type=%s", ska.KeyType) } else if !KeyMatchesQuery(key, ska.KeyQuery, ska.ExactMatch) { G.Log.Debug("| Skipped, doesn't match query=%s", ska.KeyQuery) } else if active != DLGSibkey { G.Log.Debug("| Skipped, active=%d", int(active)) } else { blocks = append(blocks, k.Blocks[i]) } } else { G.Log.Debug("| failed --> %v", err) } } return blocks }