-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_passphrase_check.go
102 lines (88 loc) · 2.33 KB
/
cmd_passphrase_check.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
// Copyright 2019 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"errors"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
"golang.org/x/net/context"
)
type CmdPassphraseCheck struct {
libkb.Contextified
passphrase string
}
func NewCmdPassphraseCheck(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
flags := []cli.Flag{}
if develUsage {
flags = append(flags, cli.StringFlag{
Name: "passphrase",
Usage: "[DEVEL ONLY DO NOT USE] pass passphrase through argument instead of invoking pinentry",
})
}
return cli.Command{
Name: "check",
Usage: "Check account passphrase.",
Flags: flags,
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdPassphraseCheckRunner(g), "check", c)
},
}
}
func NewCmdPassphraseCheckRunner(g *libkb.GlobalContext) *CmdPassphraseCheck {
return &CmdPassphraseCheck{
Contextified: libkb.NewContextified(g),
}
}
func (c *CmdPassphraseCheck) Run() error {
cli, err := GetAccountClient(c.G())
if err != nil {
return err
}
cliUser, err := GetUserClient(c.G())
if err != nil {
return err
}
passphraseState, err := cliUser.LoadPassphraseState(context.Background(), 0)
if err != nil {
return err
}
if passphraseState == keybase1.PassphraseState_RANDOM {
c.G().Log.Error("Your account does not have a passphrase, so there is nothing to check.")
c.G().Log.Info("You can set a passphrase using `keybase passphrase set`.")
return nil
}
var arg keybase1.PassphraseCheckArg
if c.passphrase != "" {
arg.Passphrase = c.passphrase
} else {
protocols := []rpc.Protocol{
NewSecretUIProtocol(c.G()),
}
if err := RegisterProtocolsWithContext(protocols, c.G()); err != nil {
return err
}
}
ret, err := cli.PassphraseCheck(context.TODO(), arg)
if err != nil {
return err
}
if !ret {
return errors.New("Invalid password")
}
c.G().Log.Info("Passphrase confirmed.")
return nil
}
func (c *CmdPassphraseCheck) ParseArgv(ctx *cli.Context) error {
c.passphrase = ctx.String("passphrase")
return nil
}
func (c *CmdPassphraseCheck) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}