-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathverifier.go
76 lines (66 loc) · 2.21 KB
/
verifier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package verifiers
import (
"context"
"fmt"
serrors "github.com/slsa-framework/slsa-verifier/v2/errors"
"github.com/slsa-framework/slsa-verifier/v2/options"
"github.com/slsa-framework/slsa-verifier/v2/register"
_ "github.com/slsa-framework/slsa-verifier/v2/verifiers/internal/gcb"
"github.com/slsa-framework/slsa-verifier/v2/verifiers/internal/gha"
"github.com/slsa-framework/slsa-verifier/v2/verifiers/utils"
)
func getVerifier(builderOpts *options.BuilderOpts) (register.SLSAVerifier, error) {
// By default, use the GHA builders
verifier := register.SLSAVerifiers[gha.VerifierName]
// If user provids a builderID, find the right verifier based on its ID.
if builderOpts.ExpectedID != nil &&
*builderOpts.ExpectedID != "" {
name, _, err := utils.ParseBuilderID(*builderOpts.ExpectedID, false)
if err != nil {
return nil, err
}
for _, v := range register.SLSAVerifiers {
if v.IsAuthoritativeFor(name) {
return v, nil
}
}
// No builder found.
return nil, fmt.Errorf("%w: %s", serrors.ErrorVerifierNotSupported, *builderOpts.ExpectedID)
}
return verifier, nil
}
func VerifyImage(ctx context.Context, artifactImage string,
provenance []byte,
provenanceOpts *options.ProvenanceOpts,
builderOpts *options.BuilderOpts,
) ([]byte, *utils.TrustedBuilderID, error) {
verifier, err := getVerifier(builderOpts)
if err != nil {
return nil, nil, err
}
return verifier.VerifyImage(ctx, provenance, artifactImage, provenanceOpts, builderOpts)
}
func VerifyArtifact(ctx context.Context,
provenance []byte, artifactHash string,
provenanceOpts *options.ProvenanceOpts,
builderOpts *options.BuilderOpts,
) ([]byte, *utils.TrustedBuilderID, error) {
verifier, err := getVerifier(builderOpts)
if err != nil {
return nil, nil, err
}
return verifier.VerifyArtifact(ctx, provenance, artifactHash,
provenanceOpts, builderOpts)
}
func VerifyNpmPackage(ctx context.Context,
attestations []byte, tarballHash string,
provenanceOpts *options.ProvenanceOpts,
builderOpts *options.BuilderOpts,
) ([]byte, *utils.TrustedBuilderID, error) {
verifier, err := getVerifier(builderOpts)
if err != nil {
return nil, nil, err
}
return verifier.VerifyNpmPackage(ctx, attestations, tarballHash,
provenanceOpts, builderOpts)
}