Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking if current device is revoked in CanLogout #16889

Merged
merged 6 commits into from Apr 10, 2019

Conversation

zapu
Copy link
Contributor

@zapu zapu commented Apr 8, 2019

If we are unable to check HasRandomPW while logging out, check if we are revoked.

Checking HasRandomPW status code would be sufficient (API session error) but this would be server trust, and also prone to other misc errors. And we are trying really hard not to log user out if they don't have passphrase.

@@ -638,6 +639,29 @@ func (h *UserHandler) LoadHasRandomPw(ctx context.Context, arg keybase1.LoadHasR
return ret.RandomPW, err
}

func isActiveDeviceRevoked(mctx libkb.MetaContext) (res bool, err error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlsteele is there an easier way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkDeviceValidForUID

@zapu zapu requested review from mlsteele and joshblum April 8, 2019 09:53
@zapu
Copy link
Contributor Author

zapu commented Apr 8, 2019

It's a simple but rather important change - comments appreciated!

We are always erring on the side of caution here, we don't want to log someone out if we are not sure if they can log back in. There is always a workaround by doing keybase logout --force which skips all checks, but during normal keybase logout it's better to be safe than sorry.

@@ -638,6 +639,29 @@ func (h *UserHandler) LoadHasRandomPw(ctx context.Context, arg keybase1.LoadHasR
return ret.RandomPW, err
}

func isActiveDeviceRevoked(mctx libkb.MetaContext) (res bool, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkDeviceValidForUID

@@ -651,6 +675,15 @@ func (h *UserHandler) CanLogout(ctx context.Context, sessionID int) (res keybase
})

if err != nil {
isRevoked, err2 := isActiveDeviceRevoked(libkb.NewMetaContext(ctx, h.G()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

streamline error handling here and make it more go-y. don't have nested-if error conditions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted it to be nested here so this is only checked if call to hasRandomPW fails, because hasRandomPW can be cached and works offline. So if CheckCurrentUIDDeviceID is only called when hasRandomPW fails, the whole RPC still have the ability to work offline (assuming hasRandomPW can find a cached value).

Unless there is some other control flow simplification that I'm missing

@zapu
Copy link
Contributor Author

zapu commented Apr 8, 2019

OK this RPC turned out to have more issues than I expected, so we are not trying to rush it for the release. Stranded users can still use keybase logout --force, although it's rather hard to get in this state, because when you become revoked or reset, you get a gregor message that logs you out.

Copy link
Member

@joshblum joshblum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

// revoked device. If so, green-light logout.
if checkUIDErr := libkb.CheckCurrentUIDDeviceID(libkb.NewMetaContext(ctx, h.G())); checkUIDErr != nil {
switch checkUIDErr.(type) {
case libkb.DeviceNotFoundError, libkb.UserNotFoundError, libkb.KeyRevokedError, libkb.NoDeviceError, libkb.NoUIDError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: dropping a newline between these errors makes it easier to read imo

@zapu
Copy link
Contributor Author

zapu commented Apr 10, 2019

@joshblum @maxtaco made the CanLogout check more straightforward but potentially more expensive - libkb.CheckCurrentUIDDeviceID is called every time, not only when HasRandomPW errors out. This is much simplier and less error prone with regards to HasRandomPW cache.

Also added a test for the revoked device + canLogout case.

@zapu zapu merged commit d4e9908 into master Apr 10, 2019
@zapu zapu deleted the zapu/CORE-10571-can-logout-revoked branch April 10, 2019 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants