Projet

Général

Profil

0001-ctl-preserve-key-length-in-py3-38240.patch

Emmanuel Cazenave, 09 décembre 2019 09:48

Télécharger (3,51 ko)

Voir les différences:

Subject: [PATCH] ctl: preserve key length in py3 (#38240)

 help/fr/api-auth.page  | 2 +-
 tests/test_hobo.py     | 9 +++------
 wcs/api_utils.py       | 3 ++-
 wcs/ctl/check_hobos.py | 3 ++-
 4 files changed, 8 insertions(+), 9 deletions(-)
help/fr/api-auth.page
125 125
        timestamp = datetime.datetime.utcnow()
126 126
    timestamp = timestamp.strftime('%Y-%m-%dT%H:%M:%SZ')
127 127
    if nonce is None:
128
        nonce = hex(random.getrandbits(128))[2:-1]
128
        nonce = hex(random.getrandbits(128))[2:].rstrip('L')
129 129
    new_query = query
130 130
    if new_query:
131 131
        new_query += '&'
tests/test_hobo.py
235 235
    assert pub.get_site_option('portal_agent_url', 'variables') == 'http://agents.example.net/'
236 236
    assert pub.get_site_option('portal_url', 'variables') == 'http://portal.example.net/'
237 237
    assert pub.get_site_option('test_wcs_url', 'variables') == 'http://wcs.example.net/'
238
    assert (pub.get_site_option('authentic.example.net', 'api-secrets')
239
            == CmdCheckHobos.shared_secret(HOBO_JSON['services'][1]['secret_key'],
240
                                           HOBO_JSON['services'][2]['secret_key']))
241
    assert (pub.get_site_option('authentic.example.net', 'wscall-secrets')
242
            == CmdCheckHobos.shared_secret(HOBO_JSON['services'][1]['secret_key'],
243
                                           HOBO_JSON['services'][2]['secret_key']))
238
    key = '109fca71e7dc8ec49708a08fa7c02795de13f34f7d29d27bd150f203b3e0ab40'
239
    assert pub.get_site_option('authentic.example.net', 'api-secrets') == key
240
    assert pub.get_site_option('authentic.example.net', 'wscall-secrets') == key
244 241
    self_domain = urlparse.urlsplit(service.get('base_url')).netloc
245 242
    assert pub.get_site_option(self_domain, 'wscall-secrets') != '0'
246 243

  
wcs/api_utils.py
156 156
        timestamp = datetime.datetime.utcnow()
157 157
    timestamp = timestamp.strftime('%Y-%m-%dT%H:%M:%SZ')
158 158
    if nonce is None:
159
        nonce = hex(random.getrandbits(128))[2:-1]
159
        # rstrip('L') for py2/3 compatibility, as py2 formats number as 0x...L, and py3 as 0x...
160
        nonce = hex(random.getrandbits(128))[2:].rstrip('L')
160 161
    new_query = query
161 162
    if new_query:
162 163
        new_query += '&'
wcs/ctl/check_hobos.py
552 552
    def shared_secret(cls, secret1, secret2):
553 553
        secret1 = hashlib.sha256(force_bytes(secret1)).hexdigest()
554 554
        secret2 = hashlib.sha256(force_bytes(secret2)).hexdigest()
555
        return hex(int(secret1, 16) ^ int(secret2, 16))[2:-1]
555
        # rstrip('L') for py2/3 compatibility, as py2 formats number as 0x...L, and py3 as 0x...
556
        return hex(int(secret1, 16) ^ int(secret2, 16))[2:].rstrip('L')
556 557

  
557 558

  
558 559
CmdCheckHobos.register()
559
-