mirror of
https://github.com/ibratabian17/OpenParty.git
synced 2026-01-15 14:22:54 -03:00
Improve CustomAuth Handler
This commit is contained in:
@@ -53,6 +53,7 @@ const generateFalseTicket = () => {
|
||||
return start + middle + end;
|
||||
};
|
||||
|
||||
|
||||
const atob = (base64) => Buffer.from(base64, 'base64').toString('utf-8');
|
||||
const parseCustomAuthHeader = (authorization) => {
|
||||
const [method, encoded] = authorization.split(" ");
|
||||
@@ -94,8 +95,7 @@ exports.initroute = (app, express, server) => {
|
||||
app.post("/v3/profiles/sessions", async (req, res) => {
|
||||
const clientIp = getClientIp(req);
|
||||
const clientIpCountry = getCountryFromIp(clientIp);
|
||||
|
||||
// Helper to generate session data
|
||||
|
||||
const generateSessionData = (profileId, username, clientIp, clientIpCountry, ticket) => {
|
||||
const now = new Date();
|
||||
const expiration = new Date(now.getTime() + 3 * 60 * 60 * 1000); // 3 hours
|
||||
@@ -119,30 +119,42 @@ exports.initroute = (app, express, server) => {
|
||||
};
|
||||
return data;
|
||||
};
|
||||
|
||||
// Remove Host header
|
||||
|
||||
const headers = { ...req.headers };
|
||||
delete headers.host;
|
||||
|
||||
|
||||
const customAuthData = parseCustomAuthHeader(headers.authorization);
|
||||
|
||||
|
||||
if (customAuthData) {
|
||||
console.log("[ACC] CustomAuth detected, verifying...");
|
||||
|
||||
|
||||
const { profileId, username, email, password } = customAuthData;
|
||||
const userData = getUserData(profileId);
|
||||
const ticket = `CustomAuth${headers.authorization.split(" t=")[1]}`
|
||||
|
||||
if (userData && atob(userData.password) === password) {
|
||||
console.log("[ACC] CustomAuth login: ", atob(username));
|
||||
updateUser(profileId, { username: atob(username), email, password, userId: profileId, ticket: `Ubi_v1 ${ticket}` });
|
||||
const sessionData = generateSessionData(profileId, username, clientIp, clientIpCountry, ticket)
|
||||
res.send(sessionData);
|
||||
return;
|
||||
} else if (userData && atob(userData.password) !== password) {
|
||||
console.log("[ACC] CustomAuth login password failed: ", atob(username));
|
||||
const ticket = `CustomAuth${headers.authorization.split(" t=")[1]}`;
|
||||
|
||||
if (userData) {
|
||||
const storedPassword = userData.password ? userData.password : null;
|
||||
|
||||
if (storedPassword === password) {
|
||||
console.log("[ACC] CustomAuth login: ", atob(username));
|
||||
updateUser(profileId, { username: atob(username), email, password, userId: profileId, ticket: `Ubi_v1 ${ticket}` });
|
||||
const sessionData = generateSessionData(profileId, username, clientIp, clientIpCountry, ticket);
|
||||
res.send(sessionData);
|
||||
return;
|
||||
} else if (storedPassword && storedPassword !== password) {
|
||||
console.log("[ACC] CustomAuth login password failed: ", atob(username));
|
||||
console.log(`[ACC] CPassword: ${storedPassword.substring(0,4)} || ${storedPassword.substring(0,4)}`);
|
||||
} else {
|
||||
console.log("[ACC] CustomAuth login password missing, verifying ticket.");
|
||||
if (userData.ticket && userData.ticket.includes(ticket)) {
|
||||
updateUser(profileId, { username: atob(username), email, password, userId: profileId, ticket: `Ubi_v1 ${ticket}` });
|
||||
const sessionData = generateSessionData(profileId, username, clientIp, clientIpCountry, ticket);
|
||||
res.send(sessionData);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!userData) {
|
||||
console.log("[ACC] CustomAuth register: ", atob(username));
|
||||
updateUser(profileId, { username: atob(username), email, password, userId: profileId, ticket: `Ubi_v1 ${ticket}` });
|
||||
@@ -150,37 +162,37 @@ exports.initroute = (app, express, server) => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
console.log("[ACC] Fetching Ticket From Official Server");
|
||||
const response = await axios.post(`${prodwsurl}/v3/profiles/sessions`, req.body, { headers });
|
||||
|
||||
|
||||
res.send(response.data);
|
||||
console.log("[ACC] Using Official Ticket");
|
||||
|
||||
// Update user mappings
|
||||
|
||||
addUserId(response.data.profileId, response.data.userId);
|
||||
updateUserTicket(response.data.profileId, `Ubi_v1 ${response.data.ticket}`);
|
||||
} catch (error) {
|
||||
console.log("[ACC] Error fetching from Ubisoft services", error.message);
|
||||
|
||||
|
||||
if (ipCache[clientIp]) {
|
||||
console.log(`[ACC] Returning cached session for IP ${clientIp}`);
|
||||
return res.send(ipCache[clientIp]);
|
||||
}
|
||||
|
||||
|
||||
const profileId = uuidv4();
|
||||
const userTicket = generateFalseTicket();
|
||||
cachedTicket[userTicket] = profileId;
|
||||
|
||||
|
||||
console.log("[ACC] Generating Fake Session for", profileId);
|
||||
|
||||
|
||||
const fakeSession = generateSessionData(profileId, "NintendoSwitch", clientIp, clientIpCountry, userTicket);
|
||||
ipCache[clientIp] = fakeSession;
|
||||
|
||||
|
||||
res.send(fakeSession);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Handle session deletion
|
||||
|
||||
Reference in New Issue
Block a user