Skip to content

Commit

Permalink
Authentication: Block expired NP tickets from being used (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden authored Aug 6, 2024
2 parents 4102177 + 49c0696 commit c7912d0
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Refresh.GameServer.Database;
using Refresh.GameServer.Extensions;
using Refresh.GameServer.Services;
using Refresh.GameServer.Time;
using Refresh.GameServer.Types.Matching;
using Refresh.GameServer.Types.Roles;
using Refresh.GameServer.Types.UserData;
Expand All @@ -32,7 +33,8 @@ public class AuthenticationEndpoints : EndpointGroup
Stream body,
GameServerConfig config,
IntegrationConfig integrationConfig,
SmtpService smtpService)
SmtpService smtpService,
IDateTimeProvider timeProvider)
{
Ticket ticket;
try
Expand Down Expand Up @@ -114,7 +116,7 @@ public class AuthenticationEndpoints : EndpointGroup
return null;
}

ticketVerified = VerifyTicket(context, (MemoryStream)body, ticket);
ticketVerified = VerifyTicket(context, (MemoryStream)body, ticket, timeProvider);
if (!ticketVerified)
{
SendVerificationFailureNotification(database, user, config);
Expand Down Expand Up @@ -185,7 +187,7 @@ public class AuthenticationEndpoints : EndpointGroup
};
}

private static bool VerifyTicket(RequestContext context, MemoryStream body, Ticket ticket)
private static bool VerifyTicket(RequestContext context, MemoryStream body, Ticket ticket, IDateTimeProvider timeProvider)
{
ITicketSigningKey signingKey;

Expand All @@ -200,6 +202,10 @@ private static bool VerifyTicket(RequestContext context, MemoryStream body, Tick
context.Logger.LogDebug(BunkumCategory.Authentication, "Using PSN LBP ticket key");
signingKey = LbpSigningKey.Instance;
}

// Dont allow use of expired tickets
if (timeProvider.Now > ticket.ExpiryDate)
return false;

// Pass this information into a new ticket verifier
// TODO: make this into a service?
Expand Down

0 comments on commit c7912d0

Please sign in to comment.