github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/client/cmd_pgp_pull_private.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package client 5 6 import ( 7 "github.com/keybase/cli" 8 "github.com/keybase/client/go/libcmdline" 9 "github.com/keybase/client/go/libkb" 10 keybase1 "github.com/keybase/client/go/protocol/keybase1" 11 "github.com/keybase/go-framed-msgpack-rpc/rpc" 12 "golang.org/x/net/context" 13 ) 14 15 type CmdPGPPullPrivate struct { 16 libkb.Contextified 17 fingerprints []keybase1.PGPFingerprint 18 force bool 19 } 20 21 func (v *CmdPGPPullPrivate) ParseArgv(ctx *cli.Context) (err error) { 22 v.force = ctx.Bool("force") 23 v.fingerprints, err = parsePGPFingerprints(ctx) 24 return err 25 } 26 27 func (v *CmdPGPPullPrivate) Run() (err error) { 28 29 if !v.force { 30 dui := v.G().UI.GetDumbOutputUI() 31 dui.Printf( 32 ColorString(v.G(), "bold", "PLEASE READ THIS CAREFULLY -- PRIVATE KEYS ARE AT STAKE!") + "\n" + 33 ` 34 This command will import PGP ` + ColorString(v.G(), "bold", "private") + ` keys from KBFS 35 (found in .keys/pgp), and export them to the local GnuPG keychain. They might have been 36 put there via ` + ColorString(v.G(), "blue", "keybase pgp push-private") + `. After this 37 operation, these keys will be available for local GnuPG operations.` + "\n\n") 38 err = v.G().UI.GetTerminalUI().PromptForConfirmation("Really pull your PGP private key from KBFS?") 39 if err != nil { 40 return err 41 } 42 } 43 44 cli, err := GetPGPClient(v.G()) 45 if err != nil { 46 return err 47 } 48 ctx := context.Background() 49 protocols := []rpc.Protocol{ 50 NewGPGUIProtocol(v.G()), 51 NewSecretUIProtocol(v.G()), 52 } 53 if err := RegisterProtocolsWithContext(protocols, v.G()); err != nil { 54 return err 55 } 56 err = cli.PGPPullPrivate(ctx, keybase1.PGPPullPrivateArg{Fingerprints: v.fingerprints}) 57 return err 58 } 59 60 func NewCmdPGPPullPrivate(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command { 61 return cli.Command{ 62 Name: "pull-private", 63 ArgumentHelp: "[<fingerprints...>]", 64 Usage: "Export PGP from KBFS and write them to the GnuPG keychain", 65 Flags: []cli.Flag{ 66 cli.BoolFlag{ 67 Name: "all", 68 Usage: "pull all PGP private keys currently proven in Keybase identity", 69 }, 70 cli.BoolFlag{ 71 Name: "f, force", 72 Usage: "force pull, and don't prompt for confirmation", 73 }, 74 }, 75 Action: func(c *cli.Context) { 76 cl.ChooseCommand(&CmdPGPPullPrivate{Contextified: libkb.NewContextified(g)}, "pull-private", c) 77 cl.SetNoStandalone() 78 }, 79 Description: `"keybase pgp pull-private" pulls PGP secret keys from /keybase/private/<you>/.keys/pgp, 80 and imports them into your local GnuPG keychain. See "keybase pgp push-private" for the command 81 that pushes keys to that KBFS location.`, 82 } 83 } 84 85 func (v *CmdPGPPullPrivate) GetUsage() libkb.Usage { 86 return libkb.Usage{ 87 Config: true, 88 GpgKeyring: true, 89 KbKeyring: true, 90 API: true, 91 } 92 }