Esempio n. 1
0
func (s *SQLEngine) consumeCreation(tx *sql.Tx, i gregor.Item) error {
	md := i.Metadata()
	qb := s.newQueryBuilder()
	qb.Build("INSERT INTO gregor_items(uid, msgid, category, body, dtime) VALUES(?,?,?,?,",
		hexEnc(md.UID()),
		hexEnc(md.MsgID()),
		i.Category().String(),
		i.Body().Bytes(),
	)
	qb.TimeOrOffset(i.DTime())
	qb.Build(")")
	err := qb.Exec(tx)
	if err != nil {
		return err
	}

	for i, t := range i.RemindTimes() {
		if t == nil {
			continue
		}
		nqb := s.newQueryBuilder()
		nqb.Build("INSERT INTO gregor_reminders(uid, msgid, seqno, rtime) VALUES(?,?,?,", hexEnc(md.UID()), hexEnc(md.MsgID()), i)
		nqb.TimeOrOffset(t)
		nqb.Build(")")
		err = nqb.Exec(tx)
		if err != nil {
			return err
		}
	}
	return nil
}
Esempio n. 2
0
func (h IdentifyUIHandler) handleShowTrackerPopupCreate(ctx context.Context, cli gregor1.IncomingInterface,
	item gregor.Item) error {

	h.G().Log.Debug("handleShowTrackerPopupCreate: %+v", item)
	if item.Body() == nil {
		return errors.New("gregor handler for show_tracker_popup: nil message body")
	}
	body, err := jsonw.Unmarshal(item.Body().Bytes())
	if err != nil {
		h.G().Log.Debug("body failed to unmarshal", err)
		return err
	}
	uidString, err := body.AtPath("uid").GetString()
	if err != nil {
		h.G().Log.Debug("failed to extract uid", err)
		return err
	}
	uid, err := keybase1.UIDFromString(uidString)
	if err != nil {
		h.G().Log.Debug("failed to convert UID from string", err)
		return err
	}

	identifyUI, err := h.G().UIRouter.GetIdentifyUI()
	if err != nil {
		h.G().Log.Debug("failed to get IdentifyUI", err)
		return err
	}
	if identifyUI == nil {
		h.G().Log.Debug("got nil IdentifyUI")
		return errors.New("got nil IdentifyUI")
	}
	secretUI, err := h.G().UIRouter.GetSecretUI(0)
	if err != nil {
		h.G().Log.Debug("failed to get SecretUI", err)
		return err
	}
	if secretUI == nil {
		h.G().Log.Debug("got nil SecretUI")
		return errors.New("got nil SecretUI")
	}
	engineContext := engine.Context{
		IdentifyUI: identifyUI,
		SecretUI:   secretUI,
	}

	identifyReason := keybase1.IdentifyReason{
		Type: keybase1.IdentifyReasonType_TRACK,
		// TODO: text here?
	}
	identifyArg := keybase1.Identify2Arg{Uid: uid, Reason: identifyReason}
	identifyEng := engine.NewIdentify2WithUID(h.G(), &identifyArg)
	identifyEng.SetResponsibleGregorItem(item)
	return identifyEng.Run(&engineContext)
}
Esempio n. 3
0
// addItem adds an item for this user
func (u *user) addItem(now time.Time, i gregor.Item) *item {
	msgID := i.Metadata().MsgID().Bytes()
	for _, it := range u.items {
		if bytes.Equal(msgID, it.item.Metadata().MsgID().Bytes()) {
			return it
		}
	}
	newItem := &item{item: i, ctime: nowIfZero(now, i.Metadata().CTime())}
	u.items = append(u.items, newItem)
	return newItem
}
Esempio n. 4
0
func (h IdentifyUIHandler) handleShowTrackerPopupDismiss(ctx context.Context, cli gregor1.IncomingInterface,
	item gregor.Item) error {

	h.G().Log.Debug("handleShowTrackerPopupDismiss: %+v", item)
	if item.Body() == nil {
		return errors.New("gregor dismissal for show_tracker_popup: nil message body")
	}
	body, err := jsonw.Unmarshal(item.Body().Bytes())
	if err != nil {
		h.G().Log.Debug("body failed to unmarshal", err)
		return err
	}
	uidString, err := body.AtPath("uid").GetString()
	if err != nil {
		h.G().Log.Debug("failed to extract uid", err)
		return err
	}
	uid, err := keybase1.UIDFromString(uidString)
	if err != nil {
		h.G().Log.Debug("failed to convert UID from string", err)
		return err
	}
	user, err := libkb.LoadUser(libkb.NewLoadUserByUIDArg(h.G(), uid))
	if err != nil {
		h.G().Log.Debug("failed to load user from UID", err)
		return err
	}

	identifyUI, err := h.G().UIRouter.GetIdentifyUI()
	if err != nil {
		h.G().Log.Debug("failed to get IdentifyUI", err)
		return err
	}
	if identifyUI == nil {
		h.G().Log.Debug("got nil IdentifyUI")
		return errors.New("got nil IdentifyUI")
	}

	reason := keybase1.DismissReason{
		Type: keybase1.DismissReasonType_HANDLED_ELSEWHERE,
	}
	identifyUI.Dismiss(user.GetName(), reason)

	return nil
}
Esempio n. 5
0
func (r *RekeyUIHandler) rekeyNeeded(ctx context.Context, item gregor.Item) (err error) {

	var msgID string
	if item.Metadata() != nil && item.Metadata().MsgID() != nil {
		msgID = item.Metadata().MsgID().String()
	} else {
		msgID = "-"
	}

	defer r.G().Trace(fmt.Sprintf("rekeyNeeded(%s)", msgID), func() error { return err })()

	if item.Body() == nil {
		err = errors.New("gregor handler for kbfs_tlf_rekey_needed: nil message body")
		return err
	}

	var problemSet keybase1.ProblemSet
	if err = json.Unmarshal(item.Body().Bytes(), &problemSet); err != nil {
		r.G().Log.Debug("recoverable problem unmarshaling gregor body: %s", err)
		err = nil
	}

	if r.G().Clock().Now().Sub(item.Metadata().CTime()) > 10*time.Second {
		r.G().Log.Debug("msg %s isn't fresh (born on %s)", msgID, item.Metadata().CTime())
		// if the message isn't fresh, get:
		var err error
		problemSet, err = r.scorer(r.G(), problemSet)
		r.G().Log.Debug("updated score for %s", msgID)
		if err != nil {
			return err
		}
	}

	// if the tlf list is empty, dismiss the gregor notification
	if len(problemSet.Tlfs) == 0 {
		r.G().Log.Debug("problem set tlf list empty, dismissing gregor notification")
		return r.G().GregorDismisser.DismissItem(item.Metadata().MsgID())
	}

	if currentDeviceSolvesProblemSet(r.G(), problemSet) {
		r.G().Log.Info("Short-circuiting update; our device is on the solution list")
		return
	}

	return r.startUpdater(ctx, problemSet, item.Metadata().MsgID())
}
Esempio n. 6
0
func (r *RekeyLogHandler) log(category string, item gregor.Item) {
	md := item.Metadata()
	r.G().Log.Debug("RekeyLogHandler: %s item message metadata: uid = %s, msg id = %s, ctime = %s, device = %s, inband type = %d", category, md.UID(), md.MsgID(), md.CTime(), md.DeviceID(), md.InBandMsgType())
	r.G().Log.Debug("RekeyLogHandler: %s item dtime = %s, remind times = %v", category, r.timeOrOffsetString(item.DTime()), item.RemindTimes())
	r.G().Log.Debug("RekeyLogHandler: %s item body: %s", category, item.Body())
}