forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paperkey_primary.go
79 lines (67 loc) · 2.06 KB
/
paperkey_primary.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
// PaperKeyPrimary creates the initial paper backup key for a user. It
// differs from the PaperKey engine in that it already knows the
// signing key and it doesn't offer to revoke any devices, plus it
// uses a different UI call to display the phrase.
package engine
import (
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol"
"golang.org/x/net/context"
)
// PaperKeyPrimary is an engine.
type PaperKeyPrimary struct {
passphrase libkb.PaperKeyPhrase
args *PaperKeyPrimaryArgs
libkb.Contextified
}
type PaperKeyPrimaryArgs struct {
SigningKey libkb.GenericKey
Me *libkb.User
}
// NewPaperKeyPrimary creates a PaperKeyPrimary engine.
func NewPaperKeyPrimary(g *libkb.GlobalContext, args *PaperKeyPrimaryArgs) *PaperKeyPrimary {
return &PaperKeyPrimary{
args: args,
Contextified: libkb.NewContextified(g),
}
}
// Name is the unique engine name.
func (e *PaperKeyPrimary) Name() string {
return "PaperKeyPrimary"
}
// GetPrereqs returns the engine prereqs.
func (e *PaperKeyPrimary) Prereqs() Prereqs {
return Prereqs{
Session: true,
}
}
// RequiredUIs returns the required UIs.
func (e *PaperKeyPrimary) RequiredUIs() []libkb.UIKind {
return []libkb.UIKind{
libkb.LoginUIKind,
}
}
// SubConsumers returns the other UI consumers for this engine.
func (e *PaperKeyPrimary) SubConsumers() []libkb.UIConsumer {
return []libkb.UIConsumer{&PaperKeyGen{}}
}
// Run starts the engine.
func (e *PaperKeyPrimary) Run(ctx *Context) error {
var err error
e.passphrase, err = libkb.MakePaperKeyPhrase(libkb.PaperKeyVersion)
if err != nil {
return err
}
kgarg := &PaperKeyGenArg{
Passphrase: e.passphrase,
Me: e.args.Me,
SigningKey: e.args.SigningKey,
}
kgeng := NewPaperKeyGen(kgarg, e.G())
if err := RunEngine(kgeng, ctx); err != nil {
return err
}
return ctx.LoginUI.DisplayPrimaryPaperKey(context.TODO(), keybase1.DisplayPrimaryPaperKeyArg{Phrase: e.passphrase.String()})
}