uploadToTransparencyLog uploads a signature to the transparency log and returns the bundle along with the raw tlog entry (needed for creating protobuf bundles).
(ctx context.Context, payload []byte, rawSignature []byte, signer signature.SignerVerifier)
| 303 | // uploadToTransparencyLog uploads a signature to the transparency log and returns the bundle |
| 304 | // along with the raw tlog entry (needed for creating protobuf bundles). |
| 305 | func uploadToTransparencyLog(ctx context.Context, payload []byte, rawSignature []byte, signer signature.SignerVerifier) (*bundle.RekorBundle, *models.LogEntryAnon, error) { |
| 306 | // Get public key or cert for transparency log upload |
| 307 | pkoc, err := getPublicKeyOrCert(signer) |
| 308 | if err != nil { |
| 309 | return nil, nil, fmt.Errorf("failed to get public key or cert: %w", err) |
| 310 | } |
| 311 | |
| 312 | // Get Rekor URL |
| 313 | rekorURL, err := rekor.StubRekor(ctx) |
| 314 | if err != nil { |
| 315 | return nil, nil, fmt.Errorf("failed to get stub rekor URL: %w", err) |
| 316 | } |
| 317 | |
| 318 | rekorClient, err := rc.GetRekorClient(rekorURL) |
| 319 | if err != nil { |
| 320 | return nil, nil, fmt.Errorf("failed to get rekor client: %w", err) |
| 321 | } |
| 322 | |
| 323 | // Compute payload checksum |
| 324 | checksum := sha256.New() |
| 325 | if _, err := checksum.Write(payload); err != nil { |
| 326 | return nil, nil, fmt.Errorf("error checksuming payload: %w", err) |
| 327 | } |
| 328 | |
| 329 | tlogEntry, err := cosign.TLogUpload(ctx, rekorClient, rawSignature, checksum, pkoc) |
| 330 | if err != nil { |
| 331 | return nil, nil, fmt.Errorf("failed to upload to transparency log: %w", err) |
| 332 | } |
| 333 | |
| 334 | // Create bundle from the actual transparency log entry |
| 335 | rekorBundle := bundle.EntryToBundle(tlogEntry) |
| 336 | if rekorBundle == nil { |
| 337 | return nil, nil, fmt.Errorf("rekorBundle is nil after EntryToBundle") |
| 338 | } |
| 339 | |
| 340 | return rekorBundle, tlogEntry, nil |
| 341 | } |
| 342 | |
| 343 | // getImageDigestAndRef returns the image, its digest, and digest reference for signing |
| 344 | func getImageDigestAndRef(ctx context.Context, imageName string) (v1.Image, v1.Hash, name.Digest, error) { |
no test coverage detected