Skip to content

Commit fe0a0c6

Browse files
authored
ActiveDevice now holds a UserVersion, not a UID (keybase#13015)
* ActiveDevice now holds a UserVersion, not a UID - plumb the difference up and down * use ActiveDevice.UV in GetMeUV
1 parent 95a9ad1 commit fe0a0c6

23 files changed

Lines changed: 202 additions & 172 deletions

‎go/engine/bootstrap.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ func (e *Bootstrap) Run(m libkb.MetaContext) error {
6161
}
6262
m.CDebugf("Bootstrap: logged in (valid active device)")
6363

64-
e.status.Uid, e.status.DeviceID, e.status.DeviceName, _, _ = e.G().ActiveDevice.AllFields()
65-
e.status.Username = e.G().Env.GetUsername().String()
64+
var uv keybase1.UserVersion
65+
uv, e.status.DeviceID, e.status.DeviceName, _, _ = e.G().ActiveDevice.AllFields()
66+
e.status.Uid = uv.Uid
67+
e.status.Username = e.G().ActiveDevice.Username(m).String()
6668
m.CDebugf("Bootstrap status: uid=%s, username=%s, deviceID=%s, deviceName=%s", e.status.Uid, e.status.Username, e.status.DeviceID, e.status.DeviceName)
6769

6870
// get user summaries

‎go/engine/common_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func (fu FakeUser) UID() keybase1.UID {
7878
return libkb.UsernameToUID(fu.Username)
7979
}
8080

81+
func (fu FakeUser) UserVersion() keybase1.UserVersion {
82+
return keybase1.UserVersion{Uid: fu.UID(), EldestSeqno: 1}
83+
}
84+
8185
func NewFakeUserOrBust(tb libkb.TestingTB, prefix string) (fu *FakeUser) {
8286
var err error
8387
if fu, err = NewFakeUser(prefix); err != nil {

‎go/engine/device_wrap.go‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,25 @@ func (e *DeviceWrap) genKeys(m libkb.MetaContext) (err error) {
122122
return nil
123123
}
124124

125+
func (e *DeviceWrap) refreshMe(m libkb.MetaContext) (err error) {
126+
defer m.CTrace("DeviceWrap#refreshMe", func() error { return err })()
127+
if !e.args.IsEldest {
128+
return nil
129+
}
130+
m.CDebugf("reloading Me because we just bumped eldest seqno")
131+
e.args.Me, err = libkb.LoadMe(libkb.NewLoadUserArgWithMetaContext(m))
132+
return err
133+
}
134+
125135
func (e *DeviceWrap) setActiveDevice(m libkb.MetaContext) (err error) {
126136
defer m.CTrace("DeviceWrap#setActiveDevice", func() error { return err })()
127137

128-
if err := m.SetActiveDevice(e.args.Me.GetUID(), e.deviceID, e.signingKey, e.encryptionKey, e.args.DeviceName); err != nil {
138+
err = e.refreshMe(m)
139+
if err != nil {
140+
return err
141+
}
142+
143+
if err := m.SetActiveDevice(e.args.Me.ToUserVersion(), e.deviceID, e.signingKey, e.encryptionKey, e.args.DeviceName); err != nil {
129144
return err
130145
}
131146

‎go/engine/kex2_provisionee.go‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,15 @@ func (e *Kex2Provisionee) handleDidCounterSign(m libkb.MetaContext, sig []byte,
268268
// load self user (to load merkle root)
269269
m.CDebugf("| running for username %s", e.username)
270270
loadArg := libkb.NewLoadUserArgWithMetaContext(m).WithName(e.username)
271-
_, err = libkb.LoadUser(loadArg)
271+
var me *libkb.User
272+
me, err = libkb.LoadUser(loadArg)
272273
if err != nil {
273274
return err
274275
}
276+
uv := me.ToUserVersion()
277+
if !uv.Uid.Equal(e.uid) {
278+
return fmt.Errorf("Wrong user for key exchange: %v != %v", uv.Uid, e.uid)
279+
}
275280

276281
// decode sig
277282
decSig, err := e.decodeSig(sig)
@@ -296,7 +301,7 @@ func (e *Kex2Provisionee) handleDidCounterSign(m libkb.MetaContext, sig []byte,
296301
}
297302

298303
// logged in, so update our temporary session to say so
299-
err = e.updateTemporarySession(m)
304+
err = e.updateTemporarySession(m, uv)
300305
if err != nil {
301306
return err
302307
}
@@ -324,7 +329,7 @@ func (e *Kex2Provisionee) handleDidCounterSign(m libkb.MetaContext, sig []byte,
324329
}
325330

326331
// update the global active device, and also store the device keys in memory under ActiveDevice
327-
if err = e.saveConfig(m); err != nil {
332+
if err = e.saveConfig(m, uv); err != nil {
328333
return err
329334
}
330335

@@ -337,10 +342,10 @@ func (e *Kex2Provisionee) handleDidCounterSign(m libkb.MetaContext, sig []byte,
337342

338343
// updateTemporarySession commits the session token and csrf token to our temporary session,
339344
// stored in our provisional login context. We'll need that to post successfully.
340-
func (e *Kex2Provisionee) updateTemporarySession(m libkb.MetaContext) (err error) {
345+
func (e *Kex2Provisionee) updateTemporarySession(m libkb.MetaContext, uv keybase1.UserVersion) (err error) {
341346
defer m.CTrace("Kex2Provisionee#updateTemporarySession", func() error { return err })()
342347
m.CDebugf("login context: %T %+v", m.LoginContext(), m.LoginContext())
343-
return m.LoginContext().SaveState(string(e.sessionToken), string(e.csrfToken), libkb.NewNormalizedUsername(e.username), e.uid, e.device.ID)
348+
return m.LoginContext().SaveState(string(e.sessionToken), string(e.csrfToken), libkb.NewNormalizedUsername(e.username), uv, e.device.ID)
344349
}
345350

346351
type decodedSig struct {
@@ -633,7 +638,7 @@ func (e *Kex2Provisionee) ephemeralKeygen(m libkb.MetaContext, userEKBox *keybas
633638
}
634639

635640
// cacheKeys caches the device keys in the Account object.
636-
func (e *Kex2Provisionee) saveConfig(m libkb.MetaContext) (err error) {
641+
func (e *Kex2Provisionee) saveConfig(m libkb.MetaContext, uv keybase1.UserVersion) (err error) {
637642
defer m.CTrace("Kex2Provisionee#saveConfig", func() error { return err })()
638643
if e.eddsa == nil {
639644
return errors.New("cacheKeys called, but eddsa key is nil")
@@ -647,7 +652,7 @@ func (e *Kex2Provisionee) saveConfig(m libkb.MetaContext) (err error) {
647652
deviceName = *e.device.Description
648653
}
649654

650-
return m.SwitchUserNewConfigActiveDevice(e.uid, libkb.NewNormalizedUsername(e.username), e.salt, e.device.ID, e.eddsa, e.dh, deviceName)
655+
return m.SwitchUserNewConfigActiveDevice(uv, libkb.NewNormalizedUsername(e.username), e.salt, e.device.ID, e.eddsa, e.dh, deviceName)
651656
}
652657

653658
func (e *Kex2Provisionee) storeEKs(m libkb.MetaContext, deviceEKStatement keybase1.DeviceEkStatement, userEKBox *keybase1.UserEkBoxed) (err error) {

‎go/engine/login_offline_test.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ func TestLoginOffline(t *testing.T) {
3939
if err := RunEngine2(m, eng); err != nil {
4040
t.Fatal(err)
4141
}
42-
uid, deviceID, deviceName, skey, ekey := tc.G.ActiveDevice.AllFields()
43-
if uid.IsNil() {
42+
uv, deviceID, deviceName, skey, ekey := tc.G.ActiveDevice.AllFields()
43+
if uv.IsNil() {
4444
t.Errorf("uid is nil, expected it to exist")
4545
}
46-
if !uid.Equal(u1.UID()) {
47-
t.Errorf("uid: %q, expected %q", uid, u1.UID())
46+
if !uv.Uid.Equal(u1.UID()) {
47+
t.Errorf("uid: %v, expected %v", uv, u1)
4848
}
4949

5050
if deviceID.IsNil() {
@@ -104,12 +104,12 @@ func TestLoginOfflineDelay(t *testing.T) {
104104
if err := RunEngine2(m, eng); err != nil {
105105
t.Fatal(err)
106106
}
107-
uid, deviceID, deviceName, skey, ekey := tc.G.ActiveDevice.AllFields()
108-
if uid.IsNil() {
107+
uv, deviceID, deviceName, skey, ekey := tc.G.ActiveDevice.AllFields()
108+
if uv.IsNil() {
109109
t.Errorf("uid is nil, expected it to exist")
110110
}
111-
if !uid.Equal(u1.UID()) {
112-
t.Errorf("uid: %q, expected %q", uid, u1.UID())
111+
if !uv.Uid.Equal(u1.UID()) {
112+
t.Errorf("uid: %v, expected %v", uv, u1.UID())
113113
}
114114

115115
if deviceID.IsNil() {

‎go/engine/login_oneshot.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (e *LoginOneshot) checkLogin(m libkb.MetaContext) (err error) {
8484
func (e *LoginOneshot) makeLoginChanges(m libkb.MetaContext) (err error) {
8585
defer m.CTrace("LoginOneshot#makeLoginChanges", func() error { return err })()
8686
nun := libkb.NewNormalizedUsername(e.upak.GetName())
87-
return m.SwitchUserToActiveOneshotDevice(e.upak.GetUID(), nun, e.device)
87+
return m.SwitchUserToActiveOneshotDevice(e.upak.ToUserVersion(), nun, e.device)
8888
}
8989

9090
func (e *LoginOneshot) commitLoginChanges(m libkb.MetaContext) (err error) {

‎go/engine/login_provision.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,14 @@ func (e *loginProvision) paper(m libkb.MetaContext, device *libkb.Device) (err e
309309
m.CDebugf("paper encryption key kid: %s", keys.EncryptionKey().GetKID())
310310

311311
u := e.arg.User
312-
uid := u.GetUID()
312+
uv := u.ToUserVersion()
313313
nn := u.GetNormalizedName()
314314

315315
// Set the active device to be a special paper key active device, which keeps
316316
// a cached copy around for DeviceKeyGen, which requires it to be in memory.
317317
// It also will establish a NIST so that API calls can proceed on behalf of the user.
318-
m = m.WithPaperKeyActiveDevice(keys, uid)
319-
m.LoginContext().SetUsernameUID(nn, uid)
318+
m = m.WithPaperKeyActiveDevice(keys, uv)
319+
m.LoginContext().SetUsernameUserVersion(nn, uv)
320320

321321
// need lksec to store device keys locally
322322
if err := e.fetchLKS(m, keys.EncryptionKey()); err != nil {

‎go/engine/login_with_paperkey.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (e *LoginWithPaperKey) Run(m libkb.MetaContext) error {
7070

7171
// Convert our paper keys into a provisional active device, to use for
7272
// API session authentication. BAM! We're "logged in".
73-
m = m.WithPaperKeyActiveDevice(kp, me.GetUID())
73+
m = m.WithPaperKeyActiveDevice(kp, me.ToUserVersion())
7474

7575
// Get the LKS client half.
7676
gen, clientLKS, err := fetchLKS(m, kp.EncryptionKey())

‎go/engine/paperprovision.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ func (e *PaperProvisionEngine) paper(m libkb.MetaContext, keys *libkb.DeviceWith
140140
// After obtaining login session, this will be called before the login state is released.
141141
// It signs this new device with the paper key.
142142
u := e.User
143-
uid := u.GetUID()
144143
nn := u.GetNormalizedName()
144+
uv := u.ToUserVersion()
145145

146146
// Set the active device to be a special paper key active device, which keeps
147147
// a cached copy around for DeviceKeyGen, which requires it to be in memory.
148148
// It also will establish a NIST so that API calls can proceed on behalf of the user.
149-
m = m.WithPaperKeyActiveDevice(keys, uid)
150-
m.LoginContext().SetUsernameUID(nn, uid)
149+
m = m.WithPaperKeyActiveDevice(keys, uv)
150+
m.LoginContext().SetUsernameUserVersion(nn, uv)
151151

152152
// need lksec to store device keys locally
153153
if err := e.fetchLKS(m, keys.EncryptionKey()); err != nil {

‎go/engine/passphrase_change.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (c *PassphraseChange) findUpdateDevice(m libkb.MetaContext) (ad *libkb.Acti
129129
m.CDebugf("| error fetching paper keys")
130130
return nil, err
131131
}
132-
ad = libkb.NewActiveDeviceWithDeviceWithKeys(m, m.CurrentUID(), kp)
132+
ad = libkb.NewActiveDeviceWithDeviceWithKeys(m, m.CurrentUserVersion(), kp)
133133
m.CDebugf("| installing paper key as thread-local active device")
134134
return ad, nil
135135
}

0 commit comments

Comments
 (0)