-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEauth.cs
555 lines (517 loc) · 21.8 KB
/
Eauth.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Text;
using System.Linq;
using System.Text.Json;
using System.Diagnostics;
using System.Windows.Forms;
namespace Eauth
{
class EauthPrimaryClass
{
/* Required configuration */
private string accountKey = ""; // account key goes here
private string applicationKey = ""; // Your application key goes here
private string applicationID = ""; // Your application ID goes here
private string applicationVersion = "1.0"; // Your application version goes here
/* Advanced configuration */
private string invalidAccountKeyMessage = "Invalid account key!";
private string invalidApplicationKeyMessage = "Invalid application key!";
private string invalidRequestMessage = "Invalid request!";
private string outdatedVersionMessage = "Outdated version, please upgrade!";
private string busySessionsMessage = "Please try again later!";
private string unavaiableSessionMessage = "Invalid session. Please re-launch the app!";
private string usedSessionMessage = "Why did the computer go to therapy? Because it had a case of 'Request Repeatitis' and couldn't stop asking for the same thing over and over again!";
private string overcrowdedSessionMessage = "Session limit exceeded. Please re-launch the app!";
private string expiredSessionMessage = "Your session has timed out. please re-launch the app!";
private string invalidUserMessage = "Incorrect login credentials!";
private string bannedUserMessage = "Access denied!";
private string incorrectHwidMessage = "Hardware ID mismatch. Please try again with the correct device!";
private string expiredUserMessage = "Your subscription has ended. Please renew to continue using our service!";
private string usedNameMessage = "Username already taken. Please choose a different username!";
private string invalidKeyMessage = "Invalid key. Please enter a valid key!";
private string upgradeYourEauthMessage = "Upgrade your Eauth plan to exceed the limits!";
private string unauthorizedSessionMessage = "Unauthorized session.";
private string invalidFileMessage = "Incorrect file credentials!";
private string invalidEmailMessage = "The email you entered is either already in use or unavailable or invalid!";
/* Dynamic configuration (this refers to configuration settings that can be changed during runtime) */
private static bool init;
private static string sessionID;
private static string appStatus;
public static string appName;
public static string loggedMessage;
public static string registeredMessage;
private static bool login;
public static string userRank;
public static string registerDate;
public static string expireDate;
public static string userHwid;
private static bool register;
private static bool reset;
public static string errorMessage;
private static readonly HttpClient _client = new HttpClient();
public static string ComputeSHA512(string input)
{
using (SHA512 sha512 = SHA512.Create())
{
byte[] inputBytes = Encoding.UTF8.GetBytes(input);
byte[] hashBytes = sha512.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
foreach (byte b in hashBytes)
{
sb.Append(b.ToString("x2"));
}
return sb.ToString();
}
}
private string GenerateAuthToken(string message, string appID)
{
long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
string authToken = timestamp.ToString().Substring(0, 4) + message + appID;
return ComputeSHA512(authToken);
}
// Send post requests to Eauth
private async Task<string> EauthRequest(Dictionary<string, string> data)
{
var url = "https://eauth.us.to/api/1.1/";
var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Headers.Add("User-Agent", "e_a_u_t_h");
var content = new FormUrlEncodedContent(data);
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
request.Content = content;
var response = await _client.SendAsync(request);
var responseContent = await response.Content.ReadAsStringAsync();
JsonDocument document = JsonDocument.Parse(responseContent);
string message = document.RootElement.GetProperty("message").GetString();
if (message == "init_success" || message == "login_success" || message == "register_success" || message == "var_grab_success")
{
string authorizationKey = response.Headers.GetValues("Key").FirstOrDefault();
if (authorizationKey != GenerateAuthToken(responseContent, applicationID))
{
Environment.Exit(0);
}
}
return responseContent;
}
// Log Eauth errors
private void LogEauthError(string message)
{
errorMessage = message;
}
public string GetHardwareID()
{
string hardwareID = string.Empty;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
hardwareID = WindowsIdentity.GetCurrent().User.Value;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
string machineIDFile = "/etc/machine-id";
if (File.Exists(machineIDFile))
{
hardwareID = File.ReadAllText(machineIDFile).Trim();
}
}
else
{
// Unsupported operating system
throw new PlatformNotSupportedException();
}
return hardwareID;
}
// Initialization request (https://eauth.gitbook.io/eauth-api-1.1-latest/step-by-step/initialization)
public async Task<bool> InitRequest()
{
if (init)
{
return init;
}
var data = new Dictionary<string, string>
{
{ "sort", "init" },
{ "appkey", applicationKey },
{ "acckey", accountKey },
{ "version", applicationVersion.ToString() },
{ "hwid", GetHardwareID() }
};
var response = await EauthRequest(data);
JsonDocument document = JsonDocument.Parse(response);
string message = document.RootElement.GetProperty("message").GetString();
if (message == "init_success")
{
// Init success
init = true;
sessionID = document.RootElement.GetProperty("session_id").GetString();
appStatus = document.RootElement.GetProperty("app_status").GetString();
appName = document.RootElement.GetProperty("app_name").GetString();
loggedMessage = document.RootElement.GetProperty("logged_message").GetString();
registeredMessage = document.RootElement.GetProperty("registered_message").GetString();
}
else if (message == "invalid_account_key")
{
LogEauthError(invalidAccountKeyMessage);
}
else if (message == "invalid_application_key")
{
LogEauthError(invalidApplicationKeyMessage);
}
else if (message == "invalid_request")
{
LogEauthError(invalidRequestMessage); // This is usually not the case
}
else if (message == "version_outdated")
{
string download_link = document.RootElement.GetProperty("download_link").GetString();
if (download_link != "")
{
Process.Start(download_link);
}
LogEauthError(outdatedVersionMessage);
}
else if (message == "maximum_sessions_reached")
{
LogEauthError(busySessionsMessage);
}
else if (message == "init_paused")
{
LogEauthError(document.RootElement.GetProperty("paused_message").GetString());
}
else if (message == "user_is_banned")
{
LogEauthError(bannedUserMessage);
}
return init;
}
// Register request (https://eauth.gitbook.io/eauth-api-1.1-latest/step-by-step/register)
public async Task<bool> RegisterRequest(string username, string email, string password, string key)
{
var data = new Dictionary<string, string>
{
{ "sort", "register" },
{ "sessionid", sessionID },
{ "username", username },
{ "email", email },
{ "password", password },
{ "key", key },
{ "hwid", GetHardwareID() }
};
var response = await EauthRequest(data);
JsonDocument document = JsonDocument.Parse(response);
string message = document.RootElement.GetProperty("message").GetString();
if (message == "register_success")
{
// Register success
register = true;
}
else if (message == "session_unavailable")
{
LogEauthError(unavaiableSessionMessage);
}
else if (message == "invalid_email")
{
LogEauthError(invalidEmailMessage);
}
else if (message == "session_already_used")
{
LogEauthError(usedSessionMessage);
}
else if (message == "invalid_request")
{
LogEauthError(invalidRequestMessage); // This is usually not the case
}
else if (message == "invalid_account_key")
{
LogEauthError(invalidAccountKeyMessage);
}
else if (message == "session_overcrowded")
{
LogEauthError(overcrowdedSessionMessage);
}
else if (message == "session_expired")
{
LogEauthError(expiredSessionMessage);
}
else if (message == "name_already_used")
{
LogEauthError(usedNameMessage);
}
else if (message == "key_unavailable")
{
LogEauthError(invalidKeyMessage);
}
else if (message == "maximum_users_reached")
{
LogEauthError(upgradeYourEauthMessage);
}
else if (message == "user_is_banned")
{
LogEauthError(bannedUserMessage);
}
return register;
}
// Login request (https://eauth.gitbook.io/eauth-api-1.1-latest/step-by-step/login)
public async Task<bool> LoginRequest(string username, string password, string key)
{
if (login)
{
return login;
}
if (key.Length > 0)
{
username = password = key;
var register_data = new Dictionary<string, string>
{
{ "sort", "register" },
{ "sessionid", sessionID },
{ "username", username },
{ "password", password },
{ "key", key },
{ "hwid", GetHardwareID() }
};
var register_response = await EauthRequest(register_data);
JsonDocument register_document = JsonDocument.Parse(register_response);
string register_message = register_document.RootElement.GetProperty("message").GetString();
if (register_message != "register_success" && register_message != "name_already_used")
{
LogEauthError(invalidKeyMessage);
}
}
var data = new Dictionary<string, string>
{
{ "sort", "login" },
{ "sessionid", sessionID },
{ "username", username },
{ "password", password },
{ "hwid", GetHardwareID() }
};
var response = await EauthRequest(data);
JsonDocument document = JsonDocument.Parse(response);
string message = document.RootElement.GetProperty("message").GetString();
if (message == "login_success")
{
// Login success
login = true;
userRank = document.RootElement.GetProperty("rank").GetString();
registerDate = document.RootElement.GetProperty("register_date").GetString();
expireDate = document.RootElement.GetProperty("expire_date").GetString();
userHwid = document.RootElement.GetProperty("hwid").GetString();
}
else if (message == "invalid_account_key")
{
LogEauthError(invalidAccountKeyMessage);
}
else if (message == "session_unavailable")
{
LogEauthError(unavaiableSessionMessage);
}
else if (message == "invalid_request")
{
LogEauthError(invalidRequestMessage); // This is usually not the case
}
else if (message == "session_already_used")
{
LogEauthError(usedSessionMessage);
}
else if (message == "session_overcrowded")
{
LogEauthError(overcrowdedSessionMessage);
}
else if (message == "session_expired")
{
LogEauthError(expiredSessionMessage);
}
else if (message == "account_unavailable")
{
LogEauthError(invalidUserMessage);
}
else if (message == "user_is_banned")
{
LogEauthError(bannedUserMessage);
}
else if (message == "hwid_incorrect")
{
LogEauthError(incorrectHwidMessage + "\n" + "HWID reset is available " + document.RootElement.GetProperty("estimated_reset_time").GetString());
}
else if (message == "subscription_expired")
{
LogEauthError(expiredUserMessage);
}
return login;
}
// Reset password request (https://eauth.gitbook.io/eauth-api-1.1-latest/step-by-step/password-reset)
public async Task<bool> ResetPasswordRequest(string email)
{
if (login || reset)
{
LogEauthError(usedSessionMessage);
return false;
}
var data = new Dictionary<string, string>
{
{ "sort", "reset_password" },
{ "sessionid", sessionID },
{ "email", email }
};
var response = await EauthRequest(data);
JsonDocument document = JsonDocument.Parse(response);
string message = document.RootElement.GetProperty("message").GetString();
if (message == "sent_email")
{
// Reset success
reset = true;
}
else if (message == "session_unavailable")
{
LogEauthError(unavaiableSessionMessage);
}
else if (message == "invalid_email")
{
LogEauthError(invalidEmailMessage);
}
else if (message == "session_unauthorized")
{
LogEauthError(unauthorizedSessionMessage);
}
else if (message == "invalid_request")
{
LogEauthError(invalidRequestMessage); // This is usually not the case
}
else if (message == "invalid_application_key")
{
LogEauthError(invalidApplicationKeyMessage);
}
else if (message == "session_expired")
{
LogEauthError(expiredSessionMessage);
}
return reset;
}
// Download request (https://eauth.gitbook.io/eauth-api-1.1-latest/step-by-step/download-file)
public async Task<bool>DownloadRequest(string fileID, string outputPath, string fileName)
{
if (!init)
{
LogEauthError(unavaiableSessionMessage);
}
var data = new Dictionary<string, string>
{
{ "sort", "download" },
{ "sessionid", sessionID },
{ "fileid", fileID }
};
var response = await EauthRequest(data);
JsonDocument document = JsonDocument.Parse(response);
string message = document.RootElement.GetProperty("message").GetString();
bool downloadStatus = false;
if (message == "download_success")
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage fResponse = await client.GetAsync(document.RootElement.GetProperty("link").GetString());
if (fResponse.IsSuccessStatusCode)
{
byte[] fileBytes = await fResponse.Content.ReadAsByteArrayAsync();
// Ensure the output directory exists
Directory.CreateDirectory(outputPath);
// Construct the full file path
string filePath = Path.Combine(outputPath, fileName);
// Write the file with the provided bytes
File.WriteAllBytes(filePath, fileBytes);
// Set return to true;
downloadStatus = true;
}
else
{
LogEauthError(invalidFileMessage);
}
}
}
else if (message == "session_unavailable")
{
LogEauthError(unavaiableSessionMessage);
}
else if (message == "session_unauthorized")
{
LogEauthError(unauthorizedSessionMessage);
}
else if (message == "invalid_request")
{
LogEauthError(invalidRequestMessage); // This is usually not the case
}
else if (message == "invalid_account_key")
{
LogEauthError(invalidAccountKeyMessage);
}
else if (message == "session_expired")
{
LogEauthError(expiredSessionMessage);
}
else if (message == "invalid_file")
{
LogEauthError(invalidFileMessage);
}
return downloadStatus;
}
// Upgrade request (https://eauth.gitbook.io/eauth-api-1.1-latest/step-by-step/upgrade)
public async Task<bool> UpgradeRequest(string username, string key)
{
bool upgrade = false;
var data = new Dictionary<string, string>
{
{ "sort", "upgrade" },
{ "sessionid", sessionID },
{ "username", username },
{ "key", key }
};
var response = await EauthRequest(data);
JsonDocument document = JsonDocument.Parse(response);
string message = document.RootElement.GetProperty("message").GetString();
if (message == "upgrade_success")
{
// Upgrade success
upgrade = true;
}
else if (message == "session_unavailable")
{
LogEauthError(unavaiableSessionMessage);
}
else if (message == "account_unavailable")
{
LogEauthError(invalidUserMessage);
}
else if (message == "key_unavailable")
{
LogEauthError(invalidKeyMessage);
}
else if (message == "invalid_email")
{
LogEauthError(invalidEmailMessage);
}
else if (message == "session_unauthorized")
{
LogEauthError(unauthorizedSessionMessage);
}
else if (message == "invalid_request")
{
LogEauthError(invalidRequestMessage); // This is usually not the case
}
else if (message == "invalid_account_key")
{
LogEauthError(invalidAccountKeyMessage);
}
else if (message == "session_expired")
{
LogEauthError(expiredSessionMessage);
}
return upgrade;
}
}
}