@@ -16,46 +16,10 @@ import (
1616 "google.golang.org/protobuf/types/known/structpb"
1717
1818 "github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
19+ "github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/provenance"
1920 "github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa"
2021)
2122
22- const (
23- SourceProvPredicateType = "https://github.com/slsa-framework/slsa-source-poc/source-provenance/v1-draft"
24- TagProvPredicateType = "https://github.com/slsa-framework/slsa-source-poc/tag-provenance/v1-draft"
25- )
26-
27- // The predicate that encodes source provenance data.
28- // The git commit this corresponds to is encoded in the surrounding statement.
29- type SourceProvenancePred struct {
30- // The commit preceding 'Commit' in the current context.
31- PrevCommit string `json:"prev_commit"`
32- RepoUri string `json:"repo_uri"`
33- ActivityType string `json:"activity_type"`
34- Actor string `json:"actor"`
35- Branch string `json:"branch"`
36- CreatedOn time.Time `json:"created_on"`
37- // TODO: get the author of the PR (if this was from a PR).
38-
39- // The controls enabled at the time this commit was pushed.
40- Controls slsa.Controls `json:"controls"`
41- }
42-
43- // Summary of a summary
44- type VsaSummary struct {
45- SourceRefs []string `json:"source_refs"`
46- VerifiedLevels []slsa.ControlName `json:"verifiedLevels"`
47- }
48-
49- type TagProvenancePred struct {
50- RepoUri string `json:"repo_uri"`
51- Actor string `json:"actor"`
52- Tag string `json:"tag"`
53- CreatedOn time.Time `json:"created_on"`
54- // The tag related controls enabled at the time this tag was created/updated.
55- Controls slsa.Controls `json:"controls"`
56- VsaSummaries []VsaSummary `json:"vsa_summaries"`
57- }
58-
5923type ProvenanceAttestor struct {
6024 verifier Verifier
6125 gh_connection * ghcontrol.GitHubConnection
@@ -65,11 +29,11 @@ func NewProvenanceAttestor(gh_connection *ghcontrol.GitHubConnection, verifier V
6529 return & ProvenanceAttestor {verifier : verifier , gh_connection : gh_connection }
6630}
6731
68- func GetSourceProvPred (statement * spb.Statement ) (* SourceProvenancePred , error ) {
32+ func GetSourceProvPred (statement * spb.Statement ) (* provenance. SourceProvenancePred , error ) {
6933 if statement == nil {
7034 return nil , errors .New ("nil statement" )
7135 }
72- if statement .GetPredicateType () != SourceProvPredicateType {
36+ if statement .GetPredicateType () != provenance . SourceProvPredicateType {
7337 return nil , fmt .Errorf ("unsupported predicate type: %s" , statement .GetPredicateType ())
7438 }
7539 if statement .GetPredicate () == nil {
@@ -80,7 +44,7 @@ func GetSourceProvPred(statement *spb.Statement) (*SourceProvenancePred, error)
8044 return nil , fmt .Errorf ("cannot marshal predicate to JSON: %w" , err )
8145 }
8246
83- var predStruct SourceProvenancePred
47+ var predStruct provenance. SourceProvenancePred
8448 // Using regular json.Unmarshal because this is just a regular struct.
8549 err = json .Unmarshal (predJson , & predStruct )
8650 if err != nil {
@@ -92,11 +56,11 @@ func GetSourceProvPred(statement *spb.Statement) (*SourceProvenancePred, error)
9256 return & predStruct , nil
9357}
9458
95- func GetTagProvPred (statement * spb.Statement ) (* TagProvenancePred , error ) {
59+ func GetTagProvPred (statement * spb.Statement ) (* provenance. TagProvenancePred , error ) {
9660 if statement == nil {
9761 return nil , errors .New ("nil statement" )
9862 }
99- if statement .GetPredicateType () != TagProvPredicateType {
63+ if statement .GetPredicateType () != provenance . TagProvPredicateType {
10064 return nil , fmt .Errorf ("unsupported predicate type: %s" , statement .GetPredicateType ())
10165 }
10266 if statement .GetPredicate () == nil {
@@ -107,7 +71,7 @@ func GetTagProvPred(statement *spb.Statement) (*TagProvenancePred, error) {
10771 return nil , fmt .Errorf ("cannot marshal predicate to JSON: %w" , err )
10872 }
10973
110- var predStruct TagProvenancePred
74+ var predStruct provenance. TagProvenancePred
11175 // Using regular json.Unmarshal because this is just a regular struct.
11276 err = json .Unmarshal (predJson , & predStruct )
11377 if err != nil {
@@ -155,7 +119,7 @@ func (pa ProvenanceAttestor) createCurrentProvenance(ctx context.Context, commit
155119
156120 curTime := time .Now ()
157121
158- var curProvPred SourceProvenancePred
122+ var curProvPred provenance. SourceProvenancePred
159123 curProvPred .PrevCommit = prevCommit
160124 curProvPred .RepoUri = pa .gh_connection .GetRepoUri ()
161125 curProvPred .Actor = controlStatus .ActorLogin
@@ -167,11 +131,11 @@ func (pa ProvenanceAttestor) createCurrentProvenance(ctx context.Context, commit
167131 // At the very least provenance is available starting now. :)
168132 curProvPred .Controls .AddControl (& slsa.Control {Name : slsa .ProvenanceAvailable , Since : curTime })
169133
170- return addPredToStatement (& curProvPred , SourceProvPredicateType , commit )
134+ return addPredToStatement (& curProvPred , provenance . SourceProvPredicateType , commit )
171135}
172136
173137// Gets provenance for the commit from git notes.
174- func (pa ProvenanceAttestor ) GetProvenance (ctx context.Context , commit , ref string ) (* spb.Statement , * SourceProvenancePred , error ) {
138+ func (pa ProvenanceAttestor ) GetProvenance (ctx context.Context , commit , ref string ) (* spb.Statement , * provenance. SourceProvenancePred , error ) {
175139 notes , err := pa .gh_connection .GetNotesForCommit (ctx , commit )
176140 if notes == "" {
177141 Debugf ("didn't find notes for commit %s" , commit )
@@ -187,9 +151,9 @@ func (pa ProvenanceAttestor) GetProvenance(ctx context.Context, commit, ref stri
187151 return pa .getProvFromReader (bundleReader , commit , ref )
188152}
189153
190- func (pa ProvenanceAttestor ) getProvFromReader (reader * BundleReader , commit , ref string ) (* spb.Statement , * SourceProvenancePred , error ) {
154+ func (pa ProvenanceAttestor ) getProvFromReader (reader * BundleReader , commit , ref string ) (* spb.Statement , * provenance. SourceProvenancePred , error ) {
191155 for {
192- stmt , err := reader .ReadStatement (MatchesTypeAndCommit (SourceProvPredicateType , commit ))
156+ stmt , err := reader .ReadStatement (MatchesTypeAndCommit (provenance . SourceProvPredicateType , commit ))
193157 if err != nil {
194158 // Ignore errors, we want to check all the lines.
195159 Debugf ("error while processing line: %v" , err )
@@ -218,7 +182,7 @@ func (pa ProvenanceAttestor) getProvFromReader(reader *BundleReader, commit, ref
218182 return nil , nil , nil
219183}
220184
221- func (pa ProvenanceAttestor ) getPrevProvenance (ctx context.Context , prevAttPath , prevCommit , ref string ) (* spb.Statement , * SourceProvenancePred , error ) {
185+ func (pa ProvenanceAttestor ) getPrevProvenance (ctx context.Context , prevAttPath , prevCommit , ref string ) (* spb.Statement , * provenance. SourceProvenancePred , error ) {
222186 if prevAttPath != "" {
223187 f , err := os .Open (prevAttPath )
224188 if err != nil {
@@ -270,7 +234,7 @@ func (pa ProvenanceAttestor) CreateSourceProvenance(ctx context.Context, prevAtt
270234 curProvPred .Controls [i ] = curControl
271235 }
272236
273- return addPredToStatement (curProvPred , SourceProvPredicateType , commit )
237+ return addPredToStatement (curProvPred , provenance . SourceProvPredicateType , commit )
274238}
275239
276240func (pa ProvenanceAttestor ) CreateTagProvenance (ctx context.Context , commit , ref , actor string ) (* spb.Statement , error ) {
@@ -302,19 +266,19 @@ func (pa ProvenanceAttestor) CreateTagProvenance(ctx context.Context, commit, re
302266 return nil , fmt .Errorf ("error getting source refs from vsa %w" , err )
303267 }
304268
305- curProvPred := TagProvenancePred {
269+ curProvPred := provenance. TagProvenancePred {
306270 RepoUri : pa .gh_connection .GetRepoUri (),
307271 Actor : actor ,
308272 Tag : ref ,
309273 CreatedOn : curTime ,
310274 Controls : controlStatus .Controls ,
311- VsaSummaries : []VsaSummary {
275+ VsaSummaries : []provenance. VsaSummary {
312276 {
313277 SourceRefs : vsaRefs ,
314278 VerifiedLevels : slsa .StringsToControlNames (vsaPred .GetVerifiedLevels ()),
315279 },
316280 },
317281 }
318282
319- return addPredToStatement (& curProvPred , TagProvPredicateType , commit )
283+ return addPredToStatement (& curProvPred , provenance . TagProvPredicateType , commit )
320284}
0 commit comments