Skip to content

Commit

Permalink
Merge pull request #1474 from keybase/maxtaco/fix-user-change-bug
Browse files Browse the repository at this point in the history
engine: bugfix for user switching
  • Loading branch information
maxtaco committed Dec 4, 2015
2 parents 46f6735 + d48345c commit 3706a22
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go/engine/device_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (d *DeviceRegister) SubConsumers() []libkb.UIConsumer {
func (d *DeviceRegister) Prereqs() Prereqs { return Prereqs{} }

func (d *DeviceRegister) Run(ctx *Context) error {
if d.args.Me.HasDeviceInCurrentInstall() {
if d.args.Me.HasCurrentDeviceInCurrentInstall() {
return ErrDeviceAlreadyRegistered
}

Expand Down
22 changes: 16 additions & 6 deletions go/engine/login_current_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func (e *LoginCurrentDevice) SubConsumers() []libkb.UIConsumer {

// Run starts the engine.
func (e *LoginCurrentDevice) Run(ctx *Context) error {
e.G().Log.Debug("+- LoginCurrentDevice.Run")
defer func() {
e.G().Log.Debug("- LoginCurrentDevice.Run")
}()
// already logged in?
in, err := e.G().LoginState().LoggedInProvisionedLoad()
if err == nil && in {
Expand All @@ -53,11 +57,19 @@ func (e *LoginCurrentDevice) Run(ctx *Context) error {
}

var config *libkb.UserConfig
loadUserArg := libkb.LoadUserArg{
PublicKeyOptional: true,
ForceReload: true,
}
if len(e.username) == 0 {
e.G().Log.Debug("| using current username")
config, err = e.G().Env.GetConfig().GetUserConfig()
loadUserArg.Self = true
} else {
e.G().Log.Debug("| using new username %s", e.username)
nu := libkb.NewNormalizedUsername(e.username)
config, err = e.G().Env.GetConfig().GetUserConfigForUsername(nu)
loadUserArg.Name = e.username
}
if err != nil {
e.G().Log.Debug("error getting user config: %s (%T)", err, err)
Expand All @@ -67,21 +79,19 @@ func (e *LoginCurrentDevice) Run(ctx *Context) error {
e.G().Log.Debug("user config is nil")
return errNoConfig
}
if config.GetDeviceID().IsNil() {
deviceID := config.GetDeviceID()
if deviceID.IsNil() {
e.G().Log.Debug("no device in user config")
return errNoDevice
}

// Make sure the device ID is still valid.
me, err := libkb.LoadMe(libkb.LoadUserArg{
PublicKeyOptional: true,
ForceReload: true,
})
me, err := libkb.LoadUser(loadUserArg)
if err != nil {
e.G().Log.Debug("error loading user profile: %#v", err)
return err
}
if !me.HasDeviceInCurrentInstall() {
if !me.HasDeviceInCurrentInstall(deviceID) {
e.G().Log.Debug("current device is not valid")
return errNoDevice
}
Expand Down
15 changes: 10 additions & 5 deletions go/libkb/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,22 +571,27 @@ func (u *User) DeviceNames() ([]string, error) {

// Returns whether or not the current install has an active device
// sibkey.
func (u *User) HasDeviceInCurrentInstall() bool {
func (u *User) HasDeviceInCurrentInstall(did keybase1.DeviceID) bool {
ckf := u.GetComputedKeyFamily()
if ckf == nil {
return false
}
did := u.G().Env.GetDeviceID()
if did.IsNil() {
return false
}

_, err := ckf.GetSibkeyForDevice(did)
if err != nil {
return false
}
return true
}

func (u *User) HasCurrentDeviceInCurrentInstall() bool {
did := u.G().Env.GetDeviceID()
if did.IsNil() {
return false
}
return u.HasDeviceInCurrentInstall(did)
}

func (u *User) SigningKeyPub() (GenericKey, error) {
// Get our key that we're going to sign with.
arg := SecretKeyArg{
Expand Down

0 comments on commit 3706a22

Please sign in to comment.