// Copyright 2024 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";

// Required in Chrome.
option optimize_for = LITE_RUNTIME;

package bound_session_credentials;

import "bound_session_params.proto";

// Debug information about previous failed rotation attempts. Attached to cookie
// rotation requests.
message RotationDebugInfo {
  // Various transient error types that might have occurred during cookie
  // rotation. See `TerminationReason` for persistent errors.
  enum FailureType {
    OTHER = 0;
    CONNECTION_ERROR = 1;
    SERVER_ERROR = 2;
    TIMEOUT = 3;
    SUCCESS_WITH_MISSING_COOKIES = 4;
  }

  // Persistent error type that may only be included in the last rotation
  // request ping before terminating the session on the client. Delivery of the
  // last ping request is not guaranteed.
  enum TerminationReason {
    reserved 2;  // ROTATION_UNEXPECTED_RESPONSE

    TERMINATION_REASON_OTHER = 0;
    ROTATION_PERSISTENT_ERROR = 1;
    ROTATION_CHALLENGE_UNEXPECTED_FORMAT = 3;
    ROTATION_CHALLENGE_LIMIT_EXCEEDED = 4;
    ROTATION_SIGN_CHALLENGE_FAILED = 5;
    ROTATION_UNKNOWN_ERROR = 6;
    TERMINATION_HEADER_RECEIVED = 7;
    SESSION_OVERRIDE = 8;
    ROTATION_CHALLENGE_SESSION_ID_MISMATCH = 9;
    ROTATION_STOPPED_TIMEOUT = 10;
  }

  // Contains how many times a specific type of error occurred.
  message FailureCounter {
    optional FailureType type = 1;
    optional int32 count = 2;
  }

  // Contains information about one single failure.
  message FailureInfo {
    optional Timestamp failure_time = 1;
    optional FailureType type = 2;
    optional bool received_challenge = 3;
    // Only set if `type` equals to `SUCCESS_WITH_MISSING_COOKIES`.
    repeated string missing_cookies = 4;
  }

  optional Timestamp request_time = 1;
  repeated FailureCounter errors_since_last_rotation = 2;
  optional FailureInfo first_failure_info = 3;
  // Only populated if the session had already been terminated and the client
  // reports its last status.
  optional TerminationReason termination_reason = 4;
}
