-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_passphrase_change.go
115 lines (99 loc) · 2.97 KB
/
cmd_passphrase_change.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"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"
context "golang.org/x/net/context"
)
type CmdPassphraseChange struct {
libkb.Contextified
ForceArg bool
}
func NewCmdPassphraseChange(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "change",
Aliases: []string{"set"},
Usage: "Change your keybase account passphrase.",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdPassphraseChangeRunner(g), "change", c)
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force",
Usage: `Change password without entering the current one. This will set
new password but will not be able to re-encrypt server-synced PGP keys.`,
},
},
}
}
func NewCmdPassphraseChangeRunner(g *libkb.GlobalContext) *CmdPassphraseChange {
return &CmdPassphraseChange{
Contextified: libkb.NewContextified(g),
}
}
func (c *CmdPassphraseChange) Run() error {
ui := c.G().UI.GetTerminalUI()
protocols := []rpc.Protocol{
NewSecretUIProtocol(c.G()),
}
if err := RegisterProtocolsWithContext(protocols, c.G()); err != nil {
return err
}
cliUser, err := GetUserClient(c.G())
if err != nil {
return err
}
forcePassphraseChange := c.ForceArg
// If the user has a randompw, we force the password change since we cannot
// prompt them for the old one.
passphraseState, err := cliUser.LoadPassphraseState(context.Background(), 0)
if err != nil {
return err
}
if passphraseState == keybase1.PassphraseState_RANDOM {
forcePassphraseChange = true
}
if forcePassphraseChange {
// Check whether the user would lose server-stored encrypted PGP keys.
// (bug) This will return true even if those keys are already lost.
hsk, err := hasServerKeys(c.G())
if err != nil {
return err
}
// Confirm with the user.
if hsk.HasServerKeys {
ui.Printf("You have uploaded an encrypted PGP private key, it will be lost.\n")
if err = ui.PromptForConfirmation("Continue with password recovery?"); err != nil {
return err
}
}
}
pp, err := PromptNewPassphrase(c.G())
if err != nil {
return err
}
if err := passphraseChange(c.G(), newChangeArg(pp, forcePassphraseChange)); err != nil {
ui.Printf("\nThere was a problem during the standard update of your passphrase.")
ui.Printf("\n%s\n\n", err)
ui.Printf("You can attempt to recover your account with the command\n")
ui.Printf("'keybase passphrase recover'.\n\n")
return err
}
c.G().Log.Info("Passphrase changed.")
return nil
}
func (c *CmdPassphraseChange) ParseArgv(ctx *cli.Context) error {
c.ForceArg = ctx.Bool("force")
return nil
}
func (c *CmdPassphraseChange) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}