-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
track.go
130 lines (107 loc) · 3.12 KB
/
track.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package engine
import (
"errors"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
type TrackEngineArg struct {
UserAssertion string
Me *libkb.User
Options keybase1.TrackOptions
ForceRemoteCheck bool
SigVersion libkb.SigVersion
}
type TrackEngine struct {
arg *TrackEngineArg
them *libkb.User
libkb.Contextified
confirmResult keybase1.ConfirmResult
}
// NewTrackEngine creates a default TrackEngine for tracking theirName.
func NewTrackEngine(g *libkb.GlobalContext, arg *TrackEngineArg) *TrackEngine {
return &TrackEngine{
arg: arg,
Contextified: libkb.NewContextified(g),
}
}
func (e *TrackEngine) Name() string {
return "Follow"
}
func (e *TrackEngine) Prereqs() Prereqs {
return Prereqs{
Device: true,
}
}
func (e *TrackEngine) RequiredUIs() []libkb.UIKind {
return []libkb.UIKind{
libkb.SecretUIKind,
libkb.IdentifyUIKind,
}
}
func (e *TrackEngine) SubConsumers() []libkb.UIConsumer {
return []libkb.UIConsumer{
&ResolveThenIdentify2{},
}
}
func (e *TrackEngine) Run(m libkb.MetaContext) error {
m.G().LocalSigchainGuard().Set(m.Ctx(), "TrackEngine")
defer m.G().LocalSigchainGuard().Clear(m.Ctx(), "TrackEngine")
arg := &keybase1.Identify2Arg{
UserAssertion: e.arg.UserAssertion,
ForceRemoteCheck: e.arg.ForceRemoteCheck,
NeedProofSet: true,
NoErrorOnTrackFailure: true,
AlwaysBlock: true,
}
if m.UIs().SessionID != 0 {
arg.IdentifyBehavior = keybase1.TLFIdentifyBehavior_GUI
} else {
arg.IdentifyBehavior = keybase1.TLFIdentifyBehavior_CLI
}
ieng := NewResolveThenIdentify2WithTrack(m.G(), arg, e.arg.Options)
if err := RunEngine2(m, ieng); err != nil {
return err
}
res, err := ieng.Result(m)
if err != nil {
return err
}
upk := res.Upk
if _, uid, _ := libkb.BootstrapActiveDeviceWithMetaContext(m); uid.Equal(upk.GetUID()) {
return errors.New("You can't follow yourself.")
}
loadarg := libkb.NewLoadUserArgWithMetaContext(m).WithUID(upk.GetUID()).WithPublicKeyOptional()
e.them, err = libkb.LoadUser(loadarg)
if err != nil {
return err
}
e.confirmResult = ieng.ConfirmResult()
if !e.confirmResult.IdentityConfirmed {
m.Debug("confirmResult: %+v", e.confirmResult)
return errors.New("Follow not confirmed")
}
// if they didn't specify local only on the command line, then if they answer no to posting
// the tracking statement publicly to keybase, change LocalOnly to true here:
if !e.arg.Options.LocalOnly && !e.confirmResult.RemoteConfirmed {
e.arg.Options.LocalOnly = true
}
if !e.arg.Options.ExpiringLocal && e.confirmResult.ExpiringLocal {
m.Debug("-ExpiringLocal-")
e.arg.Options.ExpiringLocal = true
}
targ := &TrackTokenArg{
Token: ieng.TrackToken(),
Me: e.arg.Me,
Options: e.arg.Options,
}
teng := NewTrackToken(m.G(), targ)
return RunEngine2(m, teng)
}
func (e *TrackEngine) User() *libkb.User {
return e.them
}
func (e *TrackEngine) ConfirmResult() keybase1.ConfirmResult {
return e.confirmResult
}