11import json as jsond # json
22
3- import time
3+ import time # sleep before exit
44
55import binascii # hex encoding
66
1717
1818from requests_toolbelt .adapters .fingerprint import FingerprintAdapter
1919
20- if platform .system () == "Windows" :
21- KEYSAVE_PATH = "C:\\ ProgramData\\ keysave.txt"
22- else :
23- KEYSAVE_PATH = "/usr/keysave.txt"
24-
2520
2621class api :
2722 name = ownerid = secret = version = ""
@@ -35,56 +30,59 @@ def __init__(self, name, ownerid, secret, version):
3530
3631 self .version = version
3732
38- session_id = session_iv = ""
33+ sessionid = enckey = ""
3934
4035 def init (self ):
41- self .session_iv = str (uuid4 ())[:8 ]
4236
43- init_iv = SHA256 .new (self .session_iv .encode ()).hexdigest ()
37+ init_iv = SHA256 .new (str (uuid4 ())[:8 ].encode ()).hexdigest ()
38+
39+ self .enckey = SHA256 .new (str (uuid4 ())[:8 ].encode ()).hexdigest ()
4440
4541 post_data = {
4642 "type" : binascii .hexlify (("init" ).encode ()),
4743 "ver" : encryption .encrypt (self .version , self .secret , init_iv ),
44+ "enckey" : encryption .encrypt (self .enckey , self .secret , init_iv ),
4845 "name" : binascii .hexlify (self .name .encode ()),
4946 "ownerid" : binascii .hexlify (self .ownerid .encode ()),
5047 "init_iv" : init_iv
5148 }
5249
5350 response = self .__do_request (post_data )
5451
55- if response == "program_doesnt_exist " :
56- print ("The application doesnt exist" )
52+ if response == "KeyAuth_Invalid " :
53+ print ("The application doesn't exist" )
5754 sys .exit ()
5855
5956 response = encryption .decrypt (response , self .secret , init_iv )
60-
57+ print ( response )
6158 json = jsond .loads (response )
6259
6360 if not json ["success" ]:
6461 print (json ["message" ])
6562 sys .exit ()
63+
64+ self .sessionid = json ["sessionid" ]
6665
6766 def register (self , user , password , license , hwid = None ):
6867 if hwid is None : hwid = others .get_hwid ()
6968
70- self .session_iv = str (uuid4 ())[:8 ]
71-
72- init_iv = SHA256 .new (self .session_iv .encode ()).hexdigest ()
69+ init_iv = SHA256 .new (str (uuid4 ())[:8 ].encode ()).hexdigest ()
7370
7471 post_data = {
7572 "type" : binascii .hexlify (("register" ).encode ()),
76- "username" : encryption .encrypt (user , self .secret , init_iv ),
77- "pass" : encryption .encrypt (password , self .secret , init_iv ),
78- "key" : encryption .encrypt (license , self .secret , init_iv ),
79- "hwid" : encryption .encrypt (hwid , self .secret , init_iv ),
73+ "username" : encryption .encrypt (user , self .enckey , init_iv ),
74+ "pass" : encryption .encrypt (password , self .enckey , init_iv ),
75+ "key" : encryption .encrypt (license , self .enckey , init_iv ),
76+ "hwid" : encryption .encrypt (hwid , self .enckey , init_iv ),
77+ "sessionid" : binascii .hexlify (self .sessionid .encode ()),
8078 "name" : binascii .hexlify (self .name .encode ()),
8179 "ownerid" : binascii .hexlify (self .ownerid .encode ()),
8280 "init_iv" : init_iv
8381 }
8482
8583 response = self .__do_request (post_data )
8684
87- response = encryption .decrypt (response , self .secret , init_iv )
85+ response = encryption .decrypt (response , self .enckey , init_iv )
8886
8987 json = jsond .loads (response )
9088
@@ -96,22 +94,21 @@ def register(self, user, password, license, hwid=None):
9694
9795 def upgrade (self , user , license ):
9896
99- self .session_iv = str (uuid4 ())[:8 ]
100-
101- init_iv = SHA256 .new (self .session_iv .encode ()).hexdigest ()
97+ init_iv = SHA256 .new (str (uuid4 ())[:8 ].encode ()).hexdigest ()
10298
10399 post_data = {
104100 "type" : binascii .hexlify (("upgrade" ).encode ()),
105- "username" : encryption .encrypt (user , self .secret , init_iv ),
106- "key" : encryption .encrypt (license , self .secret , init_iv ),
101+ "username" : encryption .encrypt (user , self .enckey , init_iv ),
102+ "key" : encryption .encrypt (license , self .enckey , init_iv ),
103+ "sessionid" : binascii .hexlify (self .sessionid .encode ()),
107104 "name" : binascii .hexlify (self .name .encode ()),
108105 "ownerid" : binascii .hexlify (self .ownerid .encode ()),
109106 "init_iv" : init_iv
110107 }
111108
112109 response = self .__do_request (post_data )
113110
114- response = encryption .decrypt (response , self .secret , init_iv )
111+ response = encryption .decrypt (response , self .enckey , init_iv )
115112
116113 json = jsond .loads (response )
117114
@@ -124,23 +121,22 @@ def upgrade(self, user, license):
124121 def login (self , user , password , hwid = None ):
125122 if hwid is None : hwid = others .get_hwid ()
126123
127- self .session_iv = str (uuid4 ())[:8 ]
128-
129- init_iv = SHA256 .new (self .session_iv .encode ()).hexdigest ()
124+ init_iv = SHA256 .new (str (uuid4 ())[:8 ].encode ()).hexdigest ()
130125
131126 post_data = {
132127 "type" : binascii .hexlify (("login" ).encode ()),
133- "username" : encryption .encrypt (user , self .secret , init_iv ),
134- "pass" : encryption .encrypt (password , self .secret , init_iv ),
135- "hwid" : encryption .encrypt (hwid , self .secret , init_iv ),
128+ "username" : encryption .encrypt (user , self .enckey , init_iv ),
129+ "pass" : encryption .encrypt (password , self .enckey , init_iv ),
130+ "hwid" : encryption .encrypt (hwid , self .enckey , init_iv ),
131+ "sessionid" : binascii .hexlify (self .sessionid .encode ()),
136132 "name" : binascii .hexlify (self .name .encode ()),
137133 "ownerid" : binascii .hexlify (self .ownerid .encode ()),
138134 "init_iv" : init_iv
139135 }
140136
141137 response = self .__do_request (post_data )
142138
143- response = encryption .decrypt (response , self .secret , init_iv )
139+ response = encryption .decrypt (response , self .enckey , init_iv )
144140
145141 json = jsond .loads (response )
146142
@@ -153,22 +149,21 @@ def login(self, user, password, hwid=None):
153149 def license (self , key , hwid = None ):
154150 if hwid is None : hwid = others .get_hwid ()
155151
156- self .session_iv = str (uuid4 ())[:8 ]
157-
158- init_iv = SHA256 .new (self .session_iv .encode ()).hexdigest ()
152+ init_iv = SHA256 .new (str (uuid4 ())[:8 ].encode ()).hexdigest ()
159153
160154 post_data = {
161155 "type" : binascii .hexlify (("license" ).encode ()),
162- "key" : encryption .encrypt (key , self .secret , init_iv ),
163- "hwid" : encryption .encrypt (hwid , self .secret , init_iv ),
156+ "key" : encryption .encrypt (key , self .enckey , init_iv ),
157+ "hwid" : encryption .encrypt (hwid , self .enckey , init_iv ),
158+ "sessionid" : binascii .hexlify (self .sessionid .encode ()),
164159 "name" : binascii .hexlify (self .name .encode ()),
165160 "ownerid" : binascii .hexlify (self .ownerid .encode ()),
166161 "init_iv" : init_iv
167162 }
168163
169164 response = self .__do_request (post_data )
170-
171- response = encryption .decrypt (response , self .secret , init_iv )
165+ print ( response )
166+ response = encryption .decrypt (response , self .enckey , init_iv )
172167
173168 json = jsond .loads (response )
174169
@@ -177,46 +172,107 @@ def license(self, key, hwid=None):
177172 print ("successfully logged into license" )
178173 else :
179174 print (json ["message" ])
180- if os .path .exists (KEYSAVE_PATH ):
181- os .remove (KEYSAVE_PATH )
182- time .sleep (5 )
183175 sys .exit ()
184176
185- def var (self , name , hwid = None ):
186- if hwid is None : hwid = others .get_hwid ()
177+ def var (self , name ):
187178
188- self .session_iv = str (uuid4 ())[:8 ]
189-
190- init_iv = SHA256 .new (self .session_iv .encode ()).hexdigest ()
179+ init_iv = SHA256 .new (str (uuid4 ())[:8 ].encode ()).hexdigest ()
191180
192181 post_data = {
193182 "type" : binascii .hexlify (("var" ).encode ()),
194- "key" : encryption .encrypt (self .user_data .key , self .secret , init_iv ),
195- "varid" : encryption .encrypt (name , self .secret , init_iv ),
196- "hwid" : encryption .encrypt (hwid , self .secret , init_iv ),
183+ "varid" : encryption .encrypt (name , self .enckey , init_iv ),
184+ "sessionid" : binascii .hexlify (self .sessionid .encode ()),
197185 "name" : binascii .hexlify (self .name .encode ()),
198186 "ownerid" : binascii .hexlify (self .ownerid .encode ()),
199187 "init_iv" : init_iv
200188 }
201189
202190 response = self .__do_request (post_data )
203191
204- response = encryption .decrypt (response , self .secret , init_iv )
192+ response = encryption .decrypt (response , self .enckey , init_iv )
205193
206194 json = jsond .loads (response )
207195
208196 if json ["success" ]:
209- return json ["response " ]
197+ return json ["message " ]
210198 else :
211199 print (json ["message" ])
212200 time .sleep (5 )
213201 sys .exit ()
214-
202+
203+ def file (self , fileid ):
204+
205+ init_iv = SHA256 .new (str (uuid4 ())[:8 ].encode ()).hexdigest ()
206+
207+ post_data = {
208+ "type" : binascii .hexlify (("file" ).encode ()),
209+ "fileid" : encryption .encrypt (fileid , self .enckey , init_iv ),
210+ "sessionid" : binascii .hexlify (self .sessionid .encode ()),
211+ "name" : binascii .hexlify (self .name .encode ()),
212+ "ownerid" : binascii .hexlify (self .ownerid .encode ()),
213+ "init_iv" : init_iv
214+ }
215+
216+ response = self .__do_request (post_data )
217+
218+ response = encryption .decrypt (response , self .enckey , init_iv )
219+
220+ json = jsond .loads (response )
221+
222+ if not json ["success" ]:
223+ print (json ["message" ])
224+ time .sleep (5 )
225+ sys .exit ()
226+ return binascii .unhexlify (json ["contents" ])
227+
228+ def webhook (self , webid , param ):
229+
230+ init_iv = SHA256 .new (str (uuid4 ())[:8 ].encode ()).hexdigest ()
231+
232+ post_data = {
233+ "type" : binascii .hexlify (("webhook" ).encode ()),
234+ "webid" : encryption .encrypt (webid , self .enckey , init_iv ),
235+ "params" : encryption .encrypt (param , self .enckey , init_iv ),
236+ "sessionid" : binascii .hexlify (self .sessionid .encode ()),
237+ "name" : binascii .hexlify (self .name .encode ()),
238+ "ownerid" : binascii .hexlify (self .ownerid .encode ()),
239+ "init_iv" : init_iv
240+ }
241+
242+ response = self .__do_request (post_data )
243+
244+ response = encryption .decrypt (response , self .enckey , init_iv )
245+ print (response )
246+ json = jsond .loads (response )
247+
248+ if json ["success" ]:
249+ return json ["message" ]
250+ else :
251+ print (json ["message" ])
252+ time .sleep (5 )
253+ sys .exit ()
254+
255+ def log (self , message ):
256+
257+ init_iv = SHA256 .new (str (uuid4 ())[:8 ].encode ()).hexdigest ()
258+
259+ post_data = {
260+ "type" : binascii .hexlify (("log" ).encode ()),
261+ "pcuser" : encryption .encrypt (os .getenv ('username' ), self .enckey , init_iv ),
262+ "message" : encryption .encrypt (message , self .enckey , init_iv ),
263+ "sessionid" : binascii .hexlify (self .sessionid .encode ()),
264+ "name" : binascii .hexlify (self .name .encode ()),
265+ "ownerid" : binascii .hexlify (self .ownerid .encode ()),
266+ "init_iv" : init_iv
267+ }
268+
269+ self .__do_request (post_data )
270+
215271 def __do_request (self , post_data ):
216272 headers = {"User-Agent" : "KeyAuth" }
217273
218274 rq_out = requests .post (
219- "https://keyauth.com/api/v7 /" , data = post_data , headers = headers , verify = "keyauth.pem"
275+ "https://keyauth.com/api/1.0 /" , data = post_data , headers = headers , verify = "keyauth.pem"
220276 )
221277
222278 return rq_out .text
@@ -230,11 +286,7 @@ class user_data_class:
230286 user_data = user_data_class ()
231287
232288 def __load_user_data (self , data ):
233- self .user_data .key = data ["key" ]
234-
235- self .user_data .expiry = datetime .datetime .fromtimestamp (int (data ["expiry" ]))
236-
237- self .user_data .level = data ["level" ]
289+ self .user_data .username = data ["username" ]
238290
239291
240292class others :
0 commit comments