NPv2 auth support bits

feature-npv2
NTAuthority 2015-03-07 23:10:09 +01:00
parent 7f9cc54c54
commit 58a5e8049d
5 changed files with 196 additions and 135 deletions

View File

@ -187,9 +187,9 @@ namespace NPSharp.NP
/// Authenticates a server ticket. /// Authenticates a server ticket.
/// </summary> /// </summary>
/// <returns>True if the ticket validation succeeded, otherwise false.</returns> /// <returns>True if the ticket validation succeeded, otherwise false.</returns>
public async Task<bool> ValidateTicket(IPAddress clientIP, ulong guid, Ticket ticket) public async Task<TicketValidationResult> ValidateTicket(IPAddress clientIP, ulong guid, Ticket ticket)
{ {
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<TicketValidationResult>();
RPC.AttachHandlerForNextMessage(packet => RPC.AttachHandlerForNextMessage(packet =>
{ {
@ -197,7 +197,7 @@ namespace NPSharp.NP
if (result == null) if (result == null)
return; return;
tcs.SetResult(result.Result == 0); tcs.SetResult(new TicketValidationResult(result));
}); });
RPC.Send(new AuthenticateValidateTicketMessage RPC.Send(new AuthenticateValidateTicketMessage

View File

@ -1,127 +1,130 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C6F941A5-82AF-456A-9B3A-752E5B001035}</ProjectGuid> <ProjectGuid>{C6F941A5-82AF-456A-9B3A-752E5B001035}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NPSharp</RootNamespace> <RootNamespace>NPSharp</RootNamespace>
<AssemblyName>npsharp_client</AssemblyName> <AssemblyName>npsharp_client</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages> <RestorePackages>true</RestorePackages>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;COMPILE_RPC,COMPILE_NP,COMPILE_AUTH</DefineConstants> <DefineConstants>TRACE;DEBUG;COMPILE_RPC,COMPILE_NP,COMPILE_AUTH</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;COMPILE_RPC,COMPILE_NP,COMPILE_AUTH</DefineConstants> <DefineConstants>TRACE;COMPILE_RPC,COMPILE_NP,COMPILE_AUTH</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net"> <Reference Include="log4net">
<HintPath>$(SolutionDir)\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath> <HintPath>$(SolutionDir)\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference> </Reference>
<Reference Include="protobuf-net"> <Reference Include="Newtonsoft.Json">
<HintPath>$(SolutionDir)\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath> <HintPath>..\..\..\..\packages\Newtonsoft.Json.7.0.1-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="protobuf-net">
<Reference Include="System.Core" /> <HintPath>$(SolutionDir)\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath>
<Reference Include="System.Xml" /> </Reference>
</ItemGroup> <Reference Include="System" />
<ItemGroup> <Reference Include="System.Core" />
<Compile Include="Authentication\SessionAuthenticationClient.cs" /> <Reference Include="System.Xml" />
<Compile Include="Authentication\SessionAuthenticationResult.cs" /> </ItemGroup>
<Compile Include="Master\Data\MasterGetServersEntry.cs" /> <ItemGroup>
<Compile Include="Master\Data\MasterGetServersKeywords.cs" /> <Compile Include="Authentication\SessionAuthenticationClient.cs" />
<Compile Include="Master\Messages\Client\MasterGetServersMessage.cs" /> <Compile Include="Authentication\SessionAuthenticationResult.cs" />
<Compile Include="Master\DedicatedServerEntry.cs" /> <Compile Include="Master\Data\MasterGetServersEntry.cs" />
<Compile Include="Master\Messages\MasterClientMessage.cs" /> <Compile Include="Master\Data\MasterGetServersKeywords.cs" />
<Compile Include="Master\Messages\MasterClientMessageAttribute.cs" /> <Compile Include="Master\Messages\Client\MasterGetServersMessage.cs" />
<Compile Include="Master\Messages\MasterServerMessage.cs" /> <Compile Include="Master\DedicatedServerEntry.cs" />
<Compile Include="Master\Messages\MasterServerMessageAttribute.cs" /> <Compile Include="Master\Messages\MasterClientMessage.cs" />
<Compile Include="NP\NPAuthenticationResult.cs" /> <Compile Include="Master\Messages\MasterClientMessageAttribute.cs" />
<Compile Include="NP\NPClient.cs" /> <Compile Include="Master\Messages\MasterServerMessage.cs" />
<Compile Include="NP\NPFileException.cs" /> <Compile Include="Master\Messages\MasterServerMessageAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="NP\NPAuthenticationResult.cs" />
<Compile Include="RPC\Messages\Client\AuthenticateRegisterServerMessage.cs" /> <Compile Include="NP\NPClient.cs" />
<Compile Include="RPC\Messages\Client\AuthenticateValidateTicketMessage.cs" /> <Compile Include="NP\NPFileException.cs" />
<Compile Include="RPC\Messages\Client\AuthenticateWithDetailsMessage.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RPC\Messages\Client\AuthenticateWithKeyMessage.cs" /> <Compile Include="RPC\Messages\Client\AuthenticateRegisterServerMessage.cs" />
<Compile Include="RPC\Messages\Client\AuthenticateWithTokenMessage.cs" /> <Compile Include="RPC\Messages\Client\AuthenticateValidateTicketMessage.cs" />
<Compile Include="RPC\Messages\Client\FriendsGetProfileDataMessage.cs" /> <Compile Include="RPC\Messages\Client\AuthenticateWithDetailsMessage.cs" />
<Compile Include="RPC\Messages\Client\FriendsGetUserAvatarMessage.cs" /> <Compile Include="RPC\Messages\Client\AuthenticateWithKeyMessage.cs" />
<Compile Include="RPC\Messages\Client\FriendsSetPresenceMessage.cs" /> <Compile Include="RPC\Messages\Client\AuthenticateWithTokenMessage.cs" />
<Compile Include="RPC\Messages\Client\FriendsSetSteamIDMessage.cs" /> <Compile Include="RPC\Messages\Client\FriendsGetProfileDataMessage.cs" />
<Compile Include="RPC\Messages\Client\MessagingSendDataMessage.cs" /> <Compile Include="RPC\Messages\Client\FriendsGetUserAvatarMessage.cs" />
<Compile Include="RPC\Messages\Client\StorageGetPublisherFileMessage.cs" /> <Compile Include="RPC\Messages\Client\FriendsSetPresenceMessage.cs" />
<Compile Include="RPC\Messages\Client\StorageGetUserFileMessage.cs" /> <Compile Include="RPC\Messages\Client\FriendsSetSteamIDMessage.cs" />
<Compile Include="RPC\Messages\Client\StorageSendRandomStringMessage.cs" /> <Compile Include="RPC\Messages\Client\MessagingSendDataMessage.cs" />
<Compile Include="RPC\Messages\Client\StorageWriteUserFileMessage.cs" /> <Compile Include="RPC\Messages\Client\StorageGetPublisherFileMessage.cs" />
<Compile Include="RPC\Messages\Data\FriendDetails.cs" /> <Compile Include="RPC\Messages\Client\StorageGetUserFileMessage.cs" />
<Compile Include="RPC\Messages\Data\FriendsPresence.cs" /> <Compile Include="RPC\Messages\Client\StorageSendRandomStringMessage.cs" />
<Compile Include="RPC\Messages\Data\PresenceState.cs" /> <Compile Include="RPC\Messages\Client\StorageWriteUserFileMessage.cs" />
<Compile Include="RPC\Messages\Data\ProfileData.cs" /> <Compile Include="RPC\Messages\Data\FriendDetails.cs" />
<Compile Include="RPC\Messages\Data\Ticket.cs" /> <Compile Include="RPC\Messages\Data\FriendsPresence.cs" />
<Compile Include="RPC\Messages\Data\TicketValidationResult.cs" /> <Compile Include="RPC\Messages\Data\PresenceState.cs" />
<Compile Include="RPC\Messages\PacketAttribute.cs" /> <Compile Include="RPC\Messages\Data\ProfileData.cs" />
<Compile Include="RPC\Messages\RPCClientMessage.cs" /> <Compile Include="RPC\Messages\Data\Ticket.cs" />
<Compile Include="RPC\Messages\RPCMessage.cs" /> <Compile Include="RPC\Messages\Data\TicketValidationResult.cs" />
<Compile Include="RPC\Messages\RPCServerMessage.cs" /> <Compile Include="RPC\Messages\PacketAttribute.cs" />
<Compile Include="RPC\Messages\Server\AuthenticateExternalStatusMessage.cs" /> <Compile Include="RPC\Messages\RPCClientMessage.cs" />
<Compile Include="RPC\Messages\Server\AuthenticateRegisterServerResultMessage.cs" /> <Compile Include="RPC\Messages\RPCMessage.cs" />
<Compile Include="RPC\Messages\Server\AuthenticateResultMessage.cs" /> <Compile Include="RPC\Messages\RPCServerMessage.cs" />
<Compile Include="RPC\Messages\Server\AuthenticateUserGroupMessage.cs" /> <Compile Include="RPC\Messages\Server\AuthenticateExternalStatusMessage.cs" />
<Compile Include="RPC\Messages\Server\AuthenticateValidateTicketResultMessage.cs" /> <Compile Include="RPC\Messages\Server\AuthenticateRegisterServerResultMessage.cs" />
<Compile Include="RPC\Messages\Server\CloseAppMessage.cs" /> <Compile Include="RPC\Messages\Server\AuthenticateResultMessage.cs" />
<Compile Include="RPC\Messages\Server\FriendsGetProfileDataResultMessage.cs" /> <Compile Include="RPC\Messages\Server\AuthenticateUserGroupMessage.cs" />
<Compile Include="RPC\Messages\Server\FriendsGetUserAvatarResultMessage.cs" /> <Compile Include="RPC\Messages\Server\AuthenticateValidateTicketResultMessage.cs" />
<Compile Include="RPC\Messages\Server\FriendsPresenceMessage.cs" /> <Compile Include="RPC\Messages\Server\CloseAppMessage.cs" />
<Compile Include="RPC\Messages\Server\FriendsRosterMessage.cs" /> <Compile Include="RPC\Messages\Server\FriendsGetProfileDataResultMessage.cs" />
<Compile Include="RPC\Messages\Server\HelloMessage.cs" /> <Compile Include="RPC\Messages\Server\FriendsGetUserAvatarResultMessage.cs" />
<Compile Include="RPC\Messages\Server\StoragePublisherFileMessage.cs" /> <Compile Include="RPC\Messages\Server\FriendsPresenceMessage.cs" />
<Compile Include="RPC\Messages\Server\StorageUserFileMessage.cs" /> <Compile Include="RPC\Messages\Server\FriendsRosterMessage.cs" />
<Compile Include="RPC\Messages\Server\StorageWriteUserFileResultMessage.cs" /> <Compile Include="RPC\Messages\Server\HelloMessage.cs" />
<Compile Include="RPC\RPCClientStream.cs" /> <Compile Include="RPC\Messages\Server\StoragePublisherFileMessage.cs" />
<Compile Include="RPC\RPCStream.cs" /> <Compile Include="RPC\Messages\Server\StorageUserFileMessage.cs" />
<Compile Include="Steam\CSteamID.cs" /> <Compile Include="RPC\Messages\Server\StorageWriteUserFileResultMessage.cs" />
<Compile Include="Steam\EAccountType.cs" /> <Compile Include="RPC\RPCClientStream.cs" />
<Compile Include="Steam\EUniverse.cs" /> <Compile Include="RPC\RPCStream.cs" />
<Compile Include="Steam\InteropHelp.cs" /> <Compile Include="Steam\CSteamID.cs" />
<Compile Include="Steam\SteamID_t.cs" /> <Compile Include="Steam\EAccountType.cs" />
</ItemGroup> <Compile Include="Steam\EUniverse.cs" />
<ItemGroup> <Compile Include="Steam\InteropHelp.cs" />
<None Include="packages.config" /> <Compile Include="Steam\SteamID_t.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Steam\README.txt" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ItemGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <Content Include="Steam\README.txt" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> </ItemGroup>
<PropertyGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ErrorText>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}".</ErrorText> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</PropertyGroup> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> <PropertyGroup>
</Target> <ErrorText>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}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>

View File

@ -1,11 +1,65 @@
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
namespace NPSharp.RPC.Messages.Data namespace NPSharp.RPC.Messages.Data
{ {
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public enum TicketValidationResult public class TicketValidationResult
{ {
Valid = 0, internal TicketValidationResult(Server.AuthenticateValidateTicketResultMessage message)
Invalid = 1 {
IsValid = message.Result == 0;
Identifiers = ParseIdentifierList(message.Identifiers);
}
internal IEnumerable<string> ParseIdentifierList(string serializedList)
{
// current layer1 implementation uses JSON, formatted as `[ [ <type>, <value> ]... ]` - 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<string>();
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;
}
/// <summary>
/// Whether the ticket is valid or not.
/// </summary>
public bool IsValid { get; private set; }
/// <summary>
/// A list of NPv2 authentication identifiers belonging to the ticket session.
/// </summary>
public IEnumerable<string> Identifiers { get; private set; }
} }
} }

View File

@ -14,6 +14,9 @@ namespace NPSharp.RPC.Messages.Server
public UInt64 NPID { get; set; } public UInt64 NPID { get; set; }
[ProtoMember(3)] [ProtoMember(3)]
public int GroupID { get; set; } public int GroupID { get; set; }
[ProtoMember(4, IsRequired = false)]
public string Identifiers { get; set; }
} }
} }

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="log4net" version="2.0.3" targetFramework="net45" /> <package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="protobuf-net" version="2.0.0.668" targetFramework="net45" /> <package id="Newtonsoft.Json" version="7.0.1-beta1" targetFramework="net45" />
<package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
</packages> </packages>