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

import "proto/crypto/crypto.proto";

// Choice between a key generated by the enclave instance and the key
// distributed to the enclave group with Key Provisioning.
enum KeyOrigin {
  KEY_ORIGIN_UNSPECIFIED = 0;
  INSTANCE = 1;
  GROUP = 2;
}

message DeriveSessionKeysRequest {
  KeyOrigin key_origin = 1;
  // Ephemeral Diffie-Hellman client public key that is needed to derive session
  // keys.
  bytes serialized_encapsulated_public_key = 2;
}

message DeriveSessionKeysResponse {
  // Session keys for decrypting client requests and encrypting enclave
  // responses.
  oak.crypto.v1.SessionKeys session_keys = 1;
}

message SignRequest {
  KeyOrigin key_origin = 1;
  bytes message = 2;
}

message SignResponse {
  oak.crypto.v1.Signature signature = 1;
}

message BindSessionRequest {
  // Session handshake transcript.
  bytes transcript = 1;
  // Additional data that will be signed alongside the transcript.
  // I.e. it could be an info string used to prevent confused deputy problems.
  bytes additional_data = 2;
}

message BindSessionResponse {
  oak.crypto.v1.Signature signature = 1;
}

// RPC service that is exposed to an enclave application and allows it to:
// - Encrypt/decrypt messages
// - Sign arbitrary data
service OrchestratorCrypto {
  // Derives session keys for decrypting client requests and encrypting enclave
  // responses.
  rpc DeriveSessionKeys(DeriveSessionKeysRequest)
      returns (DeriveSessionKeysResponse) {}
  // Signs the provided message using the hardware rooted signing key.
  rpc Sign(SignRequest) returns (SignResponse) {}
  // Signs the provided session handshake transcript using the hardware rooted
  // session binding key.
  rpc BindSession(BindSessionRequest) returns (BindSessionResponse) {}
}
