forked from keybase/client
/
cmd_paperprovision.go
95 lines (78 loc) · 2.22 KB
/
cmd_paperprovision.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"errors"
"golang.org/x/net/context"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
)
func NewCmdPaperProvision(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := cli.Command{
Name: "paperprovision",
ArgumentHelp: "[username] [devicename] [paperkey]",
Usage: "Establish a session with the keybase server and provision a device",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdPaperProvisionRunner(g), "paperprovision", c)
},
}
return cmd
}
type CmdPaperProvision struct {
libkb.Contextified
username string
deviceName string
paperKey string
SessionID int
}
func NewCmdPaperProvisionRunner(g *libkb.GlobalContext) *CmdPaperProvision {
return &CmdPaperProvision{
Contextified: libkb.NewContextified(g),
}
}
func (c *CmdPaperProvision) Run() (err error) {
client, err := GetPaperProvisionClient(c.G())
if err != nil {
return err
}
protocols := []rpc.Protocol{
NewProvisionUIProtocol(c.G(), libkb.KexRoleProvisionee),
NewLoginUIProtocol(c.G()),
NewSecretUIProtocol(c.G()),
NewGPGUIProtocol(c.G()),
}
if err = RegisterProtocolsWithContext(protocols, c.G()); err != nil {
return err
}
err = client.PaperProvision(context.TODO(),
keybase1.PaperProvisionArg{
Username: c.username,
DeviceName: c.deviceName,
PaperKey: c.paperKey,
SessionID: c.SessionID,
})
return
}
func (c *CmdPaperProvision) ParseArgv(ctx *cli.Context) error {
nargs := len(ctx.Args())
if nargs != 3 {
return errors.New("Username, devicename and paperkey arguments required")
}
c.username = ctx.Args()[0]
c.deviceName = ctx.Args()[1]
c.paperKey = ctx.Args()[2]
if c.username == "" || c.deviceName == "" || c.paperKey == "" {
return errors.New("Username, devicename and paperkey arguments required")
}
return nil
}
func (c *CmdPaperProvision) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
KbKeyring: true,
API: true,
}
}