gen-qe-target-info.go 1.2 KB
Newer Older
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
package main // import "github.com/inclavare-containers/runectl"

import (
	"github.com/opencontainers/runc/libenclave/intelsgx"
	"github.com/sirupsen/logrus"
	"github.com/urfave/cli"
	"io/ioutil"
)

var generateQeTargetInfoCommand = cli.Command{
	Name:  "gen-qe-target-info",
	Usage: "retrieve the target information about Quoting Enclave from aesmd",
	ArgsUsage: `[command options]

EXAMPLE:
For example, save the target information file about Quoting Enclave retrieved from aesmd:

	# runectl gen-qe-target-info --targetinfo foo`,
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "targetinfo",
			Usage: "path to the output target information file containing TARGETINFO",
		},
	},
	Action: func(context *cli.Context) error {
		if context.GlobalBool("verbose") {
			logrus.SetLevel(logrus.DebugLevel)
		}

		ti, err := intelsgx.GetQeTargetInfo()
		if err != nil {
			logrus.Print(err)
			return err
		}

		tiPath := context.String("targetinfo")
		if tiPath == "" {
			tiPath = "qe_targetinfo.bin"
		}

		if err := ioutil.WriteFile(tiPath, ti, 0664); err != nil {
			return err
		}

		logrus.Infof("quoting enclave's target info file %s saved", tiPath)

		return nil
	},
	SkipArgReorder: true,
}