Files
attest/attestation/types.go

164 lines
4.4 KiB
Go
Raw Permalink 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-22 12:22:15 -05:00
package attestation
2024-04-29 15:02:21 -05:00
import (
"crypto"
2024-04-29 15:02:21 -05:00
"encoding/base64"
"fmt"
"time"
2024-04-29 15:02:21 -05:00
"github.com/docker/attest/tlog"
2024-04-30 12:23:07 -05:00
v1 "github.com/google/go-containerregistry/pkg/v1"
2024-04-29 15:02:21 -05:00
intoto "github.com/in-toto/in-toto-golang/in_toto"
v02 "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/v0.2"
2024-09-04 16:03:55 -05:00
slsav1 "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/v1"
2024-04-29 15:02:21 -05:00
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
)
2024-04-22 12:22:15 -05:00
const (
DockerReferenceType = "vnd.docker.reference.type"
AttestationManifestType = "attestation-manifest"
InTotoPredicateType = "in-toto.io/predicate-type"
DockerReferenceDigest = "vnd.docker.reference.digest"
DockerDSSEExtKind = "application/vnd.docker.attestation-verification.v1+json"
OCIDescriptorDSSEMediaType = ociv1.MediaTypeDescriptor + "+dsse"
InTotoReferenceLifecycleStage = "vnd.docker.lifecycle-stage"
LifecycleStageExperimental = "experimental"
2024-04-22 12:22:15 -05:00
)
var base64Encoding = base64.StdEncoding.Strict()
type Layer struct {
2024-04-30 12:23:07 -05:00
Statement *intoto.Statement
Layer v1.Layer
Annotations map[string]string
}
type Manifest struct {
OriginalDescriptor *v1.Descriptor
OriginalLayers []*Layer
2024-04-30 12:23:07 -05:00
// accumulated during signing
SignedLayers []*Layer
2024-08-05 13:24:58 -05:00
// details of subject image
SubjectName string
SubjectDescriptor *v1.Descriptor
}
type ManifestImageOptions struct {
// how to output the image
skipSubject bool
replaceLayers bool
laxReferrers bool
2024-04-30 12:23:07 -05:00
}
// the following types are needed until https://github.com/secure-systems-lab/dsse/pull/61 is merged.
2024-04-22 12:22:15 -05:00
type Envelope struct {
PayloadType string `json:"payloadType"`
Payload string `json:"payload"`
Signatures []*Signature `json:"signatures"`
2024-04-22 12:22:15 -05:00
}
type Signature struct {
KeyID string `json:"keyid"`
Sig string `json:"sig"`
Extension *Extension `json:"extension,omitempty"`
2024-04-22 12:22:15 -05:00
}
type Extension struct {
Kind string `json:"kind"`
Ext *DockerDSSEExtension `json:"ext"`
2024-04-22 12:22:15 -05:00
}
type EnvelopeReference struct {
*Envelope
2024-10-07 13:36:30 -05:00
ResourceDescriptor *ResourceDescriptor `json:"resourceDescriptor"`
}
type ResourceDescriptor struct {
MediaType string `json:"mediaType"`
Digest map[string]string `json:"digest"`
2024-10-07 13:36:30 -05:00
URI string `json:"uri,omitempty"`
}
2024-08-12 14:49:52 -05:00
type AnnotatedStatement struct {
OCIDescriptor *v1.Descriptor
InTotoStatement *intoto.Statement
Annotations map[string]string
}
type DockerDSSEExtension struct {
TL *tlog.DockerTLExtension `json:"tl"`
2024-04-22 12:22:15 -05:00
}
type TransparencyLogKind string
const (
RekorTransparencyLogKind = "rekor"
)
2024-04-29 15:02:21 -05:00
type VerifyOptions struct {
Keys []*KeyMetadata `json:"keys"`
SkipTL bool `json:"skip_tl"`
TransparencyLog TransparencyLogKind `json:"tl"`
}
type KeyMetadata struct {
ID string `json:"id"`
PEM string `json:"key"`
From time.Time `json:"from"`
To *time.Time `json:"to"`
Status string `json:"status"`
SigningFormat string `json:"signing-format"`
Distrust bool `json:"distrust,omitempty"`
publicKey crypto.PublicKey
}
type (
Keys []*KeyMetadata
KeysMap map[string]*KeyMetadata
)
type SigningOptions struct {
// set this in order to log to a transparency log
TransparencyLog tlog.TransparencyLog
}
2024-08-12 14:49:52 -05:00
type Options struct {
NoReferrers bool
Attach bool
ReferrersRepo string
}
2024-04-29 15:02:21 -05:00
func DSSEMediaType(predicateType string) (string, error) {
var predicateName string
switch predicateType {
2024-09-04 16:03:55 -05:00
case slsav1.PredicateSLSAProvenance:
predicateName = "provenance"
2024-04-29 15:02:21 -05:00
case v02.PredicateSLSAProvenance:
predicateName = "provenance"
case intoto.PredicateSPDX:
predicateName = "spdx"
case VSAPredicateType:
predicateName = "verification_summary"
default:
return "", fmt.Errorf("unknown predicate type %q", predicateType)
}
return fmt.Sprintf("application/vnd.in-toto.%s+dsse", predicateName), nil
}