4
4
import binascii # hex encoding
5
5
import platform # check platform
6
6
import subprocess # needed for mac device
7
- from datetime import datetime
7
+ from datetime import datetime , timedelta
8
8
from discord_interactions import verify_key # used for signature verification
9
9
10
10
try :
@@ -512,44 +512,54 @@ def logout(self):
512
512
def __do_request (self , post_data ):
513
513
try :
514
514
response = requests .post (
515
- "https://keyauth.win/api/1.3/" , data = post_data , timeout = 10
515
+ "https://keyauth.win/api/1.3/" , data = post_data , timeout = 10
516
516
)
517
-
518
- if post_data ["type" ] == "log" or post_data ["type" ] == "file" : return response .text
519
-
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 = int (datetime .utcnow ().timestamp ())
526
-
527
- # Check if the timestamp is older than 20 seconds
528
- if current_time - unix_timestamp > 20 :
529
- print ("Timestamp OLD" )
517
+
518
+ if post_data ["type" ] == "log" or post_data ["type" ] == "file" :
519
+ return response .text
520
+
521
+ # Get the signature and timestamp from the headers
522
+ signature = response .headers .get ("x-signature-ed25519" )
523
+ timestamp = response .headers .get ("x-signature-timestamp" )
524
+
525
+ if not signature or not timestamp :
526
+ print ("Missing headers for signature verification." )
527
+ time .sleep (3 )
528
+ os ._exit (1 )
529
+
530
+ server_time = datetime .utcfromtimestamp (int (timestamp ))
531
+ current_time = datetime .utcnow ()
532
+
533
+ buffer_seconds = 5
534
+ time_difference = current_time - server_time
535
+
536
+ if time_difference > timedelta (seconds = 20 + buffer_seconds ):
537
+ print ("Timestamp is too old (exceeded 20 seconds + buffer)." )
530
538
time .sleep (3 )
531
539
os ._exit (1 )
532
540
541
+ # Proceed with creating debug folders and logging
533
542
if not os .path .exists ("C:\\ ProgramData\\ KeyAuth" ):
534
- os .makedirs ("C:\\ ProgramData\\ KeyAuth" )
535
543
os .makedirs ("C:\\ ProgramData\\ KeyAuth\\ Debug" )
536
544
537
545
exe_name = os .path .basename (__file__ )
538
- if not os .path .exists (f"C:\\ ProgramData\\ KeyAuth\\ Debug\\ { exe_name } " ):
539
- os .makedirs (f"C:\\ ProgramData\\ KeyAuth\\ Debug\\ { exe_name } " )
546
+ log_dir = f"C:\\ ProgramData\\ KeyAuth\\ Debug\\ { exe_name } "
547
+ if not os .path .exists (log_dir ):
548
+ os .makedirs (log_dir )
540
549
541
- with open (f"C: \\ ProgramData \\ KeyAuth \\ Debug \\ { exe_name } \\ log.txt" , "a" ) as log_file :
550
+ with open (f"{ log_dir } \\ log.txt" , "a" ) as log_file :
542
551
if len (response .text ) <= 200 :
543
552
execution_time = time .strftime ("%I:%M %p | %m/%d/%Y" )
544
553
log_file .write (f"\n { execution_time } | { post_data ['type' ]} \n Response: { response .text } " )
545
-
554
+
546
555
if not verify_key (response .text .encode ('utf-8' ), signature , timestamp , '5586b4bc69c7a4b487e4563a4cd96afd39140f919bd31cea7d1c6a1e8439422b' ):
547
556
print ("Signature checksum failed. Request was tampered with or session ended most likely." )
548
557
print ("Response: " + response .text )
549
558
time .sleep (3 )
550
- os ._exit (1 )
551
-
559
+ os ._exit (1 )
560
+
552
561
return response .text
562
+
553
563
except requests .exceptions .Timeout :
554
564
print ("Request timed out. Server is probably down/slow at the moment" )
555
565
@@ -611,5 +621,4 @@ def get_hwid():
611
621
output = subprocess .Popen ("ioreg -l | grep IOPlatformSerialNumber" , stdout = subprocess .PIPE , shell = True ).communicate ()[0 ]
612
622
serial = output .decode ().split ('=' , 1 )[1 ].replace (' ' , '' )
613
623
hwid = serial [1 :- 2 ]
614
- return hwid
615
-
624
+ return hwid
0 commit comments