/
rekey.go
411 lines (372 loc) · 11.4 KB
/
rekey.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
// Auto-generated by avdl-compiler v1.3.20 (https://github.com/keybase/node-avdl-compiler)
// Input file: avdl/keybase1/rekey.avdl
package keybase1
import (
"github.com/keybase/go-framed-msgpack-rpc/rpc"
context "golang.org/x/net/context"
)
type TLF struct {
Id TLFID `codec:"id" json:"id"`
Name string `codec:"name" json:"name"`
Writers []string `codec:"writers" json:"writers"`
Readers []string `codec:"readers" json:"readers"`
IsPrivate bool `codec:"isPrivate" json:"isPrivate"`
}
func (o TLF) DeepCopy() TLF {
return TLF{
Id: o.Id.DeepCopy(),
Name: o.Name,
Writers: (func(x []string) []string {
if x == nil {
return nil
}
var ret []string
for _, v := range x {
vCopy := v
ret = append(ret, vCopy)
}
return ret
})(o.Writers),
Readers: (func(x []string) []string {
if x == nil {
return nil
}
var ret []string
for _, v := range x {
vCopy := v
ret = append(ret, vCopy)
}
return ret
})(o.Readers),
IsPrivate: o.IsPrivate,
}
}
type ProblemTLF struct {
Tlf TLF `codec:"tlf" json:"tlf"`
Score int `codec:"score" json:"score"`
Solution_kids []KID `codec:"solution_kids" json:"solution_kids"`
}
func (o ProblemTLF) DeepCopy() ProblemTLF {
return ProblemTLF{
Tlf: o.Tlf.DeepCopy(),
Score: o.Score,
Solution_kids: (func(x []KID) []KID {
if x == nil {
return nil
}
var ret []KID
for _, v := range x {
vCopy := v.DeepCopy()
ret = append(ret, vCopy)
}
return ret
})(o.Solution_kids),
}
}
// ProblemSet is for a particular (user,kid) that initiated a rekey problem.
// This problem consists of one or more problem TLFs, which are individually scored
// and have attendant solutions --- devices that if they came online can rekey and
// solve the ProblemTLF.
type ProblemSet struct {
User User `codec:"user" json:"user"`
Kid KID `codec:"kid" json:"kid"`
Tlfs []ProblemTLF `codec:"tlfs" json:"tlfs"`
}
func (o ProblemSet) DeepCopy() ProblemSet {
return ProblemSet{
User: o.User.DeepCopy(),
Kid: o.Kid.DeepCopy(),
Tlfs: (func(x []ProblemTLF) []ProblemTLF {
if x == nil {
return nil
}
var ret []ProblemTLF
for _, v := range x {
vCopy := v.DeepCopy()
ret = append(ret, vCopy)
}
return ret
})(o.Tlfs),
}
}
type ProblemSetDevices struct {
ProblemSet ProblemSet `codec:"problemSet" json:"problemSet"`
Devices []Device `codec:"devices" json:"devices"`
}
func (o ProblemSetDevices) DeepCopy() ProblemSetDevices {
return ProblemSetDevices{
ProblemSet: o.ProblemSet.DeepCopy(),
Devices: (func(x []Device) []Device {
if x == nil {
return nil
}
var ret []Device
for _, v := range x {
vCopy := v.DeepCopy()
ret = append(ret, vCopy)
}
return ret
})(o.Devices),
}
}
type Outcome int
const (
Outcome_NONE Outcome = 0
Outcome_FIXED Outcome = 1
Outcome_IGNORED Outcome = 2
)
func (o Outcome) DeepCopy() Outcome { return o }
var OutcomeMap = map[string]Outcome{
"NONE": 0,
"FIXED": 1,
"IGNORED": 2,
}
var OutcomeRevMap = map[Outcome]string{
0: "NONE",
1: "FIXED",
2: "IGNORED",
}
func (e Outcome) String() string {
if v, ok := OutcomeRevMap[e]; ok {
return v
}
return ""
}
type RevokeWarning struct {
EndangeredTLFs []TLF `codec:"endangeredTLFs" json:"endangeredTLFs"`
}
func (o RevokeWarning) DeepCopy() RevokeWarning {
return RevokeWarning{
EndangeredTLFs: (func(x []TLF) []TLF {
if x == nil {
return nil
}
var ret []TLF
for _, v := range x {
vCopy := v.DeepCopy()
ret = append(ret, vCopy)
}
return ret
})(o.EndangeredTLFs),
}
}
type ShowPendingRekeyStatusArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
}
func (o ShowPendingRekeyStatusArg) DeepCopy() ShowPendingRekeyStatusArg {
return ShowPendingRekeyStatusArg{
SessionID: o.SessionID,
}
}
type GetPendingRekeyStatusArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
}
func (o GetPendingRekeyStatusArg) DeepCopy() GetPendingRekeyStatusArg {
return GetPendingRekeyStatusArg{
SessionID: o.SessionID,
}
}
type DebugShowRekeyStatusArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
}
func (o DebugShowRekeyStatusArg) DeepCopy() DebugShowRekeyStatusArg {
return DebugShowRekeyStatusArg{
SessionID: o.SessionID,
}
}
type RekeyStatusFinishArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
}
func (o RekeyStatusFinishArg) DeepCopy() RekeyStatusFinishArg {
return RekeyStatusFinishArg{
SessionID: o.SessionID,
}
}
type RekeySyncArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
Force bool `codec:"force" json:"force"`
}
func (o RekeySyncArg) DeepCopy() RekeySyncArg {
return RekeySyncArg{
SessionID: o.SessionID,
Force: o.Force,
}
}
type GetRevokeWarningArg struct {
Session int `codec:"session" json:"session"`
ActingDevice DeviceID `codec:"actingDevice" json:"actingDevice"`
TargetDevice DeviceID `codec:"targetDevice" json:"targetDevice"`
}
func (o GetRevokeWarningArg) DeepCopy() GetRevokeWarningArg {
return GetRevokeWarningArg{
Session: o.Session,
ActingDevice: o.ActingDevice.DeepCopy(),
TargetDevice: o.TargetDevice.DeepCopy(),
}
}
type RekeyInterface interface {
// ShowPendingRekeyStatus shows either pending gregor-initiated rekey harassments
// or nothing if none were pending.
ShowPendingRekeyStatus(context.Context, int) error
// GetPendingRekeyStatus returns the pending ProblemSetDevices.
GetPendingRekeyStatus(context.Context, int) (ProblemSetDevices, error)
// DebugShowRekeyStatus is used by the CLI to kick off a "ShowRekeyStatus" window for
// the current user.
DebugShowRekeyStatus(context.Context, int) error
// RekeyStatusFinish is called when work is completed on a given RekeyStatus window. The Outcome
// can be Fixed or Ignored.
RekeyStatusFinish(context.Context, int) (Outcome, error)
// RekeySync flushes the current rekey loop and gets to a good stopping point
// to assert state. Good for race-free testing, not very useful in production.
// Force overrides a long-snooze.
RekeySync(context.Context, RekeySyncArg) error
// GetRevokeWarning computes the TLFs that will be endangered if actingDevice
// revokes targetDevice.
GetRevokeWarning(context.Context, GetRevokeWarningArg) (RevokeWarning, error)
}
func RekeyProtocol(i RekeyInterface) rpc.Protocol {
return rpc.Protocol{
Name: "keybase.1.rekey",
Methods: map[string]rpc.ServeHandlerDescription{
"showPendingRekeyStatus": {
MakeArg: func() interface{} {
ret := make([]ShowPendingRekeyStatusArg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]ShowPendingRekeyStatusArg)
if !ok {
err = rpc.NewTypeError((*[]ShowPendingRekeyStatusArg)(nil), args)
return
}
err = i.ShowPendingRekeyStatus(ctx, (*typedArgs)[0].SessionID)
return
},
MethodType: rpc.MethodCall,
},
"getPendingRekeyStatus": {
MakeArg: func() interface{} {
ret := make([]GetPendingRekeyStatusArg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]GetPendingRekeyStatusArg)
if !ok {
err = rpc.NewTypeError((*[]GetPendingRekeyStatusArg)(nil), args)
return
}
ret, err = i.GetPendingRekeyStatus(ctx, (*typedArgs)[0].SessionID)
return
},
MethodType: rpc.MethodCall,
},
"debugShowRekeyStatus": {
MakeArg: func() interface{} {
ret := make([]DebugShowRekeyStatusArg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]DebugShowRekeyStatusArg)
if !ok {
err = rpc.NewTypeError((*[]DebugShowRekeyStatusArg)(nil), args)
return
}
err = i.DebugShowRekeyStatus(ctx, (*typedArgs)[0].SessionID)
return
},
MethodType: rpc.MethodCall,
},
"rekeyStatusFinish": {
MakeArg: func() interface{} {
ret := make([]RekeyStatusFinishArg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]RekeyStatusFinishArg)
if !ok {
err = rpc.NewTypeError((*[]RekeyStatusFinishArg)(nil), args)
return
}
ret, err = i.RekeyStatusFinish(ctx, (*typedArgs)[0].SessionID)
return
},
MethodType: rpc.MethodCall,
},
"rekeySync": {
MakeArg: func() interface{} {
ret := make([]RekeySyncArg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]RekeySyncArg)
if !ok {
err = rpc.NewTypeError((*[]RekeySyncArg)(nil), args)
return
}
err = i.RekeySync(ctx, (*typedArgs)[0])
return
},
MethodType: rpc.MethodCall,
},
"getRevokeWarning": {
MakeArg: func() interface{} {
ret := make([]GetRevokeWarningArg, 1)
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[]GetRevokeWarningArg)
if !ok {
err = rpc.NewTypeError((*[]GetRevokeWarningArg)(nil), args)
return
}
ret, err = i.GetRevokeWarning(ctx, (*typedArgs)[0])
return
},
MethodType: rpc.MethodCall,
},
},
}
}
type RekeyClient struct {
Cli rpc.GenericClient
}
// ShowPendingRekeyStatus shows either pending gregor-initiated rekey harassments
// or nothing if none were pending.
func (c RekeyClient) ShowPendingRekeyStatus(ctx context.Context, sessionID int) (err error) {
__arg := ShowPendingRekeyStatusArg{SessionID: sessionID}
err = c.Cli.Call(ctx, "keybase.1.rekey.showPendingRekeyStatus", []interface{}{__arg}, nil)
return
}
// GetPendingRekeyStatus returns the pending ProblemSetDevices.
func (c RekeyClient) GetPendingRekeyStatus(ctx context.Context, sessionID int) (res ProblemSetDevices, err error) {
__arg := GetPendingRekeyStatusArg{SessionID: sessionID}
err = c.Cli.Call(ctx, "keybase.1.rekey.getPendingRekeyStatus", []interface{}{__arg}, &res)
return
}
// DebugShowRekeyStatus is used by the CLI to kick off a "ShowRekeyStatus" window for
// the current user.
func (c RekeyClient) DebugShowRekeyStatus(ctx context.Context, sessionID int) (err error) {
__arg := DebugShowRekeyStatusArg{SessionID: sessionID}
err = c.Cli.Call(ctx, "keybase.1.rekey.debugShowRekeyStatus", []interface{}{__arg}, nil)
return
}
// RekeyStatusFinish is called when work is completed on a given RekeyStatus window. The Outcome
// can be Fixed or Ignored.
func (c RekeyClient) RekeyStatusFinish(ctx context.Context, sessionID int) (res Outcome, err error) {
__arg := RekeyStatusFinishArg{SessionID: sessionID}
err = c.Cli.Call(ctx, "keybase.1.rekey.rekeyStatusFinish", []interface{}{__arg}, &res)
return
}
// RekeySync flushes the current rekey loop and gets to a good stopping point
// to assert state. Good for race-free testing, not very useful in production.
// Force overrides a long-snooze.
func (c RekeyClient) RekeySync(ctx context.Context, __arg RekeySyncArg) (err error) {
err = c.Cli.Call(ctx, "keybase.1.rekey.rekeySync", []interface{}{__arg}, nil)
return
}
// GetRevokeWarning computes the TLFs that will be endangered if actingDevice
// revokes targetDevice.
func (c RekeyClient) GetRevokeWarning(ctx context.Context, __arg GetRevokeWarningArg) (res RevokeWarning, err error) {
err = c.Cli.Call(ctx, "keybase.1.rekey.getRevokeWarning", []interface{}{__arg}, &res)
return
}