Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func (v *Verifier) VerifyArtifact(ctx context.Context, dgst digest.Digest, bundl
for _, o := range opt {
o(opts)
}
if opts.TlogThreshold != nil && *opts.TlogThreshold < 0 {
return nil, errors.New("transparency log threshold must not be negative")
}

anyCert, err := anyCerificateIdentity()
if err != nil {
Expand All @@ -78,7 +81,23 @@ func (v *Verifier) VerifyArtifact(ctx context.Context, dgst digest.Digest, bundl
return nil, errors.Wrap(err, "getting trusted root")
}

gv, err := verify.NewVerifier(trustedRoot, verify.WithSignedCertificateTimestamps(1), verify.WithTransparencyLog(1), verify.WithObserverTimestamps(1))
verifierOpts := []verify.VerifierOption{
verify.WithSignedCertificateTimestamps(1),
verify.WithObserverTimestamps(1),
}
// Sigstore thresholds count distinct logs, not individual entries.
logIDs := make(map[string]struct{})
for _, entry := range b.GetVerificationMaterial().GetTlogEntries() {
logIDs[string(entry.GetLogId().GetKeyId())] = struct{}{}
}
tlogThreshold := len(logIDs)
if opts.TlogThreshold != nil {
tlogThreshold = *opts.TlogThreshold
}
if tlogThreshold > 0 {
verifierOpts = append(verifierOpts, verify.WithTransparencyLog(tlogThreshold))
}
gv, err := verify.NewVerifier(trustedRoot, verifierOpts...)
if err != nil {
return nil, errors.Wrap(err, "creating verifier")
}
Expand Down Expand Up @@ -368,6 +387,7 @@ func anyCerificateIdentity() (verify.PolicyOption, error) {

type ArtifactVerifyOpts struct {
SLSANotRequired bool
TlogThreshold *int
}

type ArtifactVerifyOpt func(*ArtifactVerifyOpts)
Expand All @@ -378,6 +398,15 @@ func WithSLSANotRequired() ArtifactVerifyOpt {
}
}

// WithTlogThreshold sets the minimum number of verified transparency logs.
// By default, all distinct logs in the bundle are required. Explicit zero skips
// log verification and returns no log timestamps, so a TSA timestamp is required.
func WithTlogThreshold(threshold int) ArtifactVerifyOpt {
return func(o *ArtifactVerifyOpts) {
o.TlogThreshold = &threshold
}
}

func loadBundle(dt []byte) (*bundle.Bundle, error) {
var bundle bundle.Bundle
bundle.Bundle = new(protobundle.Bundle)
Expand Down
Loading