GitHub PullRequestReviewCommentEvent at 2014-11-27 05:09:47
Repository: gaia
Actor: snowmantw
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/20979442","id":20979442,"diff_hunk":"@@ -0,0 +1,142 @@\n+/* exported PasscodeHelper */\n+/* globals crypto, TextEncoder */\n+(function (exports) {\n+  'use strict';\n+\n+  const SET_DIGEST_VALUE = 'lockscreen.passcode-lock.digest.value';\n+  const SET_DIGEST_SALT = 'lockscreen.passcode-lock.digest.salt';\n+  const SET_DIGEST_ITERATIONS = 'lockscreen.passcode-lock.digest.iterations';\n+  const SET_DIGEST_ALGORITHM = 'lockscreen.passcode-lock.digest.algorithm';\n+  const DEFAULT_ALGORITHM = 'SHA-1';//XXX Update to SHA-256 after bug 554827\n+  const DEFAULT_ITERATIONS = 5000;\n+\n+  var PasscodeHelper = {\n+    /*\n+     * PasscodeHelper.setPassccode(string) -> Promise => digest (or false)\n+     * PasscodeHelper.checkPasscode(string) -> Promise resolves to a boolean\n+     * */\n+\n+    _encode: function (str) {\n+      return new TextEncoder('utf-8').encode(str);\n+    },\n+    _toTypedArray: function (obj) {\n+      // SettingsAPI doesnt like arrays and gives us an Object { 1: .., 2: .. }\n+      var a = [];\n+      for (var key in obj) {\n+        a.push(obj[key]);\n+      }\n+      return new Uint8Array(a);\n+    },\n+    _deriveBits: function (pwKey, salt, iterations, algorithm) {\n+      var length = 256;\n+      var params = {\n+        name: 'PBKDF2',\n+        hash: algorithm,\n+        salt: salt,\n+        iterations: iterations\n+      };\n+      return crypto.subtle.deriveBits(params, pwKey, length);\n+    },\n+    _makeDigest: function (pass, salt, iterations, algorithm) {\n+      var bytes = this._encode(pass);\n+      return crypto.subtle.importKey('raw', bytes, 'PBKDF2', false, [\n+        'deriveBits'\n+      ]).then((pwKey) => {\n+        return this._deriveBits(pwKey, salt, iterations, algorithm);\n+      }).catch((error) => {\n+        console.error('PasscodeHelper: _derive_bits() failed!', error);\n+        return Promise.resolve(false);\n+      });\n+    },\n+    setPasscode: function (newPass) {\n+      // Always generate a new salt.\n+      var salt = crypto.getRandomValues(new Uint8Array(8));\n+      var lock = navigator.mozSettings.createLock();\n+      var getFromSettings = Promise.all([\n+        lock.get(SET_DIGEST_ITERATIONS),\n+        lock.get(SET_DIGEST_ALGORITHM)\n+      ]);\n+      var digest = getFromSettings.then((values) => {\n+        /* the combined lock.get() makes it quite ugly. we get\n+         an Array of objects, each with just one key/value,\n+         which is the requested setting. let's destruct as follows:\n+         */\n+        var iterations = parseInt(values[0][SET_DIGEST_ITERATIONS]) ||\n+          DEFAULT_ITERATIONS;\n+        var algorithm = (typeof(values[1][SET_DIGEST_ALGORITHM]) == 'string') ?\n+          values[1][SET_DIGEST_ALGORITHM] : DEFAULT_ALGORITHM;\n+\n+        return this._makeDigest(newPass, salt, iterations, algorithm)\n+          .then((digest) => {\n+            // Note: We can now store the salt, since digest was generated!\n+            var digestUint8 = new Uint8Array(digest);\n+            var lock = navigator.mozSettings.createLock();\n+            var newSettings = {};\n+            newSettings[SET_DIGEST_SALT] = salt;\n+            newSettings[SET_DIGEST_VALUE] = digestUint8;\n+            newSettings[SET_DIGEST_ITERATIONS] = iterations;\n+            newSettings[SET_DIGEST_ALGORITHM] = algorithm;\n+            return lock.set(newSettings).then(() => {\n+              return digestUint8;\n+            }).catch((error) => {\n+              console.error('PasscodeHelper: Couldnt store new digest');\n+              return Promise.resolve(false);\n+            });\n+          }).catch((error) => {\n+            console.error('PasscodeHelper: Could not make digest:', error);\n+            return Promise.resolve(false);\n+          });\n+      }).catch((error) => {\n+        console.error('PasscodeHelper: No Settings?', error);\n+        return Promise.resolve(false);\n+        });\n+      return digest;\n+    },\n+    checkPasscode: function (testPass) {\n+      //get salt & digest out of settings\n+      var lock = navigator.mozSettings.createLock();\n+      var storedParams = Promise.all([\n+        lock.get(SET_DIGEST_SALT),\n+        lock.get(SET_DIGEST_ITERATIONS),\n+        lock.get(SET_DIGEST_ALGORITHM),\n+        lock.get(SET_DIGEST_VALUE)\n+      ]);\n+      var result = storedParams.then((values) => {\n+        /* the combined lock.get() makes it quite ugly. we get\n+         an Array of objects, each with just one key/value,\n+         which is the requested setting. let's destruct as follows:\n+         */\n+        var salt = this._toTypedArray(values[0][SET_DIGEST_SALT]);\n+        var iterations = values[1][SET_DIGEST_ITERATIONS];\n+        var algorithm = values[2][SET_DIGEST_ALGORITHM];\n+        var storedDigest = this._toTypedArray(values[3][SET_DIGEST_VALUE]);\n+\n+        return this._makeDigest(testPass, salt, iterations, algorithm)","path":"shared/js/passcode_helper.js","position":114,"original_position":114,"commit_id":"e3b0a48b46d67cbfacd0e803284120ee7cc7c700","original_commit_id":"e3b0a48b46d67cbfacd0e803284120ee7cc7c700","user":{"login":"snowmantw","id":129153,"avatar_url":"https://avatars.githubusercontent.com/u/129153?v=3","gravatar_id":"","url":"https://api.github.com/users/snowmantw","html_url":"https://github.com/snowmantw","followers_url":"https://api.github.com/users/snowmantw/followers","following_url":"https://api.github.com/users/snowmantw/following{/other_user}","gists_url":"https://api.github.com/users/snowmantw/gists{/gist_id}","starred_url":"https://api.github.com/users/snowmantw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snowmantw/subscriptions","organizations_url":"https://api.github.com/users/snowmantw/orgs","repos_url":"https://api.github.com/users/snowmantw/repos","events_url":"https://api.github.com/users/snowmantw/events{/privacy}","received_events_url":"https://api.github.com/users/snowmantw/received_events","type":"User","site_admin":false},"body":"The same. Function in return statement is too large.","created_at":"2014-11-27T05:09:47Z","updated_at":"2014-11-27T05:09:47Z","html_url":"https://github.com/mozilla-b2g/gaia/pull/26301#discussion_r20979442","pull_request_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/26301","_links":{"self":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/20979442"},"html":{"href":"https://github.com/mozilla-b2g/gaia/pull/26301#discussion_r20979442"},"pull_request":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/26301"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/26301","id":24699445,"html_url":"https://github.com/mozilla-b2g/gaia/pull/26301","diff_url":"https://github.com/mozilla-b2g/gaia/pull/26301.diff","patch_url":"https://github.com/mozilla-b2g/gaia/pull/26301.patch","issue_url":"https://api.github.com/repos/mozilla-b2g/gaia/issues/26301","number":26301,"state":"open","locked":false,"title":"Bug 1100945: adding a PasscodeHelper","user":{"login":"mozfreddyb","id":5418775,"avatar_url":"https://avatars.githubusercontent.com/u/5418775?v=3","gravatar_id":"","url":"https://api.github.com/users/mozfreddyb","html_url":"https://github.com/mozfreddyb","followers_url":"https://api.github.com/users/mozfreddyb/followers","following_url":"https://api.github.com/users/mozfreddyb/following{/other_user}","gists_url":"https://api.github.com/users/mozfreddyb/gists{/gist_id}","starred_url":"https://api.github.com/users/mozfreddyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozfreddyb/subscriptions","organizations_url":"https://api.github.com/users/mozfreddyb/orgs","repos_url":"https://api.github.com/users/mozfreddyb/repos","events_url":"https://api.github.com/users/mozfreddyb/events{/privacy}","received_events_url":"https://api.github.com/users/mozfreddyb/received_events","type":"User","site_admin":false},"body":"This should do as an initial draft.\r\nLooking forward to any kinds of feedback, especially lines 70-73 and 88-100. :)","created_at":"2014-11-19T16:12:42Z","updated_at":"2014-11-27T05:09:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"327d51350bda473064a1352a737bfa1d9558a3a0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/26301/commits","review_comments_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/26301/comments","review_comment_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/{number}","comments_url":"https://api.github.com/repos/mozilla-b2g/gaia/issues/26301/comments","statuses_url":"https://api.github.com/repos/mozilla-b2g/gaia/statuses/e3b0a48b46d67cbfacd0e803284120ee7cc7c700","head":{"label":"mozfreddyb:origin-mozfreddyb/bug-1100945-passcodehelper","ref":"origin-mozfreddyb/bug-1100945-passcodehelper","sha":"e3b0a48b46d67cbfacd0e803284120ee7cc7c700","user":{"login":"mozfreddyb","id":5418775,"avatar_url":"https://avatars.githubusercontent.com/u/5418775?v=3","gravatar_id":"","url":"https://api.github.com/users/mozfreddyb","html_url":"https://github.com/mozfreddyb","followers_url":"https://api.github.com/users/mozfreddyb/followers","following_url":"https://api.github.com/users/mozfreddyb/following{/other_user}","gists_url":"https://api.github.com/users/mozfreddyb/gists{/gist_id}","starred_url":"https://api.github.com/users/mozfreddyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozfreddyb/subscriptions","organizations_url":"https://api.github.com/users/mozfreddyb/orgs","repos_url":"https://api.github.com/users/mozfreddyb/repos","events_url":"https://api.github.com/users/mozfreddyb/events{/privacy}","received_events_url":"https://api.github.com/users/mozfreddyb/received_events","type":"User","site_admin":false},"repo":{"id":12944840,"name":"gaia","full_name":"mozfreddyb/gaia","owner":{"login":"mozfreddyb","id":5418775,"avatar_url":"https://avatars.githubusercontent.com/u/5418775?v=3","gravatar_id":"","url":"https://api.github.com/users/mozfreddyb","html_url":"https://github.com/mozfreddyb","followers_url":"https://api.github.com/users/mozfreddyb/followers","following_url":"https://api.github.com/users/mozfreddyb/following{/other_user}","gists_url":"https://api.github.com/users/mozfreddyb/gists{/gist_id}","starred_url":"https://api.github.com/users/mozfreddyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozfreddyb/subscriptions","organizations_url":"https://api.github.com/users/mozfreddyb/orgs","repos_url":"https://api.github.com/users/mozfreddyb/repos","events_url":"https://api.github.com/users/mozfreddyb/events{/privacy}","received_events_url":"https://api.github.com/users/mozfreddyb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mozfreddyb/gaia","description":"Gaia is a HTML5-based Phone UI for the Boot 2 Gecko Project. NOTE: For details of what branches are used for what releases, see https://wiki.mozilla.org/Release_Management/B2G_Landing","fork":true,"url":"https://api.github.com/repos/mozfreddyb/gaia","forks_url":"https://api.github.com/repos/mozfreddyb/gaia/forks","keys_url":"https://api.github.com/repos/mozfreddyb/gaia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozfreddyb/gaia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozfreddyb/gaia/teams","hooks_url":"https://api.github.com/repos/mozfreddyb/gaia/hooks","issue_events_url":"https://api.github.com/repos/mozfreddyb/gaia/issues/events{/number}","events_url":"https://api.github.com/repos/mozfreddyb/gaia/events","assignees_url":"https://api.github.com/repos/mozfreddyb/gaia/assignees{/user}","branches_url":"https://api.github.com/repos/mozfreddyb/gaia/branches{/branch}","tags_url":"https://api.github.com/repos/mozfreddyb/gaia/tags","blobs_url":"https://api.github.com/repos/mozfreddyb/gaia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozfreddyb/gaia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozfreddyb/gaia/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozfreddyb/gaia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozfreddyb/gaia/statuses/{sha}","languages_url":"https://api.github.com/repos/mozfreddyb/gaia/languages","stargazers_url":"https://api.github.com/repos/mozfreddyb/gaia/stargazers","contributors_url":"https://api.github.com/repos/mozfreddyb/gaia/contributors","subscribers_url":"https://api.github.com/repos/mozfreddyb/gaia/subscribers","subscription_url":"https://api.github.com/repos/mozfreddyb/gaia/subscription","commits_url":"https://api.github.com/repos/mozfreddyb/gaia/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozfreddyb/gaia/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozfreddyb/gaia/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozfreddyb/gaia/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozfreddyb/gaia/contents/{+path}","compare_url":"https://api.github.com/repos/mozfreddyb/gaia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozfreddyb/gaia/merges","archive_url":"https://api.github.com/repos/mozfreddyb/gaia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozfreddyb/gaia/downloads","issues_url":"https://api.github.com/repos/mozfreddyb/gaia/issues{/number}","pulls_url":"https://api.github.com/repos/mozfreddyb/gaia/pulls{/number}","milestones_url":"https://api.github.com/repos/mozfreddyb/gaia/milestones{/number}","notifications_url":"https://api.github.com/repos/mozfreddyb/gaia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozfreddyb/gaia/labels{/name}","releases_url":"https://api.github.com/repos/mozfreddyb/gaia/releases{/id}","created_at":"2013-09-19T09:15:44Z","updated_at":"2014-08-04T08:54:43Z","pushed_at":"2014-11-26T11:28:59Z","git_url":"git://github.com/mozfreddyb/gaia.git","ssh_url":"git@github.com:mozfreddyb/gaia.git","clone_url":"https://github.com/mozfreddyb/gaia.git","svn_url":"https://github.com/mozfreddyb/gaia","homepage":"https://wiki.mozilla.org/B2G","size":847101,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla-b2g:master","ref":"master","sha":"64704b265db4f8f16c72102fdff4c6b70d7f4292","user":{"login":"mozilla-b2g","id":1261292,"avatar_url":"https://avatars.githubusercontent.com/u/1261292?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-b2g","html_url":"https://github.com/mozilla-b2g","followers_url":"https://api.github.com/users/mozilla-b2g/followers","following_url":"https://api.github.com/users/mozilla-b2g/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-b2g/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-b2g/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-b2g/subscriptions","organizations_url":"https://api.github.com/users/mozilla-b2g/orgs","repos_url":"https://api.github.com/users/mozilla-b2g/repos","events_url":"https://api.github.com/users/mozilla-b2g/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-b2g/received_events","type":"Organization","site_admin":false},"repo":{"id":2317369,"name":"gaia","full_name":"mozilla-b2g/gaia","owner":{"login":"mozilla-b2g","id":1261292,"avatar_url":"https://avatars.githubusercontent.com/u/1261292?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-b2g","html_url":"https://github.com/mozilla-b2g","followers_url":"https://api.github.com/users/mozilla-b2g/followers","following_url":"https://api.github.com/users/mozilla-b2g/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-b2g/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-b2g/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-b2g/subscriptions","organizations_url":"https://api.github.com/users/mozilla-b2g/orgs","repos_url":"https://api.github.com/users/mozilla-b2g/repos","events_url":"https://api.github.com/users/mozilla-b2g/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-b2g/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-b2g/gaia","description":"Gaia is a HTML5-based Phone UI for the Boot 2 Gecko Project. NOTE: For details of what branches are used for what releases, see","fork":false,"url":"https://api.github.com/repos/mozilla-b2g/gaia","forks_url":"https://api.github.com/repos/mozilla-b2g/gaia/forks","keys_url":"https://api.github.com/repos/mozilla-b2g/gaia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-b2g/gaia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-b2g/gaia/teams","hooks_url":"https://api.github.com/repos/mozilla-b2g/gaia/hooks","issue_events_url":"https://api.github.com/repos/mozilla-b2g/gaia/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-b2g/gaia/events","assignees_url":"https://api.github.com/repos/mozilla-b2g/gaia/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-b2g/gaia/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-b2g/gaia/tags","blobs_url":"https://api.github.com/repos/mozilla-b2g/gaia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-b2g/gaia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-b2g/gaia/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-b2g/gaia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-b2g/gaia/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-b2g/gaia/languages","stargazers_url":"https://api.github.com/repos/mozilla-b2g/gaia/stargazers","contributors_url":"https://api.github.com/repos/mozilla-b2g/gaia/contributors","subscribers_url":"https://api.github.com/repos/mozilla-b2g/gaia/subscribers","subscription_url":"https://api.github.com/repos/mozilla-b2g/gaia/subscription","commits_url":"https://api.github.com/repos/mozilla-b2g/gaia/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-b2g/gaia/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-b2g/gaia/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-b2g/gaia/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla-b2g/gaia/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-b2g/gaia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-b2g/gaia/merges","archive_url":"https://api.github.com/repos/mozilla-b2g/gaia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-b2g/gaia/downloads","issues_url":"https://api.github.com/repos/mozilla-b2g/gaia/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-b2g/gaia/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-b2g/gaia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-b2g/gaia/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-b2g/gaia/releases{/id}","created_at":"2011-09-03T01:38:46Z","updated_at":"2014-11-27T03:26:24Z","pushed_at":"2014-11-27T03:26:23Z","git_url":"git://github.com/mozilla-b2g/gaia.git","ssh_url":"git@github.com:mozilla-b2g/gaia.git","clone_url":"https://github.com/mozilla-b2g/gaia.git","svn_url":"https://github.com/mozilla-b2g/gaia","homepage":"https://wiki.mozilla.org/B2G","size":1554122,"stargazers_count":1815,"watchers_count":1815,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2081,"mirror_url":null,"open_issues_count":710,"forks":2081,"open_issues":710,"watchers":1815,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/26301"},"html":{"href":"https://github.com/mozilla-b2g/gaia/pull/26301"},"issue":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/issues/26301"},"comments":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/issues/26301/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/26301/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/26301/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/statuses/e3b0a48b46d67cbfacd0e803284120ee7cc7c700"}}}}