Ejemplo n.º 1
0
func (c *CmdDecrypt) Run() error {
	cli, err := GetSaltpackClient(c.G())
	if err != nil {
		return err
	}

	// Can't do this in ParseArgv, need to wait until later
	// in the initialization
	c.spui.terminal = c.G().UI.GetTerminalUI()

	protocols := []rpc.Protocol{
		NewStreamUIProtocol(c.G()),
		NewSecretUIProtocol(c.G()),
		NewIdentifyUIProtocol(c.G()),
		keybase1.SaltpackUiProtocol(c.spui),
	}
	if err := RegisterProtocolsWithContext(protocols, c.G()); err != nil {
		return err
	}

	snk, src, err := c.filter.ClientFilterOpen()
	if err != nil {
		return err
	}

	var info keybase1.SaltpackEncryptedMessageInfo
	arg := keybase1.SaltpackDecryptArg{
		Source: src,
		Sink:   snk,
		Opts:   c.opts,
	}
	info, err = cli.SaltpackDecrypt(context.TODO(), arg)
	if _, ok := err.(libkb.NoDecryptionKeyError); ok {
		c.explainDecryptionFailure(&info)
	} else if c.senderfile != nil {
		if info.Sender.Username != "" {
			if _, err := c.senderfile.Write([]byte(info.Sender.Username)); err != nil {
				c.G().Log.Errorf("failure writing sender file: %s", err)
			}
		}
		c.senderfile.Close()
	}

	cerr := c.filter.Close(err)
	return libkb.PickFirstError(err, cerr)
}
Ejemplo n.º 2
0
func (c *CmdVerify) Run() (err error) {
	cli, err := GetSaltpackClient(c.G())
	if err != nil {
		return err
	}

	c.spui = &SaltpackUI{
		Contextified: libkb.NewContextified(c.G()),
		terminal:     c.G().UI.GetTerminalUI(),
	}

	protocols := []rpc.Protocol{
		NewStreamUIProtocol(c.G()),
		NewSecretUIProtocol(c.G()),
		NewIdentifyUIProtocol(c.G()),
		keybase1.SaltpackUiProtocol(c.spui),
	}

	if err = RegisterProtocolsWithContext(protocols, c.G()); err != nil {
		return err
	}
	snk, src, err := c.ClientFilterOpen()
	if err == nil {
		arg := keybase1.SaltpackVerifyArg{
			Source: src,
			Sink:   snk,
			Opts: keybase1.SaltpackVerifyOptions{
				Signature: c.detachedData,
				SignedBy:  c.signedBy,
			},
		}
		err = cli.SaltpackVerify(context.TODO(), arg)
	}
	cerr := c.Close(err)
	return libkb.PickFirstError(err, cerr)
}