|
| 1 | +package document |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/distributed-lab/enclave-extras/nitro-attestation-cli/internal/document" |
| 7 | + "github.com/spf13/cobra" |
| 8 | +) |
| 9 | + |
| 10 | +var ( |
| 11 | + readInput string |
| 12 | + readPublicKey bool |
| 13 | + readUserData bool |
| 14 | + readNonce bool |
| 15 | + pcrsToVerify = map[int]struct{}{} |
| 16 | +) |
| 17 | + |
| 18 | +var readCmd = &cobra.Command{ |
| 19 | + Use: "read", |
| 20 | + Short: "", |
| 21 | + Long: "", |
| 22 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 23 | + return document.ReadAttestationDocument(document.ReadAttestationDocumentOptions{ |
| 24 | + UserData: readUserData, |
| 25 | + Nonce: readNonce, |
| 26 | + PublicKey: readPublicKey, |
| 27 | + Input: readInput, |
| 28 | + PCRsToVerify: pcrsToVerify, |
| 29 | + }) |
| 30 | + }, |
| 31 | +} |
| 32 | + |
| 33 | +func init() { |
| 34 | + readCmd.Flags().StringVar(&readInput, "input", "", "Input file to read") |
| 35 | + readCmd.Flags().BoolVar(&readPublicKey, "public-key", false, "Print public key as raw string") |
| 36 | + readCmd.Flags().BoolVar(&readUserData, "user-data", false, "Print user data as raw string") |
| 37 | + readCmd.Flags().BoolVar(&readNonce, "nonce", false, "Print nonce as raw string") |
| 38 | + |
| 39 | + readCmd.MarkFlagRequired("input") |
| 40 | + addVerifyPCRFlags(readCmd) |
| 41 | +} |
| 42 | + |
| 43 | +func addVerifyPCRFlags(cmd *cobra.Command) { |
| 44 | + for pcr := 0; pcr < 32; pcr++ { |
| 45 | + cmd.Flags().Bool(fmt.Sprintf("verify-pcr%d", pcr), false, fmt.Sprintf("Verify PCR %d", pcr)) |
| 46 | + } |
| 47 | + cmd.PreRun = func(cmd *cobra.Command, args []string) { |
| 48 | + for pcr := 0; pcr < 32; pcr++ { |
| 49 | + val, err := cmd.Flags().GetBool(fmt.Sprintf("verify-pcr%d", pcr)) |
| 50 | + if err == nil && val { |
| 51 | + pcrsToVerify[pcr] = struct{}{} |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments