Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP A PBKDF2 implementation for internal database password hashing #12232

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deps/rabbit_common/app.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def all_beam_files(name = "all_beam_files"):
"src/rabbit_password_hashing_md5.erl",
"src/rabbit_password_hashing_sha256.erl",
"src/rabbit_password_hashing_sha512.erl",
"src/rabbit_password_hashing_pbkdf2_hmac_sha512_v1.erl",
"src/rabbit_pbe.erl",
"src/rabbit_peer_discovery_backend.erl",
"src/rabbit_policy_validator.erl",
Expand Down Expand Up @@ -159,6 +160,7 @@ def all_test_beam_files(name = "all_test_beam_files"):
"src/rabbit_password_hashing_md5.erl",
"src/rabbit_password_hashing_sha256.erl",
"src/rabbit_password_hashing_sha512.erl",
"src/rabbit_password_hashing_pbkdf2_hmac_sha512_v1.erl",
"src/rabbit_pbe.erl",
"src/rabbit_peer_discovery_backend.erl",
"src/rabbit_policy_validator.erl",
Expand Down Expand Up @@ -249,6 +251,7 @@ def all_srcs(name = "all_srcs"):
"src/rabbit_password_hashing_md5.erl",
"src/rabbit_password_hashing_sha256.erl",
"src/rabbit_password_hashing_sha512.erl",
"src/rabbit_password_hashing_pbkdf2_hmac_sha512_v1.erl",
"src/rabbit_pbe.erl",
"src/rabbit_peer_discovery_backend.erl",
"src/rabbit_policy_validator.erl",
Expand Down
7 changes: 5 additions & 2 deletions deps/rabbit_common/src/rabbit_password.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ salted_hash(Salt, Cleartext) ->
salted_hash(hashing_mod(), Salt, Cleartext).

salted_hash(Mod, Salt, Cleartext) ->
Fun = fun Mod:hash/1,
Fun(<<Salt/binary, Cleartext/binary>>).
ModuleInfoFun = fun Mod:module_info/1,
case lists:member({hash,2}, ModuleInfoFun(exports)) of
true -> Fun = fun Mod:hash/2, Fun(Salt, Cleartext);
false -> Fun = fun Mod:hash/1, Fun(<<Salt/binary, Cleartext/binary>>)
end.

hashing_mod() ->
rabbit_misc:get_env(rabbit, password_hashing_module,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%% 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 https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%%

-module(rabbit_password_hashing_pbkdf2_hmac_sha512_v1).

%% TODO: I don't know if I should extend this behaviour, or change the other
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behaviors can have optional callbacks. Changing other implementations does not seem to be necessary.

%% implementations to do salt prefixing themselves.
%% -behaviour(rabbit_password_hashing).

-export([hash/2]).

%% OWASP-recommended iteration count, as of 2024.
-define(ITERATIONS, 210000).
-define(KEYLEN, 64).

hash(Salt, Binary) ->
crypto:pbkdf2_hmac(sha512, Binary, Salt, ?ITERATIONS, ?KEYLEN).
5 changes: 3 additions & 2 deletions deps/rabbitmq_management/priv/www/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,9 @@ <h2>Reference</h2>
<code>password_hash</code> must be generated using the algorithm described
<a href="https://rabbitmq.com/passwords.html#computing-password-hash">here</a>.
You may also specify the hash function being used by adding the <code>hashing_algorithm</code>
key to the body. Currently recognised algorithms are <code>rabbit_password_hashing_sha256</code>,
<code>rabbit_password_hashing_sha512</code>, and <code>rabbit_password_hashing_md5</code>.
key to the body. Currently recognised algorithms are <code>rabbit_password_hashing_pbkdf2_hmac_sha512_v1</code>,
<code>rabbit_password_hashing_sha256</code>, <code>rabbit_password_hashing_sha512</code>,
and <code>rabbit_password_hashing_md5</code>.
</td>
</tr>
<tr>
Expand Down
1 change: 1 addition & 0 deletions moduleindex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ rabbit_common:
- rabbit_password_hashing_md5
- rabbit_password_hashing_sha256
- rabbit_password_hashing_sha512
- rabbit_password_hashing_pbkdf2_hmac_sha512_v1
- rabbit_pbe
- rabbit_peer_discovery_backend
- rabbit_policy_validator
Expand Down