2
2
import json as jsond # json
3
3
import time # sleep before exit
4
4
import binascii # hex encoding
5
- from uuid import uuid4 # gen random guid
6
5
import platform # check platform
7
6
import subprocess # needed for mac device
8
- import hmac # signature checksum
9
- import hashlib # signature checksum
7
+ from datetime import datetime
8
+ from discord_interactions import verify_key # used for signature verification
10
9
11
10
try :
12
11
if os .name == 'nt' :
28
27
29
28
class api :
30
29
31
- name = ownerid = secret = version = hash_to_check = ""
30
+ name = ownerid = version = hash_to_check = ""
32
31
33
- def __init__ (self , name , ownerid , secret , version , hash_to_check ):
34
- if len (ownerid ) != 10 and len ( secret ) != 64 :
35
- print ("Go to Manage Applications on dashboard , copy python code, and replace code in main.py with that" )
32
+ def __init__ (self , name , ownerid , version , hash_to_check ):
33
+ if len (ownerid ) != 10 :
34
+ print ("Visit https://keyauth.cc/app/ , copy Pthon code, and replace code in main.py with that" )
36
35
time .sleep (3 )
37
36
os ._exit (1 )
38
37
39
38
self .name = name
40
39
41
40
self .ownerid = ownerid
42
41
43
- self .secret = secret
44
-
45
42
self .version = version
46
43
self .hash_to_check = hash_to_check
47
44
self .init ()
@@ -54,16 +51,11 @@ def init(self):
54
51
print ("You've already initialized!" )
55
52
time .sleep (3 )
56
53
os ._exit (1 )
57
-
58
- sent_key = str (uuid4 ())[:16 ]
59
-
60
- self .enckey = sent_key + "-" + self .secret
61
54
62
55
post_data = {
63
56
"type" : "init" ,
64
57
"ver" : self .version ,
65
58
"hash" : self .hash_to_check ,
66
- "enckey" : sent_key ,
67
59
"name" : self .name ,
68
60
"ownerid" : self .ownerid
69
61
}
@@ -96,9 +88,6 @@ def init(self):
96
88
97
89
self .sessionid = json ["sessionid" ]
98
90
self .initialized = True
99
-
100
- if json ["newSession" ]:
101
- time .sleep (0.1 )
102
91
103
92
def register (self , user , password , license , hwid = None ):
104
93
self .checkinit ()
@@ -523,15 +512,23 @@ def logout(self):
523
512
def __do_request (self , post_data ):
524
513
try :
525
514
response = requests .post (
526
- "https://keyauth.win/api/1.2 /" , data = post_data , timeout = 10
515
+ "https://keyauth.win/api/1.3 /" , data = post_data , timeout = 10
527
516
)
528
517
529
- key = self .secret if post_data ["type" ] == "init" else self .enckey
530
- if post_data ["type" ] == "log" : return response .text
531
-
532
- client_computed = hmac .new (key .encode ('utf-8' ), response .text .encode ('utf-8' ), hashlib .sha256 ).hexdigest ()
518
+ if post_data ["type" ] == "log" or post_data ["type" ] == "file" : return response .text
533
519
534
- signature = response .headers ["signature" ]
520
+ signature = response .headers ["x-signature-ed25519" ]
521
+ timestamp = response .headers ["x-signature-timestamp" ]
522
+
523
+ unix_timestamp = int (timestamp )
524
+ # Get the current time
525
+ current_time = datetime .now ().timestamp ()
526
+
527
+ # Check if the timestamp is older than 15 seconds
528
+ if current_time - unix_timestamp > 15 :
529
+ print ("Timestamp OLD" )
530
+ time .sleep (3 )
531
+ os ._exit (1 )
535
532
536
533
if not os .path .exists ("C:\\ ProgramData\\ KeyAuth" ):
537
534
os .makedirs ("C:\\ ProgramData\\ KeyAuth" )
@@ -543,11 +540,10 @@ def __do_request(self, post_data):
543
540
544
541
with open (f"C:\\ ProgramData\\ KeyAuth\\ Debug\\ { exe_name } \\ log.txt" , "a" ) as log_file :
545
542
if len (response .text ) <= 200 :
546
- tampered = not hmac .compare_digest (client_computed , signature )
547
543
execution_time = time .strftime ("%I:%M %p | %m/%d/%Y" )
548
- log_file .write (f"\n { execution_time } | { post_data ['type' ]} \n Response: { response .text } \n Was response tampered with? { tampered } \n " )
544
+ log_file .write (f"\n { execution_time } | { post_data ['type' ]} \n Response: { response .text } " )
549
545
550
- if not hmac . compare_digest ( client_computed , signature ):
546
+ if not verify_key ( response . text . encode ( 'utf-8' ) , signature , timestamp , '5586b4bc69c7a4b487e4563a4cd96afd39140f919bd31cea7d1c6a1e8439422b' ):
551
547
print ("Signature checksum failed. Request was tampered with or session ended most likely." )
552
548
print ("Response: " + response .text )
553
549
time .sleep (3 )
0 commit comments