Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pull/402'
Browse files Browse the repository at this point in the history
* origin/pull/402:
  Per feedback, and enhancements
  Verified JSON support
  • Loading branch information
Foxboron committed Nov 27, 2024
2 parents 0c8ea2c + 90974b0 commit cd6dd1c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/sbctl/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,32 @@ import (
"github.com/spf13/cobra"
)

type VerifiedFile struct {
FileName string `json:"file_name"`
// IsSigned should be set to one of these values:
// - 0: "unsigned"
// - 1: "signed"
// - -1: "file does not exist"
IsSigned int8 `json:"is_signed"`
}

var (
ErrInvalidHeader = errors.New("invalid pe header")
verifyCmd = &cobra.Command{
Use: "verify",
Short: "Find and check if files in the ESP are signed or not",
RunE: RunVerify,
}
verifiedFiles []VerifiedFile
)

func VerifyOneFile(state *config.State, f string) error {
o, err := state.Fs.Open(f)
fileentry := VerifiedFile{FileName: f, IsSigned: 0}
if errors.Is(err, os.ErrNotExist) {
logging.Warn("%s does not exist", f)
fileentry.IsSigned = -1
verifiedFiles = append(verifiedFiles, fileentry)
return nil
} else if errors.Is(err, os.ErrPermission) {
logging.Warn("%s permission denied. Can't read file\n", f)
Expand All @@ -52,11 +65,15 @@ func VerifyOneFile(state *config.State, f string) error {
if err != nil {
return err
}

if ok {
logging.Ok("%s is signed", f)
fileentry.IsSigned = 1
} else {
logging.NotOk("%s is not signed", f)
}
verifiedFiles = append(verifiedFiles, fileentry)

return nil
}

Expand Down Expand Up @@ -91,6 +108,9 @@ func RunVerify(cmd *cobra.Command, args []string) error {
return err
}
}
if cmdOptions.JsonOutput {
return JsonOut(verifiedFiles)
}
return nil
}
logging.Print("Verifying file database and EFI images in %s...\n", espPath)
Expand Down Expand Up @@ -125,6 +145,9 @@ func RunVerify(cmd *cobra.Command, args []string) error {
}); err != nil {
return err
}
if cmdOptions.JsonOutput {
return JsonOut(verifiedFiles)
}
return nil
}

Expand Down

0 comments on commit cd6dd1c

Please sign in to comment.