createAndPushAttestationInternal is the internal implementation that supports both SLSA v0.2 and v1
(ctx context.Context, imageName, keyName string, patches *godog.Table, useV1 bool)
| 445 | |
| 446 | // createAndPushAttestationInternal is the internal implementation that supports both SLSA v0.2 and v1 |
| 447 | func createAndPushAttestationInternal(ctx context.Context, imageName, keyName string, patches *godog.Table, useV1 bool) (context.Context, error) { |
| 448 | var state *imageState |
| 449 | ctx, err := testenv.SetupState(ctx, &state) |
| 450 | if err != nil { |
| 451 | return ctx, err |
| 452 | } |
| 453 | |
| 454 | if state.Attestations[imageName] != "" { |
| 455 | // we already created the attestation |
| 456 | return ctx, nil |
| 457 | } |
| 458 | |
| 459 | image, digest, _, err := getImageDigestAndRef(ctx, imageName) |
| 460 | if err != nil { |
| 461 | return ctx, err |
| 462 | } |
| 463 | |
| 464 | var statement any |
| 465 | |
| 466 | if useV1 { |
| 467 | // SLSA v1.0 |
| 468 | statement, err = attestation.CreateV1StatementFor(imageName, image) |
| 469 | if err != nil { |
| 470 | return ctx, err |
| 471 | } |
| 472 | } else { |
| 473 | // SLSA v0.2 |
| 474 | v02Statement, err := attestation.CreateStatementFor(imageName, image) |
| 475 | if err != nil { |
| 476 | return ctx, err |
| 477 | } |
| 478 | |
| 479 | statement, err = applyPatches(v02Statement, patches) |
| 480 | if err != nil { |
| 481 | return ctx, err |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | signedAttestation, err := attestation.SignStatement(ctx, keyName, statement) |
| 486 | if err != nil { |
| 487 | return ctx, err |
| 488 | } |
| 489 | |
| 490 | // Extract signature information from the signed attestation |
| 491 | var sig *cosign.Signatures |
| 492 | sig, err = unmarshallSignatures(signedAttestation) |
| 493 | if err != nil { |
| 494 | return ctx, err |
| 495 | } |
| 496 | if sig == nil { |
| 497 | return ctx, fmt.Errorf("failed to extract signature from attestation: no signatures found") |
| 498 | } |
| 499 | |
| 500 | state.AttestationSignatures[imageName] = Signature{ |
| 501 | KeyID: sig.KeyID, |
| 502 | Signature: sig.Sig, |
| 503 | } |
| 504 |
no test coverage detected