diff --git a/help/fr/api-auth.page b/help/fr/api-auth.page index 1775dc13c..01dc5122e 100644 --- a/help/fr/api-auth.page +++ b/help/fr/api-auth.page @@ -125,7 +125,7 @@ def sign_query(query, key, algo='sha256', orig=None, timestamp=None, nonce=None) timestamp = datetime.datetime.utcnow() timestamp = timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') if nonce is None: - nonce = hex(random.getrandbits(128))[2:-1] + nonce = hex(random.getrandbits(128))[2:].rstrip('L') new_query = query if new_query: new_query += '&' diff --git a/tests/test_hobo.py b/tests/test_hobo.py index 089822b95..30ad28be0 100644 --- a/tests/test_hobo.py +++ b/tests/test_hobo.py @@ -235,12 +235,9 @@ def test_configure_site_options(): assert pub.get_site_option('portal_agent_url', 'variables') == 'http://agents.example.net/' assert pub.get_site_option('portal_url', 'variables') == 'http://portal.example.net/' assert pub.get_site_option('test_wcs_url', 'variables') == 'http://wcs.example.net/' - assert (pub.get_site_option('authentic.example.net', 'api-secrets') - == CmdCheckHobos.shared_secret(HOBO_JSON['services'][1]['secret_key'], - HOBO_JSON['services'][2]['secret_key'])) - assert (pub.get_site_option('authentic.example.net', 'wscall-secrets') - == CmdCheckHobos.shared_secret(HOBO_JSON['services'][1]['secret_key'], - HOBO_JSON['services'][2]['secret_key'])) + key = '109fca71e7dc8ec49708a08fa7c02795de13f34f7d29d27bd150f203b3e0ab40' + assert pub.get_site_option('authentic.example.net', 'api-secrets') == key + assert pub.get_site_option('authentic.example.net', 'wscall-secrets') == key self_domain = urlparse.urlsplit(service.get('base_url')).netloc assert pub.get_site_option(self_domain, 'wscall-secrets') != '0' diff --git a/wcs/api_utils.py b/wcs/api_utils.py index 61473704f..d5570cc0c 100644 --- a/wcs/api_utils.py +++ b/wcs/api_utils.py @@ -156,7 +156,8 @@ def sign_query(query, key, algo='sha256', timestamp=None, nonce=None): timestamp = datetime.datetime.utcnow() timestamp = timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') if nonce is None: - nonce = hex(random.getrandbits(128))[2:-1] + # rstrip('L') for py2/3 compatibility, as py2 formats number as 0x...L, and py3 as 0x... + nonce = hex(random.getrandbits(128))[2:].rstrip('L') new_query = query if new_query: new_query += '&' diff --git a/wcs/ctl/check_hobos.py b/wcs/ctl/check_hobos.py index 8cef45a15..83c1d39e6 100644 --- a/wcs/ctl/check_hobos.py +++ b/wcs/ctl/check_hobos.py @@ -552,7 +552,8 @@ class CmdCheckHobos(Command): def shared_secret(cls, secret1, secret2): secret1 = hashlib.sha256(force_bytes(secret1)).hexdigest() secret2 = hashlib.sha256(force_bytes(secret2)).hexdigest() - return hex(int(secret1, 16) ^ int(secret2, 16))[2:-1] + # rstrip('L') for py2/3 compatibility, as py2 formats number as 0x...L, and py3 as 0x... + return hex(int(secret1, 16) ^ int(secret2, 16))[2:].rstrip('L') CmdCheckHobos.register()