From ee2270c55a987452b041b38db03e7c925aa294c4 Mon Sep 17 00:00:00 2001 From: jvyden Date: Wed, 24 Apr 2024 14:48:48 -0400 Subject: [PATCH] Revert "PS4 OAuth support" --- .../Authentication/TokenPlatform.cs | 1 - .../Game/Handshake/AuthenticationEndpoints.cs | 56 ++++--------------- 2 files changed, 11 insertions(+), 46 deletions(-) diff --git a/Refresh.GameServer/Authentication/TokenPlatform.cs b/Refresh.GameServer/Authentication/TokenPlatform.cs index 244645f3..e052eda8 100644 --- a/Refresh.GameServer/Authentication/TokenPlatform.cs +++ b/Refresh.GameServer/Authentication/TokenPlatform.cs @@ -7,5 +7,4 @@ public enum TokenPlatform Vita = 2, Website = 3, PSP = 4, - PS4 = 5, } \ No newline at end of file diff --git a/Refresh.GameServer/Endpoints/Game/Handshake/AuthenticationEndpoints.cs b/Refresh.GameServer/Endpoints/Game/Handshake/AuthenticationEndpoints.cs index 83dd3ddf..ab7604a1 100644 --- a/Refresh.GameServer/Endpoints/Game/Handshake/AuthenticationEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/Handshake/AuthenticationEndpoints.cs @@ -1,4 +1,3 @@ -using System.Diagnostics; using System.Net; using System.Xml.Serialization; using Bunkum.Core; @@ -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; } @@ -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; } } @@ -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)) { @@ -157,17 +138,14 @@ 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; } @@ -175,7 +153,7 @@ public class AuthenticationEndpoints : EndpointGroup { 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; } @@ -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) {