@@ -77,7 +77,23 @@ func main() {
77
77
log .Fatal (err )
78
78
}
79
79
80
- marshalledEntryFromMirrorFS , tufRepo , rootJSON , err := genTUFRepo (sigstoreKeysMap )
80
+ tufRepo , rootJSON , err := genTUFRepo (map [string ][]byte {
81
+ "rekor.pem" : []byte (sigstoreKeysMap ["rekor" ]),
82
+ "ctfe.pem" : []byte (sigstoreKeysMap ["ctfe" ]),
83
+ "fulcio.pem" : []byte (sigstoreKeysMap ["fulcio" ]),
84
+ })
85
+ if err != nil {
86
+ log .Fatal (err )
87
+ }
88
+
89
+ tufRepoWithTrustedRootJSON , rootJSONWithTrustedRootJSON , err := genTUFRepo (map [string ][]byte {
90
+ "trusted_root.json" : marshalledEntry ,
91
+ })
92
+ if err != nil {
93
+ log .Fatal (err )
94
+ }
95
+
96
+ marshalledEntryFromMirrorFS , err := genTrustedRoot (sigstoreKeysMap )
81
97
if err != nil {
82
98
log .Fatal (err )
83
99
}
@@ -92,6 +108,8 @@ func main() {
92
108
mustWriteFile ("marshalledEntryFromMirrorFS.json" , marshalledEntryFromMirrorFS )
93
109
mustWriteFile ("tufRepo.tar" , tufRepo )
94
110
mustWriteFile ("root.json" , rootJSON )
111
+ mustWriteFile ("tufRepoWithTrustedRootJSON.tar" , tufRepoWithTrustedRootJSON )
112
+ mustWriteFile ("rootWithTrustedRootJSON.json" , rootJSONWithTrustedRootJSON )
95
113
}
96
114
97
115
func mustWriteFile (path string , data []byte ) {
@@ -204,39 +222,37 @@ func genLogID(pkBytes []byte) (string, error) {
204
222
return cosign .GetTransparencyLogID (pk )
205
223
}
206
224
207
- func genTUFRepo (sigstoreKeysMap map [string ]string ) ([]byte , []byte , []byte , error ) {
208
- files := map [string ][]byte {}
209
- files ["rekor.pem" ] = []byte (sigstoreKeysMap ["rekor" ])
210
- files ["ctfe.pem" ] = []byte (sigstoreKeysMap ["ctfe" ])
211
- files ["fulcio.pem" ] = []byte (sigstoreKeysMap ["fulcio" ])
212
-
225
+ func genTUFRepo (files map [string ][]byte ) ([]byte , []byte , error ) {
213
226
defer os .RemoveAll (path .Join (os .TempDir (), "tuf" )) // TODO: Update scaffolding to use os.MkdirTemp and remove this
214
227
ctx := context .Background ()
215
228
local , dir , err := repo .CreateRepo (ctx , files )
216
229
if err != nil {
217
- return nil , nil , nil , err
230
+ return nil , nil , err
218
231
}
219
232
meta , err := local .GetMeta ()
220
233
if err != nil {
221
- return nil , nil , nil , err
234
+ return nil , nil , err
222
235
}
223
236
rootJSON , ok := meta ["root.json" ]
224
237
if ! ok {
225
- return nil , nil , nil , err
238
+ return nil , nil , err
226
239
}
227
240
228
241
var compressed bytes.Buffer
229
242
if err := repo .CompressFS (os .DirFS (dir ), & compressed , map [string ]bool {"keys" : true , "staged" : true }); err != nil {
230
- return nil , nil , nil , err
243
+ return nil , nil , err
231
244
}
245
+ return compressed .Bytes (), rootJSON , nil
246
+ }
232
247
248
+ func genTrustedRoot (sigstoreKeysMap map [string ]string ) ([]byte , error ) {
233
249
tlogKey , _ , err := config .DeserializePublicKey ([]byte (sigstoreKeysMap ["rekor" ]))
234
250
if err != nil {
235
- return nil , nil , nil , err
251
+ return nil , err
236
252
}
237
253
ctlogKey , _ , err := config .DeserializePublicKey ([]byte (sigstoreKeysMap ["ctfe" ]))
238
254
if err != nil {
239
- return nil , nil , nil , err
255
+ return nil , err
240
256
}
241
257
242
258
trustRoot := & config.SigstoreKeys {
@@ -257,8 +273,8 @@ func genTUFRepo(sigstoreKeysMap map[string]string) ([]byte, []byte, []byte, erro
257
273
}
258
274
err = populateLogIDs (trustRoot )
259
275
if err != nil {
260
- return nil , nil , nil , err
276
+ return nil , err
261
277
}
262
278
trustRootBytes := []byte (protojson .Format (trustRoot ))
263
- return trustRootBytes , compressed . Bytes (), rootJSON , nil
279
+ return trustRootBytes , nil
264
280
}
0 commit comments