Skip to content

Commit

Permalink
Noobaa Account: Replace bcrypt password hashing by argon2
Browse files Browse the repository at this point in the history
As bcrypt is not under active maintenance, we need to
replace it with argon2 hashing module.

Signed-off-by: Ashish Pandey <[email protected]>
  • Loading branch information
aspandey committed Aug 5, 2024
1 parent a7069fc commit 3b46af7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"ajv": "8.17.1",
"aws-sdk": "2.1659.0",
"bcrypt": "5.1.1",
"argon2": "0.40.3",
"big-integer": "1.6.52",
"bindings": "1.5.0",
"bufferutil": "4.0.8",
Expand Down
12 changes: 11 additions & 1 deletion src/server/common_services/auth_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

const _ = require('lodash');
const bcrypt = require('bcrypt');
const argon2 = require('argon2');
const ip_module = require('ip');

const P = require('../../util/promise');
Expand Down Expand Up @@ -36,6 +37,13 @@ const s3_bucket_policy_utils = require('../../endpoint/s3/s3_bucket_policy_utils
* a previously authenticated account.
*
*/

function compare_password_hash(password, target_account) {
if (bcrypt.compare(password.unwrap(), target_account.password.unwrap()))
return true;
return (argon2.verify(target_account.password.unwrap(), password.unwrap()))
}

function create_auth(req) {

const email = req.rpc_params.email;
Expand Down Expand Up @@ -66,7 +74,9 @@ function create_auth(req) {
if (!password) return;

return P.resolve()
.then(() => bcrypt.compare(password.unwrap(), target_account.password.unwrap()))
.then(() => compare_password_hash(password, target_account))
// .then(() => bcrypt.compare(password.unwrap(), target_account.password.unwrap()))
// .then(() => argon2.verify(target_account.password.unwrap(), password.unwrap()))
.then(match => {
if (!match) {
dbg.log0('password mismatch', email, system_name);
Expand Down
16 changes: 10 additions & 6 deletions src/server/system_services/account_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const net = require('net');
const chance = require('chance')();
const GoogleStorage = require('../../util/google_storage_wrap');
const bcrypt = require('bcrypt');
const argon2 = require('argon2');
const server_rpc = require('../server_rpc');

const config = require('../../../config');
Expand Down Expand Up @@ -79,7 +80,7 @@ async function create_account(req) {

if (req.rpc_params.has_login) {
account.password = req.rpc_params.password;
const password_hash = await bcrypt_password(account.password.unwrap());
const password_hash = await argon2_password(account.password.unwrap());
account.password = password_hash;
}

Expand Down Expand Up @@ -574,7 +575,7 @@ async function reset_password(req) {

const params = req.rpc_params;

const password = await bcrypt_password(params.password.unwrap());
const password = await argon2_password(params.password.unwrap());

const changes = {
password: new SensitiveString(password),
Expand Down Expand Up @@ -1334,7 +1335,7 @@ function ensure_support_account() {
}

console.log('CREATING SUPPORT ACCOUNT...');
return bcrypt_password(system_store.get_server_secret())
return argon2_password(system_store.get_server_secret())
.then(password => {
const support_account = {
_id: system_store.new_system_store_id(),
Expand All @@ -1358,9 +1359,9 @@ function ensure_support_account() {
});
}

function bcrypt_password(password) {
function argon2_password(password) {
return P.resolve()
.then(() => password && bcrypt.hash(password, 10));
.then(() => password && argon2.hash(password));
}

function is_support_or_admin_or_me(system, account, target_account) {
Expand Down Expand Up @@ -1454,7 +1455,10 @@ async function verify_authorized_account(req) {
if (req.role === 'operator') {
return true;
}
return bcrypt.compare(req.rpc_params.verification_password.unwrap(), req.account.password.unwrap());
if (bcrypt.compare(req.rpc_params.verification_password.unwrap(), req.account.password.unwrap())) {
return true;
}
return argon2.verify(req.account.password.unwrap(), req.rpc_params.verification_password.unwrap());
}

function _list_connection_usage(account, credentials) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/system_services/schemas/account_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {

// password login
has_login: { type: 'boolean' },
password: { wrapper: SensitiveString }, // bcrypted password
password: { wrapper: SensitiveString }, // argon2 password
next_password_change: { date: true },

// default policy for new buckets
Expand Down
15 changes: 0 additions & 15 deletions src/tools/bcrypt_cli.js

This file was deleted.

0 comments on commit 3b46af7

Please sign in to comment.