@@ -19,19 +19,25 @@ import (
1919 "context"
2020 "errors"
2121 "fmt"
22+ "io"
2223 "os"
2324 "time"
2425
2526 "github.com/chainloop-dev/chainloop/app/cli/internal/action"
2627 "github.com/jedib0t/go-pretty/v6/table"
2728 "github.com/jedib0t/go-pretty/v6/text"
2829 "github.com/muesli/reflow/wrap"
30+ "github.com/secure-systems-lab/go-securesystemslib/dsse"
2931 "github.com/spf13/cobra"
3032)
3133
3234const formatStatement = "statement"
3335const formatAttestation = "attestation"
3436
37+ // outputs the payload in PAE encoding, so that it matches the signature in the attestation,
38+ // and it's easily verifiable by external tools
39+ const formatPayloadPAE = "payload-pae"
40+
3541func newWorkflowWorkflowRunDescribeCmd () * cobra.Command {
3642 var runID , attestationDigest , publicKey string
3743 var verifyAttestation bool
@@ -58,7 +64,7 @@ func newWorkflowWorkflowRunDescribeCmd() *cobra.Command {
5864 return err
5965 }
6066
61- return encodeAttestationOutput (res )
67+ return encodeAttestationOutput (res , os . Stdout )
6268 },
6369 }
6470
@@ -73,7 +79,7 @@ func newWorkflowWorkflowRunDescribeCmd() *cobra.Command {
7379 }
7480
7581 // Override default output flag
76- cmd .InheritedFlags ().StringVarP (& flagOutputFormat , "output" , "o" , "table" , "output format, valid options are table, json, attestation or statement " )
82+ cmd .InheritedFlags ().StringVarP (& flagOutputFormat , "output" , "o" , "table" , "output format, valid options are table, json, attestation, statement or payload-pae " )
7783
7884 return cmd
7985}
@@ -193,7 +199,7 @@ func predicateV1Table(att *action.WorkflowRunAttestationItem) {
193199 }
194200}
195201
196- func encodeAttestationOutput (run * action.WorkflowRunItemFull ) error {
202+ func encodeAttestationOutput (run * action.WorkflowRunItemFull , writer io. Writer ) error {
197203 // Try to encode as a table or json
198204 err := encodeOutput (run , workflowRunDescribeTableOutput )
199205 // It was correctly encoded, we are done
@@ -217,7 +223,18 @@ func encodeAttestationOutput(run *action.WorkflowRunItemFull) error {
217223 return encodeJSON (run .Attestation .Statement ())
218224 case formatAttestation :
219225 return encodeJSON (run .Attestation .Envelope )
226+ case formatPayloadPAE :
227+ return encodePAE (run , writer )
220228 default :
221229 return ErrOutputFormatNotImplemented
222230 }
223231}
232+
233+ func encodePAE (run * action.WorkflowRunItemFull , writer io.Writer ) error {
234+ payload , err := run .Attestation .Envelope .DecodeB64Payload ()
235+ if err != nil {
236+ return fmt .Errorf ("could not decode attestation payload: %w" , err )
237+ }
238+ _ , err = fmt .Fprint (writer , string (dsse .PAE (run .Attestation .Envelope .PayloadType , payload )))
239+ return err
240+ }
0 commit comments