// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file contains the definition of protocol buffers for native browser
// fingerprinting.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;

package autofill.risk;

message Fingerprint {
  // A simple protocol message to represent objects with width and height.
  message Dimension {
    optional int32 width = 1;
    optional int32 height = 2;
  }

  // Characteristics of the user's machine that are relatively durable,
  // i.e. that are expected to change relatively infrequently.
  message MachineCharacteristics {
    // A simple protocol message that represents a plugin.
    // e.g. flash, shockwave, acrobat reader, gears, picasa
    message Plugin {
      optional string name = 1;
      optional string description = 2;
      repeated string mime_type = 3;
      optional string version = 4;
    }

    // Information on the CPU.
    message Cpu {
      // e.g. "GenuineIntel"
      optional string vendor_name = 1;
      // e.g. "Intel(R) Xeon(R) CPU           X5650  @ 2.67GHz\000"
      optional string brand = 2;
    }

    // Information on the GPU.
    message Graphics {
      // The GPU manufacturer's vendor id.
      optional uint32 vendor_id = 1;

      // The GPU manufacturer's device id for the chip set.
      optional uint32 device_id = 2;

      // The driver version on the GPU.
      optional string driver_version = 3;

      // The driver date on the GPU.
      optional string driver_date = 4;
    }

    // Browser features that integrate with Risk.
    enum BrowserFeature {
      FEATURE_UNKNOWN = 0;  // Should not be reachable.
      DEPRECATED_FEATURE_AUTOCHECKOUT = 1;
      FEATURE_REQUEST_AUTOCOMPLETE = 2;
    }

    // A hash of the concatenatation of:
    //   * The username of the user currently logged into computer / device.
    //   * The user-assigned computer or device name.
    optional fixed64 user_and_device_name_hash = 1;

    // Build version string for the current operating system.
    optional string operating_system_build = 2;

    // Browser install time (hours since epoch).
    optional int64 browser_install_time_hours = 3;

    // Fonts installed on the machine.
    repeated string font = 4;

    // Plug-ins installed on the machine.
    repeated Plugin plugin = 5;

    // Delta in ms of the device's time zone from UTC.
    optional int64 utc_offset_ms = 6;

    // IETF-formatted language tag. e.g. "en", "en-US", "es-419", etc.
    // http://en.wikipedia.org/wiki/IETF_language_tag
    optional string browser_language = 7;

    // User-requested language code of viewed sites. Languages in
    // accept-languages.
    repeated string requested_language = 8;

    // Default charset of the browser. (e.g. ISO-8859-1)
    optional string charset = 9;

    // The number of physical screens.
    optional int32 screen_count = 10;

    // Information about the user's monitor's physical screen size.
    // (e.g. 1024 x 768)
    optional Dimension screen_size = 11;

    // The color depth of the user's screen (obtained from screen.colorDepth
    // or screen.pixelDepth)
    optional int32 screen_color_depth = 12;

    // Information about the size of the portion of the screen that is unusable
    // to a program (i.e. on Windows, the portion of the screen that is taken
    // up by the taskbar)
    optional Dimension unavailable_screen_size = 13;

    optional string user_agent = 14;

    // Total size of each hard drive partition.
    repeated int32 partition_size = 15;

    optional Cpu cpu = 16;

    // Total RAM in bytes.
    optional int64 ram = 17;

    // Graphics card being used.
    optional Graphics graphics_card = 18;

    // Build version string for browser.
    optional string browser_build = 19;

    // The client-side feature corresponding to this request.
    optional BrowserFeature browser_feature = 20;
  }

  // Contains properties relating to more transient computer / browser state.
  message TransientState {
    // Corresponds to window.innerWidth / innerHeight
    optional Dimension inner_window_size = 1;

    // Corresponds to window.outerWidth / outerHeight
    optional Dimension outer_window_size = 2;
  }

  // Measures computer / network performance.
  message Performance {
    // Bandwidth in MB/s. network.connection.bandwidth
    optional float bandwidth = 1;
    // Whether bandwidth cost is metered. network.connection.metered
    optional bool metered = 2;
    // Whether it's wifi, 3g, 2g, etc. network.connection.type
    optional string network_type = 3;
  }

  // Properties describing the user -- especially the user's state in the
  // physical world.
  message UserCharacteristics {
    message Vector {
      optional int32 x = 1;
      optional int32 y = 2;
      optional int32 z = 3;
    }

    message Location {
      // Meters above sea level.
      optional double altitude = 1;
      // Latitude in degrees.
      optional double latitude = 2;
      // Longitude in degrees.
      optional double longitude = 3;
      // Accuracy in meters. 95% probability of being in this radius of
      // lat / long.
      optional double accuracy = 4;
      // Milliseconds since epoch since measurement.
      optional int64 time_in_ms = 5;
    }

    // Average force by finger presses. TouchEvent.force
    optional float force = 1;
    // Average finger width. TouchEvent.radiusX
    optional float touch_width = 2;
    // Average finger height. TouchEvent.radiusY
    optional float touch_height = 3;
    // TouchEvent.rotationAngle
    optional int32 touch_rotation = 4;
    // Orientation while user is navigating flow and the device is roughly
    // stable. x for alpha, y for beta, z for gamma
    // TODO(isherman): Orientation data is only available asynchronously in
    // Chrome.
    optional Vector device_orientation = 5;
    // Acceleration while measuring orientation.
    // TODO(isherman): Acceleration data is not available in Chrome.
    optional Vector device_acceleration = 6;
    optional Location location = 7;
  }

  // Metadata associated with data collection or the user that doesn't actually
  // fingerprint the device.
  message Metadata {
    // When this data was collected / received, in milliseconds since the epoch.
    optional int64 timestamp_ms = 1;
    // Obfuscated Gaia id associated with transaction.
    optional uint64 obfuscated_gaia_id = 2;
    // Version of the native library generating this proto.
    // This may be manually bumped when the code populating the proto has
    // significantly changed.
    optional int32 fingerprinter_version = 3;
  }

  // Computer / browser fingerprint.
  optional MachineCharacteristics machine_characteristics = 1;

  optional Performance performance = 2;

  optional UserCharacteristics user_characteristics = 3;

  optional TransientState transient_state = 4;

  // Metadata associated with data collection.
  optional Metadata metadata = 5;
}
