133
edits
(→Establish secure connection: Add source link) |
(→Architecture Designs: add disconnect and reconnection description) |
||
| (26 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
== Introduction == | == Introduction == | ||
Remote control is a | Remote control is a feature for Firefox OS on TV. After [https://addons.mozilla.org/en-US/android/addon/send-tab-to-tv/ Send tab to TV], user can easily extend browsing experience on TV via Firefox on Android, using virtual touchpad to control TV. | ||
Meta Bug: {{Bug|1205939}} | Meta Bug: {{Bug|1205939}} | ||
| Line 17: | Line 17: | ||
* [[Firefox_OS/Remote_Control_Service|Remote Control Service]]: Entry point of remote control feature. Control service related logic and data in runtime. | * [[Firefox_OS/Remote_Control_Service|Remote Control Service]]: Entry point of remote control feature. Control service related logic and data in runtime. | ||
* | * TLS server: Serves connections from user. | ||
User interaction of remote control is divided into | User interaction of remote control is divided into two parts: | ||
# | # Peer authentication | ||
# Control event processing | # Control event processing | ||
Any error occurs will close connection between server and client, reconnection is required. Server side error will sends message back to client to let user know what happen on Fennec. | |||
[ | === Peer authentication === | ||
Remote control is designed to protect data transmitted between client and server, for example: user input string may contains privacy data. The connection is based on self-signed TLS server. To prevent man in the middle(MITM) attack, we adopt [https://en.wikipedia.org/wiki/Password_Authenticated_Key_Exchange_by_Juggling J-PAKE] to exchange symmetric key for peer authentication. Following describes how it works: | |||
[[File:RemoteControl_FirstTimeHandshake.png]] | |||
# The user sends the tab to TV on fennec. | |||
# Client sends request to handshake without ID. | |||
# Server replies with the handshake type is 1st time handshake. | |||
# Client computes J-PAKE round 1 and sends the result to server. | |||
# Server generates PIN code and show on screen, computes J-PAKE round 1 and sends the result to client. | |||
# User enter PIN code, client computs J-PAKE round 2 with PIN code attached first 12 characters of server's TLS certificate fingerprint as weak secret. | |||
# Client sends round 2 result to server. | |||
# Server computes J-PAKE round 2 with PIN code attached first 12 characters of server's TLS certificate fingerprint as weak secret. | |||
# Server dismisses PIN code notification on screen, sends round 2 result to client. | |||
# Both client and server compute J-PAKE final round, gets AES and HMAC key. | |||
# Server use two keys to get a signature of H(H(AES key)), then send the signature to client. | |||
# Client verifies the signature matches it has. | |||
# Client use two keys to get a signature of H(AES key), then send the signature to server. | |||
# Server verifies the signature matches it has. | |||
# Server replies with the handshake finish with client's ID for connection in the future. | |||
==== Re-authentication ==== | |||
User is only required to input PIN code when first time connect to TV. In the second time, client and server leverage previous AES key value and derive new AES and HMAC key. This can reduce number of user input and make the procedure from send tab to TV to remote control more smoothly. | |||
[[File:RemoteControl SecondTimeHandshake.png]] | |||
# The user sends the tab to TV on fennec. | |||
# Client sends request to handshake with ID. | |||
# Server looks up ID/AES key mapping and replies with the handshake type is 2nd time handshake. | |||
# Client computes J-PAKE round 1 and sends the result to server. | |||
# Server computes J-PAKE round 1 and sends the result to client. | |||
# Client and server computes J-PAKE round 2 with first 4 characters of previous AES key value attached first 12 characters of server's TLS certificate fingerprint as weak secret. | |||
# Client sends round 2 result to server. | |||
# Server sends round 2 result to client. | |||
# Both client and server compute J-PAKE final round, gets new AES and HMAC key. | |||
# Server use two keys to get a signature of H(H(AES key)), then send the signature to client. | |||
# Client verifies the signature matches it has. | |||
# Client use two keys to get a signature of H(AES key), then send the signature to server. | |||
# Server verifies the signature matches it has. | |||
# Server replies with the handshake finish. | |||
After authentication, client can sends control event to server. | |||
=== Control event processing === | === Control event processing === | ||
Control page provides: 1) a virtual touchpad, 2) a virtual vertical scrollbar, 3) 3 function keys. Every touch, swipe or click will be generated to an event in JSON format | Control page provides: 1) a virtual touchpad, 2) a virtual vertical scrollbar, 3) 3 function keys. Every touch, swipe or click will be generated to an event in JSON format then send to TV. Following describes how control event is sent and processed: | ||
[[File:RemoteControl ControlEventProcessing.png]] | [[File:RemoteControl ControlEventProcessing.png]] | ||
# User operates control page. | # User operates control page. | ||
# Client generates | # Client generates and sends the event in JSON format. | ||
# | # Server parses the event to JSON object, dispatch to client.sjs. | ||
# Client.sjs parses event and dispatch to Gecko or Gaia system app. | # Client.sjs parses event and dispatch to Gecko or Gaia system app. | ||
=== Data | === Data used in JPAKE authentication === | ||
==== Singer ID for JPAKE round 1 & 2: ==== | |||
* TV: server | |||
* Fennec addon: client | |||
==== Weak secret: ==== | |||
* TV: concatenate PIN and first 12 characters of TLS server cert SHA 256 fingerprint | |||
* Fennec addon: concatenate user input PIN and first 12 characters connected TLS server cert SHA 256 fingerprint | |||
==== HMAC Input for JAPKE final: ==== | |||
We use "AES_256_CBC-HMAC256", as aHkdfInfo, includes the full crypto spec, should be the same in both TV and fennec addon | |||
==== Key confirmation: ==== | |||
Double hash of AES key: | |||
# AES | ## TV converts AES key to array buffer | ||
# | ## Sign AES key array buffer, get signature 1 (array buffer) | ||
# | ## Sign signature 1, get signature 2 | ||
## Convert signature 2 to base 64, send to Fennec addon | |||
## Fennec addon do the same as TV from step 1 to 4 | |||
## Compare received base 64 string of self and TV's signature 2 | |||
=== | Single hash of AES key: | ||
==== | ## Fennec addon converts AES key to array buffer | ||
## Sign AES key array buffer, get signature 1 (array buffer) | |||
## Convert signature 1 to base 64, send to TV | |||
## TV use HMAC key, received signature, AES key array buffer to verify if the signature is valid. | |||
=== Authentication and Event Protocol === | |||
==== Request handshake ==== | |||
Request | Request | ||
{ | { | ||
action: ' | type: 'auth' | ||
action: 'request_handshake' | |||
detail: { | |||
id: <id assigned by server, optional> | |||
} | |||
} | } | ||
Response | Response | ||
{ | { | ||
type: 'auth' | |||
action: 'response_handshake' | |||
detail: 1 or 2, 1 for 1st handshake, 2 for 2nd handshake | |||
} | } | ||
==== J-PAKE key exchange ==== | |||
Client send round 1 | |||
{ | { | ||
type: 'auth' | |||
action: 'jpake_client_1', | |||
detail: { | |||
gx1: gx1.value, | |||
gx2: gx2.value, | |||
zkp_x1: { gr: gv1.value, b: r1.value, id: 'client' }, | |||
zkp_x2: { gr: gv2.value, b: r2.value, id: 'client' } | |||
} | |||
} | } | ||
Server reply round 1 | |||
{ | { | ||
action: ' | type: 'auth' | ||
action: 'jpake_server_1', | |||
detail: { | |||
gx1: gx1.value, | |||
gx2: gx2.value, | |||
zkp_x1: { gr: gv1.value, b: r1.value, id: 'server' }, | |||
zkp_x2: { gr: gv2.value, b: r2.value, id: 'server' } | |||
} | |||
} | } | ||
Client send round 2 | |||
{ | { | ||
type: 'auth' | |||
action: 'jpake_client_2', | |||
detail: { | |||
A: A.value, | |||
zkp_A: { gr: gvA.value, b: rA.value, id: 'client' } | |||
} | |||
} | } | ||
Server reply round 2 | |||
{ | { | ||
type: 'auth' | |||
action: 'jpake_server_2', | |||
detail: { | |||
A: A.value, | |||
zkp_A: { gr: gvA.value, b: rA.value, id: 'server' } | |||
} | |||
} | } | ||
==== | |||
==== Key confirmation ==== | |||
Server key confirmation | |||
{ | { | ||
action: ' | type: 'auth' | ||
action: 'server_key_confirm' | |||
detail: { | |||
signature: <double signature of AES key by HMAC key, in base64> | |||
} | |||
} | } | ||
Client key confirmation | |||
{ | { | ||
type: 'auth' | |||
action: 'client_key_confirmation' | |||
detail: { | |||
signature: <signature of AES key by HMAC key, in base64> | |||
} | |||
} | } | ||
Server finish handshake | |||
{ | { | ||
type: 'auth' | |||
action: 'finish_handshake' | |||
detail: { | |||
id: <id assigned by server, optional> | |||
} | |||
action: ' | |||
} | } | ||
==== Touch Events ==== | ==== Touch Events ==== | ||
{ | { | ||
type: 'touchstart', | type: 'command' | ||
action: 'touchstart', | |||
detail: { | detail: { | ||
width: <touch panel width, integer, in pixels>, | width: <touch panel width, integer, in pixels>, | ||
| Line 185: | Line 204: | ||
{ | { | ||
type: 'touchmove', | type: 'command' | ||
action: 'touchmove', | |||
detail: { | detail: { | ||
dx: <dx between current point and starting point, integer, in pixels>, | dx: <dx between current point and starting point, integer, in pixels>, | ||
| Line 195: | Line 215: | ||
{ | { | ||
type: 'touchend', | type: 'command' | ||
action: 'touchend', | |||
detail: { | detail: { | ||
dx: <same as "touchmove">, | dx: <same as "touchmove">, | ||
| Line 212: | Line 233: | ||
{ | { | ||
type: 'keypress', | type: 'command' | ||
action: 'keypress', | |||
detail: <KeyEvent constant, string, sush as "DOM_VK_RETURN"> | detail: <KeyEvent constant, string, sush as "DOM_VK_RETURN"> | ||
} | } | ||
| Line 219: | Line 241: | ||
{ | { | ||
type: ' | type: 'command' | ||
action: 'textinput', | |||
detail: { | detail: { | ||
clear: <whether to clear the entire string in the current focused input field, boolean>, | clear: <whether to clear the entire string in the current focused input field, boolean>, | ||
| Line 227: | Line 250: | ||
} | } | ||
==== | ==== Server reply error ==== | ||
{ | { | ||
type: | type: common, or the event type sent from client | ||
error: <error message of exception or root cause> | |||
} | } | ||
== Bug Status == | == Bug Status == | ||
edits