/
context.go
706 lines (613 loc) · 19.4 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
package libkb
import (
"fmt"
"runtime/debug"
"time"
logger "github.com/adamwalz/keybase-client/go/logger"
"github.com/adamwalz/keybase-client/go/profiling"
keybase1 "github.com/adamwalz/keybase-client/go/protocol/keybase1"
context "golang.org/x/net/context"
)
type APITokener interface {
Tokens() (session, csrf string)
}
type MetaContext struct {
ctx context.Context
g *GlobalContext
loginContext LoginContext
activeDevice *ActiveDevice
apiTokener APITokener
uis UIs
}
func (m MetaContext) Dump() {
m.Debug("MetaContext#Dump:")
if m.activeDevice != nil {
m.Debug("- Local ActiveDevice:")
m.activeDevice.Dump(m, "-- ")
}
m.Debug("- Global ActiveDevice:")
m.g.ActiveDevice.Dump(m, "-- ")
if m.loginContext != nil {
m.Debug("- Login Context:")
m.loginContext.Dump(m, "-- ")
}
}
func NewMetaContext(ctx context.Context, g *GlobalContext) MetaContext {
return MetaContext{ctx: ctx, g: g}
}
func (m MetaContext) WithLoginContext(l LoginContext) MetaContext {
m.loginContext = l
return m
}
func (m MetaContext) WithAPITokener(t APITokener) MetaContext {
m.apiTokener = t
return m
}
func (m MetaContext) WithCtx(c context.Context) MetaContext {
m.ctx = c
return m
}
func (m MetaContext) G() *GlobalContext {
return m.g
}
func (m MetaContext) Ctx() context.Context {
return m.ctx
}
func (m MetaContext) LoginContext() LoginContext {
return m.loginContext
}
func (m MetaContext) VLogf(lev VDebugLevel, msg string, args ...interface{}) {
m.g.VDL.CLogfWithAddedDepth(m.ctx, lev, 1, msg, args...)
}
func (m MetaContext) Trace(msg string, err *error) func() {
return CTrace(m.ctx, m.g.Log.CloneWithAddedDepth(1), msg, err, m.G().Clock())
}
func (m MetaContext) VTrace(lev VDebugLevel, msg string, err *error) func() {
return m.g.CVTrace(m.ctx, lev, msg, err)
}
func (m MetaContext) PerfTrace(msg string, err *error) func() {
return CTrace(m.ctx, m.g.PerfLog.CloneWithAddedDepth(1), msg, err, m.G().Clock())
}
func (m MetaContext) TimeBuckets() (MetaContext, *profiling.TimeBuckets) {
var ret *profiling.TimeBuckets
m.ctx, ret = m.G().CTimeBuckets(m.ctx)
return m, ret
}
func (m MetaContext) TimeTracer(label string, enabled bool) profiling.TimeTracer {
return m.G().CTimeTracer(m.Ctx(), label, enabled)
}
func (m MetaContext) Debug(f string, args ...interface{}) {
m.g.Log.CloneWithAddedDepth(1).CDebugf(m.ctx, f, args...)
}
func (m MetaContext) PerfDebug(f string, args ...interface{}) {
m.g.PerfLog.CloneWithAddedDepth(1).CDebugf(m.ctx, f, args...)
}
func (m MetaContext) Warning(f string, args ...interface{}) {
m.g.Log.CloneWithAddedDepth(1).CWarningf(m.ctx, f, args...)
}
func (m MetaContext) Error(f string, args ...interface{}) {
m.g.Log.CloneWithAddedDepth(1).CErrorf(m.ctx, f, args...)
}
func (m MetaContext) Info(f string, args ...interface{}) {
m.g.Log.CloneWithAddedDepth(1).CInfof(m.ctx, f, args...)
}
func (m MetaContext) ActiveDevice() *ActiveDevice {
if m.activeDevice != nil {
m.Debug("MetaContext#ActiveDevice: thread local")
return m.activeDevice
}
m.Debug("MetaContext#ActiveDevice: global")
return m.G().ActiveDevice
}
func (m MetaContext) NIST() (*NIST, error) {
nist, uid, _, err := m.ActiveDevice().NISTAndUIDDeviceID(m.Ctx())
if err != nil {
return nil, err
}
if !uid.Equal(m.CurrentUID()) {
m.Debug("MetaContext#NIST: Not returning nist, since for wrong UID: %s != %s", uid, m.CurrentUID())
return nil, nil
}
return nist, nil
}
func NewMetaContextTODO(g *GlobalContext) MetaContext {
return MetaContext{ctx: context.TODO(), g: g}
}
func NewMetaContextBackground(g *GlobalContext) MetaContext {
return MetaContext{ctx: context.Background(), g: g}
}
func (m MetaContext) WithDelegatedIdentifyUI(u IdentifyUI) MetaContext {
m.uis.IdentifyUI = u
return m
}
func (m MetaContext) WithContext(ctx context.Context) MetaContext {
m.ctx = ctx
return m
}
func (m MetaContext) WithContextCancel() (MetaContext, func()) {
var f func()
m.ctx, f = context.WithCancel(m.ctx)
return m, f
}
func (m MetaContext) BackgroundWithCancel() (MetaContext, func()) {
var f func()
m.ctx, f = context.WithCancel(context.Background())
return m, f
}
func (m MetaContext) BackgroundWithLogTags() MetaContext {
m.ctx = CopyTagsToBackground(m.ctx)
return m
}
func (m MetaContext) WithTimeout(timeout time.Duration) (MetaContext, func()) {
var f func()
m.ctx, f = context.WithTimeout(m.ctx, timeout)
return m, f
}
func (m MetaContext) WithLogTag(k string) MetaContext {
m.ctx = WithLogTag(m.ctx, k)
return m
}
func (m MetaContext) WithLogTags(tags map[string]string) MetaContext {
for k, v := range tags {
m.ctx = WithLogTagWithValue(m.ctx, k, v)
}
return m
}
func (m MetaContext) WithTimeBuckets() (MetaContext, *profiling.TimeBuckets) {
ctx, tbs := m.G().CTimeBuckets(m.ctx)
m.ctx = ctx
return m, tbs
}
func (m MetaContext) EnsureCtx() MetaContext {
if m.ctx == nil {
m.ctx = context.Background()
m.Debug("installing background context.Context")
}
return m
}
func (m MetaContext) WithSecretUI(u SecretUI) MetaContext {
m.uis.SecretUI = u
return m
}
func (m MetaContext) WithLogUI(u LogUI) MetaContext {
m.uis.LogUI = u
return m
}
func (m MetaContext) WithPgpUI(u PgpUI) MetaContext {
m.uis.PgpUI = u
return m
}
func (m MetaContext) WithIdentifyUI(u IdentifyUI) MetaContext {
m.uis.IdentifyUI = u
return m
}
func (m MetaContext) WithGPGUI(u GPGUI) MetaContext {
m.uis.GPGUI = u
return m
}
func (m MetaContext) WithSaltpackUI(s SaltpackUI) MetaContext {
m.uis.SaltpackUI = s
return m
}
func (m MetaContext) UIs() UIs {
return m.uis
}
func (m MetaContext) WithUIs(u UIs) MetaContext {
m.uis = u
return m
}
func (m MetaContext) WithActiveDevice(a *ActiveDevice) MetaContext {
m.activeDevice = a
return m
}
func (m MetaContext) WithProvisioningKeyActiveDevice(d *DeviceWithKeys, uv keybase1.UserVersion) MetaContext {
return m.WithActiveDevice(d.ToProvisioningKeyActiveDevice(m, uv))
}
func (m MetaContext) WithGlobalActiveDevice() MetaContext {
m.activeDevice = nil
return m
}
func (m MetaContext) SecretKeyPromptArg(ska SecretKeyArg, reason string) SecretKeyPromptArg {
return SecretKeyPromptArg{
SecretUI: m.uis.SecretUI,
Ska: ska,
Reason: reason,
}
}
func (m MetaContext) WithNewProvisionalLoginContext() MetaContext {
return m.WithLoginContext(newProvisionalLoginContext(m))
}
func (m MetaContext) WithNewProvisionalLoginContextForUser(u *User) MetaContext {
return m.WithNewProvisionalLoginContextForUserVersionAndUsername(u.ToUserVersion(), u.GetNormalizedName())
}
func (m MetaContext) WithNewProvisionalLoginContextForUserVersionAndUsername(uv keybase1.UserVersion, un NormalizedUsername) MetaContext {
plc := newProvisionalLoginContextWithUserVersionAndUsername(m, uv, un)
err := m.ActiveDevice().CopyCacheToLoginContextIfForUserVersion(m, plc, uv)
if err != nil {
m.Debug("WithNewProvisionalLoginContextForUserVersionAndUsername: error %+v", err)
}
return m.WithLoginContext(plc)
}
func (m MetaContext) CommitProvisionalLogin() MetaContext {
m.Debug("MetaContext#CommitProvisionalLogin")
lctx := m.loginContext
m.loginContext = nil
if lctx != nil {
if ppsc := lctx.PassphraseStreamCache(); ppsc != nil {
m.ActiveDevice().CachePassphraseStream(ppsc)
}
}
return m
}
type UIs struct {
GPGUI GPGUI
LogUI LogUI
LoginUI LoginUI
SecretUI SecretUI
IdentifyUI IdentifyUI
PgpUI PgpUI
ProveUI ProveUI
ProvisionUI ProvisionUI
SaltpackUI SaltpackUI
// Usually set to `NONE`, meaning none specified.
// But if we know it, specify the end client type here
// since some things like GPG shell-out work differently
// depending.
ClientType keybase1.ClientType
SessionID int
}
func (e UIs) HasUI(kind UIKind) bool {
switch kind {
case GPGUIKind:
return e.GPGUI != nil
case LogUIKind:
return e.LogUI != nil
case LoginUIKind:
return e.LoginUI != nil
case SecretUIKind:
return e.SecretUI != nil
case IdentifyUIKind:
return e.IdentifyUI != nil
case PgpUIKind:
return e.PgpUI != nil
case ProveUIKind:
return e.ProveUI != nil
case ProvisionUIKind:
return e.ProvisionUI != nil
case SaltpackUIKind:
return e.SaltpackUI != nil
}
panic(fmt.Sprintf("unhandled kind: %d", kind))
}
type MetaContextified struct {
m MetaContext
}
func (m MetaContextified) M() MetaContext {
return m.m
}
func (m MetaContextified) G() *GlobalContext {
return m.m.g
}
func NewMetaContextified(m MetaContext) MetaContextified {
return MetaContextified{m: m}
}
// SwitchUserNewConfig switches the global active "user" as far as the global
// config file is concerned. It switches the user to a new user, and therefore
// you should specify the username, salt, and device ID for this user on this
// device. It will take out the global `switchUserMu` and also clear out the
// global ActiveDevice at the same time. We follow the same pattern here and
// elsewhere: atomically mutate the `current_user` of the config file as we set
// the global ActiveDevice.
func (m MetaContext) SwitchUserNewConfig(u keybase1.UID, n NormalizedUsername, salt []byte, d keybase1.DeviceID) error {
return m.switchUserNewConfig(u, n, salt, d, nil)
}
func (m MetaContext) switchUserNewConfig(u keybase1.UID, n NormalizedUsername, salt []byte, d keybase1.DeviceID, ad *ActiveDevice) error {
g := m.G()
defer g.switchUserMu.Acquire(m, "switchUserNewConfig")()
cw := g.Env.GetConfigWriter()
if cw == nil {
return NoConfigWriterError{}
}
// Note that `true` here means that an existing user config entry will
// be overwritten.
if err := cw.SetUserConfig(NewUserConfig(u, n, salt, d), true /* overwrite */); err != nil {
return err
}
// Clear stayLoggedOut, so that if the service restarts for any reason
// we will know that we are logged in.
if g.Env.GetStayLoggedOut() {
if err := cw.SetStayLoggedOut(false); err != nil {
return err
}
}
return g.ActiveDevice.SetOrClear(m, ad)
}
// SwitchUserNewConfigActiveDevice creates a new config file stanza and an
// active device for the given user, all while holding the switchUserMu lock.
func (m MetaContext) SwitchUserNewConfigActiveDevice(uv keybase1.UserVersion, n NormalizedUsername, salt []byte, d keybase1.DeviceID, sigKey GenericKey, encKey GenericKey, deviceName string, keychainMode KeychainMode) error {
ad := NewProvisionalActiveDevice(m, uv, d, sigKey, encKey, deviceName, keychainMode)
return m.switchUserNewConfig(uv.Uid, n, salt, d, ad)
}
// SwitchUserNukeConfig removes the given username from the config file, and
// then switches to not having a current user (by clearing the ActiveDevice,
// etc). It does this in a critical section, holding switchUserMu.
func (m MetaContext) SwitchUserNukeConfig(n NormalizedUsername) error {
g := m.G()
defer g.switchUserMu.Acquire(m, "SwitchUserNukeConfig")()
cw := g.Env.GetConfigWriter()
cr := g.Env.GetConfig()
if cw == nil {
return NoConfigWriterError{}
}
if cr == nil {
return NoConfigFileError{}
}
uid := cr.GetUIDForUsername(n)
err := cw.NukeUser(n)
if err != nil {
return err
}
if g.ActiveDevice.UID().Equal(uid) {
err := g.ActiveDevice.Clear()
if err != nil {
return err
}
}
return nil
}
func (m MetaContext) SwitchUser(n NormalizedUsername) error {
return m.SwitchUserToActiveDevice(n, nil)
}
func (m MetaContext) SwitchUserToActiveDevice(n NormalizedUsername, ad *ActiveDevice) (err error) {
defer m.Trace(fmt.Sprintf("MetaContext#SwitchUserToActiveDevice(%s,ActiveDevice:%v)", n.String(), (ad != nil)), &err)()
g := m.G()
if n.IsNil() {
return nil
}
if !n.IsValid() {
return NewBadUsernameError(n.String())
}
defer g.switchUserMu.Acquire(m, "SwitchUserToActiveDevice %v", n)()
cw := g.Env.GetConfigWriter()
if cw == nil {
return NoConfigWriterError{}
}
err = cw.SwitchUser(n)
if _, ok := err.(UserNotFoundError); ok {
m.Debug("| No user %s found; clearing out config", n)
err = nil
}
if err != nil {
return err
}
err = g.ActiveDevice.SetOrClear(m, ad)
if err != nil {
return err
}
m.CommitProvisionalLogin()
return nil
}
func (m MetaContext) SwitchUserDeprovisionNukeConfig(username NormalizedUsername) error {
g := m.G()
defer g.switchUserMu.Acquire(m, "SwitchUserDeprovisionNukeConfig %v", username)()
cw := g.Env.GetConfigWriter()
if cw == nil {
return NoConfigWriterError{}
}
if err := cw.NukeUser(username); err != nil {
return err
}
// The config entries we just nuked could still be in memory. Clear them.
return cw.SetUserConfig(nil, true /* overwrite; ignored */)
}
// SetActiveOneshotDevice acquires the switchUserMu mutex, setting the active
// device to one that corresponds to the given UID and DeviceWithKeys, and also
// sets the config file to a temporary in-memory config (not writing to disk)
// to satisfy local requests for g.Env.*
func (m MetaContext) SwitchUserToActiveOneshotDevice(uv keybase1.UserVersion, nun NormalizedUsername, d *DeviceWithKeys) (err error) {
defer m.Trace("MetaContext#SwitchUserToActiveOneshotDevice", &err)()
g := m.G()
defer g.switchUserMu.Acquire(m, "SwitchUserToActiveOneshotDevice")()
cw := g.Env.GetConfigWriter()
if cw == nil {
return NoConfigWriterError{}
}
ad := d.ToProvisioningKeyActiveDevice(m, uv)
err = g.ActiveDevice.Copy(m, ad)
if err != nil {
return err
}
uc := NewOneshotUserConfig(uv.Uid, nun, nil, d.DeviceID())
err = cw.SetUserConfig(uc, false)
if err != nil {
return err
}
return nil
}
// SwitchUserLoggedOut clears the active device and the current_user stanza of
// the config file, all while holding the switchUserMu
func (m MetaContext) SwitchUserLoggedOut() (err error) {
defer m.Trace("MetaContext#SwitchUserLoggedOut", &err)()
g := m.G()
defer g.switchUserMu.Acquire(m, "SwitchUserLoggedOut")()
cw := g.Env.GetConfigWriter()
if cw == nil {
return NoConfigWriterError{}
}
err = g.ActiveDevice.Clear()
if err != nil {
return err
}
err = cw.SetUserConfig(nil, false)
if err != nil {
return err
}
return nil
}
// SetActiveDevice sets the active device to have the UserVersion, deviceID,
// sigKey, encKey and deviceName as specified, and does so while grabbing the
// global switchUser lock, since it should be sycnhronized with attempts to
// switch the global logged in user. It does not, however, change the
// `current_user` in the config file, or edit the global config file in any
// way.
func (m MetaContext) SetActiveDevice(uv keybase1.UserVersion, deviceID keybase1.DeviceID,
sigKey, encKey GenericKey, deviceName string, keychainMode KeychainMode) error {
g := m.G()
defer g.switchUserMu.Acquire(m, "SetActiveDevice")()
if !g.Env.GetUID().Equal(uv.Uid) {
return NewUIDMismatchError("UID switched out from underneath provisioning process")
}
return g.ActiveDevice.Set(m, uv, deviceID, sigKey, encKey, deviceName, 0, keychainMode)
}
func (m MetaContext) SetSigningKey(uv keybase1.UserVersion, deviceID keybase1.DeviceID, sigKey GenericKey, deviceName string) error {
g := m.G()
defer g.switchUserMu.Acquire(m, "SetSigningKey")()
return g.ActiveDevice.setSigningKey(g, uv, deviceID, sigKey, deviceName)
}
func (m MetaContext) SetEncryptionKey(uv keybase1.UserVersion, deviceID keybase1.DeviceID, encKey GenericKey) error {
g := m.G()
defer g.switchUserMu.Acquire(m, "SetEncryptionKey")()
return g.ActiveDevice.setEncryptionKey(uv, deviceID, encKey)
}
// LogoutAndDeprovisionIfRevoked loads the user and checks if the current
// device keys have been revoked. If so, it calls Logout and then runs the
// ClearSecretsOnDeprovision
func (m MetaContext) LogoutAndDeprovisionIfRevoked() (err error) {
m = m.WithLogTag("LOIR")
defer m.Trace("GlobalContext#LogoutAndDeprovisionIfRevoked", &err)()
if !m.ActiveDevice().Valid() {
m.Debug("LogoutAndDeprovisionIfRevoked: skipping check (not logged in)")
return nil
}
if m.G().Env.GetSkipLogoutIfRevokedCheck() {
m.Debug("LogoutAndDeprovisionIfRevoked: skipping check (SkipLogoutIfRevokedCheck)")
return nil
}
doLogout := false
err = CheckCurrentUIDDeviceID(m)
switch err.(type) {
case nil:
m.Debug("LogoutAndDeprovisionIfRevoked: current device ok")
case DeviceNotFoundError:
m.Debug("LogoutAndDeprovisionIfRevoked: device not found error; user was likely reset; calling logout (%s)", err)
doLogout = true
case KeyRevokedError:
m.Debug("LogoutAndDeprovisionIfRevoked: key revoked error error; device was revoked; calling logout (%s)", err)
doLogout = true
default:
m.Debug("LogoutAndDeprovisionIfRevoked: non-actionable error: %s", err)
}
if doLogout {
username := m.G().Env.GetUsername()
if err := m.LogoutWithOptions(LogoutOptions{KeepSecrets: false, Force: true}); err != nil {
return err
}
return ClearSecretsOnDeprovision(m, username)
}
return nil
}
func (m MetaContext) PassphraseStream() *PassphraseStream {
if m.LoginContext() != nil {
if m.LoginContext().PassphraseStreamCache() == nil {
return nil
}
return m.LoginContext().PassphraseStreamCache().PassphraseStream()
}
return m.ActiveDevice().PassphraseStream()
}
func (m MetaContext) PassphraseStreamAndTriplesec() (*PassphraseStream, Triplesec) {
var ppsc *PassphraseStreamCache
if m.LoginContext() != nil {
ppsc = m.LoginContext().PassphraseStreamCache()
} else {
ppsc = m.ActiveDevice().PassphraseStreamCache()
}
if ppsc == nil {
return nil, nil
}
return ppsc.PassphraseStreamAndTriplesec()
}
func (m MetaContext) TriplesecAndGeneration() (ret Triplesec, ppgen PassphraseGeneration) {
var pps *PassphraseStream
pps, ret = m.PassphraseStreamAndTriplesec()
if pps == nil {
return nil, ppgen
}
ppgen = pps.Generation()
if ppgen.IsNil() {
return nil, ppgen
}
return ret, ppgen
}
func (m MetaContext) CurrentUsername() NormalizedUsername {
if m.LoginContext() != nil {
return m.LoginContext().GetUsername()
}
return m.ActiveDevice().Username(m)
}
func (m MetaContext) CurrentUID() keybase1.UID {
if m.LoginContext() != nil {
return m.LoginContext().GetUID()
}
return m.ActiveDevice().UID()
}
func (m MetaContext) CurrentUserVersion() keybase1.UserVersion {
if m.LoginContext() != nil {
return m.LoginContext().GetUserVersion()
}
return m.ActiveDevice().UserVersion()
}
func (m MetaContext) HasAnySession() (ret bool) {
defer m.Trace("MetaContext#HasAnySession", nil)()
if m.LoginContext() != nil {
ok, _ := m.LoginContext().LoggedInLoad()
if ok {
m.Debug("| has temporary login session")
return true
}
}
if m.ActiveDevice().Valid() {
m.Debug("| has valid device")
return true
}
return false
}
func (m MetaContext) SyncSecrets() (ss *SecretSyncer, err error) {
defer m.Trace("MetaContext#SyncSecrets", &err)()
if m.LoginContext() != nil {
err = m.LoginContext().RunSecretSyncer(m, keybase1.UID(""))
if err != nil {
return nil, err
}
return m.LoginContext().SecretSyncer(), nil
}
return m.ActiveDevice().SyncSecrets(m)
}
func (m MetaContext) SyncSecretsForUID(u keybase1.UID) (ss *SecretSyncer, err error) {
defer m.Trace("MetaContext#SyncSecrets", &err)()
return m.ActiveDevice().SyncSecretsForUID(m, u, false /* force */)
}
func (m MetaContext) ProvisionalSessionArgs() (token string, csrf string) {
if m.LoginContext() == nil {
return "", ""
}
sess := m.LoginContext().LocalSession()
if sess == nil || !sess.IsValid() {
return "", ""
}
return sess.token, sess.csrf
}
func (m MetaContext) Keyring() (ret *SKBKeyringFile, err error) {
defer m.Trace("MetaContext#Keyring", &err)()
if m.LoginContext() != nil {
return m.LoginContext().Keyring(m)
}
return m.ActiveDevice().Keyring(m)
}
var _ logger.ContextInterface = MetaContext{}
func (m MetaContext) UpdateContextToLoggerContext(c context.Context) logger.ContextInterface {
return m.WithContext(c)
}
func (m MetaContext) DebugStack() {
m.Debug("stack trace:\n%s", string(debug.Stack()))
}