Skip to content

Commit

Permalink
Add method "generate_hardware_string" (#40)
Browse files Browse the repository at this point in the history
* Add method "generate_hardware_string"

* Update pyluba/aliyun/cloud_gateway.py

* Update pyluba/aliyun/cloud_gateway.py

---------

Co-authored-by: Andrea Cagnola <[email protected]>
Co-authored-by: Michael Arthur <[email protected]>
  • Loading branch information
3 people authored Jul 2, 2024
1 parent bb317a6 commit ecde651
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pyluba/aliyun/cloud_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ def __init__(self):
self._app_secret = APP_SECRET
self.domain = ALIYUN_DOMAIN

uuid1 = str(uuid.uuid1()) # 128 chatarrers
self._client_id = uuid1[:8] # First 8 Characters
self._device_sn = uuid1.replace("-", "")[:32]
self._utdid = self.generate_random_string(32) # 32 Characters
self._client_id = self.generate_hardware_string(8) # 8 charatters
self._device_sn = self.generate_hardware_string(32) # 32 charatters
self._utdid = self.generate_hardware_string(32) # 32 charatters

@staticmethod
def generate_random_string(length):
characters = string.ascii_letters + string.digits
random_string = ''.join(random.choice(characters) for _ in range(length))
return random_string

def generate_hardware_string(self, length):
hashed_uuid = hashlib.sha1(f"{uuid.getnode()}".encode()).hexdigest()
return "".join(itertools.islice(itertools.cycle(hashed_uuid), length))

def sign(self, data):
keys = ["appKey", "clientId", "deviceSn", "timestamp"]
Expand Down

0 comments on commit ecde651

Please sign in to comment.