{"action":"opened","issue":{"url":"https://api.github.com/repos/mozilla/fxa-js-client/issues/286","repository_url":"https://api.github.com/repos/mozilla/fxa-js-client","labels_url":"https://api.github.com/repos/mozilla/fxa-js-client/issues/286/labels{/name}","comments_url":"https://api.github.com/repos/mozilla/fxa-js-client/issues/286/comments","events_url":"https://api.github.com/repos/mozilla/fxa-js-client/issues/286/events","html_url":"https://github.com/mozilla/fxa-js-client/issues/286","id":377370226,"node_id":"MDU6SXNzdWUzNzczNzAyMjY=","number":286,"title":"Replace sjcl w/ node-jose","user":{"login":"shane-tomlinson","id":848085,"node_id":"MDQ6VXNlcjg0ODA4NQ==","avatar_url":"https://avatars3.githubusercontent.com/u/848085?v=4","gravatar_id":"","url":"https://api.github.com/users/shane-tomlinson","html_url":"https://github.com/shane-tomlinson","followers_url":"https://api.github.com/users/shane-tomlinson/followers","following_url":"https://api.github.com/users/shane-tomlinson/following{/other_user}","gists_url":"https://api.github.com/users/shane-tomlinson/gists{/gist_id}","starred_url":"https://api.github.com/users/shane-tomlinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shane-tomlinson/subscriptions","organizations_url":"https://api.github.com/users/shane-tomlinson/orgs","repos_url":"https://api.github.com/users/shane-tomlinson/repos","events_url":"https://api.github.com/users/shane-tomlinson/events{/privacy}","received_events_url":"https://api.github.com/users/shane-tomlinson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-05T12:02:01Z","updated_at":"2018-11-05T12:02:01Z","closed_at":null,"author_association":"MEMBER","body":"We use node-jose within the content-server, using it here would provide a couple of advantages:\r\n\r\n1. node-jose delegates to a browser's native WebCrypto functionality if available whereas sjcl does everything in JS. Operations done in natively by WebCrypto are ~ 2x as fast as operations done in JS.\r\n2. We could use 1 shared copy of an underlying crypto library resulting in a smaller download.\r\n\r\nThe underlying push is we are considering [increasing the number of rounds of PBKDF2](https://bugzilla.mozilla.org/show_bug.cgi?id=1320222) run on the user's pw before sending the hash to the backend. On older mobile devices 100k rounds of PBKDF2 can take a long time using sjcl, ~8 seconds on a Moto G4 Play. Cutting that in half would make the experience a lot more acceptable.\r\n\r\nI think all of the functionality we use in sjcl has an equivalent in node-jose:\r\n\r\n* [sjcl.codec.hex.fromBits(bits)](https://github.com/mozilla/fxa-js-client/blob/6b7c4ca065b704763e824a1beb1cd15e85270249/client/FxAccountClient.js#L709) - I believe we could use `Buffer.from(bits).toString('hex')`\r\n* [sjcl.codec.utf8String.toBits(string)](https://github.com/mozilla/fxa-js-client/blob/6b7c4ca065b704763e824a1beb1cd15e85270249/client/lib/credentials.js#L24) - `Buffer.from(string, 'utf8')`\r\n* [sjcl.misc.hmac(keys.hmacKey, sjcl.hash.sha256)](https://github.com/mozilla/fxa-js-client/blob/6b7c4ca065b704763e824a1beb1cd15e85270249/client/lib/credentials.js#L115) - [jose.JWA.sign('HS256', key, msg)](https://github.com/cisco/node-jose/blob/master/test/algorithms/hmac-test.js#L42)\r\n* [hkdf could be done by node-jose](https://github.com/cisco/node-jose/blob/master/test/algorithms/hkdf-test.js#L16)\r\n* [sjcl.misc.pbkdf2](https://github.com/mozilla/fxa-js-client/blob/6b7c4ca065b704763e824a1beb1cd15e85270249/client/lib/pbkdf2.js#L19) by [jose.JWA.derive('PBKDF2-SHA-256', key, props)](https://github.com/cisco/node-jose/blob/master/test/algorithms/pbes2-test.js#L17)\r\n\r\nThere are a few other low level bit operations (bitSlice, xor, concat) that seem like we should be able to take care of ourselves."}}
{"actor":{"display_login":"shane-tomlinson"}}