|
3 | 3 | import time # sleep before exit |
4 | 4 |
|
5 | 5 | import binascii # hex encoding |
6 | | -import hashlib |
7 | 6 |
|
8 | 7 | # https requests |
9 | 8 |
|
|
30 | 29 | exit(0) |
31 | 30 |
|
32 | 31 | class api: |
33 | | - name = ownerid = secret = version = "" |
| 32 | + name = ownerid = secret = version = hash_to_check = "" |
34 | 33 |
|
35 | | - def __init__(self, name, ownerid, secret, version): |
| 34 | + def __init__(self, name, ownerid, secret, version, hash_to_check): |
36 | 35 | self.name = name |
37 | 36 |
|
38 | 37 | self.ownerid = ownerid |
39 | 38 |
|
40 | 39 | self.secret = secret |
41 | 40 |
|
42 | 41 | self.version = version |
| 42 | + self.hash_to_check = hash_to_check |
43 | 43 | self.init() |
44 | 44 |
|
45 | 45 | sessionid = enckey = "" |
46 | 46 | initialized = False |
47 | 47 |
|
48 | 48 | def init(self): |
| 49 | + |
49 | 50 | if self.sessionid != "": |
50 | 51 | print("You've already initialized!") |
51 | 52 | time.sleep(2) |
52 | 53 | exit(0) |
53 | | - |
54 | 54 | init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() |
55 | 55 |
|
56 | 56 | self.enckey = SHA256.new(str(uuid4())[:8].encode()).hexdigest() |
57 | 57 |
|
58 | 58 | post_data = { |
59 | 59 | "type": binascii.hexlify(("init").encode()), |
60 | 60 | "ver": encryption.encrypt(self.version, self.secret, init_iv), |
61 | | - "hash": self.getchecksum(), |
| 61 | + "hash": self.hash_to_check, |
62 | 62 | "enckey": encryption.encrypt(self.enckey, self.secret, init_iv), |
63 | 63 | "name": binascii.hexlify(self.name.encode()), |
64 | 64 | "ownerid": binascii.hexlify(self.ownerid.encode()), |
@@ -415,17 +415,6 @@ def checkinit(self): |
415 | 415 | if not self.initialized: |
416 | 416 | print("Initialize first, in order to use the functions") |
417 | 417 | sys.exit() |
418 | | - |
419 | | - def getchecksum(self): |
420 | | - path = os.path.realpath(__file__) |
421 | | - md5_hash = hashlib.md5() |
422 | | - |
423 | | - a_file = open(path, "rb") |
424 | | - content = a_file.read() |
425 | | - md5_hash.update(content) |
426 | | - |
427 | | - digest = md5_hash.hexdigest() |
428 | | - return digest |
429 | 418 |
|
430 | 419 | def __do_request(self, post_data): |
431 | 420 |
|
|
0 commit comments