func (v *CmdDumpKeyfamily) printKey(key keybase1.PublicKey, subkeys []keybase1.PublicKey, indent int) error { if key.KID == "" { return fmt.Errorf("Found a key with an empty KID.") } eldestStr := "" if key.IsEldest { eldestStr = " (eldest)" } dui := v.G().UI.GetDumbOutputUI() dui.Printf("%s%s%s\n", indentSpace(indent), key.KID, eldestStr) if key.PGPFingerprint != "" { dui.Printf("%sPGP Fingerprint: %s\n", indentSpace(indent+1), libkb.PGPFingerprintFromHexNoError(key.PGPFingerprint).ToQuads()) dui.Printf("%sPGP Identities:\n", indentSpace(indent+1)) for _, identity := range key.PGPIdentities { commentStr := "" if identity.Comment != "" { commentStr = fmt.Sprintf(" (%s)", identity.Comment) } emailStr := "" if identity.Email != "" { emailStr = fmt.Sprintf(" <%s>", identity.Email) } dui.Printf("%s%s%s%s\n", indentSpace(indent+2), identity.Username, commentStr, emailStr) } } if key.DeviceID != "" || key.DeviceType != "" || key.DeviceDescription != "" { dui.Printf("%sDevice:\n", indentSpace(indent+1)) if key.DeviceID != "" { dui.Printf("%sID: %s\n", indentSpace(indent+2), key.DeviceID) } if key.DeviceType != "" { dui.Printf("%sType: %s\n", indentSpace(indent+2), key.DeviceType) } if key.DeviceDescription != "" { dui.Printf("%sDescription: %s\n", indentSpace(indent+2), key.DeviceDescription) } } dui.Printf("%sCreated: %s\n", indentSpace(indent+1), keybase1.FromTime(key.CTime)) dui.Printf("%sExpires: %s\n", indentSpace(indent+1), keybase1.FromTime(key.ETime)) if len(subkeys) > 0 { dui.Printf("%sSubkeys:\n", indentSpace(indent+1)) for _, subkey := range subkeys { v.printKey(subkey, nil, indent+2) } } return nil }
// Get returns a user object. If none exists for uid, it will return nil. func (c *Identify2Cache) Get(uid keybase1.UID, gctf GetCheckTimeFunc, timeout time.Duration) (*keybase1.UserPlusKeys, error) { v, err := c.cache.Get(string(uid)) if err != nil { if err == ramcache.ErrNotFound { return nil, nil } return nil, err } up, ok := v.(*keybase1.UserPlusKeys) if !ok { return nil, fmt.Errorf("invalid type in cache: %T", v) } if gctf != nil { then := gctf(*up) if then == 0 { return nil, TimeoutError{} } thenTime := keybase1.FromTime(then) if time.Since(thenTime) > timeout { return nil, TimeoutError{} } } return up, nil }
func (k *KBPKIClient) hasVerifyingKey(ctx context.Context, uid keybase1.UID, verifyingKey VerifyingKey, atServerTime time.Time) (bool, error) { userInfo, err := k.loadUserPlusKeys(ctx, uid) if err != nil { return false, err } for _, key := range userInfo.VerifyingKeys { if verifyingKey.kid.Equal(key.kid) { return true, nil } } for key, t := range userInfo.RevokedVerifyingKeys { if !verifyingKey.kid.Equal(key.kid) { continue } revokedTime := keybase1.FromTime(t.Unix) // Trust the server times -- if the key was valid at the given // time, we are good to go. TODO: use Merkle data to check // the server timestamps, to prove the server isn't lying. if atServerTime.Before(revokedTime) { k.log.CDebugf(ctx, "Trusting revoked verifying key %s for user %s "+ "(revoked time: %v vs. server time %v)", verifyingKey.kid, uid, revokedTime, atServerTime) return true, nil } k.log.CDebugf(ctx, "Not trusting revoked verifying key %s for "+ "user %s (revoked time: %v vs. server time %v)", verifyingKey.kid, uid, revokedTime, atServerTime) return false, nil } return false, nil }
func (i *Identify2WithUIDTester) Get(uid keybase1.UID, gctf libkb.GetCheckTimeFunc, timeout time.Duration) (*keybase1.UserPlusKeys, error) { res := i.cache[uid] stats := &i.slowStats if timeout == libkb.Identify2CacheShortTimeout { stats = &i.fastStats } if res == nil { stats.miss++ return nil, nil } if gctf != nil { then := gctf(*res) if then == 0 { stats.notime++ return nil, libkb.TimeoutError{} } thenTime := keybase1.FromTime(then) if i.now.Sub(thenTime) > timeout { stats.timeout++ return nil, libkb.TimeoutError{} } } stats.hit++ return res, nil }
// Helper used to retrieve metadata blocks from the MD server. func (md *MDServerRemote) get(ctx context.Context, id TlfID, handle *BareTlfHandle, bid BranchID, mStatus MergeStatus, start, stop MetadataRevision) (TlfID, []*RootMetadataSigned, error) { // figure out which args to send if id == NullTlfID && handle == nil { panic("nil TlfID and handle passed into MDServerRemote.get") } arg := keybase1.GetMetadataArg{ StartRevision: start.Number(), StopRevision: stop.Number(), BranchID: bid.String(), Unmerged: mStatus == Unmerged, LogTags: LogTagsFromContextToMap(ctx), } var err error if id == NullTlfID { arg.FolderHandle, err = md.config.Codec().Encode(handle) if err != nil { return id, nil, err } } else { arg.FolderID = id.String() } // request response, err := md.client.GetMetadata(ctx, arg) if err != nil { return id, nil, err } // response id = ParseTlfID(response.FolderID) if id == NullTlfID { return id, nil, MDInvalidTlfID{response.FolderID} } // deserialize blocks rmdses := make([]*RootMetadataSigned, len(response.MdBlocks)) for i, block := range response.MdBlocks { ver := MetadataVer(block.Version) if ver < FirstValidMetadataVer { return id, nil, InvalidMetadataVersionError{id, ver} } else if ver > md.config.MetadataVersion() { return id, nil, NewMetadataVersionError{id, ver} } var rmds RootMetadataSigned err = md.config.Codec().Decode(block.Block, &rmds) if err != nil { return id, rmdses, err } rmds.untrustedServerTimestamp = keybase1.FromTime(block.Timestamp) rmdses[i] = &rmds } return id, rmdses, nil }
func ImportTrackSummary(s *keybase1.TrackSummary) *TrackSummary { if s == nil { return nil } return &TrackSummary{ time: keybase1.FromTime(s.Time), isRemote: s.IsRemote, username: s.Username, } }
func (p PgpUI) OutputSignatureSuccess(_ context.Context, arg keybase1.OutputSignatureSuccessArg) error { signedAt := keybase1.FromTime(arg.SignedAt) un := ColorString("bold", arg.Username) output := func(fmtString string, args ...interface{}) { s := fmt.Sprintf(fmtString, args...) s = ColorString("green", s) p.w.Write([]byte(s)) } if signedAt.IsZero() { output("Signature verified. Signed by %s.\n", un) } else { output("Signature verified. Signed by %s %s (%s).\n", un, humanize.Time(signedAt), signedAt) } output("PGP Fingerprint: %s.\n", arg.Fingerprint) return nil }
// Check checks for an update. If not requested (by user) and not forced it will // exit early if check has already been applied within checkDuration(). func (u *UpdateChecker) Check(force bool, requested bool) error { if !requested && !force { if lastCheckedPTime := u.updater.config.GetUpdateLastChecked(); lastCheckedPTime > 0 { lastChecked := keybase1.FromTime(lastCheckedPTime) if time.Now().Before(lastChecked.Add(checkDuration())) { u.log.Debug("Already checked: %s", lastChecked) return nil } } } checkTime := time.Now() _, err := u.updater.Update(u.ui, force, requested) if err != nil { return err } u.log.Debug("Saving updater last checked: %s", checkTime) u.updater.config.SetUpdateLastChecked(keybase1.ToTime(checkTime)) return nil }
func (t *Tracker2Syncer) loadFromStorage(uid keybase1.UID) error { var err error var found bool var tmp keybase1.UserSummary2Set defer t.G().Trace(fmt.Sprintf("loadFromStorage(%s)", uid), func() error { return err })() found, err = t.G().LocalDb.GetInto(&tmp, t.dbKey(uid)) if err != nil { return err } if !found { t.G().Log.Debug("| no cached copy found") return nil } cachedAt := keybase1.FromTime(tmp.Time) if time.Now().Sub(cachedAt) > cacheTimeout { t.G().Log.Debug("| expired; cached at %s", cachedAt) return nil } t.G().Log.Debug("| found a record, cached %s", cachedAt) t.res = &tmp return nil }
func (c *CmdDecrypt) explainDecryptionFailure(info *keybase1.SaltpackEncryptedMessageInfo) { if info == nil { return } out := c.G().UI.GetTerminalUI().ErrorWriter() prnt := func(s string, args ...interface{}) { fmt.Fprintf(out, s, args...) } if len(info.Devices) > 0 { prnt("Decryption failed; try one of these devices instead:\n") for _, d := range info.Devices { t := keybase1.FromTime(d.CTime) prnt(" * %s (%s); provisioned %s (%s)\n", ColorString("bold", d.Name), d.Type, humanize.Time(t), t.Format("2006-01-02 15:04:05 MST")) } if info.NumAnonReceivers > 0 { prnt("Additionally, there were %d hidden receivers for this message\n", info.NumAnonReceivers) } } else if info.NumAnonReceivers > 0 { prnt("Decryption failed; it was encrypted for %d hidden receivers, which may or may not you\n", info.NumAnonReceivers) } else { prnt("Decryption failed; message wasn't encrypted for any of your known keys\n") } }
func (u *UpdateChecker) Check(force bool, requested bool) error { ui, _ := u.ui.GetUpdateUI() if ui == nil && !force { return fmt.Errorf("No UI for update check") } if !requested && !force { if lastCheckedPTime := u.updater.config.GetUpdateLastChecked(); lastCheckedPTime > 0 { lastChecked := keybase1.FromTime(lastCheckedPTime) if time.Now().Before(lastChecked.Add(checkDuration())) { u.log.Debug("Already checked: %s", lastChecked) return nil } } } _, err := u.updater.Update(ui, force, requested) if err != nil { return err } u.log.Debug("Updater checked") u.updater.config.SetUpdateLastChecked(keybase1.ToTime(time.Now())) return nil }
func (u *Updater) checkForUpdate(skipAssetDownload bool, force bool, requested bool) (update *keybase1.Update, err error) { u.log.Info("Checking for update, current version is %s", u.options.Version) if u.options.Force { force = true } // Don't snooze if the user requested/wants an update (check) or we're forcing a check if !requested && !force { if snz := u.config.GetUpdatePreferenceSnoozeUntil(); snz > 0 { snoozeUntil := keybase1.FromTime(snz) if time.Now().Before(snoozeUntil) { u.log.Info("Snoozing until %s", snoozeUntil) return nil, nil } u.log.Debug("Snooze expired at %s", snoozeUntil) // Clear out the snooze u.config.SetUpdatePreferenceSnoozeUntil(keybase1.Time(0)) } } currentSemVersion, err := semver.Make(u.options.Version) if err != nil { return } u.log.Info("Using updater source: %s", u.source.Description()) u.log.Debug("Using options: %#v", u.options) update, err = u.source.FindUpdate(u.options) if err != nil || update == nil { return } u.log.Info("Checking update with version: %s", update.Version) updateSemVersion, err := semver.Make(update.Version) if err != nil { return } // Update instruction might be empty, if so we'll fill in with the default // instructions for the platform. if update.Instructions == nil || *update.Instructions == "" { instructions, err := libkb.PlatformSpecificUpgradeInstructionsString() if err != nil { u.log.Errorf("Error trying to get update instructions: %s", err) } if instructions == "" { instructions = u.options.DefaultInstructions } if instructions != "" { u.log.Debug("Using default platform instructions: %s", instructions) update.Instructions = &instructions } else { u.log.Debug("No instructions set for update") } } if skipVersion := u.config.GetUpdatePreferenceSkip(); len(skipVersion) != 0 { u.log.Debug("Update preference: skip %s", skipVersion) if vers, err := semver.Make(skipVersion); err != nil { u.log.Warning("Bad 'skipVersion' in config file: %q", skipVersion) } else if vers.GE(updateSemVersion) { u.log.Debug("Skipping updated version via config preference: %q", update.Version) return nil, nil } } if updateSemVersion.EQ(currentSemVersion) { // Versions are the same, we are up to date u.log.Info("Update matches current version: %s = %s", updateSemVersion, currentSemVersion) if !force { update = nil return } } else if updateSemVersion.LT(currentSemVersion) { u.log.Info("Update is older version: %s < %s", updateSemVersion, currentSemVersion) if !force { update = nil return } } if !skipAssetDownload && update.Asset != nil { downloadPath, _, dlerr := u.downloadAsset(*update.Asset) if dlerr != nil { err = dlerr return } update.Asset.LocalPath = downloadPath } return }
func (u *Updater) checkForUpdate(skipAssetDownload bool, force bool, requested bool) (update *keybase1.Update, err error) { u.log.Info("Checking for update, current version is %s", u.options.Version) if u.options.Force { force = true } // Don't snooze if the user requested/wants an update (check) or we're forcing a check if !requested && !force { if snz := u.config.GetUpdatePreferenceSnoozeUntil(); snz > 0 { snoozeUntil := keybase1.FromTime(snz) if time.Now().Before(snoozeUntil) { u.log.Info("Snoozing until %s", snoozeUntil) return nil, nil } u.log.Debug("Snooze expired at %s", snoozeUntil) // Clear out the snooze u.config.SetUpdatePreferenceSnoozeUntil(keybase1.Time(0)) } } currentSemVersion, err := semver.Make(u.options.Version) if err != nil { return } u.log.Info("Using updater source: %s", u.source.Description()) u.log.Debug("Using options: %#v", u.options) update, err = u.source.FindUpdate(u.options) if err != nil || update == nil { return } u.log.Info("Checking update with version: %s", update.Version) updateSemVersion, err := semver.Make(update.Version) if err != nil { return } if skp := u.config.GetUpdatePreferenceSkip(); len(skp) != 0 { u.log.Debug("Update preference: skip %s", skp) if vers, err := semver.Make(skp); err != nil { u.log.Warning("Bad 'skipVersion' in config file: %q", skp) } else if vers.GE(updateSemVersion) { u.log.Debug("Skipping updated version via config preference: %q", update.Version) return nil, nil } } if updateSemVersion.EQ(currentSemVersion) { // Versions are the same, we are up to date u.log.Info("Update matches current version: %s = %s", updateSemVersion, currentSemVersion) if !force { update = nil return } } else if updateSemVersion.LT(currentSemVersion) { u.log.Info("Update is older version: %s < %s", updateSemVersion, currentSemVersion) if !force { update = nil return } } if !skipAssetDownload { downloadPath, _, dlerr := u.downloadAsset(update.Asset) if dlerr != nil { err = dlerr return } update.Asset.LocalPath = downloadPath } return }