forked from keybase/client
/
paperkey_primary.go
93 lines (79 loc) · 2.55 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// 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/keybase1"
"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
EncryptionKey libkb.NaclDHKeyPair
Me *libkb.User
LoginContext libkb.LoginContext // optional
PerUserKeyring *libkb.PerUserKeyring // optional
}
// 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,
EncryptionKey: e.args.EncryptionKey,
LoginContext: e.args.LoginContext,
PerUserKeyring: e.args.PerUserKeyring,
}
kgeng := NewPaperKeyGen(kgarg, e.G())
if err := RunEngine(kgeng, ctx); err != nil {
return err
}
// If they refuse to write down their key, don't kill the login flow, just print an
// ugly warning, which likely they won't see...
w := ctx.LoginUI.DisplayPrimaryPaperKey(context.TODO(), keybase1.DisplayPrimaryPaperKeyArg{Phrase: e.passphrase.String()})
if w != nil {
e.G().Log.Errorf("Display paper key failure: %s", w.Error())
}
return nil
}