Firefox OS/Remote Control

From MozillaWiki
< Firefox OS
Revision as of 10:07, 6 January 2016 by Eric Tsai (talk | contribs) (→‎Architecture Designs: Add steps of key exchange)
Jump to navigation Jump to search

Introduction

Remote control is a new feature for Firefox OS on TV. We hope user can control TV at any device without installing any APP. Consider compatibility, remote control uses HTTP and AJAX as communication protocol between TV and user. User can easily connect to TV via open his/her browser, enter URL on TV and use the virtual touchpad to control TV just in seconds.

Meta Bug: bug 1205939

Prototype Demo Video: http://bit.ly/1Fa2ST1

UX & Visual Spec

UX Spec: http://bit.ly/1jrWqgn

Visual Spec: http://bit.ly/1jrWQU3

Architecture Designs

  • Remote Control Service: Entry point of remote control feature. Control service related logic and data in runtime.
  • HTTP Server: Serves connections from user. Two types files can be served:
    • Static file: Stored in Remote Control Client App, packaged in app://remote-control-client.gaiamobile.org
    • Service script: Handle AJAX request and response for secure connection initialization, PIN code pairing and control event processing. Packaged in resource://gre/res/remotecontrol
  • Remote Control App: Provides service related user interface on TV. Communicate with Remote Control Service via MozSettings.

User interaction of remote control is divided into three parts:

  1. Establish secure connection
  2. PIN code pairing (optional, by user settings)
  3. Control event processing

Establish secure connection

Remote control is designed to protect data transmitted between client and server, for example: user input string may contains privacy data. Client is forced to exchange symmetric key (AES-GCM) with server in the first time. After key exchange, server uses UUID in cookie to identify client and key to decrypt messages. Following describes how keys are exchanged:

  1. User opens the URL
  2. Client requests page without valid UUID.
  3. Server response secure.html as requested page for key exchange.
  4. Client acquire RSA public key from secure.sjs.
  5. Secure.sjs replies RSA public key SPKI in base64.
  6. Client import RSA public key and wrap symmetric key.
  7. Client sends wrapped symmetric key to secure.sjs in base64.
  8. Secure.sjs replies with a ticket number.
  9. Secure.sjs unwraps symmetric key with RSA private key.
  10. Secure.sjs saves symmetric key.
  11. Remote Control Service generates a new UUID, encrypted with symmetric key and binds encrypted UUID with ticket number.
  12. Client polls encrypted UUID from secure.sjs.
  13. Client decrypt received UUID to double confirm server receives correct symmetric key.
  14. Client reloads the URL with UUID.


PIN code pairing

Control event processing

Ajax Protocol

Touch Events

 {
   type: 'touchstart',
   detail: {
     width: <touch panel width, integer, in pixels>,
     height: <touch panel height, integer, in pixels>,
     identifier: <A simple unique identifier for server to distinguish touch events between different clients, string>
   }
 }
 {
   type: 'touchmove',
   detail: {
     dx: <dx between current point and starting point, integer, in pixels>,
     dy: <dy between current point and starting point, integer, in pixels>,
     identifier: <should be identical with "touchstart">,
     duration: <duration from "touchstart", integer, in milliseconds>
   }
 }
 {
   type: 'touchend',
   detail: {
     dx: <same as "touchmove">,
     dy: <same as "touchmove">,
     identifier: <should be identical with "touchstart">,
     duration: <same as "touchmove">,
     swipe: <the gesture within this touch, string, should be "left", "right", "up" and "down">
   }
 }

Scroll Events

There are "scrollstart", "scrollmove" and "scrollend" events which details are all identical with corresponding touch events above.

Key Events

 {
   type: 'keypress',
   detail: <KeyEvent constant, string, sush as "DOM_VK_RETURN">
 }

Input Events

 {
   type: 'input',
   detail: {
     clear: <whether to clear the entire string in the current focused input field, boolean>,
     string: <new string to append, string>,
     keycode: <a specified key to be pressed after the string inputted, integer>
   }
 }

Custom Events

 {
   type: 'custom',
   action: <custom action name, string>,
   ...
 }

Pairing

Meta Bug: bug 1207996

Flowchart

First Time Connection

RemoteControl FirstConnect.png

Enter PIN Code

RemoteControl EnterPIN.png

Resume Connection

RemoteControl ResumeConnection.png

Dismiss Pairing

RemoteControl DismissPairing.png

Protocol

from client to server via AJAX

 {
   pincode: <pincode>
 }

response when success

 {
   verified: true,
   uuid: <uuid>
 }

reponse when error

 {
   verified: false,
   reason: 'expired' / 'invalid'
 }

internal events at server side

 {
   type: 'mozChromeRemoteControlEvent',
   detail: {
     action: 'pin-created',
     pincode: <pincode>
   }
 }
 {
   type: 'mozChromeRemoteControlEvent',
   detail: {
     action: 'pin-destroyed'
   }
 }
 {
   type: 'mozContentEvent',
   detail: {
     type: 'remote-control-pin-dismissed',
     detail: {
       reason: 'timeout' / 'manually'
     }
   }
 }

Secure Connection

To protect private data between user and TV, we provide a secure connection which refers to SSL and jCryption. Here is the concept:

  1. Client requests RSA public key from TV.
  2. Client sends symmetric key and PIN code (if any) to TV, encrypted with public key.
  3. TV decrypts symmetric key with private key
  4. TV generates an UUID, encrypts with symmetric key then sends 2 UUIDs to client, one is encrypted the other is not.
  5. Client decrypts UUID with symmetric key, confirm UUID
  6. Begin remote control with symmetric key.

Goal of Remote Control is to create an easy to use way for every device, we hide public key exchange at the background. User doesn't need to input a long URL with public key nor scan QRCode. Everything is done automatically without interrupting user experience.

Remote Security.png

Bug Status

Top blockers of bug 1205939 - [TV][2.5][meta][TV side] Remote Control

Bugzilla query error

Array ( [type] => error [message] => http-bad-status [params] => Array ( [0] => 429 [1] => Unknown Error ) ) 1


Top blockers of bug 1207971 - [TV 2.5][meta] Provide a TV remote control app

Bugzilla query error

Array ( [type] => error [message] => http-bad-status [params] => Array ( [0] => 429 [1] => Unknown Error ) ) 1


Top blockers of bug 1208006 - [TV 2.5][meta] Implement a client-side page for TV remote control

Bugzilla query error

Array ( [type] => error [message] => http-bad-status [params] => Array ( [0] => 429 [1] => Unknown Error ) ) 1


Top blockers of bug 1212385 - [TV 2.5][meta] Remote Control features in Smart System

Bugzilla query error

Array ( [type] => error [message] => http-bad-status [params] => Array ( [0] => 429 [1] => Unknown Error ) ) 1


Top blockers of bug 1215457 - [TV 2.5] Secure connection between remote control server and client

Bugzilla query error

Array ( [type] => error [message] => http-bad-status [params] => Array ( [0] => 429 [1] => Unknown Error ) ) 1