// Copyright 2022 The Sigstore Authors.
//
// 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.

syntax = "proto3";
package dev.sigstore.bundle.v1;

import "google/api/field_behavior.proto";

// https://raw.githubusercontent.com/secure-systems-lab/dsse/9c813476bd36de70a5738c72e784f123ecea16af/envelope.proto
import "envelope.proto";
import "sigstore_common.proto";
import "sigstore_rekor.proto";

option go_package = "github.com/sigstore/protobuf-specs/gen/pb-go/bundle/v1";
option java_package = "dev.sigstore.proto.bundle.v1";
option java_multiple_files = true;
option java_outer_classname = "BundleProto";
option ruby_package = "Sigstore::Bundle::V1";

// Notes on versioning.
// The primary message ('Bundle') MUST be versioned, by populating the
// 'media_type' field. Semver-ish (only major/minor versions) scheme MUST
// be used. The current version as specified by this file is:
// application/vnd.dev.sigstore.bundle+json;version=0.2
// The semantic version is thus '0.2'.

// Various timestamped counter signatures over the artifacts signature.
// Currently only RFC3161 signatures are provided. More formats may be added
// in the future.
message TimestampVerificationData {
        // A list of RFC3161 signed timestamps provided by the user.
        // This can be used when the entry has not been stored on a
        // transparency log, or in conjunction for a stronger trust model.
        // Clients MUST verify the hashed message in the message imprint
        // against the signature in the bundle.
        repeated dev.sigstore.common.v1.RFC3161SignedTimestamp rfc3161_timestamps = 1;
}

// VerificationMaterial captures details on the materials used to verify
// signatures.
message VerificationMaterial {
        oneof content {
                dev.sigstore.common.v1.PublicKeyIdentifier public_key = 1 [(google.api.field_behavior) = REQUIRED];
                dev.sigstore.common.v1.X509CertificateChain x509_certificate_chain = 2 [(google.api.field_behavior) = REQUIRED];
        }
        // An inclusion proof and an optional signed timestamp from the log.
        // Client verification libraries MAY provide an option to support v0.1
        // bundles for backwards compatibility, which may contain an inclusion
        // promise and not an inclusion proof. In this case, the client MUST
        // validate the promise.
        // Verifiers SHOULD NOT allow v0.1 bundles if they're used in an
        // ecosystem which never produced them.
        repeated dev.sigstore.rekor.v1.TransparencyLogEntry tlog_entries = 3;
        // Timestamp may also come from
        // tlog_entries.inclusion_promise.signed_entry_timestamp.
        TimestampVerificationData timestamp_verification_data = 4;
}

message Bundle {
        // MUST be application/vnd.dev.sigstore.bundle+json;version=0.1
        // or application/vnd.dev.sigstore.bundle+json;version=0.2
        // when encoded as JSON.
        string media_type = 1;
        // When a signer is identified by a X.509 certificate, a verifier MUST
        // verify that the signature was computed at the time the certificate
        // was valid as described in the Sigstore client spec: "Verification
        // using a Bundle".
        // <https://docs.google.com/document/d/1kbhK2qyPPk8SLavHzYSDM8-Ueul9_oxIMVFuWMWKz0E/edit#heading=h.x8bduppe89ln>
        VerificationMaterial verification_material = 2 [(google.api.field_behavior) = REQUIRED];
        oneof content {
                dev.sigstore.common.v1.MessageSignature message_signature = 3 [(google.api.field_behavior) = REQUIRED];
                // A DSSE envelope can contain arbitrary payloads.
                // Verifiers must verify that the payload type is a
                // supported and expected type. This is part of the DSSE
                // protocol which is defined here:
                // <https://github.com/secure-systems-lab/dsse/blob/master/protocol.md>
                io.intoto.Envelope dsse_envelope = 4 [(google.api.field_behavior) = REQUIRED];
        }
        // Reserved for future additions of artifact types.
        reserved 5 to 50;
}
