Files
attest/sign.go

49 lines
1.6 KiB
Go
Raw Normal View History

2024-10-17 13:40:17 -05:00
/*
Copyright Docker attest authors
2024-10-17 13:40:17 -05:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2024-04-29 12:52:39 -05:00
package attest
2024-04-29 15:02:21 -05:00
import (
"context"
"fmt"
"github.com/docker/attest/attestation"
2024-04-29 15:02:21 -05:00
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/secure-systems-lab/go-securesystemslib/dsse"
)
// this is only relevant if there are (unsigned) in-toto statements.
func SignStatements(ctx context.Context, idx v1.ImageIndex, signer dsse.SignerVerifier, opts *attestation.SigningOptions) ([]*attestation.Manifest, error) {
2024-04-30 12:23:07 -05:00
// extract attestation manifests from index
2024-08-12 14:49:52 -05:00
attestationManifests, err := attestation.ManifestsFromIndex(idx)
2024-04-29 15:02:21 -05:00
if err != nil {
return nil, fmt.Errorf("failed to load attestation manifests from index: %w", err)
2024-04-29 15:02:21 -05:00
}
2024-04-30 12:23:07 -05:00
// sign every attestation layer in each manifest
for _, manifest := range attestationManifests {
for _, layer := range manifest.OriginalLayers {
2024-09-24 14:34:48 -05:00
// skip layers without statements
if layer.Statement != nil {
err = manifest.Add(ctx, signer, layer.Statement, opts)
if err != nil {
return nil, fmt.Errorf("failed to sign attestation layer %w", err)
}
}
2024-04-29 15:02:21 -05:00
}
}
return attestationManifests, nil
2024-04-29 15:02:21 -05:00
}