From fea659d2e1adc7f52615e824636ccea6a84c660f Mon Sep 17 00:00:00 2001 From: Ryan Kelly Date: Fri, 18 Jan 2019 12:12:29 +1100 Subject: [PATCH] Add initial TLS1.3 PSK-mode implementation. --- .circleci/config.yml | 5 +- .gitignore | 3 + README.md | 22 +- demo/test_client.html | 6 +- demo/test_server.html | 7 +- dist/FxAccountsPairingChannel.babel.umd.js | 6067 +++++++++++++++++++- dist/FxAccountsPairingChannel.js | 2547 +++++++- package-lock.json | 2386 +++++--- package.json | 8 +- src/alerts.js | 76 + src/constants.js | 9 + src/crypto.js | 119 + src/extensions.js | 266 + src/index.js | 126 +- src/keyschedule.js | 133 + src/messages.js | 399 ++ src/recordlayer.js | 346 ++ src/rot128.js | 124 - src/states.js | 418 ++ src/tlsconnection.js | 253 + src/utils.js | 357 +- test/.eslintrc.yml | 28 +- test/FxAccountsPairingChannel.js | 126 +- test/helpers.js | 265 + test/karma.conf.js | 10 +- test/keyschedule.js | 124 + test/misc.js | 27 + test/recordlayer.js | 396 ++ test/tlsconnection.js | 1542 +++++ test/utils.js | 475 ++ test/vectors/generate_test_vectors.py | 374 ++ test/vectors/test_vectors.js | 114 + webpack.config.js | 64 +- 33 files changed, 15820 insertions(+), 1402 deletions(-) create mode 100644 src/alerts.js create mode 100644 src/constants.js create mode 100644 src/crypto.js create mode 100644 src/extensions.js create mode 100644 src/keyschedule.js create mode 100644 src/messages.js create mode 100644 src/recordlayer.js delete mode 100644 src/rot128.js create mode 100644 src/states.js create mode 100644 src/tlsconnection.js create mode 100644 test/helpers.js create mode 100644 test/keyschedule.js create mode 100644 test/misc.js create mode 100644 test/recordlayer.js create mode 100644 test/tlsconnection.js create mode 100644 test/utils.js create mode 100644 test/vectors/generate_test_vectors.py create mode 100644 test/vectors/test_vectors.js diff --git a/.circleci/config.yml b/.circleci/config.yml index ad2a52c..afeb7e0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,9 +18,12 @@ jobs: shell: /bin/bash --login command: | sudo npm install -g npm@6 - npm install + npm ci DISPLAY=:99 FIREFOX_BIN=./firefox/firefox-bin npm test + - store_artifacts: + path: ./coverage/ + - run: npm run lint workflows: version: 2 diff --git a/.gitignore b/.gitignore index ad46b30..84ffd6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Build with coverage info enabled. +dist/FxAccountsPairingChannel.babel.umd.coverage.js + # Logs logs *.log diff --git a/README.md b/README.md index fa48b22..7e28cce 100644 --- a/README.md +++ b/README.md @@ -8,19 +8,15 @@ It will be used by the Firefox Accounts pairing flow, with one side of the channel being web content from https://accounts.firefox.com and the other side of the channel being a signed-in Firefox instance. -The connection will *eventually* be secured using a pre-shared key -and TLS1.3, but that code is still in progress. To parallelize -client development we've published an initial version with a -correctly-shapred API but no meaningful security. API === -The main abstraction is the `InsecurePairingChannel` class. +The main abstraction is the `PairingChannel` class. One side of the connection can create a new channel like this: ``` -const channel = await InsecurePairingChannel.create(CHANNEL_SERVER_URL); +const channel = await PairingChannel.create(CHANNEL_SERVER_URL); console.log(channel.channelId, channel.channelKey); ``` @@ -29,7 +25,7 @@ the intended client, perhaps by scanning a QR code. It can then connect to the channel like this: ``` -const channel = await InsecurePairingChannel.connect(CHANNEL_SERVER_URL, channelId, channelKey); +const channel = await PairingChannel.connect(CHANNEL_SERVER_URL, channelId, channelKey); ``` Both ends of the channel can then send and receive messages using a websocket-like @@ -46,4 +42,14 @@ channel.addEventListener("message", event => { You can try out a more complete demo of this API by loading `./demo/test_client.html` and `./demo/test_server.html` in -parallel webpages and watching them pass messages back and forth. \ No newline at end of file +parallel webpages and watching them pass messages back and forth. + + +Crypto +====== + +Under the hood, the `PairingChannel` implements the "externally-provisioned +pre-shared key" mode of [TLS1.3](https://tools.ietf.org/html/rfc8446). +Each side of the channel can thus be assured that its peer is in posession +of the `channelKey`, and that their traffic is protected from anyone who +does not possess this key. diff --git a/demo/test_client.html b/demo/test_client.html index 8030ee6..e22330c 100644 --- a/demo/test_client.html +++ b/demo/test_client.html @@ -22,15 +22,15 @@

fxa-pairing-tls demo client