-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hashing the mq password instead of calling add_user. It created timin…
…g issues. Workers contacted the broker with correct credentials, but the broker did not have that user setup yet. It is now already setup at boottime
- Loading branch information
Showing
6 changed files
with
84 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'''Creating a rabbitmq hash of a supplied password''' | ||
|
||
import sys | ||
import os | ||
from base64 import b64encode | ||
import hashlib | ||
|
||
# inspired by https://gist.github.com/komuw/c6fb1a1c757afb43fe69bdd736d5cf63 | ||
def hash_pass(password): | ||
"""Hashing password according to RabbitMQ specs.""" | ||
# 1.Generate a random 32 bit salt: | ||
# This will generate 32 bits of random data: | ||
salt = os.urandom(4) | ||
|
||
# 2.Concatenate that with the UTF-8 representation of the password (in this case "simon") | ||
tmp0 = salt + password.encode('utf-8') | ||
|
||
# 3. Take the SHA256 hash and get the bytes back | ||
tmp1 = hashlib.sha256(tmp0).digest() | ||
|
||
# 4. Concatenate the salt again: | ||
salted_hash = salt + tmp1 | ||
|
||
# 5. convert to base64 encoding: | ||
pass_hash = b64encode(salted_hash).decode("utf-8") | ||
|
||
return pass_hash | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
if len(sys.argv) > 1: | ||
print(hash_pass(sys.argv[1])) | ||
else: | ||
password = input() | ||
print(hash_pass(password.strip())) |