//
// Copyright 2022 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.session.v1;

import "proto/session/messages.proto";

option java_multiple_files = true;
option java_package = "com.google.oak.session.v1";

message RequestWrapper {
  oneof request {
    InvokeRequest invoke_request = 2;
    GetEndorsedEvidenceRequest get_endorsed_evidence_request = 3;
  }
}

message ResponseWrapper {
  oneof response {
    InvokeResponse invoke_response = 2;
    GetEndorsedEvidenceResponse get_endorsed_evidence_response = 3;
  }
}

// Service definition for streaming communication with an Oak server.
service StreamingSession {
  // Generally speaking, Oak doesn't provide out-of-the-box service definitions,
  // as this is almost never something that someone needs, and it restricts the
  // server capability.
  //
  // Instead, you should define Oak-enabled methods using the provided transport
  // message types, along with the application SDK methods that make it easy to
  // implement the Oak functionality for these methods.
  option deprecated = true;

  // Used to send a sequence of messages ensuring that they are all handled by
  // the same server instance, by virtue of being multiplexed over a single gRPC
  // stream.
  //
  // The `RequestWrapper` and `ResponseWrapper` messages are thin wrappers
  // around the underlying messages exchanged by client and server, giving it a
  // minimal amount of structure and type safety.
  //
  // The expected message sequence starts with the client sending a
  // `GetEndorsedEvidenceRequest` message in order to fetch the evidence of the
  // enclave. This method may be handled by the untrusted launcher or by the
  // enclave, depending on the server implementation.
  //
  // Then the client encrypts the payload with the public key contained in the
  // evidence via a hybrid encryption protocol, and sends the encrypted payload
  // as part of a `InvokeRequest` message.
  rpc Stream(stream RequestWrapper) returns (stream ResponseWrapper);
}
