// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;

package biod;

option go_package = "chromiumos/system_api/biod_messages_proto";

import "constants.proto";

// Included in biod's AuthScanDone signal
message FingerprintMessage {
  oneof msg {
    FingerprintError error = 1;
    ScanResult scan_result = 2;
  }
}

// Returned from biod's GetNonce method.
message GetNonceReply {
  optional bytes nonce = 1;
}

// Included in biod's EnrollScanDone signal.
message EnrollScanDone {
  optional ScanResult scan_result = 1;
  optional bool done = 2;
  optional int32 percent_complete = 3;
  optional bytes auth_nonce = 4;
}

// Included in AuthStackManager's AuthScanDone signal.
message AuthScanDone {
  optional bytes auth_nonce = 1;
}

message StartEnrollSessionRequest {
  optional bytes gsc_nonce = 1;
  optional bytes encrypted_label_seed = 2;
  optional bytes iv = 3;
}

// Returned from biod's StartEnrollSession method.
message StartEnrollSessionReply {
  optional FingerprintError error = 1;
}

message StartAuthSessionRequest {
  optional bytes user_id = 1;
  optional bytes gsc_nonce = 2;
  optional bytes encrypted_label_seed = 3;
  optional bytes iv = 4;
}

// Returned from biod's StartAuthSession method.
message StartAuthSessionReply {
  optional FingerprintError error = 1;
}

// Included in StatusChanged signal.
message BiometricsManagerStatusChanged {
  optional BiometricsManagerStatus status = 1;
}

message FpPublicKey {
  optional bytes x = 1;
  optional bytes y = 2;
}

// TODO(b/298346899): This proto is deprecated and will be removed after
// callers migrate to the new proto. Note that the new service itself
// hasn't launched yet so we didn't keep the implementation backward
// compatible with this proto. As of now, usage of this proto will already
// result in failures.
message CreateCredentialRequest {
  optional string user_id = 1;
  optional bytes gsc_nonce = 2;
  optional bytes encrypted_label_seed = 3;
  optional bytes iv = 4;
  optional FpPublicKey pub = 5;
}

// TODO(b/298346899): Rename this back to CreateCredentialRequest after callers
// have switched over.
message CreateCredentialRequestV2 {
  optional FpPublicKey pub = 1;
}

message CreateCredentialReply {
  // These values are persisted to logs. Entries should not be renumbered and
  // numeric values should never be reused.
  enum CreateCredentialStatus {
    UNKNOWN = 0;
    SUCCESS = 1;
    INCORRECT_STATE = 2;       // biod isn't ready for creating credential.
    NO_TEMPLATE = 3;           // failed to retrieve template from AuthStack.
    NO_SECRET = 4;             // failed to retrieve secrets from AuthStack.
    CREATE_RECORD_FAILED = 5;  // failed to create record for the template.
  }

  optional CreateCredentialStatus status = 1;
  optional bytes encrypted_secret = 2;
  optional bytes iv = 3;
  optional FpPublicKey pub = 4;
  optional string record_id = 5;
}

// TODO(b/298346899): This proto is deprecated and will be removed after
// callers migrate to the new proto. Note that the new service itself
// hasn't launched yet so we didn't keep the implementation backward
// compatible with this proto. As of now, usage of this proto will already
// result in failures.
message AuthenticateCredentialRequest {
  optional bytes gsc_nonce = 1;
  optional bytes encrypted_label_seed = 2;
  optional bytes iv = 3;
  optional FpPublicKey pub = 4;
}

// TODO(b/298346899): Rename this back to AuthenticateCredentialRequest after
// callers have switched over.
message AuthenticateCredentialRequestV2 {
  optional FpPublicKey pub = 1;
}

message AuthenticateCredentialReply {
  // These values are persisted to logs. Entries should not be renumbered and
  // numeric values should never be reused.
  enum AuthenticateCredentialStatus {
    UNKNOWN = 0;
    SUCCESS = 1;
    INCORRECT_STATE = 2;   // biod isn't ready for authenticating credential.
    SET_NONCE_FAILED = 3;  // Failed to establish nonce session.
    UPLOAD_TEMPLATES_FAILED = 4;  // Failed to upload templates for match.
    MATCH_FAILED = 5;             // The match command itself failed.
    NO_TEMPLATES = 6;    // AuthStack reports there are no templates to match.
    NO_SECRET = 7;       // Failed to retrieve match secret.
    INTERNAL_ERROR = 8;  // AuthStack internal error.
  }

  optional AuthenticateCredentialStatus status = 1;
  optional ScanResult scan_result = 2;
  optional bytes encrypted_secret = 3;
  optional bytes iv = 4;
  optional FpPublicKey pub = 5;
  optional string record_id = 6;
}

message DeleteCredentialRequest {
  optional string user_id = 1;
  optional string record_id = 2;
}

message DeleteCredentialReply {
  enum DeleteCredentialStatus {
    UNKNOWN = 0;
    SUCCESS = 1;
    INCORRECT_STATE = 2;
    // The credential to delete doesn't exist. No need for deletion.
    NOT_EXIST = 3;
    // The credential to delete exists, but deletion failed.
    DELETION_FAILED = 4;
  }
  optional DeleteCredentialStatus status = 1;
}
