-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd_pgp_decrypt.go
118 lines (109 loc) · 3.01 KB
/
cmd_pgp_decrypt.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
116
117
118
// 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"
rpc "github.com/keybase/go-framed-msgpack-rpc"
"golang.org/x/net/context"
)
func NewCmdPGPDecrypt(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "decrypt",
Usage: "PGP decrypt messages or files for keybase users",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdPGPDecrypt{Contextified: libkb.NewContextified(g)}, "decrypt", c)
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "l, local",
Usage: "Only track locally, don't send a statement to the server.",
},
cli.BoolFlag{
Name: "y",
Usage: "Approve remote tracking without prompting.",
},
cli.BoolFlag{
Name: "s, signed",
Usage: "Assert signed.",
},
cli.StringFlag{
Name: "S, signed-by",
Usage: "Assert signed by the given user (can use user assertion format).",
},
cli.StringFlag{
Name: "m, message",
Usage: "Provide the message on the command line.",
},
cli.StringFlag{
Name: "i, infile",
Usage: "Specify an input file.",
},
cli.StringFlag{
Name: "o, outfile",
Usage: "Specify an outfile (stdout by default).",
},
},
Description: `Use of this command requires at least one PGP secret key imported
into the local Keybase keyring. It will try all secret keys in the local keyring that match the
given ciphertext, and will succeed so long as one such key is available.`,
}
}
type CmdPGPDecrypt struct {
libkb.Contextified
UnixFilter
trackOptions keybase1.TrackOptions
signed bool
signedBy string
}
func (c *CmdPGPDecrypt) Run() error {
cli, err := GetPGPClient()
if err != nil {
return err
}
protocols := []rpc.Protocol{
NewStreamUIProtocol(),
NewSecretUIProtocol(c.G()),
NewIdentifyTrackUIProtocol(c.G()),
}
if err := RegisterProtocols(protocols); err != nil {
return err
}
snk, src, err := c.ClientFilterOpen()
if err != nil {
return err
}
opts := keybase1.PGPDecryptOptions{
AssertSigned: c.signed,
SignedBy: c.signedBy,
TrackOptions: c.trackOptions,
}
arg := keybase1.PGPDecryptArg{Source: src, Sink: snk, Opts: opts}
_, err = cli.PGPDecrypt(context.TODO(), arg)
cerr := c.Close(err)
return libkb.PickFirstError(err, cerr)
}
func (c *CmdPGPDecrypt) ParseArgv(ctx *cli.Context) error {
msg := ctx.String("message")
outfile := ctx.String("outfile")
infile := ctx.String("infile")
if err := c.FilterInit(msg, infile, outfile); err != nil {
return err
}
c.trackOptions = keybase1.TrackOptions{
LocalOnly: ctx.Bool("local"),
BypassConfirm: ctx.Bool("y"),
}
c.signed = ctx.Bool("signed")
c.signedBy = ctx.String("signed-by")
return nil
}
func (c *CmdPGPDecrypt) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}