44import binascii # hex encoding
55import platform # check platform
66import subprocess # needed for mac device
7- from datetime import datetime
7+ from datetime import datetime , timedelta
88from discord_interactions import verify_key # used for signature verification
99
1010try :
@@ -512,44 +512,54 @@ def logout(self):
512512 def __do_request (self , post_data ):
513513 try :
514514 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
516516 )
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)." )
530538 time .sleep (3 )
531539 os ._exit (1 )
532540
541+ # Proceed with creating debug folders and logging
533542 if not os .path .exists ("C:\\ ProgramData\\ KeyAuth" ):
534- os .makedirs ("C:\\ ProgramData\\ KeyAuth" )
535543 os .makedirs ("C:\\ ProgramData\\ KeyAuth\\ Debug" )
536544
537545 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 )
540549
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 :
542551 if len (response .text ) <= 200 :
543552 execution_time = time .strftime ("%I:%M %p | %m/%d/%Y" )
544553 log_file .write (f"\n { execution_time } | { post_data ['type' ]} \n Response: { response .text } " )
545-
554+
546555 if not verify_key (response .text .encode ('utf-8' ), signature , timestamp , '5586b4bc69c7a4b487e4563a4cd96afd39140f919bd31cea7d1c6a1e8439422b' ):
547556 print ("Signature checksum failed. Request was tampered with or session ended most likely." )
548557 print ("Response: " + response .text )
549558 time .sleep (3 )
550- os ._exit (1 )
551-
559+ os ._exit (1 )
560+
552561 return response .text
562+
553563 except requests .exceptions .Timeout :
554564 print ("Request timed out. Server is probably down/slow at the moment" )
555565
@@ -611,5 +621,4 @@ def get_hwid():
611621 output = subprocess .Popen ("ioreg -l | grep IOPlatformSerialNumber" , stdout = subprocess .PIPE , shell = True ).communicate ()[0 ]
612622 serial = output .decode ().split ('=' , 1 )[1 ].replace (' ' , '' )
613623 hwid = serial [1 :- 2 ]
614- return hwid
615-
624+ return hwid
0 commit comments