From 58a5e8049d0a2610b1c4f2afbbc5fcd50df9fd53 Mon Sep 17 00:00:00 2001 From: NTAuthority Date: Sat, 7 Mar 2015 23:10:09 +0100 Subject: [PATCH] NPv2 auth support bits --- src/client/NP/NPClient.cs | 6 +- src/client/NPSharp.Client.csproj | 245 +++++++++--------- .../Messages/Data/TicketValidationResult.cs | 64 ++++- ...AuthenticateValidateTicketResultMessage.cs | 5 +- src/client/packages.config | 11 +- 5 files changed, 196 insertions(+), 135 deletions(-) diff --git a/src/client/NP/NPClient.cs b/src/client/NP/NPClient.cs index 27ba3dd..ffa384d 100644 --- a/src/client/NP/NPClient.cs +++ b/src/client/NP/NPClient.cs @@ -187,9 +187,9 @@ namespace NPSharp.NP /// Authenticates a server ticket. /// /// True if the ticket validation succeeded, otherwise false. - public async Task ValidateTicket(IPAddress clientIP, ulong guid, Ticket ticket) + public async Task ValidateTicket(IPAddress clientIP, ulong guid, Ticket ticket) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); RPC.AttachHandlerForNextMessage(packet => { @@ -197,7 +197,7 @@ namespace NPSharp.NP if (result == null) return; - tcs.SetResult(result.Result == 0); + tcs.SetResult(new TicketValidationResult(result)); }); RPC.Send(new AuthenticateValidateTicketMessage diff --git a/src/client/NPSharp.Client.csproj b/src/client/NPSharp.Client.csproj index a82e3a9..d466d27 100644 --- a/src/client/NPSharp.Client.csproj +++ b/src/client/NPSharp.Client.csproj @@ -1,127 +1,130 @@ - - - - - Debug - AnyCPU - {C6F941A5-82AF-456A-9B3A-752E5B001035} - Library - Properties - NPSharp - npsharp_client - v4.5 - 512 - ..\..\ - true - - - true - full - false - bin\Debug\ - TRACE;DEBUG;COMPILE_RPC,COMPILE_NP,COMPILE_AUTH - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE;COMPILE_RPC,COMPILE_NP,COMPILE_AUTH - prompt - 4 - - - - $(SolutionDir)\packages\log4net.2.0.3\lib\net40-full\log4net.dll - - - $(SolutionDir)\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". - - - + + + + + Debug + AnyCPU + {C6F941A5-82AF-456A-9B3A-752E5B001035} + Library + Properties + NPSharp + npsharp_client + v4.5 + 512 + ..\..\ + true + + + true + full + false + bin\Debug\ + TRACE;DEBUG;COMPILE_RPC,COMPILE_NP,COMPILE_AUTH + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE;COMPILE_RPC,COMPILE_NP,COMPILE_AUTH + prompt + 4 + + + + $(SolutionDir)\packages\log4net.2.0.3\lib\net40-full\log4net.dll + + + ..\..\..\..\packages\Newtonsoft.Json.7.0.1-beta1\lib\net45\Newtonsoft.Json.dll + + + $(SolutionDir)\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + - + --> + \ No newline at end of file diff --git a/src/client/RPC/Messages/Data/TicketValidationResult.cs b/src/client/RPC/Messages/Data/TicketValidationResult.cs index 87056fd..d98e622 100644 --- a/src/client/RPC/Messages/Data/TicketValidationResult.cs +++ b/src/client/RPC/Messages/Data/TicketValidationResult.cs @@ -1,11 +1,65 @@ +using System.Collections.Generic; +using System.IO; + +using Newtonsoft.Json.Linq; + namespace NPSharp.RPC.Messages.Data { /// - /// Represents the outcome of a ticket validation attempt. + /// Represents the outcome of a ticket validation attempt, including eventual NPv2 authentication identifiers passed by the server. /// - public enum TicketValidationResult - { - Valid = 0, - Invalid = 1 + public class TicketValidationResult + { + internal TicketValidationResult(Server.AuthenticateValidateTicketResultMessage message) + { + IsValid = message.Result == 0; + + Identifiers = ParseIdentifierList(message.Identifiers); + } + + internal IEnumerable ParseIdentifierList(string serializedList) + { + // current layer1 implementation uses JSON, formatted as `[ [ , ]... ]` - we'll concatenate these as strings to prevent this implementation detail + // this is consistent with the external API for `profiles` in Citizen itself + JToken jsonValue; + + try + { + jsonValue = JToken.Parse(serializedList); + } + catch (FileLoadException) + { + return new string[0]; + } + + var identifiers = new List(); + + if (jsonValue.Type == JTokenType.Array) + { + var array = (JArray)jsonValue; + + foreach (var identifierToken in array.Children()) + { + if (identifierToken.Type == JTokenType.Array) + { + var identifierArray = (JArray)identifierToken; + + identifiers.Add(string.Format("{0}:{1}", identifierArray[0], identifierArray[1])); + } + } + } + + return identifiers; + } + + /// + /// Whether the ticket is valid or not. + /// + public bool IsValid { get; private set; } + + /// + /// A list of NPv2 authentication identifiers belonging to the ticket session. + /// + public IEnumerable Identifiers { get; private set; } } } \ No newline at end of file diff --git a/src/client/RPC/Messages/Server/AuthenticateValidateTicketResultMessage.cs b/src/client/RPC/Messages/Server/AuthenticateValidateTicketResultMessage.cs index 1f55659..32eef88 100644 --- a/src/client/RPC/Messages/Server/AuthenticateValidateTicketResultMessage.cs +++ b/src/client/RPC/Messages/Server/AuthenticateValidateTicketResultMessage.cs @@ -14,6 +14,9 @@ namespace NPSharp.RPC.Messages.Server public UInt64 NPID { get; set; } [ProtoMember(3)] - public int GroupID { get; set; } + public int GroupID { get; set; } + + [ProtoMember(4, IsRequired = false)] + public string Identifiers { get; set; } } } \ No newline at end of file diff --git a/src/client/packages.config b/src/client/packages.config index 9c39bb2..1f02dcb 100644 --- a/src/client/packages.config +++ b/src/client/packages.config @@ -1,6 +1,7 @@ - - - - - + + + + + + \ No newline at end of file