Created
April 24, 2015 02:31
-
-
Save paralin/07b4e12fbab10b9ee8ad to your computer and use it in GitHub Desktop.
AuthTicket.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Collections.Immutable; | |
using System.IO; | |
using System.Linq; | |
using System.Net; | |
using SteamKit2; | |
namespace nora.clara | |
{ | |
public class AuthTicket | |
{ | |
int timeStart; | |
private Client bot; | |
public AuthTicket(Client bot) | |
{ | |
this.bot = bot; | |
timeStart = Environment.TickCount; | |
} | |
public Ticket GetTicket() | |
{ | |
byte[] ticketData; | |
using (MemoryStream ms = new MemoryStream()) | |
{ | |
using (BinaryWriter bw = new BinaryWriter(ms)) | |
{ | |
byte[] token = bot.Bot.NextToken().ToArray(); | |
bw.Write(token.Length); | |
bw.Write(token); | |
byte[] sessionHeader = BuildSessionHeader(); | |
bw.Write(sessionHeader.Length); | |
bw.Write(sessionHeader); | |
byte[] ownershipSectionWithSig = BuildOwnershipSectionWithSignature(); | |
bw.Write(ownershipSectionWithSig.Length); | |
bw.Write(ownershipSectionWithSig); | |
ticketData = ms.ToArray(); | |
} | |
} | |
byte[] ticketCrc = CryptoHelper.CRCHash( ticketData ); | |
return new Ticket() | |
{ | |
Data = ticketData, | |
CRC = BitConverter.ToUInt32( ticketCrc, 0 ), | |
}; | |
} | |
public class Ticket | |
{ | |
public byte[] Data { get; set; } | |
public uint CRC { get; set; } | |
} | |
public uint GetIP() | |
{ | |
return BitConverter.ToUInt32( bot.Bot.PublicIP.GetAddressBytes(), 0 ); | |
} | |
byte[] BuildSessionHeader() | |
{ | |
using (MemoryStream ms = new MemoryStream()) | |
{ | |
using (BinaryWriter bw = new BinaryWriter(ms)) | |
{ | |
bw.Write((uint) 1); | |
bw.Write((uint) 2); | |
bw.Write(GetIP()); | |
bw.Write((uint) 0); | |
var time = (DateTime.UtcNow - bot.Bot.TimeConnected).TotalMilliseconds; | |
bw.Write(time); | |
bw.Write(bot.Bot.ConnectCount++); | |
return ms.ToArray(); | |
} | |
} | |
} | |
byte[] BuildOwnershipSectionWithSignature() | |
{ | |
using (MemoryStream ms = new MemoryStream()) | |
{ | |
using (BinaryWriter bw = new BinaryWriter(ms)) | |
{ | |
bw.Write(bot.AppOwnershipTicket.Length); | |
bw.Write(bot.AppOwnershipTicket); | |
return ms.ToArray(); | |
} | |
} | |
} | |
public static byte[] CreateAuthTicket(Client bot) | |
{ | |
var tick = new AuthTicket(bot); | |
return tick.GetTicket().Data; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment