Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: make self-encryption optional #1606

Merged
merged 2 commits into from
Dec 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions go/client/cmd_encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (

type CmdEncrypt struct {
libkb.Contextified
filter UnixFilter
recipients []string
filter UnixFilter
recipients []string
noSelfEncrypt bool
}

func NewCmdEncrypt(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
Expand All @@ -36,17 +37,10 @@ func NewCmdEncrypt(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Comma
// https://keybase.atlassian.net/browse/CORE-2142
// .
//
// TODO: Make self-encryption optional:
// https://keybase.atlassian.net/browse/CORE-2143
// .
cli.StringFlag{
Name: "i, infile",
Usage: "Specify an input file.",
},
cli.BoolFlag{
Name: "l, local",
Usage: "Only track locally, don't send a statement to the server.",
},
cli.StringFlag{
Name: "m, message",
Usage: "Provide the message on the command line.",
Expand All @@ -56,8 +50,8 @@ func NewCmdEncrypt(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Comma
Usage: "Specify an outfile (stdout by default).",
},
cli.BoolFlag{
Name: "y",
Usage: "Approve remote tracking without prompting.",
Name: "no-self",
Usage: "Don't encrypt for yourself",
},
},
}
Expand All @@ -84,7 +78,8 @@ func (c *CmdEncrypt) Run() error {
}

opts := keybase1.SaltPackEncryptOptions{
Recipients: c.recipients,
Recipients: c.recipients,
NoSelfEncrypt: c.noSelfEncrypt,
}
arg := keybase1.SaltPackEncryptArg{Source: src, Sink: snk, Opts: opts}
err = cli.SaltPackEncrypt(context.TODO(), arg)
Expand All @@ -109,6 +104,7 @@ func (c *CmdEncrypt) ParseArgv(ctx *cli.Context) error {
msg := ctx.String("message")
outfile := ctx.String("outfile")
infile := ctx.String("infile")
c.noSelfEncrypt = ctx.Bool("no-self")
if err := c.filter.FilterInit(msg, infile, outfile); err != nil {
return err
}
Expand Down
11 changes: 9 additions & 2 deletions go/engine/saltpack_decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ func (e *SaltPackDecrypt) SubConsumers() []libkb.UIConsumer {

// Run starts the engine.
func (e *SaltPackDecrypt) Run(ctx *Context) (err error) {
me, err := libkb.LoadMe(libkb.NewLoadUserArg(e.G()))

defer libkb.Trace(e.G().Log, "SaltPackDecrypt::Run", func() error { return err })()

var me *libkb.User
me, err = libkb.LoadMe(libkb.NewLoadUserArg(e.G()))
if err != nil {
return err
}
Expand All @@ -59,6 +63,7 @@ func (e *SaltPackDecrypt) Run(ctx *Context) (err error) {
Me: me,
KeyType: libkb.DeviceEncryptionKeyType,
}
e.G().Log.Debug("| GetSecretKeyWithPrompt")
key, err := e.G().Keyrings.GetSecretKeyWithPrompt(
ctx.LoginContext, ska, ctx.SecretUI,
"decrypting a message/file")
Expand All @@ -71,5 +76,7 @@ func (e *SaltPackDecrypt) Run(ctx *Context) (err error) {
return libkb.KeyCannotDecryptError{}
}

return libkb.SaltPackDecrypt(e.arg.Source, e.arg.Sink, kp)
e.G().Log.Debug("| SaltPackDecrypt")
err = libkb.SaltPackDecrypt(e.arg.Source, e.arg.Sink, kp)
return err
}
1 change: 0 additions & 1 deletion go/engine/saltpack_decrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func TestSaltPackDecrypt(t *testing.T) {
}
// Should encrypt for self, too.
arg := &SaltPackEncryptArg{
Recips: []string{},
Source: strings.NewReader(msg),
Sink: sink,
}
Expand Down
21 changes: 11 additions & 10 deletions go/engine/saltpack_encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ package engine

import (
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol"
"io"
)

type SaltPackEncryptArg struct {
Recips []string // user assertions
Source io.Reader
Sink io.WriteCloser
NoSelfEncrypt bool
HideSender bool
Opts keybase1.SaltPackEncryptOptions
Source io.Reader
Sink io.WriteCloser
}

// SaltPackEncrypt encrypts data read from a source into a sink
Expand Down Expand Up @@ -86,8 +85,10 @@ func (e *SaltPackEncrypt) loadMe(ctx *Context) error {

// Run starts the engine.
func (e *SaltPackEncrypt) Run(ctx *Context) (err error) {

libkb.Trace(e.G().Log, "SaltPackEncrypt::Run", func() error { return err })
e.G().Log.Debug("+ SaltPackEncrypt::Run")
defer func() {
e.G().Log.Debug("- SaltPackEncrypt::Run -> %v", err)
}()

var receivers []libkb.NaclDHKeyPublic
var sender libkb.NaclDHKeyPair
Expand All @@ -96,15 +97,15 @@ func (e *SaltPackEncrypt) Run(ctx *Context) (err error) {
return err
}

if !e.arg.NoSelfEncrypt && e.me != nil {
if !e.arg.Opts.NoSelfEncrypt && e.me != nil {
receivers, err = e.loadMyPublicKeys()
if err != nil {
return err
}
}

kfarg := DeviceKeyfinderArg{
Users: e.arg.Recips,
Users: e.arg.Opts.Recipients,
NeedEncryptKeys: true,
Self: e.me,
}
Expand All @@ -128,7 +129,7 @@ func (e *SaltPackEncrypt) Run(ctx *Context) (err error) {
}
}

if !e.arg.HideSender && e.me != nil {
if !e.arg.Opts.HideSelf && e.me != nil {
ska := libkb.SecretKeyArg{
Me: e.me,
KeyType: libkb.DeviceEncryptionKeyType,
Expand Down
77 changes: 72 additions & 5 deletions go/engine/saltpack_encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
package engine

import (
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol"
saltpack "github.com/keybase/client/go/saltpack"
"strings"
"testing"

"github.com/keybase/client/go/libkb"
)

func TestSaltPackEncrypt(t *testing.T) {
Expand All @@ -26,7 +27,7 @@ func TestSaltPackEncrypt(t *testing.T) {
run := func(Recips []string) {
sink := libkb.NewBufferCloser()
arg := &SaltPackEncryptArg{
Recips: Recips,
Opts: keybase1.SaltPackEncryptOptions{Recipients: Recips},
Source: strings.NewReader("id2 and encrypt, id2 and encrypt"),
Sink: sink,
}
Expand Down Expand Up @@ -60,7 +61,9 @@ func TestSaltPackEncryptSelfNoKey(t *testing.T) {

sink := libkb.NewBufferCloser()
arg := &SaltPackEncryptArg{
Recips: []string{"t_tracy+t_tracy@rooter", "t_george", "t_kb+gbrltest@twitter"},
Opts: keybase1.SaltPackEncryptOptions{
Recipients: []string{"t_tracy+t_tracy@rooter", "t_george", "t_kb+gbrltest@twitter"},
},
Source: strings.NewReader("track and encrypt, track and encrypt"),
Sink: sink,
}
Expand All @@ -83,7 +86,9 @@ func TestSaltPackEncryptLoggedOut(t *testing.T) {

sink := libkb.NewBufferCloser()
arg := &SaltPackEncryptArg{
Recips: []string{"t_tracy+t_tracy@rooter", "t_george", "t_kb+gbrltest@twitter"},
Opts: keybase1.SaltPackEncryptOptions{
Recipients: []string{"t_tracy+t_tracy@rooter", "t_george", "t_kb+gbrltest@twitter"},
},
Source: strings.NewReader("track and encrypt, track and encrypt"),
Sink: sink,
}
Expand All @@ -94,3 +99,65 @@ func TestSaltPackEncryptLoggedOut(t *testing.T) {
t.Fatalf("Got unexpected error: %s", err)
}
}

func TestSaltPackEncryptNoSelf(t *testing.T) {
tc := SetupEngineTest(t, "SaltPackEncrypt")
defer tc.Cleanup()

u1 := CreateAndSignupFakeUser(tc, "nalcp")
u2 := CreateAndSignupFakeUser(tc, "nalcp")

msg := "for your eyes only (not even mine!)"

trackUI := &FakeIdentifyUI{
Proofs: make(map[string]string),
}
ctx := &Context{IdentifyUI: trackUI, SecretUI: u2.NewSecretUI()}

sink := libkb.NewBufferCloser()
arg := &SaltPackEncryptArg{
Opts: keybase1.SaltPackEncryptOptions{
Recipients: []string{u1.Username},
NoSelfEncrypt: true,
},
Source: strings.NewReader(msg),
Sink: sink,
}

eng := NewSaltPackEncrypt(arg, tc.G)
if err := RunEngine(eng, ctx); err != nil {
t.Fatal(err)
}

out := sink.Bytes()
if len(out) == 0 {
t.Fatal("no output")
}

// decrypt it
decoded := libkb.NewBufferCloser()
decarg := &SaltPackDecryptArg{
Source: strings.NewReader(string(out)),
Sink: decoded,
}
dec := NewSaltPackDecrypt(decarg, tc.G)
err := RunEngine(dec, ctx)
if err != saltpack.ErrNoDecryptionKey {
t.Fatalf("Expected err=%v, but got %v", saltpack.ErrNoDecryptionKey, err)
}

Logout(tc)
u1.Login(tc.G)

ctx = &Context{IdentifyUI: trackUI, SecretUI: u1.NewSecretUI()}
decarg.Source = strings.NewReader(string(out))
dec = NewSaltPackDecrypt(decarg, tc.G)
err = RunEngine(dec, ctx)
if err != nil {
t.Fatal(err)
}
decmsg := decoded.String()
if decmsg != msg {
t.Errorf("decoded: %s, expected: %s", decmsg, msg)
}
}
6 changes: 3 additions & 3 deletions go/protocol/keybase_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -4606,9 +4606,9 @@ func (c RevokeClient) RevokeSigs(ctx context.Context, __arg RevokeSigsArg) (err
}

type SaltPackEncryptOptions struct {
Recipients []string `codec:"recipients" json:"recipients"`
HideSelf bool `codec:"hideSelf" json:"hideSelf"`
EncryptForSelf bool `codec:"encryptForSelf" json:"encryptForSelf"`
Recipients []string `codec:"recipients" json:"recipients"`
HideSelf bool `codec:"hideSelf" json:"hideSelf"`
NoSelfEncrypt bool `codec:"noSelfEncrypt" json:"noSelfEncrypt"`
}

type SaltPackEncryptArg struct {
Expand Down
1 change: 0 additions & 1 deletion go/saltpack/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ func (ds *decryptStream) processEncryptionHeader(hdr *EncryptionHeader) error {
ds.mki.SenderIsAnon = true
ds.mki.SenderKey = ephemeralKey
}

copy(ds.sessionKey[:], keys.SessionKey)

return nil
Expand Down
2 changes: 1 addition & 1 deletion go/service/saltpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (h *SaltPackHandler) SaltPackEncrypt(_ context.Context, arg keybase1.SaltPa
src := libkb.NewRemoteStreamBuffered(arg.Source, cli, arg.SessionID)
snk := libkb.NewRemoteStreamBuffered(arg.Sink, cli, arg.SessionID)
earg := &engine.SaltPackEncryptArg{
Recips: arg.Opts.Recipients,
Opts: arg.Opts,
Sink: snk,
Source: src,
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/avdl/saltpack.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ protocol saltPack {
record SaltPackEncryptOptions {
array<string> recipients; // user assertions
boolean hideSelf;
boolean encryptForSelf;
boolean noSelfEncrypt;
}

void saltPackEncrypt(int sessionID, Stream source, Stream sink, SaltPackEncryptOptions opts);
Expand Down
4 changes: 2 additions & 2 deletions protocol/js/flow-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4175,13 +4175,13 @@ export type saltPack_RemoteProof = {
export type saltPack_SaltPackEncryptOptions = {
recipients: Array<string>;
hideSelf: boolean;
encryptForSelf: boolean;
noSelfEncrypt: boolean;
}

export type SaltPackEncryptOptions = {
recipients: Array<string>;
hideSelf: boolean;
encryptForSelf: boolean;
noSelfEncrypt: boolean;
}

export type secretUi_Feature = {
Expand Down
2 changes: 1 addition & 1 deletion protocol/json/saltpack.json
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
"name" : "hideSelf",
"type" : "boolean"
}, {
"name" : "encryptForSelf",
"name" : "noSelfEncrypt",
"type" : "boolean"
} ]
} ],
Expand Down
4 changes: 2 additions & 2 deletions react-native/react/constants/types/flow-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4175,13 +4175,13 @@ export type saltPack_RemoteProof = {
export type saltPack_SaltPackEncryptOptions = {
recipients: Array<string>;
hideSelf: boolean;
encryptForSelf: boolean;
noSelfEncrypt: boolean;
}

export type SaltPackEncryptOptions = {
recipients: Array<string>;
hideSelf: boolean;
encryptForSelf: boolean;
noSelfEncrypt: boolean;
}

export type secretUi_Feature = {
Expand Down