//
// Copyright 2023 The Project Oak 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 oak.containers;

import "google/protobuf/empty.proto";
import "proto/attestation/evidence.proto";
import "proto/attestation/endorsement.proto";
import "proto/session/messages.proto";

// As images can be large (hundreds of megabytes), the launcher chunks up the
// response into smaller pieces to respect proto/gRPC limits. The image needs to
// be reassembled in the stage1 or the orchestrator.
message GetImageResponse {
  bytes image_chunk = 1;
}

message GetApplicationConfigResponse {
  // Arbitrary config that the container can retrieve from the orchestrator.
  // Included in the attestation measurements conducted by the orchestrator.
  bytes config = 1;
}

message SendAttestationEvidenceRequest {
  oak.attestation.v1.Evidence dice_evidence = 2;
}

// Defines the service exposed by the launcher, that can be invoked by the
// stage1 and the orchestrator.
service Launcher {
  // Provides stage1 with the Oak system image (which contains the Linux
  // distribution and the orchestrator binary).
  rpc GetOakSystemImage(google.protobuf.Empty)
      returns (stream GetImageResponse) {}

  // Provides orchestrator with the trusted container image.
  rpc GetContainerBundle(google.protobuf.Empty)
      returns (stream GetImageResponse) {}

  // This method is used by the orchestrator to load and measure the trusted
  // application config. The orchestrator will later, separately expose this
  // config to the application.
  rpc GetApplicationConfig(google.protobuf.Empty)
      returns (GetApplicationConfigResponse) {}

  // Provides the orchestrator with the endorsements of the trusted application
  // and the container.
  rpc GetEndorsements(google.protobuf.Empty)
      returns (oak.attestation.v1.Endorsements) {}

  // Sends Attestation Evidence containing the Attestation Report with
  // corresponding measurements and public keys to the Launcher. This API is
  // called exactly once after the Attestation Evidence is generated. Calling
  // this API a second time will result in an error.
  rpc SendAttestationEvidence(SendAttestationEvidenceRequest)
      returns (google.protobuf.Empty) {}

  // Notifies the launcher that the trusted app is ready to serve requests and
  // listening on the pre-arranged port (8080).
  rpc NotifyAppReady(google.protobuf.Empty) returns (google.protobuf.Empty) {}
}

// Defines the service exposed by the orchestrator, that can be invoked by the
// application.
service Orchestrator {
  // Exposes the previously loaded trusted application config to the
  // application, which may choose to retrieve it.
  rpc GetApplicationConfig(google.protobuf.Empty)
      returns (GetApplicationConfigResponse) {}

  // Notifies the orchestrator that the trusted app is ready to serve requests
  // and listening on the pre-arranged port (8080).
  rpc NotifyAppReady(google.protobuf.Empty) returns (google.protobuf.Empty) {}

  // Provide the endorsed evidence for this TEE to the caller.
  rpc GetEndorsedEvidence(google.protobuf.Empty)
      returns (oak.session.v1.EndorsedEvidence) {}
}
