<commit_before>// Copyright 2015 Google Inc. All Rights Reserved.
//
// 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 google.security.e2ekeys.v2;

option java_package = "com.google.security.e2ekeys.v2";
option java_multiple_files = true;
option java_outer_classname = "E2EKeysProto";

import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

// The E2EKeyService API represents a directory of public keys.
// The key server has the following verifiable security properties:
// - The server keeps a single history of the directory.
// - The server gives consistent answers to queries regardless of audience.
//    - The server publishes a signed epoch head (SEH) of all its data every
//      epoch.
//    - Users can verify that a given entry is contained in that SEH.
//    - Only one entry in the server is valid for any particular user id.
//
// The API defines the following resource model:
//
// - The API has a collection of
//   [EntryProfileAndProof][google.security.e2ekeys.v2.EntryProfileAndProof]
//   resources named `/users/*`.
//
// - Each User has a collection of [Key][google.security.e2ekeys.v2.Key] 
//   resources named by `/users/*/keys/*`.
//
service E2EKeyService {
  // GetUser returns a user's profile, the comittment in the merkle tree, a
  // proof that there is only one entry for this user, and a proof that it is
  // the same data being provided to everyone else.
  // GetUser also supports querying past values by setting the epoch field.
  rpc GetUser(GetUserRequest) returns (EntryProfileAndProof);

  // ListUserHistory returns a list of UserProofs covering a period of time.
  rpc ListUserHistory(ListUserHistoryRequest) returns (ListUserHistoryResponse);

  // blocking or polling?
  rpc UpdateUser(UpdateUserRequest) returns (protobuf.Empty);

  // List the Signed Epoch Heads, from epoch to epoch.
  rpc ListSEH(ListSEHRequest) returns (ListSEHResponse);

  // List the EntryUpdates by update number.
  rpc ListUpdate(ListUpdateRequest) returns (ListUpdateResponse);

  // ListSteps combines SEH and EntryUpdates into single list.
  rpc ListSteps(ListStepsRequest) returns (ListStepsResponse);
}

//
// Data types.
//

// SignedEpochHead represents a signed state of the Merkel tree.
message SignedEpochHead {
  // Signature of this epoch's hash, using the signature type of the key.
  bytes head_sig = 1;
  // Serialized TimestampedEpochHead.
  bytes head = 2;
  // key_hash is the first 4 bytes of the SHA256 hash of the key used for
  // signing. May be used for key rotation and/or multiple signatures.
  uint64 key_hash = 3;
}

message TimestampedEpochHead {
  EpochHead head = 1;
  // The timestamp of this signature.
  google.protobuf.Timestamp current_time = 2;
}

// EpochHead is the head node of the Merkle Tree as well as additional metadata 
// for the tree.
message EpochHead {
  // epoch number
  uint64 epoch = 1;
  // Hash of previous SEH.
  bytes previous_seh = 3;
  // The value of the head node of the merkle tree.
  bytes head = 4;
  // realm is the domain...
  string realm = 5;
}

message UVF {
  //TODO: fill with data needed for to verify the Unpredictable Verifiable
  //Function.
}

message EntryProfileAndProof {
  // Entry contains the public portion of the user's data, and a comitment to
  // profile.
  Entry entry = 1;
  // Profile contains the user's keys.
  bytes profile = 2;
  // merkle_tree_neighbors is a list of all the adjacent nodes along the path
  // from the bottommost node to the head.
  repeated bytes merkle_tree_neighbors = 3;
  // The signed epoch head.  A server may choose to return multiple signatures
  // of the same head for the same epoch.
  repeated SignedEpochHead seh = 4;
  // index_signature is the signed portion the unpredictable verifiable
  // function on user_id. If H(index_signature) != entry.index, but they share
  // a common prefix of len(merkle_tree_neighbors), this is a proof of
  // non-existance for user_id.
  UVF index_signature = 5;
  // user_id supports sending this as a complete proof to a third party. 
  // user_id is not filled by the server.
  string user_id = 6;
}

// Step is a combined, ordered list of SignedEntryUpdates and SignedEpochHeads
// which are made available to verifiers.
message Step {
  oneof type {
    // entry_changed contains serialized SignedEntryUpdate.
    bytes entry_changed = 1;
    SignedEpochHead seh = 2;
  }
  // epoch of this udpate.
  uint64 epoch = 3;
  // sequence is the ordered sequence number of this step.
  // Equal to epoch_num + update sequence number.
  uint64 sequence = 4;
}

// EntryUpdate is the proto a client sends to update their profile.
message EntryUpdateRequest {
  // signed_update contains serialized SignedEntryUpdate and authorizes the
  // change to profile.
  bytes signed_update = 1;
  // profile is the serialized protobuf Profile.
  // profile is private and must not be released to verifiers.
  bytes profile = 2;
}

message SignedEntryUpdate {
  // Signature of entry, by the entry_key inside entry.
  // Proves ownership of new key.
  bytes signature_new = 1;
  // Signature of entry, by the entry_key from the previous epoch.
  // Proves the the correct owner is making this change.
  bytes signature_old = 2;
  // entry is the serialized protobuf Entry.
  bytes entry = 3;
}

// Entry is the leaf node object for the Merkle Tree. Its unique index in the
// tree is identified by a hash of an verifiable unpredictable function on the
// user_id.
message Entry {
  // entry_key allows verifiers to validate updates to Entry.
  // entry_key is a ECDSH key.
  bytes entry_key = 1;<commit_msg>closes #44<commit_after>// Copyright 2015 Google Inc. All Rights Reserved.
//
// 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 google.security.e2ekeys.v2;

option java_package = "com.google.security.e2ekeys.v2";
option java_multiple_files = true;
option java_outer_classname = "E2EKeysProto";

import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

// The E2EKeyService API represents a directory of public keys.
// The key server has the following verifiable security properties:
// - The server keeps a single history of the directory.
// - The server gives consistent answers to queries regardless of audience.
//    - The server publishes a signed epoch head (SEH) of all its data every
//      epoch.
//    - Users can verify that a given entry is contained in that SEH.
//    - Only one entry in the server is valid for any particular user id.
//
// The API defines the following resource model:
//
// - The API has a collection of
//   [EntryProfileAndProof][google.security.e2ekeys.v2.EntryProfileAndProof]
//   resources named `/users/*`.
//
// - Each User has a collection of [Key][google.security.e2ekeys.v2.Key] 
//   resources named by `/users/*/keys/*`.
//
service E2EKeyService {
  // GetUser returns a user's profile, the comittment in the merkle tree, a
  // proof that there is only one entry for this user, and a proof that it is
  // the same data being provided to everyone else.
  // GetUser also supports querying past values by setting the epoch field.
  rpc GetUser(GetUserRequest) returns (EntryProfileAndProof);

  // ListUserHistory returns a list of UserProofs covering a period of time.
  rpc ListUserHistory(ListUserHistoryRequest) returns (ListUserHistoryResponse);

  // blocking or polling?
  rpc UpdateUser(UpdateUserRequest) returns (protobuf.Empty);

  // List the Signed Epoch Heads, from epoch to epoch.
  rpc ListSEH(ListSEHRequest) returns (ListSEHResponse);

  // List the EntryUpdates by update number.
  rpc ListUpdate(ListUpdateRequest) returns (ListUpdateResponse);

  // ListSteps combines SEH and EntryUpdates into single list.
  rpc ListSteps(ListStepsRequest) returns (ListStepsResponse);
}

//
// Data types.
//

// SignedEpochHead represents a signed state of the Merkel tree.
message SignedEpochHead {
  // Signature of this epoch's hash, using the signature type of the key.
  bytes head_sig = 1;
  // Serialized TimestampedEpochHead.
  bytes head = 2;
  // key_hash is the first 4 bytes of the SHA256 hash of the key used for
  // signing. May be used for key rotation and/or multiple signatures.
  uint64 key_hash = 3;
}

message TimestampedEpochHead {
  EpochHead head = 1;
  // The timestamp of this signature.
  google.protobuf.Timestamp current_time = 2;
}

// EpochHead is the head node of the Merkle Tree as well as additional metadata 
// for the tree.
message EpochHead {
  // epoch number
  uint64 epoch = 1;
  // Hash of previous SEH.
  bytes previous_seh = 3;
  // The value of the head node of the merkle tree.
  bytes head = 4;
  // realm is the domain...
  string realm = 5;
}

message UVF {
  //TODO: fill with data needed for to verify the Unpredictable Verifiable
  //Function.
}

message EntryProfileAndProof {
  // Entry contains the public portion of the user's data, and a comitment to
  // profile.
  Entry entry = 1;
  // Profile contains the user's keys.
  bytes profile = 2;
  // merkle_tree_neighbors is a list of all the adjacent nodes along the path
  // from the bottommost node to the head.
  repeated bytes merkle_tree_neighbors = 3;
  // The signed epoch head.  A server may choose to return multiple signatures
  // of the same head for the same epoch.
  repeated SignedEpochHead seh = 4;
  // index_signature is the signed portion the unpredictable verifiable
  // function on user_id. If H(index_signature) != entry.index, but they share
  // a common prefix of len(merkle_tree_neighbors), this is a proof of
  // non-existance for user_id.
  UVF index_signature = 5;
  // user_id supports sending this as a complete proof to a third party. 
  // user_id is not filled by the server.
  string user_id = 6;
}

// Step is a combined, ordered list of SignedEntryUpdates and SignedEpochHeads
// which are made available to verifiers.
message Step {
  oneof type {
    // entry_changed contains serialized SignedEntryUpdate.
    bytes entry_changed = 1;
    SignedEpochHead seh = 2;
  }
  // epoch of this udpate.
  uint64 epoch = 3;
  // sequence is the ordered sequence number of this step.
  // Equal to epoch_num + update sequence number.
  uint64 sequence = 4;
}

// EntryUpdate is the proto a client sends to update their profile.
message EntryUpdateRequest {
  // signed_update contains serialized SignedEntryUpdate and authorizes the
  // change to profile.
  bytes signed_update = 1;
  // profile is the serialized protobuf Profile.
  // profile is private and must not be released to verifiers.
  bytes profile = 2;
}

message SignedEntryUpdate {
  // Signature of entry, by the entry_key inside entry.
  // Proves ownership of new key.
  map<uint64, bytes> signature_new = 1;
  // Signature of entry, by the entry_key from the previous epoch.
  // Proves the the correct owner is making this change.
  map<uint64, bytes> signature_old = 2;
  // entry is the serialized protobuf Entry.
  bytes entry = 3;
}

// Entry is the leaf node object for the Merkle Tree. Its unique index in the
// tree is identified by a hash of an verifiable unpredictable function on the
// user_id.
message Entry {
  // entry_key allows verifiers to validate updates to Entry.
  // entry_key is a ECDSH key.
  bytes entry_key = 1;
{'fraction_non_alphanumeric': 0.07711058747054522, 'fraction_numerical': 0.009750548468351345, 'mean_word_length': 3.285515320334262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7449817', 'n_tokens_mistral': 3591, 'n_tokens_neox': 3466, 'n_words': 1564}