示例#1
0
// Run starts the engine.
func (d *DevList) Run(ctx *Context) error {
	uid := d.G().GetMyUID()
	var err error
	var devs libkb.DeviceKeyMap
	aerr := d.G().LoginState().Account(func(a *libkb.Account) {
		if err = libkb.RunSyncer(a.SecretSyncer(), uid, a.LoggedIn(), a.LocalSession()); err != nil {
			return
		}
		devs, err = a.SecretSyncer().ActiveDevices(libkb.AllDeviceTypes)
	}, "DevList - ActiveDevices")
	if aerr != nil {
		return aerr
	}
	if err != nil {
		return err
	}

	var pdevs []keybase1.Device
	for k, v := range devs {
		pdevs = append(pdevs, keybase1.Device{
			Type:     v.Type,
			Name:     v.Display(),
			DeviceID: k,
			CTime:    keybase1.TimeFromSeconds(v.CTime),
			MTime:    keybase1.TimeFromSeconds(v.MTime),
		})
	}
	sort.Sort(dname(pdevs))
	d.devices = pdevs

	return nil
}
示例#2
0
func (e *PaperKeyGen) getClientHalfFromSecretStore() ([]byte, libkb.PassphraseGeneration, error) {
	zeroGen := libkb.PassphraseGeneration(0)

	secretStore := libkb.NewSecretStore(e.G(), e.arg.Me.GetNormalizedName())
	if secretStore == nil {
		return nil, zeroGen, errors.New("No secret store available")
	}

	secret, err := secretStore.RetrieveSecret()
	if err != nil {
		return nil, zeroGen, err
	}

	devid := e.G().Env.GetDeviceID()
	if devid.IsNil() {
		return nil, zeroGen, fmt.Errorf("no device id set")
	}

	var dev libkb.DeviceKey
	aerr := e.G().LoginState().Account(func(a *libkb.Account) {
		if err = libkb.RunSyncer(a.SecretSyncer(), e.arg.Me.GetUID(), a.LoggedIn(), a.LocalSession()); err != nil {
			return
		}
		dev, err = a.SecretSyncer().FindDevice(devid)
	}, "BackupKeygen.Run() -- retrieving passphrase generation)")
	if aerr != nil {
		return nil, zeroGen, aerr
	}
	if err != nil {
		return nil, zeroGen, err
	}

	serverHalf, err := hex.DecodeString(dev.LksServerHalf)
	if err != nil {
		return nil, zeroGen, err
	}

	if len(secret) != len(serverHalf) {
		return nil, zeroGen, fmt.Errorf("secret has length %d, server half has length %d", len(secret), len(serverHalf))
	}

	clientHalf := make([]byte, len(secret))
	libkb.XORBytes(clientHalf, secret, serverHalf)

	return clientHalf, dev.PPGen, nil
}
示例#3
0
// Run starts the engine.
func (e *ListTrackersEngine) Run(ctx *Context) error {
	if err := e.ensureUID(); err != nil {
		return err
	}
	ts := libkb.NewTrackerSyncer(e.uid, e.G())
	var err error
	aerr := e.G().LoginState().Account(func(a *libkb.Account) {
		err = libkb.RunSyncer(ts, e.uid, a.LoggedIn(), a.LocalSession())
	}, "ListTrackersEngine - Run")
	if aerr != nil {
		return aerr
	}
	if err != nil {
		return err
	}
	e.trackers = ts.Trackers()
	return nil
}
示例#4
0
func (e *DeviceHistory) getLastUsedTimes() (map[keybase1.DeviceID]time.Time, error) {
	uid := e.G().GetMyUID()
	var err error
	var devs libkb.DeviceKeyMap
	aerr := e.G().LoginState().Account(func(a *libkb.Account) {
		if err = libkb.RunSyncer(a.SecretSyncer(), uid, a.LoggedIn(), a.LocalSession()); err != nil {
			return
		}
		devs, err = a.SecretSyncer().ActiveDevices(libkb.AllDeviceTypes)
	}, "DeviceHistory - ")
	if aerr != nil {
		return nil, aerr
	}
	if err != nil {
		return nil, err
	}

	ret := map[keybase1.DeviceID]time.Time{}
	for deviceID, dev := range devs {
		ret[deviceID] = time.Unix(dev.LastUsedTime, 0)
	}
	return ret, nil
}