diff --git a/ego/cli/elf.go b/ego/cli/elf.go index 6838692..61baac9 100644 --- a/ego/cli/elf.go +++ b/ego/cli/elf.go @@ -14,10 +14,11 @@ import ( "io" "os" "strings" - - "github.com/fatih/color" ) +// ErrErrUnsupportedImportEClient is returned when an EGo binary uses the eclient package instead of the enclave package. +var ErrUnsupportedImportEClient = errors.New("unsupported import: github.com/edgelesssys/ego/eclient") + func (c *Cli) embedConfigAsPayload(path string, jsonData []byte) error { // Load ELF executable f, err := c.fs.OpenFile(path, os.O_RDWR, 0) @@ -128,11 +129,7 @@ func (c *Cli) checkUnsupportedImports(path string) error { // Iterate through all symbols and find whether it matches a known unsupported one for _, symbol := range symbols { if strings.Contains(symbol.Name, "github.com/edgelesssys/ego/eclient") { - boldPrint := color.New(color.Bold).SprintFunc() - fmt.Printf("ERROR: You cannot import the %s package within the EGo enclave.\n", boldPrint("github.com/edgelesssys/ego/eclient")) - fmt.Printf("It is intended to be used for applications running outside the SGX enclave.\n") - fmt.Printf("You can use the %s package as a replacement for usage inside the enclave.\n", boldPrint("github.com/edgelesssys/ego/enclave")) - return errors.New("unsupported import: github.com/edgelesssys/ego/eclient") + return ErrUnsupportedImportEClient } } diff --git a/ego/ego/cmd/sign.go b/ego/ego/cmd/sign.go index ac9a139..5e6d377 100644 --- a/ego/ego/cmd/sign.go +++ b/ego/ego/cmd/sign.go @@ -7,18 +7,15 @@ package cmd import ( - "log" - - "ego/cli" - "github.com/spf13/cobra" ) func newSignCmd() *cobra.Command { return &cobra.Command{ - Use: "sign [executable | config.json]", - Short: "Sign an executable built with ego-go", - Long: "Sign an executable built with ego-go. Executables must be signed before they can be run in an enclave.", + Use: "sign [executable | config.json]", + Short: "Sign an executable built with ego-go", + Long: "Sign an executable built with ego-go. Executables must be signed before they can be run in an enclave.", + SilenceErrors: true, Example: ` ego sign Generates a new key "private.pem" and a default configuration "enclave.json" in the current directory and signs the executable. @@ -36,10 +33,11 @@ func newSignCmd() *cobra.Command { filename = args[0] } err := newCli().Sign(filename) - if err == cli.ErrNoOEInfo { - log.Fatalln("ERROR: The .oeinfo section is missing in the binary.\nMaybe the binary was not built with 'ego-go build'?") + handleErr(err) + if err != nil { + return err } - return err + return nil }, } } diff --git a/ego/ego/cmd/signerid.go b/ego/ego/cmd/signerid.go index e56b5cd..f8a0168 100644 --- a/ego/ego/cmd/signerid.go +++ b/ego/ego/cmd/signerid.go @@ -8,9 +8,6 @@ package cmd import ( "fmt" - "log" - - "ego/internal/launch" "github.com/spf13/cobra" ) @@ -21,13 +18,12 @@ func newSigneridCmd() *cobra.Command { Short: "Print the SignerID of a signed executable", Long: "Print the SignerID either from a signed executable or by reading a key file.", Args: cobra.ExactArgs(1), + SilenceErrors: true, DisableFlagsInUseLine: true, RunE: func(cmd *cobra.Command, args []string) error { id, err := newCli().Signerid(args[0]) - if err == launch.ErrOECrypto { - log.Fatalf("ERROR: signerid failed with %v.\nMake sure to pass a valid public key.", err) - } + handleErr(err) if err != nil { return err } diff --git a/ego/ego/cmd/util.go b/ego/ego/cmd/util.go index 186c166..d82423c 100644 --- a/ego/ego/cmd/util.go +++ b/ego/ego/cmd/util.go @@ -13,6 +13,7 @@ import ( "ego/cli" "ego/internal/launch" + "github.com/fatih/color" "github.com/klauspost/cpuid/v2" "github.com/spf13/afero" "github.com/spf13/cobra" @@ -69,7 +70,16 @@ func handleErr(err error) { fmt.Println("ERROR: failed to initialize the enclave") fmt.Println("Install the SGX base package with: sudo ego install libsgx-enclave-common") fmt.Println("Or temporarily fix the error with: sudo mount -o remount,exec /dev") + case launch.ErrOECrypto: + fmt.Printf("ERROR: signerid failed with %v.\nMake sure to pass a valid public key.\n", err) + case cli.ErrNoOEInfo: + fmt.Println("ERROR: The .oeinfo section is missing in the binary.\nMaybe the binary was not built with 'ego-go build'?") + case cli.ErrUnsupportedImportEClient: + boldPrint := color.New(color.Bold).SprintFunc() + fmt.Printf("ERROR: You cannot import the %s package within the EGo enclave.\n", boldPrint("github.com/edgelesssys/ego/eclient")) + fmt.Printf("It is intended to be used for applications running outside the SGX enclave.\n") + fmt.Printf("You can use the %s package as a replacement for usage inside the enclave.\n", boldPrint("github.com/edgelesssys/ego/enclave")) default: - fmt.Println(err) + fmt.Println("ERROR:", err) } } diff --git a/src/integration_test.sh b/src/integration_test.sh index 3227765..5bf9ce1 100755 --- a/src/integration_test.sh +++ b/src/integration_test.sh @@ -54,5 +54,5 @@ mkdir -p /tmp/ego-unsupported-import-test cd $egoPath/ego/cmd/unsupported-import-test run ego-go build -o /tmp/ego-unsupported-import-test/unsupported-import cd /tmp/ego-unsupported-import-test -run ego sign unsupported-import |& grep "unsupported import" -run ego run unsupported-import |& grep "unsupported import" +run ego sign unsupported-import |& grep "You cannot import the github.com/edgelesssys/ego/eclient package" +run ego run unsupported-import |& grep "You cannot import the github.com/edgelesssys/ego/eclient package"