Skip to content

Commit

Permalink
Revert "PS4 OAuth support" (#431)
Browse files Browse the repository at this point in the history
Reverts #411
  • Loading branch information
jvyden authored Apr 24, 2024
2 parents 4d475c8 + ee2270c commit b1bcb8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 46 deletions.
1 change: 0 additions & 1 deletion Refresh.GameServer/Authentication/TokenPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ public enum TokenPlatform
Vita = 2,
Website = 3,
PSP = 4,
PS4 = 5,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics;
using System.Net;
using System.Xml.Serialization;
using Bunkum.Core;
Expand Down Expand Up @@ -33,50 +32,34 @@ public class AuthenticationEndpoints : EndpointGroup
IntegrationConfig integrationConfig,
SmtpService smtpService)
{
bool oauth = context.QueryString.Get("oauth") == "1";

string username;
Ticket? ticket = null;

Ticket ticket;
try
{
if (!oauth)
{
ticket = Ticket.ReadFromStream(body);
username = ticket.Username;
}
else
{
(username, _) = ReadPsnOauthTicket(body);
}
ticket = Ticket.ReadFromStream(body);
}
catch(Exception e)
{
context.Logger.LogWarning(BunkumCategory.Authentication, "Could not read ticket: " + e);
return null;
}


TokenPlatform? platform = ticket?.IssuerId switch
TokenPlatform? platform = ticket.IssuerId switch
{
0x100 => TokenPlatform.PS3,
0x33333333 => TokenPlatform.RPCS3,
_ => null,
};

if (platform == null && oauth)
platform = TokenPlatform.PS4;

GameUser? user = database.GetUserByUsername(username);
GameUser? user = database.GetUserByUsername(ticket.Username);
if (user == null)
{
if (config.RequireGameLoginToRegister)
{
// look for a registration, then use that to create a user
QueuedRegistration? registration = database.GetQueuedRegistrationByUsername(username);
QueuedRegistration? registration = database.GetQueuedRegistrationByUsername(ticket.Username);
if (registration == null)
{
context.Logger.LogWarning(BunkumCategory.Authentication, $"Rejecting {username}'s login because there was no matching queued registration");
context.Logger.LogWarning(BunkumCategory.Authentication, $"Rejecting {ticket.Username}'s login because there was no matching queued registration");
return null;
}

Expand All @@ -102,7 +85,7 @@ public class AuthenticationEndpoints : EndpointGroup
}
else
{
context.Logger.LogWarning(BunkumCategory.Authentication, $"Rejecting {username}'s login because there was no matching username");
context.Logger.LogWarning(BunkumCategory.Authentication, $"Rejecting {ticket.Username}'s login because there was no matching username");
return null;
}
}
Expand All @@ -119,10 +102,8 @@ public class AuthenticationEndpoints : EndpointGroup
}

bool ticketVerified = false;
if (config.UseTicketVerification && !oauth)
if (config.UseTicketVerification)
{
Debug.Assert(ticket != null);

if ((platform is TokenPlatform.PS3 or TokenPlatform.Vita or TokenPlatform.PSP && !user.PsnAuthenticationAllowed) ||
(platform is TokenPlatform.RPCS3 && !user.RpcnAuthenticationAllowed))
{
Expand Down Expand Up @@ -157,25 +138,22 @@ public class AuthenticationEndpoints : EndpointGroup
// check if we're connecting from a beta build
bool parsedBeta = byte.TryParse(context.QueryString.Get("beta"), out byte isBeta);
if (parsedBeta && isBeta == 1) game = TokenGame.BetaBuild;

if (oauth)
game ??= TokenGame.LittleBigPlanet3; // ps4 only has LBP3

game ??= TokenGameUtility.FromTitleId(ticket!.TitleId);
game ??= TokenGameUtility.FromTitleId(ticket.TitleId);

if (platform == null)
{
database.AddLoginFailNotification("The server could not determine what platform you were trying to connect from.", user);
context.Logger.LogWarning(BunkumCategory.Authentication, $"Could not determine platform from ticket.\n" +
$"Missing IssuerID: {ticket?.IssuerId}");
$"Missing IssuerID: {ticket.IssuerId}");
return null;
}

if (game == null)
{
database.AddLoginFailNotification("The server could not determine what game you were trying to connect from.", user);
context.Logger.LogWarning(BunkumCategory.Authentication, $"Could not determine game from ticket.\n" +
$"Missing TitleID: {ticket?.TitleId}");
$"Missing TitleID: {ticket.TitleId}");
return null;
}

Expand Down Expand Up @@ -203,18 +181,6 @@ public class AuthenticationEndpoints : EndpointGroup
ServerBrand = $"{config.InstanceName} (Refresh {VersionInformation.Version})",
};
}

private static (string, int) ReadPsnOauthTicket(Stream body)
{
// example code: jvyden420:123456
using StreamReader reader = new(body);
string oauthTicket = reader.ReadToEnd();

string username = oauthTicket[..oauthTicket.IndexOf(':')];
int code = int.Parse(oauthTicket[(oauthTicket.IndexOf(':') + 1)..]);

return (username, code);
}

private static bool VerifyTicket(RequestContext context, MemoryStream body, Ticket ticket)
{
Expand Down

0 comments on commit b1bcb8e

Please sign in to comment.