Skip to content

Commit f4304f5

Browse files
Mikhail Swiftcolek42
authored andcommitted
feat: add timestamping options
Signed-off-by: Mikhail Swift <mikhail@testifysec.com>
1 parent 29c1ff1 commit f4304f5

9 files changed

Lines changed: 31 additions & 12 deletions

File tree

cmd/run.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
witness "github.com/testifysec/go-witness"
2424
"github.com/testifysec/go-witness/archivist"
2525
"github.com/testifysec/go-witness/attestation"
26+
"github.com/testifysec/go-witness/dsse"
2627
"github.com/testifysec/go-witness/log"
28+
"github.com/testifysec/go-witness/timestamp"
2729
"github.com/testifysec/witness/options"
2830
)
2931

@@ -63,22 +65,25 @@ func runRun(ctx context.Context, ro options.RunOptions, args []string) error {
6365
return fmt.Errorf("no signers found")
6466
}
6567

66-
signer := signers[0]
67-
6868
out, err := loadOutfile(ro.OutFilePath)
6969
if err != nil {
7070
return fmt.Errorf("failed to open out file: %w", err)
7171
}
7272

73-
defer out.Close()
73+
timestampers := []dsse.Timestamper{}
74+
for _, url := range ro.TimestampServers {
75+
timestampers = append(timestampers, timestamp.NewTimestamper(timestamp.TimestampWithUrl(url)))
76+
}
7477

78+
defer out.Close()
7579
result, err := witness.Run(
7680
ro.StepName,
77-
signer,
81+
signers[0],
7882
witness.RunWithTracing(ro.Tracing),
7983
witness.RunWithCommand(args),
8084
witness.RunWithAttestors(ro.Attestations),
8185
witness.RunWithAttestationOpts(attestation.WithWorkingDir(ro.WorkingDir)),
86+
witness.RunWithTimestampers(timestampers...),
8287
)
8388

8489
if err != nil {

cmd/sign.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121

2222
"github.com/spf13/cobra"
2323
witness "github.com/testifysec/go-witness"
24+
"github.com/testifysec/go-witness/dsse"
2425
"github.com/testifysec/go-witness/log"
26+
"github.com/testifysec/go-witness/timestamp"
2527
"github.com/testifysec/witness/options"
2628
)
2729

@@ -71,7 +73,10 @@ func runSign(so options.SignOptions) error {
7173
return fmt.Errorf("no signers found")
7274
}
7375

74-
signer := signers[0]
76+
timestampers := []dsse.Timestamper{}
77+
for _, url := range so.TimestampServers {
78+
timestampers = append(timestampers, timestamp.NewTimestamper(timestamp.TimestampWithUrl(url)))
79+
}
7580

7681
inFile, err := os.Open(so.InFilePath)
7782
if err != nil {
@@ -84,5 +89,5 @@ func runSign(so options.SignOptions) error {
8489
}
8590

8691
defer outFile.Close()
87-
return witness.Sign(inFile, so.DataType, outFile, signer)
92+
return witness.Sign(inFile, so.DataType, outFile, dsse.SignWithSigners(signers[0]), dsse.SignWithTimestampers(timestampers...))
8893
}

cmd/verify_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
witness "github.com/testifysec/go-witness"
2929
"github.com/testifysec/go-witness/attestation/commandrun"
3030
"github.com/testifysec/go-witness/cryptoutil"
31+
"github.com/testifysec/go-witness/dsse"
3132
"github.com/testifysec/go-witness/policy"
3233
"github.com/testifysec/witness/options"
3334
)
@@ -238,7 +239,7 @@ func signPolicyRSA(t *testing.T, p []byte) (signedPolicy []byte, pub []byte) {
238239

239240
writer := bytes.NewBuffer(outBytes)
240241

241-
err = witness.Sign(reader, "https://witness.testifysec.com/policy/v0.1", writer, sign)
242+
err = witness.Sign(reader, "https://witness.testifysec.com/policy/v0.1", writer, dsse.SignWithSigners(sign))
242243
if err != nil {
243244
t.Error(err)
244245
}

docs/witness_run.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ witness run [cmd] [flags]
2222
-o, --outfile string File to which to write signed data. Defaults to stdout
2323
--spiffe-socket string Path to the SPIFFE Workload API socket
2424
-s, --step string Name of the step being run
25+
--timestamp-servers strings Timestamp Authority Servers to use when signing envelope
2526
--trace Enable tracing for the command
2627
-d, --workingdir string Directory from which commands will run
2728
```

docs/witness_sign.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ witness sign [file] [flags]
2424
-k, --key string Path to the signing key
2525
-o, --outfile string File to write signed data. Defaults to stdout
2626
--spiffe-socket string Path to the SPIFFE Workload API socket
27+
--timestamp-servers strings Timestamp Authority Servers to use when signing envelope
2728
```
2829

2930
### Options inherited from parent commands

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/spf13/pflag v1.0.5
99
github.com/spf13/viper v1.12.0
1010
github.com/stretchr/testify v1.8.0
11-
github.com/testifysec/go-witness v0.1.14
11+
github.com/testifysec/go-witness v0.1.15
1212
)
1313

1414
require (

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,8 @@ github.com/testifysec/archivist-api v0.0.0-20221012004029-f5ceac2d8a3b h1:HBEM8C
13601360
github.com/testifysec/archivist-api v0.0.0-20221012004029-f5ceac2d8a3b/go.mod h1:4BAH0+DBqP7QQRfJuUw4Tm+LNrptYa0qOjJNcN0Lf7Q=
13611361
github.com/testifysec/go-witness v0.1.14 h1:MEFXx/W8OgaIri3HfbAKpJfg3qkWaT04GaWYujZZhLE=
13621362
github.com/testifysec/go-witness v0.1.14/go.mod h1:xBejEG5VrwCqJogmWxr//8sQKSwnR+9v70xMmwhOPzs=
1363+
github.com/testifysec/go-witness v0.1.15 h1:FnD20gvWrQMxxbquzhxH7waf6Aiip3aPnvJtGk2i+TQ=
1364+
github.com/testifysec/go-witness v0.1.15/go.mod h1:xBejEG5VrwCqJogmWxr//8sQKSwnR+9v70xMmwhOPzs=
13631365
github.com/thales-e-security/pool v0.0.2 h1:RAPs4q2EbWsTit6tpzuvTFlgFRJ3S8Evf5gtvVDbmPg=
13641366
github.com/thales-e-security/pool v0.0.2/go.mod h1:qtpMm2+thHtqhLzTwgDBj/OuNnMpupY8mv0Phz0gjhU=
13651367
github.com/theupdateframework/go-tuf v0.0.0-20211203210025-7ded50136bf9/go.mod h1:n2n6wwC9BEnYS/C/APAtNln0eM5zYAYOkOTx6VEG/mA=

options/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type RunOptions struct {
2424
OutFilePath string
2525
StepName string
2626
Tracing bool
27+
TimestampServers []string
2728
}
2829

2930
func (ro *RunOptions) AddFlags(cmd *cobra.Command) {
@@ -34,6 +35,7 @@ func (ro *RunOptions) AddFlags(cmd *cobra.Command) {
3435
cmd.Flags().StringVarP(&ro.OutFilePath, "outfile", "o", "", "File to which to write signed data. Defaults to stdout")
3536
cmd.Flags().StringVarP(&ro.StepName, "step", "s", "", "Name of the step being run")
3637
cmd.Flags().BoolVar(&ro.Tracing, "trace", false, "Enable tracing for the command")
38+
cmd.Flags().StringSliceVar(&ro.TimestampServers, "timestamp-servers", []string{}, "Timestamp Authority Servers to use when signing envelope")
3739
}
3840

3941
type ArchivistOptions struct {

options/sign.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ package options
1717
import "github.com/spf13/cobra"
1818

1919
type SignOptions struct {
20-
KeyOptions KeyOptions
21-
DataType string
22-
OutFilePath string
23-
InFilePath string
20+
KeyOptions KeyOptions
21+
DataType string
22+
OutFilePath string
23+
InFilePath string
24+
TimestampServers []string
2425
}
2526

2627
func (so *SignOptions) AddFlags(cmd *cobra.Command) {
2728
so.KeyOptions.AddFlags(cmd)
2829
cmd.Flags().StringVarP(&so.DataType, "datatype", "t", "https://witness.testifysec.com/policy/v0.1", "The URI reference to the type of data being signed. Defaults to the Witness policy type")
2930
cmd.Flags().StringVarP(&so.OutFilePath, "outfile", "o", "", "File to write signed data. Defaults to stdout")
3031
cmd.Flags().StringVarP(&so.InFilePath, "infile", "f", "", "Witness policy file to sign")
32+
cmd.Flags().StringSliceVar(&so.TimestampServers, "timestamp-servers", []string{}, "Timestamp Authority Servers to use when signing envelope")
3133
}

0 commit comments

Comments
 (0)