From 045b5882d94fc2d4ba7b194bf65ebfbf9d2e1d6d Mon Sep 17 00:00:00 2001 From: "Rinck H. Sonnenberg" Date: Tue, 26 Oct 2021 11:38:17 +0200 Subject: [PATCH] updated bytes() function to distinguish between python 2/3 --- ahvl/lookup.py | 23 +++++++++++++++++++---- setup.py | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ahvl/lookup.py b/ahvl/lookup.py index 42f3afd..a96fcc9 100644 --- a/ahvl/lookup.py +++ b/ahvl/lookup.py @@ -18,6 +18,9 @@ from ahvl.generate.sshhostkey import GenerateSSHHostKey from ahvl.generate.gpgkey import GenerateGPGKey +# to be able to check the python version/distinguish between p2/p3 bytes() function +import sys + # # message # @@ -167,19 +170,31 @@ def return_postgresmd5(self, secret, options): def return_pbkdf2sha256(self, secret, options): from passlib.hash import pbkdf2_sha256 - return pbkdf2_sha256.hash(secret, salt=bytes(self.find_salt(options))) + if sys.version_info.major == 2: + return pbkdf2_sha256.hash(secret, salt=bytes(self.find_salt(options))) + else: + return pbkdf2_sha256.hash(secret, salt=bytes(self.find_salt(options), encoding='utf8')) def return_pbkdf2sha512(self, secret, options): from passlib.hash import pbkdf2_sha512 - return pbkdf2_sha512.hash(secret, salt=bytes(self.find_salt(options)), rounds=58000) + if sys.version_info.major == 2: + return pbkdf2_sha512.hash(secret, salt=bytes(self.find_salt(options)), rounds=58000) + else: + return pbkdf2_sha512.hash(secret, salt=bytes(self.find_salt(options), encoding='utf8'), rounds=58000) def return_argon2(self, secret, options): from passlib.hash import argon2 - return argon2.using(salt=bytes(self.find_salt(options)), rounds=32).hash(secret) + if sys.version_info.major == 2: + return argon2.using(salt=bytes(self.find_salt(options)), rounds=32).hash(secret) + else: + return argon2.using(salt=bytes(self.find_salt(options), encoding='utf8'), rounds=32).hash(secret) def return_grubpbkdf2sha512(self, secret, options): from passlib.hash import grub_pbkdf2_sha512 - return grub_pbkdf2_sha512.hash(secret, salt=bytes(self.find_salt(options)), rounds=38000) + if sys.version_info.major == 2: + return grub_pbkdf2_sha512.hash(secret, salt=bytes(self.find_salt(options)), rounds=38000) + else: + return grub_pbkdf2_sha512.hash(secret, salt=bytes(self.find_salt(options), encoding='utf8'), rounds=38000) # # find salt diff --git a/setup.py b/setup.py index 1679ed5..2c70448 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="ahvl", - version="1.2.0", + version="1.2.1", author="RH Sonnenberg", author_email="r.sonnenberg@netson.nl", description="Base libraries for the Ansible HashiCorp Vault Lookup (AHVL) Plugin by Netson", @@ -18,7 +18,7 @@ long_description_content_type="text/markdown", license='MIT', url="https://github.com/netson/ahvl", - download_url='https://github.com/netson/ahvl/archive/v1.2.0.tar.gz', + download_url='https://github.com/netson/ahvl/archive/v1.2.1.tar.gz', packages=find_packages(), classifiers=[ "Programming Language :: Python :: 3",