diff --git a/lib/bcrypt-compute.js b/lib/bcrypt-compute.js index a3bcec32e33252f1864598190b66bf8cfe9380bb..24f64de6170d5be319aaf1afb70989da1b408ae2 100644 --- a/lib/bcrypt-compute.js +++ b/lib/bcrypt-compute.js @@ -6,10 +6,10 @@ const bcrypt = require('bcrypt'); process.on('message', function(m) { if (m.op === 'encrypt') { - var r = bcrypt.encrypt_sync(m.pass, bcrypt.gen_salt_sync(m.factor)); + var r = bcrypt.hashSync(m.pass, bcrypt.genSaltSync(m.factor)); process.send({r:r}); } else if (m.op === 'compare') { - var r = bcrypt.compare_sync(m.pass, m.hash); + var r = bcrypt.compareSync(m.pass, m.hash); process.send({r:r}); } }); diff --git a/lib/bcrypt.js b/lib/bcrypt.js index d3ee871cfb9aa06c47b7f36ad3fa14cea607e1ca..e78b846c7b405a92dcaa5ad4eb407eb2f17d0116 100644 --- a/lib/bcrypt.js +++ b/lib/bcrypt.js @@ -46,8 +46,8 @@ exports.compare = function(pass, hash, cb) { }) }; -exports.get_rounds = function(hash) { - return bcrypt.get_rounds(hash); +exports.getRounds = function(hash) { + return bcrypt.getRounds(hash); }; exports.shutdown = function() { diff --git a/lib/wsapi/authenticate_user.js b/lib/wsapi/authenticate_user.js index 6c0d21db8c3e99a115d6874d1c9d2871a6c8c727..97ee9f325a5035cbf21be6eda320e6c478697109 100644 --- a/lib/wsapi/authenticate_user.js +++ b/lib/wsapi/authenticate_user.js @@ -72,7 +72,7 @@ exports.process = function(req, res) { // if the work factor has changed, update the hash here. issue #204 // NOTE: this runs asynchronously and will not delay the response - if (config.get('bcrypt_work_factor') != bcrypt.get_rounds(hash)) { + if (config.get('bcrypt_work_factor') != bcrypt.getRounds(hash)) { logger.info("updating bcrypted password for user " + uid); // this request must be forwarded to dbwriter, and we'll use the @@ -104,7 +104,7 @@ exports.process = function(req, res) { } else { logger.info("bcrypt rounds of password for " + uid + " successfully updated (from " + - bcrypt.get_rounds(hash) + " to " + bcrypt.getRounds(hash) + " to " + config.get('bcrypt_work_factor') + ")"); } }); diff --git a/package.json b/package.json index 0f0506dae2542e3c56889a321c9be41395a2adc1..82327586b043930903d40e55d5e0d17f6e25c564 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "dependencies": { "JSONSelect": "0.4.0", - "bcrypt": "0.4.1", + "bcrypt": "0.7.1", "compute-cluster": "0.0.6", "connect": "1.7.2", "convict": "0.0.6", diff --git a/tests/bcrypt-compatibility-test.js b/tests/bcrypt-compatibility-test.js new file mode 100644 index 0000000000000000000000000000000000000000..415e56cabaa6e1bfe4ba4f6cd5e418ea8ee275be --- /dev/null +++ b/tests/bcrypt-compatibility-test.js @@ -0,0 +1,34 @@ +#!/usr/bin/env node + +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +require('./lib/test_env.js'); + +const assert = +require('assert'), +vows = require('vows'), +config = require('../lib/configuration.js'), +bcrypt = require('bcrypt'); + +var suite = vows.describe('bcrypt-compatibility'); + +suite.addBatch({ + "new bcrypt of password for given salt": { + topic: function () { + var salt = "$2a$04$rakQlaS/TyfjZmoVuRs9ku"; + bcrypt.hash("Thisismypassword1!", salt, this.callback); + }, + "should match old bcrypt": function (hash) { + assert.strictEqual(hash, '$2a$04$rakQlaS/TyfjZmoVuRs9kuQHFk2oShl8DNmVbxgSZyOE8Hzgk0One'); + } + }, + "get rounds of old hash should match new bcrypt": function () { + var hash = '$2a$04$rakQlaS/TyfjZmoVuRs9kuQHFk2oShl8DNmVbxgSZyOE8Hzgk0One'; + assert.strictEqual(4, bcrypt.getRounds(hash)); + } +}); + +if (process.argv[1] === __filename) suite.run(); +else suite.export(module); diff --git a/tests/heartbeat-test.js b/tests/heartbeat-test.js index 6dd5341b4b586f303cc43069fdfbb5046ff8a311..303046d0043034e19696476c7bedd0485bad77b4 100755 --- a/tests/heartbeat-test.js +++ b/tests/heartbeat-test.js @@ -13,7 +13,6 @@ start_stop = require('./lib/start-stop.js'), wsapi = require('./lib/wsapi.js'), db = require('../lib/db.js'), config = require('../lib/configuration.js'), -bcrypt = require('bcrypt'), http = require('http'); var suite = vows.describe('heartbeat'); @@ -58,7 +57,7 @@ start_stop.addStartupBatches(suite); suite.addBatch({ "stopping the browserid process": { topic: function() { - process.kill(parseInt(process.env['BROWSERID_PID'], 10), 'SIGSTOP'); + process.kill(parseInt(process.env['BROWSERID_PID'], 10), 'SIGSTOP'); this.callback(); }, "then doing a deep __heartbeat__ on router": { @@ -88,7 +87,7 @@ suite.addBatch({ }, "but upon SIGCONT": { topic: function(e, code) { - process.kill(parseInt(process.env['BROWSERID_PID'], 10), 'SIGCONT'); + process.kill(parseInt(process.env['BROWSERID_PID'], 10), 'SIGCONT'); this.callback(); }, "a deep heartbeat": { @@ -119,7 +118,7 @@ suite.addBatch({ suite.addBatch({ "stopping the static process": { topic: function() { - process.kill(parseInt(process.env['STATIC_PID'], 10), 'SIGSTOP'); + process.kill(parseInt(process.env['STATIC_PID'], 10), 'SIGSTOP'); this.callback(); }, "then doing a deep __heartbeat__ on router": { @@ -149,7 +148,7 @@ suite.addBatch({ }, "but upon SIGCONT": { topic: function(e, code) { - process.kill(parseInt(process.env['STATIC_PID'], 10), 'SIGCONT'); + process.kill(parseInt(process.env['STATIC_PID'], 10), 'SIGCONT'); this.callback(); }, "a deep heartbeat": { diff --git a/tests/password-bcrypt-update-test.js b/tests/password-bcrypt-update-test.js index 033e9109f29269645e38ae45e1c3476881c14616..49a8e60846417dc2a6771856c5ff77f9f6d3ab86 100755 --- a/tests/password-bcrypt-update-test.js +++ b/tests/password-bcrypt-update-test.js @@ -94,7 +94,7 @@ suite.addBatch({ "is bcrypted with the expected number of rounds": function(err, r) { assert.isNull(err); assert.equal(typeof r, 'string'); - assert.equal(config.get('bcrypt_work_factor'), bcrypt.get_rounds(r)); + assert.equal(config.get('bcrypt_work_factor'), bcrypt.getRounds(r)); } } }); @@ -143,7 +143,7 @@ suite.addBatch({ "its bcrypted with 8 rounds": function(err, r) { assert.isNull(err); assert.equal(typeof r, 'string'); - assert.equal(8, bcrypt.get_rounds(r)); + assert.equal(8, bcrypt.getRounds(r)); } } } diff --git a/tests/password-update-test.js b/tests/password-update-test.js index 98ca7384226b05d41c59f7f245209544bbce2eee..a33ac55680e34f4f5bfc6c2c3c06691b4d77d0a2 100755 --- a/tests/password-update-test.js +++ b/tests/password-update-test.js @@ -12,8 +12,7 @@ vows = require('vows'), start_stop = require('./lib/start-stop.js'), wsapi = require('./lib/wsapi.js'), db = require('../lib/db.js'), -config = require('../lib/configuration.js'), -bcrypt = require('bcrypt'); +config = require('../lib/configuration.js'); var suite = vows.describe('password-length'); diff --git a/tests/session-context-test.js b/tests/session-context-test.js index 6c2fe805a1c2a519ff1a7a9bccb434f018c06e5a..9fbdc8bdd1a7f2297b97c9264af39db64d042427 100755 --- a/tests/session-context-test.js +++ b/tests/session-context-test.js @@ -12,8 +12,7 @@ vows = require('vows'), start_stop = require('./lib/start-stop.js'), wsapi = require('./lib/wsapi.js'), db = require('../lib/db.js'), -config = require('../lib/configuration.js'), -bcrypt = require('bcrypt'); +config = require('../lib/configuration.js'); var suite = vows.describe('session-context'); diff --git a/tests/session-duration-test.js b/tests/session-duration-test.js index a28c7f20f7333e4790dc1621948e06e272a1542b..f40a2f7b068bcbcf89293623ea145fdbb3bae33c 100755 --- a/tests/session-duration-test.js +++ b/tests/session-duration-test.js @@ -14,7 +14,6 @@ start_stop = require('./lib/start-stop.js'), wsapi = require('./lib/wsapi.js'), db = require('../lib/db.js'), config = require('../lib/configuration.js'), -bcrypt = require('bcrypt'), primary = require('./lib/primary.js'), ca = require('../lib/keysigner/ca.js'), jwcrypto = require('jwcrypto'); diff --git a/tests/session-prolong-test.js b/tests/session-prolong-test.js index 2df5cc4d2a2a7e1ad80cb847f233479389f5e9b5..b4348502cdb7d9c2ac01ed389a8787070ff0cd49 100755 --- a/tests/session-prolong-test.js +++ b/tests/session-prolong-test.js @@ -12,8 +12,7 @@ vows = require('vows'), start_stop = require('./lib/start-stop.js'), wsapi = require('./lib/wsapi.js'), db = require('../lib/db.js'), -config = require('../lib/configuration.js'), -bcrypt = require('bcrypt'); +config = require('../lib/configuration.js'); var suite = vows.describe('session-prolong');