-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAPI.js
482 lines (408 loc) · 18.8 KB
/
API.js
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
const crypto = require('crypto');
const axios = require('axios');
const os = require('os')
const { execSync, spawnSync } = require('child_process')
const endpoint = "https://api.authspire.com/v1"
var initialized
var variables = [];
class API {
/**
* @param {string} [app_name] - Name of your application found in the dashboard
* @param {string} [userid] - Your userid can be found in your account settings.
* @param {string} [secret] - Application secret found in the dashboard
* @param {string} [currentVersion] - Current application version.
* @param {string} [publicKey] - Your public key for encryption.
**/
constructor (app_name, userid, secret, currentVersion, publicKey) {
if(API.IsEmpty(app_name) || API.IsEmpty(userid) || API.IsEmpty(secret) || API.IsEmpty(currentVersion) || API.IsEmpty(publicKey)) {
API.Error(InvalidApplication)
}
this.app_name = app_name;
this.userid = userid;
this.secret = secret;
this.currentVersion = currentVersion;
this.publicKey = Encryption.FormatPublicKey(publicKey);
};
Initialize = () => new Promise(async (resolve) => {
this.key = randomString(32);
this.iv = randomString(16);
const data = {
action: Buffer.from("app_info").toString("base64"),
userid: Buffer.from(this.userid).toString("base64"),
app_name: Buffer.from(this.app_name).toString("base64"),
secret: Encryption.AESEncrypt(this.secret, this.key, this.iv),
version: Encryption.AESEncrypt(this.currentVersion, this.key, this.iv),
hash: this.your_hash_here, //Encryption.AESEncrypt(this.your_hash, this.key, this.iv), to use with your hash
key: Encryption.RSAEncrypt(this.key, this.publicKey),
iv: Encryption.RSAEncrypt(this.iv, this.publicKey)
};
let response = await Post(data);
if (response.status == "success") {
this.application_status = Encryption.AESDecrypt(response.application_status, this.key, this.iv);
this.application_hash = Encryption.AESDecrypt(response.application_hash, this.key, this.iv);
this.application_name = Encryption.AESDecrypt(response.application_name, this.key, this.iv);
this.application_version = Encryption.AESDecrypt(response.application_version, this.key, this.iv);
this.application_update_url = Encryption.AESDecrypt(response.update_url, this.key, this.iv);
this.application_user_count = Encryption.AESDecrypt(response.user_count, this.key, this.iv);
initialized = true;
}
else if (response.status == "update_available") {
this.update_url = Encryption.AESDecrypt(response.update_url, this.key, this.iv);
this.application_version = Encryption.AESDecrypt(response.application_version, this.key, this.iv);
API.UpdateApplication(this.update_url, this.application_version)
return resolve(false);
}
else if (response.status == "invalid_hash") {
Error(ApplicationManipulated);
return resolve(false);
}
else if (response.status == "invalid_app") {
Error(InvalidApplication);
return resolve(false);
}
else if (response.status == "paused") {
Error(ApplicationPaused);
return resolve(false);
}
else if (response.status == "locked") {
Error(ApplicationDisabled);
return resolve(false);
}
resolve(true);
})
Login = (username, password) => new Promise(async (resolve) => {
if(!initialized) {
Error(NotInitialized);
return resolve(false);
}
if(!(username || password)) {
Error(NotInitialized);
return resolve(false);
}
this.key = randomString(32);
this.iv = randomString(16);
const data = {
action: Buffer.from("login").toString("base64"),
userid: Buffer.from(this.userid).toString("base64"),
app_name: Buffer.from(this.app_name).toString("base64"),
secret: Encryption.AESEncrypt(this.secret, this.key, this.iv),
username: Encryption.AESEncrypt(username, this.key, this.iv),
password: Encryption.AESEncrypt(password, this.key, this.iv),
hwid: Encryption.AESEncrypt(API.GetUniqueId(), this.key, this.iv),
key: Encryption.RSAEncrypt(this.key, this.publicKey),
iv: Encryption.RSAEncrypt(this.iv, this.publicKey)
};
let response = await Post(data);
if(response.status == "ok") {
this.user_username = Encryption.AESDecrypt(response.username, this.key, this.iv);
this.user_email = Encryption.AESDecrypt(response.email, this.key, this.iv);
this.user_ip = Encryption.AESDecrypt(response.ip, this.key, this.iv);
this.user_expires = Encryption.AESDecrypt(response.expires, this.key, this.iv);
this.user_hwid = Encryption.AESDecrypt(response.hwid, this.key, this.iv);
this.user_last_login = Encryption.AESDecrypt(response.last_login, this.key, this.iv);
this.user_created_at = Encryption.AESDecrypt(response.created_at, this.key, this.iv);
this.user_variable = Encryption.AESDecrypt(response.variable, this.key, this.iv);
this.user_level = Encryption.AESDecrypt(response.level, this.key, this.iv);
let app_variables = Encryption.AESDecrypt(response.app_variables, this.key, this.iv);
app_variables.split(";").forEach(function(app_variable) {
let app_variable_split = app_variable.split(";");
try {
variables.push(app_variable_split[0], app_variable_split[1]);
} catch { }
});
} else if(response.status == "invalid_user") {
Error(InvalidUserCredentials)
return resolve(false)
} else if(response.status == "invalid_details") {
Error(InvalidUserCredentials)
return resolve(false)
} else if(response.status == "license_expired") {
Error(UserLicenseExpired)
return resolve(false)
} else if(response.status == "invalid_hwid") {
Error(UserLicenseTaken)
return resolve(false)
} else if(response.status == "banned") {
Error(UserBanned)
return resolve(false)
} else if(response.status == "blacklisted") {
Error(UserBlacklisted)
return resolve(false)
} else if(response.status == "vpn_blocked") {
Error(VPNBlocked)
return resolve(false)
}
return resolve(true)
})
Register = (username, password, license, email) => new Promise(async (resolve) => {
if(!initialized) {
Error(NotInitialized);
return resolve(false);
}
if(!(username || password || license || email)) {
Error(InvalidLogInfo);
return resolve(false);
}
this.key = randomString(32);
this.iv = randomString(16);
const data = {
action: Buffer.from("register").toString("base64"),
userid: Buffer.from(this.userid).toString("base64"),
app_name: Buffer.from(this.app_name).toString("base64"),
secret: Encryption.AESEncrypt(this.secret, this.key, this.iv),
username: Encryption.AESEncrypt(username, this.key, this.iv),
password: Encryption.AESEncrypt(password, this.key, this.iv),
license: Encryption.AESEncrypt(license, this.key, this.iv),
email: Encryption.AESEncrypt(email, this.key, this.iv),
hwid: Encryption.AESEncrypt(API.GetUniqueId(), this.key, this.iv),
key: Encryption.RSAEncrypt(this.key, this.publicKey),
iv: Encryption.RSAEncrypt(this.iv, this.publicKey)
};
let response = await Post(data);
if(response.status == "user_added") {
return resolve(true)
} else if(response.status == "invalid_details") {
Error(RegisterInvalidDetails)
return resolve(false)
} else if(response.status == "email_taken") {
Error(RegisterEmailTaken)
return resolve(false)
} else if(response.status == "invalid_license") {
Error(RegisterInvalidLicense)
return resolve(false)
} else if(response.status == "user_already_exists") {
Error(UserExists)
return resolve(false)
} else if(response.status == "blacklisted") {
Error(UserBlacklisted)
return resolve(false)
} else if(response.status == "vpn_blocked") {
Error(VPNBlocked)
return resolve(false)
}
return resolve(true)
});
License = (license) => new Promise(async (resolve) => {
if(!initialized) {
Error(NotInitialized);
return resolve(false);
}
if(!(license)) {
Error(InvalidLoginInfo);
return resolve(false);
}
this.key = randomString(32);
this.iv = randomString(16);
const data = {
action: Buffer.from("license").toString("base64"),
userid: Buffer.from(this.userid).toString("base64"),
app_name: Buffer.from(this.app_name).toString("base64"),
secret: Encryption.AESEncrypt(this.secret, this.key, this.iv),
license: Encryption.AESEncrypt(license, this.key, this.iv),
hwid: Encryption.AESEncrypt(API.GetUniqueId(), this.key, this.iv),
key: Encryption.RSAEncrypt(this.key, this.publicKey),
iv: Encryption.RSAEncrypt(this.iv, this.publicKey)
};
let response = await Post(data);
if(response.status == "ok") {
this.user_username = Encryption.AESDecrypt(response.username, this.key, this.iv);
this.user_email = Encryption.AESDecrypt(response.email, this.key, this.iv);
this.user_ip = Encryption.AESDecrypt(response.ip, this.key, this.iv);
this.user_expires = Encryption.AESDecrypt(response.expires, this.key, this.iv);
this.user_hwid = Encryption.AESDecrypt(response.hwid, this.key, this.iv);
this.user_last_login = Encryption.AESDecrypt(response.last_login, this.key, this.iv);
this.user_created_at = Encryption.AESDecrypt(response.created_at, this.key, this.iv);
this.user_variable = Encryption.AESDecrypt(response.variable, this.key, this.iv);
this.user_level = Encryption.AESDecrypt(response.level, this.key, this.iv);
let app_variables = Encryption.AESDecrypt(response.app_variables, this.key, this.iv);
app_variables.split(";").forEach(function(app_variable) {
let app_variable_split = app_variable.split(":");
try {
variables.push(app_variable_split);
} catch { }
});
return resolve(true)
} else if(response.status == "invalid_user") {
Error(InvalidUserCredentials)
return resolve(false)
} else if(response.status == "user_limit_reached") {
Error(UserLimitReached)
return resolve(false)
} else if(response.status == "invalid_license") {
Error(RegisterInvalidLicense)
return resolve(false)
} else if(response.status == "license_expired") {
Error(UserLicenseExpired)
return resolve(false)
} else if(response.status == "invalid_hwid") {
Error(UserLicenseTaken)
return resolve(false)
} else if(response.status == "banned") {
Error(UserBanned)
return resolve(false)
} else if(response.status == "license_taken") {
Error(UserLicenseTaken)
return resolve(false)
} else if(response.status == "blacklisted") {
Error(UserBlacklisted)
return resolve(false)
} else if(response.status == "vpn_blocked") {
Error(VPNBlocked)
return resolve(false)
}
return resolve(true)
});
AddLog = (username, action) => new Promise(async (resolve) => {
if(!initialized) {
Error(NotInitialized);
return resolve(false);
}
if(!(username || action)) {
Error(InvalidLoginInfo);
return resolve(false);
}
this.key = randomString(32);
this.iv = randomString(16);
const data = {
action: Buffer.from("log").toString("base64"),
userid: Buffer.from(this.userid).toString("base64"),
app_name: Buffer.from(this.app_name).toString("base64"),
secret: Encryption.AESEncrypt(this.secret, this.key, this.iv),
username: Encryption.AESEncrypt(username, this.key, this.iv),
user_action: Encryption.AESEncrypt(action, this.key, this.iv),
key: Encryption.RSAEncrypt(this.key, this.publicKey),
iv: Encryption.RSAEncrypt(this.iv, this.publicKey)
};
let response = await Post(data);
if (response.status == "log_added") {
return resolve(true)
}
else if (response.status == "failed") {
Error(FailedToAddLog)
return resolve(false)
}
else if (response.status == "invalid_log_info") {
Error(InvalidLogInfo)
return resolve(false)
}
else if (response.status == "log_limit_reached") {
Error(LogLimitReached);
return resolve(false);
}
resolve(true);
})
GetVariable = (secret) => new Promise(async (resolve) => {
if(!initialized) {
Error(NotInitialized);
return resolve(false);
}
for (let index = 0; index < variables.length; index++) {
if(variables[index][0] == secret) {
resolve(variables[index][1]);
}
}
});
static UpdateApplication(url, version) {
if (os.platform() != 'win32') return
const msg = `Update ${version} available!`;
spawnSync("powershell.exe", [`
Add-Type -AssemblyName PresentationCore,PresentationFramework;
[System.Windows.MessageBox]::Show('${msg}');
`]);
execSync("start " + url)
}
static IsEmpty(input) {
if (input == '') {
return true
} else {
return false
}
}
static GetUniqueId() {
if (os.platform() != 'win32') return false
const cmd = execSync('wmic useraccount where name="%username%" get sid').toString('utf-8')
const system_id = cmd.split('\n')[1].trim()
return system_id
}
}
function Error(msg) {
console.log(msg)
return process.exit(-1)
}
function Post(data) {
return new Promise(async (resolve) => {
const request = await axios({
method: 'POST',
url: endpoint,
data: new URLSearchParams(data).toString()
}).catch((err) => {
Misc.error(err)
})
if (request && request.data) {
resolve(request.data)
} else {
resolve(null)
}
})
}
class Encryption {
static RSAEncrypt(input, key) {
var buffer = Buffer.from(input)
var encrypted = crypto.publicEncrypt({ key: key, padding: crypto.constants.RSA_PKCS1_PADDING,}, buffer)
return encrypted.toString("base64")
}
static AESDecrypt(input_enc, key, iv) {
const cipher = crypto.createDecipheriv("aes-256-cbc", key, iv)
let dec = cipher.update(input_enc, "base64", "utf-8")
dec += cipher.final("utf-8")
return dec
}
static AESEncrypt(input, key, iv) {
const cipher = crypto.createCipheriv("aes-256-cbc", key, iv)
let enc = cipher.update(input, "utf-8", "base64")
enc += cipher.final("base64")
return enc
}
static FormatPublicKey(publicKey) {
let finalPublicKey = "-----BEGIN PUBLIC KEY-----\n"
const chunks = publicKey.match(/.{1,64}(?:\s|)/g);
chunks.forEach((chunk, index) => {
finalPublicKey += chunk + "\n"
})
finalPublicKey += "-----END PUBLIC KEY-----"
return finalPublicKey
}
}
const randomString = (length = 8) => {
let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let str = '';
for (let i = 0; i < length; i++) {
str += chars.charAt(Math.floor(Math.random() * chars.length));
}
return str;
};
const ServerOffline = "Server is currently not responding, try again later!";
const RegisterInvalidLicense = "The license you entered is invalid or already taken!";
const RegisterInvalidDetails = "You entered an invalid username or email!";
const RegisterUsernameTaken = "This username is already taken!";
const RegisterEmailTaken = "This email is already taken!";
const UserExists = "A user with this username already exists!";
const UserLicenseTaken = "This license is already binded to another machine!";
const UserLicenseExpired = "Your license has expired!";
const UserBanned = "You have been banned for violating the TOS!";
const UserBlacklisted = "Your IP/HWID has been blacklisted!";
const VPNBlocked = "You cannot use a vpn with our service! Please disable it.";
const InvalidUser = "User doesn't exist!";
const InvalidUserCredentials = "Username or password doesn't match!";
const InvalidLoginInfo = "Invalid login information!";
const InvalidLogInfo = "Invalid log information!";
const LogLimitReached = "You can only add a maximum of 50 logs as a free user, upgrade to premium to enjoy no log limits!";
const UserLimitReached = "You can only add a maximum of 30 users as a free user, upgrade to premium to enjoy no user limits!";
const FailedToAddLog = "Failed to add log, contact the provider!";
const InvalidApplication = "Application could not be initialized, please check your secret and userid.";
const ApplicationPaused = "This application is currently under construction, please try again later!";
const NotInitialized = "Please initialize your application first!";
const NotLoggedIn = "Please log into your application first!";
const ApplicationDisabled = "Application has been disabled by the provider.";
const ApplicationManipulated = "File corrupted! This program has been manipulated or cracked. This file won't work anymore.";
module.exports = API