ctl: preserve key length in py3 (#38240)
This commit is contained in:
parent
ecab37694f
commit
e80f55d694
|
@ -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 += '&'
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -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 += '&'
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue