@@ -15,20 +15,21 @@ import (
15
15
16
16
cjson "github.com/docker/go/canonical/json"
17
17
"github.com/go-openapi/runtime"
18
- "github.com/go-openapi/strfmt"
19
- "github.com/go-openapi/swag"
20
18
"github.com/sigstore/cosign/v2/pkg/cosign"
21
19
"github.com/sigstore/rekor/pkg/generated/client"
22
20
"github.com/sigstore/rekor/pkg/generated/client/entries"
23
21
"github.com/sigstore/rekor/pkg/generated/client/index"
24
22
"github.com/sigstore/rekor/pkg/generated/models"
25
23
"github.com/sigstore/rekor/pkg/sharding"
26
24
"github.com/sigstore/rekor/pkg/types"
27
- intotod "github.com/sigstore/rekor/pkg/types/intoto/v0.0.1"
25
+ "github.com/sigstore/rekor/pkg/types/dsse"
26
+ dsse_v001 "github.com/sigstore/rekor/pkg/types/dsse/v0.0.1"
27
+ "github.com/sigstore/rekor/pkg/types/intoto"
28
+ intoto_v001 "github.com/sigstore/rekor/pkg/types/intoto/v0.0.1"
28
29
rverify "github.com/sigstore/rekor/pkg/verify"
29
30
"github.com/sigstore/sigstore/pkg/cryptoutils"
30
31
"github.com/sigstore/sigstore/pkg/signature"
31
- "github.com/sigstore/sigstore/pkg/signature/dsse"
32
+ dsseverifier "github.com/sigstore/sigstore/pkg/signature/dsse"
32
33
"github.com/slsa-framework/slsa-github-generator/signing/envelope"
33
34
34
35
serrors "github.com/slsa-framework/slsa-verifier/v2/errors"
@@ -123,14 +124,19 @@ func extractCert(e *models.LogEntryAnon) (*x509.Certificate, error) {
123
124
124
125
var publicKeyB64 []byte
125
126
switch e := eimpl .(type ) {
126
- case * intotod .V001Entry :
127
+ case * intoto_v001 .V001Entry :
127
128
publicKeyB64 , err = e .IntotoObj .PublicKey .MarshalText ()
128
- if err != nil {
129
- return nil , err
129
+ case * dsse_v001.V001Entry :
130
+ if len (e .DSSEObj .Signatures ) > 1 {
131
+ return nil , errors .New ("multiple signatures on DSSE envelopes are not currently supported" )
130
132
}
133
+ publicKeyB64 , err = e .DSSEObj .Signatures [0 ].Verifier .MarshalText ()
131
134
default :
132
135
return nil , errors .New ("unexpected tlog entry type" )
133
136
}
137
+ if err != nil {
138
+ return nil , err
139
+ }
134
140
135
141
publicKey , err := base64 .StdEncoding .DecodeString (string (publicKeyB64 ))
136
142
if err != nil {
@@ -149,19 +155,31 @@ func extractCert(e *models.LogEntryAnon) (*x509.Certificate, error) {
149
155
return certs [0 ], err
150
156
}
151
157
152
- func intotoEntry (certPem , provenance []byte ) (* intotod. V001Entry , error ) {
158
+ func intotoEntry (certPem , provenance []byte ) (models. ProposedEntry , error ) {
153
159
if len (certPem ) == 0 {
154
160
return nil , fmt .Errorf ("no signing certificate found in intoto envelope" )
155
161
}
156
- cert := strfmt .Base64 (certPem )
157
- return & intotod.V001Entry {
158
- IntotoObj : models.IntotoV001Schema {
159
- Content : & models.IntotoV001SchemaContent {
160
- Envelope : string (provenance ),
161
- },
162
- PublicKey : & cert ,
163
- },
164
- }, nil
162
+ var pubKeyBytes [][]byte
163
+ pubKeyBytes = append (pubKeyBytes , certPem )
164
+
165
+ return types .NewProposedEntry (context .Background (), intoto .KIND , intoto_v001 .APIVERSION , types.ArtifactProperties {
166
+ ArtifactBytes : provenance ,
167
+ PublicKeyBytes : pubKeyBytes ,
168
+ })
169
+ }
170
+
171
+ func dsseEntry (certPem , provenance []byte ) (models.ProposedEntry , error ) {
172
+ if len (certPem ) == 0 {
173
+ return nil , fmt .Errorf ("no signing certificate found in intoto envelope" )
174
+ }
175
+
176
+ var pubKeyBytes [][]byte
177
+ pubKeyBytes = append (pubKeyBytes , certPem )
178
+
179
+ return types .NewProposedEntry (context .Background (), dsse .KIND , dsse_v001 .APIVERSION , types.ArtifactProperties {
180
+ ArtifactBytes : provenance ,
181
+ PublicKeyBytes : pubKeyBytes ,
182
+ })
165
183
}
166
184
167
185
// getUUIDsByArtifactDigest finds all entry UUIDs by the digest of the artifact binary.
@@ -195,15 +213,15 @@ func GetValidSignedAttestationWithCert(rClient *client.Rekor,
195
213
return nil , fmt .Errorf ("error getting certificate from provenance: %w" , err )
196
214
}
197
215
198
- e , err := intotoEntry (certPem , provenance )
216
+ intotoEntry , err := intotoEntry (certPem , provenance )
199
217
if err != nil {
200
218
return nil , fmt .Errorf ("error creating intoto entry: %w" , err )
201
219
}
202
- entry := models. Intoto {
203
- APIVersion : swag . String ( e . APIVersion ()),
204
- Spec : e . IntotoObj ,
220
+ dsseEntry , err := dsseEntry ( certPem , provenance )
221
+ if err != nil {
222
+ return nil , err
205
223
}
206
- searchLogQuery .SetEntries ([]models.ProposedEntry {& entry })
224
+ searchLogQuery .SetEntries ([]models.ProposedEntry {intotoEntry , dsseEntry })
207
225
208
226
params .SetEntry (& searchLogQuery )
209
227
resp , err := rClient .Entries .SearchLogQuery (params )
@@ -347,7 +365,7 @@ func verifySignedAttestation(signedAtt *SignedAttestation, trustedRoot *TrustedR
347
365
}
348
366
349
367
// 2. Verify signature using validated certificate.
350
- verifier = dsse .WrapVerifier (verifier )
368
+ verifier = dsseverifier .WrapVerifier (verifier )
351
369
if err := verifier .VerifySignature (bytes .NewReader (attBytes ), bytes .NewReader (attBytes )); err != nil {
352
370
return fmt .Errorf ("%w: %s" , serrors .ErrorInvalidSignature , err )
353
371
}
0 commit comments