protected TResponsePayload PostProtoPayload <TRequest, TResponsePayload>(RequestEnvelope.Types.PlatformRequest platfReq) where TRequest : IMessage <TRequest> where TResponsePayload : IMessage <TResponsePayload>, new() { var tries = 0; while (tries < 3) { try { var requestEnvelops = GetRequestBuilder().GetPlatformRequestEnvelope(platfReq); return(Client.PokemonHttpClient.PostProtoPayload <TRequest, TResponsePayload>(Client.ApiUrl, requestEnvelops, Client.ApiFailure)); } catch (AccessTokenExpiredException) { Logger.Warning("Invalid Token, Re-Authenticating..."); Client.ReadyToUse = false; Client.Login.Reauthenticate().Wait(); Client.ReadyToUse = true; } catch (InvalidPlatformException) { Logger.Warning("Invalid Platform, Re-Login..."); Client.ReadyToUse = false; Client.Login.DoLogin().Wait(); Client.ReadyToUse = true; } catch (RedirectException) { Logger.Warning("Redirect Exception"); Task.Delay(1000).Wait(); } tries++; } Logger.Error("Too many tries. Returning"); return(new TResponsePayload()); }
protected TResponsePayload PostProtoPayload <TRequest, TResponsePayload>(RequestEnvelope.Types.PlatformRequest platfReq) where TRequest : IMessage <TRequest> where TResponsePayload : IMessage <TResponsePayload>, new() { var tries = 0; while (tries < 3) { try { Logger.Debug("Before of GetPlatformRequestEnvelope: platfReq :" + platfReq); var requestEnvelops = GetRequestBuilder().GetPlatformRequestEnvelope(platfReq); return(Client.PokemonHttpClient.PostProtoPayload <TRequest, TResponsePayload>(Client.ApiUrl, requestEnvelops, Client.ApiFailure)); } catch (AccessTokenExpiredException) { Logger.Warning("Invalid Token. Waiting 11 minutes before of reopen"); Client.ReadyToUse = false; verboseWait(11 * 60000); Client.Login.DoLogin().Wait(); Client.ReadyToUse = true; } catch (InvalidPlatformException) { Logger.Warning("Invalid Platform. Waiting 11 minutes before of reopen"); Client.ReadyToUse = false; verboseWait(11 * 60000); Client.Login.DoLogin().Wait(); Client.ReadyToUse = true; } catch (RedirectException) { Task.Delay(1000).Wait(); } tries++; } Logger.Error("Too many tries. Returning"); return(new TResponsePayload()); }
public GetStoreItemsResponse GetStoreItems() { var plafReques = new RequestEnvelope.Types.PlatformRequest(); plafReques.Type = POGOProtos.Networking.Platform.PlatformRequestType.GetStoreItems; var result = PostProtoPayload <Request, GetStoreItemsResponse>(plafReques); return(result); }
protected TResponsePayload PostProtoPayload <TRequest, TResponsePayload>(RequestEnvelope.Types.PlatformRequest platfReq) where TRequest : IMessage <TRequest> where TResponsePayload : IMessage <TResponsePayload>, new() { var requestEnvelops = GetRequestBuilder().GetPlatformRequestEnvelope(platfReq); return(Client.PokemonHttpClient.PostProtoPayload <TRequest, TResponsePayload>(Client.ApiUrl, requestEnvelops, Client.ApiFailure)); }
public BuyItemPokeCoinsResponse BuyItemPokeCoins(string item) { var message = new BuyItemPokeCoinsRequest() { ItemId = item }; var plafReques = new RequestEnvelope.Types.PlatformRequest() { Type = POGOProtos.Networking.Platform.PlatformRequestType.BuyItemPokecoins, RequestMessage = message.ToByteString() }; var result = PostProtoPayload <Request, BuyItemPokeCoinsResponse>(plafReques); return(result); }
public RequestEnvelope GetPlatformRequestEnvelope(RequestEnvelope.Types.PlatformRequest platfReq, bool firstRequest = false) { var req = new Request(); req.RequestType = RequestType.Echo; var _requestEnvelope = new RequestEnvelope { StatusCode = 2, //1 RequestId = _requestBuilderID.Next(), //3 Requests = { req }, //4 Latitude = _latitude, //7 Longitude = _longitude, //8 Accuracy = _altitude, //9 AuthTicket = _authTicket, //11 MsSinceLastLocationfix = (long)TRandomDevice.Triangular(300, 30000, 10000) //12 }; _requestEnvelope.PlatformRequests.Add(platfReq); if (_authTicket != null && !firstRequest) { _requestEnvelope.AuthTicket = _authTicket; } else { _requestEnvelope.AuthInfo = new RequestEnvelope.Types.AuthInfo { Provider = _authType == AuthType.Google ? "google" : "ptc", Token = new RequestEnvelope.Types.AuthInfo.Types.JWT { Contents = _authToken, Unknown2 = _token2 } }; } //Logger.Debug("GetPlatformRequestEnvelope"); //Logger.Debug("_requestEnvelope"+ _requestEnvelope); _requestEnvelope.PlatformRequests.Add(GenerateSignature(_requestEnvelope)); return(_requestEnvelope); }
private RequestEnvelope.Types.PlatformRequest GetSignatureRequest(RequestData requestData) { var serializedTicket = requestData.RequestEnvelope.AuthTicket != null?requestData.RequestEnvelope.AuthTicket.ToByteArray() : requestData.RequestEnvelope.AuthInfo.ToByteArray(); var locationSeed = CalculateHash32(serializedTicket, 0x61656632); var locationBytes = BitConverter.GetBytes(requestData.RequestEnvelope.Latitude).Reverse() .Concat(BitConverter.GetBytes(requestData.RequestEnvelope.Longitude).Reverse()) .Concat(BitConverter.GetBytes(requestData.RequestEnvelope.Accuracy).Reverse()).ToArray(); // sig.LocationHash1 = BitConverter.ToUInt32(locationHasher.ComputeHash(locationBytes), 0); // sig.LocationHash2 = BitConverter.ToUInt32(_locationSeedHasher.ComputeHash(locationBytes), 0); requestData.DecryptedSignature.LocationHash1 = xxHash32.CalculateHash(locationBytes, locationSeed); requestData.DecryptedSignature.LocationHash2 = CalculateHash32(locationBytes, 0x61656632); var seed = xxHash64.CalculateHash(serializedTicket, serializedTicket.Length, 0x61656632); requestData.DecryptedSignature.RequestHash.Clear(); foreach (var req in requestData.RequestEnvelope.Requests) { var reqBytes = req.ToByteArray(); requestData.DecryptedSignature.RequestHash.Add(xxHash64.CalculateHash(reqBytes, reqBytes.Length, seed)); //requestContext.DecryptedSignature.Unknown25 = 7363665268261373700; } var platformRequest = new RequestEnvelope.Types.PlatformRequest() { Type = PlatformRequestType.SendEncryptedSignature, RequestMessage = new SendEncryptedSignatureRequest() { EncryptedSignature = ByteString.CopyFrom(Encryption.Encrypt(requestData.DecryptedSignature.ToByteArray())), }.ToByteString(), }; return(platformRequest); }
//public int GetNextUk27() //{ // return Uk27Random.Next(); //} //private RequestEnvelope.Types.PlatformRequest GenerateSignature(IEnumerable<IMessage> requests) /// <summary> /// EB Check IMessage /// </summary> /// <param name="requestEnvelope"></param> /// <returns></returns> /// Also pogolib does /// internal async Task<PlatformRequest> GenerateSignatureAsync(RequestEnvelope requestEnvelope) private RequestEnvelope.Types.PlatformRequest GenerateSignature(RequestEnvelope requestEnvelope) { var timestampSinceStart = (long)(Utils.GetTime(true) - _client.StartTime); var locationFixes = BuildLocationFixes(requestEnvelope, timestampSinceStart); if (requestEnvelope.Requests.Count > 0) { requestEnvelope.Accuracy = locationFixes[0].Altitude; requestEnvelope.MsSinceLastLocationfix = (long)locationFixes[0].TimestampSnapshot; } var _activityStatus = new Signature.Types.ActivityStatus() { Stationary = true, Tilting = (TRandomDevice.Next(1, 2) == 1) }; //if (_client.Platform == Platform.Ios) // _activityStatus.Tilting = (TRandomDevice.Next(1,2)==1); #region GenerateSignature var signature = new Signature { TimestampSinceStart = (ulong)timestampSinceStart, Timestamp = (ulong)Utils.GetTime(true), // true means in Ms SensorInfo = { new Signature.Types.SensorInfo { // Values are not the same used in PogoLib TimestampSnapshot = (ulong)(timestampSinceStart + TRandomDevice.Next(100, 250)), LinearAccelerationX = GenRandom(0.12271042913198471), LinearAccelerationY = GenRandom(-0.015570580959320068), LinearAccelerationZ = GenRandom(0.010850906372070313), RotationRateX = GenRandom(-0.0120010357350111), RotationRateY = GenRandom(-0.04214850440621376), RotationRateZ = GenRandom(0.94571763277053833), AttitudePitch = GenRandom(-47.149471283, 61.8397789001), AttitudeYaw = GenRandom(-47.149471283, 61.8397789001), AttitudeRoll = GenRandom(-47.149471283, 5), GravityZ = GenRandom(9.8), GravityX = GenRandom(0.02), GravityY = GenRandom(0.3), MagneticFieldX = GenRandom(-10, 10), MagneticFieldY = GenRandom(-10, 10), MagneticFieldZ = GenRandom(-40, -20), MagneticFieldAccuracy = -1, Status = 3 } }, DeviceInfo = _DeviceInfo,// dInfo, LocationFix = { locationFixes }, ActivityStatus = _activityStatus, SessionHash = _sessionHash, Unknown25 = Resources.Api.IOSUnknown25, Unknown27 = Uk27Random.Next() }; #endregion //signature.SessionHash = _sessionHash; //signature.Unknown25 = Resources.Api.AndroidUnknown25; //if (_client.Platform == Platform.Ios) //signature.Unknown25 = Resources.Api.IOSUnknown25; var serializedTicket = requestEnvelope.AuthTicket != null?requestEnvelope.AuthTicket.ToByteArray() : requestEnvelope.AuthInfo.ToByteArray(); /*var locationBytes = BitConverter.GetBytes(_latitude).Reverse() * .Concat(BitConverter.GetBytes(_longitude).Reverse()) * .Concat(BitConverter.GetBytes(locationFixes[0].Altitude).Reverse()).ToArray(); */ var requestsBytes = requestEnvelope.Requests.Select(x => x.ToByteArray()).ToArray(); var hashRequest = new HashRequestContent() { Timestamp = signature.Timestamp, Latitude64 = BitConverter.DoubleToInt64Bits(requestEnvelope.Latitude), Longitude64 = BitConverter.DoubleToInt64Bits(requestEnvelope.Longitude), Accuracy64 = BitConverter.DoubleToInt64Bits(requestEnvelope.Accuracy), AuthTicket = serializedTicket, SessionData = signature.SessionHash.ToByteArray(), Requests = new List <byte[]>(requestsBytes) }; HashResponseContent responseContent; responseContent = _client.Hasher.RequestHashes(hashRequest); signature.LocationHash1 = unchecked ((int)responseContent.LocationAuthHash); signature.LocationHash2 = unchecked ((int)responseContent.LocationHash); signature.RequestHash.AddRange(responseContent.RequestHashes.Select(x => (ulong)x).ToArray()); var encryptedSignature = new RequestEnvelope.Types.PlatformRequest { Type = PlatformRequestType.SendEncryptedSignature, RequestMessage = new SendEncryptedSignatureRequest { EncryptedSignature = ByteString.CopyFrom(_client.Crypter.Encrypt(signature.ToByteArray(), (uint)timestampSinceStart)) }.ToByteString() }; return(encryptedSignature); }
private RequestEnvelope.Types.PlatformRequest GenerateSignature(IEnumerable <IMessage> requests) { var sig = new POGOProtos.Networking.Envelopes.Signature(); sig.TimestampSinceStart = (ulong)_internalWatch.ElapsedMilliseconds; sig.Timestamp = (ulong)DateTime.UtcNow.ToUnixTime(); sig.SensorInfo = new POGOProtos.Networking.Envelopes.Signature.Types.SensorInfo() { GravityZ = GenRandom(9.8), GravityX = GenRandom(0.02), GravityY = GenRandom(0.3), TimestampSnapshot = (ulong)_internalWatch.ElapsedMilliseconds - 230, LinearAccelerationX = GenRandom(0.12271042913198471), LinearAccelerationY = GenRandom(-0.015570580959320068), LinearAccelerationZ = GenRandom(0.010850906372070313), MagneticFieldX = GenRandom(17.950439453125), MagneticFieldY = GenRandom(-23.36273193359375), MagneticFieldZ = GenRandom(-48.8250732421875), RotationVectorX = GenRandom(-0.0120010357350111), RotationVectorY = GenRandom(-0.04214850440621376), RotationVectorZ = GenRandom(0.94571763277053833), GyroscopeRawX = GenRandom(7.62939453125e-005), GyroscopeRawY = GenRandom(-0.00054931640625), GyroscopeRawZ = GenRandom(0.0024566650390625), AccelerometerAxes = 3 }; sig.DeviceInfo = new POGOProtos.Networking.Envelopes.Signature.Types.DeviceInfo() { DeviceId = this.DeviceId, AndroidBoardName = this.AndroidBoardName, // might al AndroidBootloader = this.AndroidBootloader, DeviceBrand = this.DeviceBrand, DeviceModel = this.DeviceModel, // might als DeviceModelIdentifier = this.DeviceModelIdentifier, DeviceModelBoot = this.DeviceModelBoot, HardwareManufacturer = this.HardwareManufacturer, HardwareModel = this.HardwareModel, FirmwareBrand = this.FirmwareBrand, FirmwareTags = this.FirmwareTags, FirmwareType = this.FirmwareType, FirmwareFingerprint = this.FirmwareFingerprint }; Random r = new Random(); int accuracy = r.Next(15, 50); sig.LocationFix.Add(new POGOProtos.Networking.Envelopes.Signature.Types.LocationFix() { Provider = "gps", //Unk4 = 120, TimestampSnapshot = (ulong)_internalWatch.ElapsedMilliseconds - 200, Latitude = (float)_latitude, Longitude = (float)_longitude, Altitude = (float)_altitude, HorizontalAccuracy = accuracy, // Genauigkeit von GPS undso ProviderStatus = 3, Floor = 3, LocationType = 1 }); //Compute 10 var x = new System.Data.HashFunction.xxHash(32, 0x1B845238); var firstHash = BitConverter.ToUInt32(x.ComputeHash(_authTicket.ToByteArray()), 0); x = new System.Data.HashFunction.xxHash(32, firstHash); var locationBytes = BitConverter.GetBytes(_latitude).Reverse() .Concat(BitConverter.GetBytes(_longitude).Reverse()) .Concat(BitConverter.GetBytes(_altitude).Reverse()).ToArray(); sig.LocationHash1 = BitConverter.ToUInt32(x.ComputeHash(locationBytes), 0); //Compute 20 x = new System.Data.HashFunction.xxHash(32, 0x1B845238); sig.LocationHash2 = BitConverter.ToUInt32(x.ComputeHash(locationBytes), 0); //Compute 24 x = new System.Data.HashFunction.xxHash(64, 0x1B845238); var seed = BitConverter.ToUInt64(x.ComputeHash(_authTicket.ToByteArray()), 0); x = new System.Data.HashFunction.xxHash(64, seed); foreach (var req in requests) { sig.RequestHash.Add(BitConverter.ToUInt64(x.ComputeHash(req.ToByteArray()), 0)); } // NEW Random Byte Array every session. if (sessionhash_array == null) { byte[] rByte = new byte[16]; r.NextBytes(rByte); sessionhash_array = rByte; } sig.SessionHash = ByteString.CopyFrom(sessionhash_array); sig.Unknown25 = -8537042734809897855; // Generated via xxHash64("\"b8fa9757195897aae92c53dbcf8a60fb3d86d745\"".ToByteArray(), 0x88533787) | 0.33 Version var iv = new byte[32]; new Random().NextBytes(iv); var platformRequest = new RequestEnvelope.Types.PlatformRequest() { Type = PlatformRequestType.SendEncryptedSignature, RequestMessage = new SendEncryptedSignatureRequest() { EncryptedSignature = ByteString.CopyFrom(EncryptionHelper.Encrypt(sig.ToByteArray(), iv)), }.ToByteString(), }; return(platformRequest); }
private RequestEnvelope.Types.PlatformRequest GenerateSignature(IEnumerable<IMessage> requests) { var ticketBytes = _authTicket.ToByteArray(); var sig = new SignalAgglomUpdates() { EpochTimestampMs = (ulong)Utils.GetTime(true), TimestampMsSinceStart = (ulong)(Utils.GetTime(true) - _startTime), LocationHashByTokenSeed = (uint)Utils.GenerateLocation1(ticketBytes, _latitude, _longitude, _accuracy), LocationHash = (uint)Utils.GenerateLocation2(_latitude, _longitude, _accuracy), SensorUpdates = new SignalAgglomUpdates.Types.SensorUpdate() { GravityX = GenRandom(-0.31110161542892456, 0.1681540310382843), GravityY = GenRandom(-0.6574847102165222, -0.07290205359458923), GravityZ = GenRandom(-0.9943905472755432, -0.7463029026985168), Timestamp = (ulong)(Utils.GetTime(true) - _startTime - RandomDevice.Next(100, 400)), AccelerationX = GenRandom(-0.139084026217, 0.138112977147), AccelerationY = GenRandom(-0.2, 0.19), AccelerationZ = GenRandom(-0.2, 0.4), MagneticFieldX = GenRandom(-47.149471283, 61.8397789001), MagneticFieldY = GenRandom(-47.149471283, 61.8397789001), MagneticFieldZ = GenRandom(-47.149471283, 5), AttitudePitch = GenRandom(0.0729667818829, 0.0729667818829), AttitudeYaw = GenRandom(-2.788630499244109, 3.0586791383810468), AttitudeRoll = GenRandom(-0.34825887123552773, 0.19347580173737935), RotationRateX = GenRandom(-0.9703824520111084, 0.8556089401245117), RotationRateY = GenRandom(-1.7470258474349976, 1.4218578338623047), RotationRateZ = GenRandom(-0.9681901931762695, 0.8396636843681335), Status = 3 }, DeviceInfo = new SignalAgglomUpdates.Types.DeviceInfo() { DeviceId = settings.DeviceId, AndroidBoardName = settings.AndroidBoardName, AndroidBootloader = settings.AndroidBootloader, DeviceBrand = settings.DeviceBrand, DeviceModel = settings.DeviceModel, DeviceModelIdentifier = settings.DeviceModelIdentifier, DeviceCommsModel = settings.DeviceModelBoot, HardwareManufacturer = settings.HardwareManufacturer, HardwareModel = settings.HardwareModel, FirmwareBrand = settings.FirmwareBrand, FirmwareTags = settings.FirmwareTags, FirmwareType = settings.FirmwareType, FirmwareFingerprint = settings.FirmwareFingerprint } }; if (settings.DeviceBrand == "APPLE") sig.LocationUpdates.Add(new SignalAgglomUpdates.Types.LocationUpdate() { Name = "fused", TimestampMs = (Utils.GetTime(true) - _startTime - RandomDevice.Next(100, 300)), Latitude = (float)_latitude, Longitude = (float)_longitude, Altitude = (-(float)_altitude) - 13, DeviceSpeed = (float)_currentSpeed, DeviceCourse = -1, HorizontalAccuracy = (float)_accuracy, VerticalAccuracy = RandomDevice.Next(2, 5), ProviderStatus = 3, Floor = 0, LocationType = 1 }); else sig.LocationUpdates.Add(new SignalAgglomUpdates.Types.LocationUpdate() { Name = "fused", TimestampMs = (Utils.GetTime(true) - _startTime - RandomDevice.Next(100, 300)), Latitude = (float)_latitude, Longitude = (float)_longitude, Altitude = (-(float)_altitude) - 13, HorizontalAccuracy = (float)_accuracy, VerticalAccuracy = RandomDevice.Next(2, 5), ProviderStatus = 3, Floor = 0, LocationType = 1 }); //Compute 10 var x = new System.Data.HashFunction.xxHash(32, 0x1B845238); var firstHash = BitConverter.ToUInt32(x.ComputeHash(_authTicket.ToByteArray()), 0); x = new System.Data.HashFunction.xxHash(32, firstHash); var locationBytes = BitConverter.GetBytes(_latitude).Reverse() .Concat(BitConverter.GetBytes(_longitude).Reverse()) .Concat(BitConverter.GetBytes(_accuracy).Reverse()).ToArray(); sig.LocationHashByTokenSeed = BitConverter.ToUInt32(x.ComputeHash(locationBytes), 0); //Compute 20 x = new System.Data.HashFunction.xxHash(32, 0x1B845238); sig.LocationHash = BitConverter.ToUInt32(x.ComputeHash(locationBytes), 0); //Compute 24 x = new System.Data.HashFunction.xxHash(64, 0x1B845238); var seed = BitConverter.ToUInt64(x.ComputeHash(_authTicket.ToByteArray()), 0); x = new System.Data.HashFunction.xxHash(64, seed); foreach (var req in requests) sig.RequestHashes.Add(BitConverter.ToUInt64(x.ComputeHash(req.ToByteArray()), 0)); sig.Field22 = SessionHash; //static for now sig.Field25 = 7363665268261373700; RequestEnvelope.Types.PlatformRequest val = new RequestEnvelope.Types.PlatformRequest(); val.Type = PlatformRequestType.SendEncryptedSignature; SendEncryptedSignatureRequest sigRequest = new SendEncryptedSignatureRequest(); sigRequest.EncryptedSignature = ByteString.CopyFrom(Encrypt(sig.ToByteArray())); val.RequestMessage = sigRequest.ToByteString(); return val; }
private RequestEnvelope.Types.PlatformRequest GenerateSignature(IEnumerable <IMessage> requests) { byte[] ticket = _authTicket.ToByteArray(); if (sessionhash_array == null) { byte[] rByte = new byte[16]; Random ra = new Random(); ra.NextBytes(rByte); sessionhash_array = rByte; } // Device Signature.Types.DeviceInfo dInfo = new Signature.Types.DeviceInfo { DeviceId = this.DeviceId, AndroidBoardName = this.AndroidBoardName, // might al AndroidBootloader = this.AndroidBootloader, DeviceBrand = this.DeviceBrand, DeviceModel = this.DeviceModel, // might als DeviceModelIdentifier = this.DeviceModelIdentifier, DeviceModelBoot = this.DeviceModelBoot, HardwareManufacturer = this.HardwareManufacturer, HardwareModel = this.HardwareModel, FirmwareBrand = this.FirmwareBrand, FirmwareTags = this.FirmwareTags, FirmwareType = this.FirmwareType, FirmwareFingerprint = this.FirmwareFingerprint }; var sig = new Signature { SessionHash = ByteString.CopyFrom(sessionhash_array), Unknown25 = -8408506833887075802, // Could change every Update TimestampSinceStart = (ulong)(Utils.GetTime(true) - _client.StartTime), Timestamp = (ulong)DateTime.UtcNow.ToUnixTime(), LocationHash1 = Utils.GenLocation1(ticket, _latitude, _longitude, _altitude), LocationHash2 = Utils.GenLocation2(_latitude, _longitude, _altitude), DeviceInfo = dInfo }; sig.SensorInfo.Add(new POGOProtos.Networking.Envelopes.Signature.Types.SensorInfo { GravityZ = GenRandom(9.8), GravityX = GenRandom(0.02), GravityY = GenRandom(0.3), TimestampSnapshot = (ulong)(Utils.GetTime(true) - _client.StartTime - RandomDevice.Next(100, 500)), LinearAccelerationX = GenRandom(0.12271042913198471), LinearAccelerationY = GenRandom(-0.015570580959320068), LinearAccelerationZ = GenRandom(0.010850906372070313), MagneticFieldX = GenRandom(17.950439453125), MagneticFieldY = GenRandom(-23.36273193359375), MagneticFieldZ = GenRandom(-48.8250732421875), RotationRateX = GenRandom(-0.0120010357350111), RotationRateY = GenRandom(-0.04214850440621376), RotationRateZ = GenRandom(0.94571763277053833), AttitudePitch = GenRandom(-47.149471283, 61.8397789001), AttitudeYaw = GenRandom(-47.149471283, 61.8397789001), AttitudeRoll = GenRandom(-47.149471283, 5), MagneticFieldAccuracy = -1, Status = 3 }); Random r = new Random(); int accuracy = r.Next(15, 50); sig.LocationFix.Add(new POGOProtos.Networking.Envelopes.Signature.Types.LocationFix() { Provider = "gps", TimestampSnapshot = (ulong)(Utils.GetTime(true) - _client.StartTime - RandomDevice.Next(100, 300)), Latitude = (float)_latitude, Longitude = (float)_longitude, Altitude = (float)_altitude, HorizontalAccuracy = accuracy, // Genauigkeit von GPS undso ProviderStatus = 3, Floor = 3, LocationType = 1 }); foreach (var requst in requests) { sig.RequestHash.Add(Utils.GenRequestHash(ticket, requst.ToByteArray())); } var encryptedSig = new RequestEnvelope.Types.PlatformRequest { Type = PlatformRequestType.SendEncryptedSignature, RequestMessage = new SendEncryptedSignatureRequest { EncryptedSignature = ByteString.CopyFrom(PCrypt.Encrypt(sig.ToByteArray(), (uint)_client.StartTime)) }.ToByteString() }; return(encryptedSig); }
private RequestEnvelope.Types.PlatformRequest GenerateSignature(RequestEnvelope requestEnvelope) { byte[] ticketBytes = requestEnvelope.AuthTicket != null?requestEnvelope.AuthTicket.ToByteArray() : requestEnvelope.AuthInfo.ToByteArray(); // Common device info Signature.Types.DeviceInfo deviceInfo = new Signature.Types.DeviceInfo { DeviceId = _settings.DeviceId, DeviceBrand = _settings.DeviceBrand, DeviceModel = _settings.DeviceModel, DeviceModelBoot = _settings.DeviceModelBoot, HardwareManufacturer = _settings.HardwareManufacturer, HardwareModel = _settings.HardwareModel, FirmwareBrand = _settings.FirmwareBrand, FirmwareType = _settings.FirmwareType }; // Android if (_client.Platform == Platform.Android) { deviceInfo.AndroidBoardName = _settings.AndroidBoardName; deviceInfo.AndroidBootloader = _settings.AndroidBootloader; deviceInfo.DeviceModelIdentifier = _settings.DeviceModelIdentifier; deviceInfo.FirmwareTags = _settings.FirmwareTags; deviceInfo.FirmwareFingerprint = _settings.FirmwareFingerprint; } var sig = new Signature { SessionHash = SessionHash, Unknown25 = _client.Hasher.Client_Unknown25, Timestamp = (ulong)Utils.GetTime(true), TimestampSinceStart = (ulong)(Utils.GetTime(true) - _client.StartTime), //LocationHash1 = (int)Utils.GenerateLocation1(ticketBytes, _latitude, _longitude, _horizontalAccuracy), //LocationHash2 = (int)Utils.GenerateLocation2(_latitude, _longitude, _horizontalAccuracy), DeviceInfo = deviceInfo }; sig.SensorInfo.Add(new SensorInfo() { TimestampSnapshot = (ulong)(Utils.GetTime(true) - _client.StartTime - RandomDevice.Next(100, 500)), LinearAccelerationX = TRandomDevice.Triangular(-3, 1, 0), LinearAccelerationY = TRandomDevice.Triangular(-2, 3, 0), LinearAccelerationZ = TRandomDevice.Triangular(-4, 2, 0), MagneticFieldX = TRandomDevice.Triangular(-50, 50, 0), MagneticFieldY = TRandomDevice.Triangular(-60, 50, -5), MagneticFieldZ = TRandomDevice.Triangular(-60, 40, -30), AttitudePitch = GenRandom(-47.149471283, 61.8397789001), AttitudeYaw = GenRandom(-47.149471283, 61.8397789001), AttitudeRoll = GenRandom(-47.149471283, 5), RotationRateX = GenRandom(0.0729667818829, 0.0729667818829), RotationRateY = GenRandom(-2.788630499244109, 3.0586791383810468), RotationRateZ = GenRandom(-0.34825887123552773, 0.19347580173737935), GravityX = TRandomDevice.Triangular(-1, 1, 0.15), GravityY = TRandomDevice.Triangular(-1, 1, -.2), GravityZ = TRandomDevice.Triangular(-1, .7, -0.8), MagneticFieldAccuracy = -1, Status = 3 }); Signature.Types.LocationFix locationFix = new Signature.Types.LocationFix { Provider = TRandomDevice.Choice(new List <string>(new string[] { "network", "network", "network", "network", "fused" })), Latitude = (float)_latitude, Longitude = (float)_longitude, Altitude = (float)_altitude, HorizontalAccuracy = _horizontalAccuracy, TimestampSnapshot = (ulong)(Utils.GetTime(true) - _client.StartTime - RandomDevice.Next(100, 300)), ProviderStatus = 3, LocationType = 1 }; if (_horizontalAccuracy >= 65) { locationFix.HorizontalAccuracy = TRandomDevice.Choice(new List <int>(new int[] { _horizontalAccuracy, 65, 65, (int)Math.Round(GenRandom(66, 80)), 200 })); if (_client.Platform == Platform.Ios) { locationFix.VerticalAccuracy = (float)TRandomDevice.Triangular(35, 100, 65); } } else { locationFix.HorizontalAccuracy = _horizontalAccuracy; if (_client.Platform == Platform.Ios) { if (_horizontalAccuracy > 10) { locationFix.VerticalAccuracy = (float)TRandomDevice.Choice(new List <double>(new double[] { 24, 32, 48, 48, 64, 64, 96, 128 })); } else { locationFix.VerticalAccuracy = (float)TRandomDevice.Choice(new List <double>(new double[] { 3, 4, 6, 6, 8, 12, 24 })); } } } if (_client.Platform == Platform.Ios) { if (RandomDevice.NextDouble() > 0.95) { // No reading for roughly 1 in 20 updates locationFix.Course = -1; locationFix.Speed = -1; } else { _course = (float)TRandomDevice.Triangular(0, 360, _course); // Course is iOS only. locationFix.Course = _course; // Speed is iOS only. locationFix.Speed = _speed; } } sig.LocationFix.Add(locationFix); //foreach (var request in requestEnvelope.Requests) // sig.RequestHash.Add(Utils.GenerateRequestHash(ticketBytes, request.ToByteArray())); string envelopString = JsonConvert.SerializeObject(requestEnvelope); HashRequestContent hashRequest = new HashRequestContent() { Latitude = _latitude, Longitude = _longitude, Altitude = _altitude, AuthTicket = ticketBytes, SessionData = SessionHash.ToByteArray(), Requests = new List <byte[]>(), Timestamp = sig.Timestamp }; foreach (var request in requestEnvelope.Requests) { hashRequest.Requests.Add(request.ToByteArray()); } var res = _client.Hasher.RequestHashesAsync(hashRequest).Result; foreach (var item in res.RequestHashes) { sig.RequestHash.Add((unchecked ((ulong)item))); } //sig.RequestHash.AddRange(res.RequestHashes.Cast<ulong>().ToList()); sig.LocationHash1 = unchecked ((int)res.LocationAuthHash); sig.LocationHash2 = unchecked ((int)res.LocationHash); var encryptedSignature = new RequestEnvelope.Types.PlatformRequest { Type = PlatformRequestType.SendEncryptedSignature, RequestMessage = new SendEncryptedSignatureRequest { EncryptedSignature = ByteString.CopyFrom(_client.Cryptor.Encrypt(sig.ToByteArray(), (uint)_client.StartTime)) }.ToByteString() }; return(encryptedSignature); }
private async Task <RequestEnvelope.Types.PlatformRequest> GenerateSignature(RequestEnvelope requestEnvelope, GeoCoordinate currentLocation) { byte[] ticketBytes = requestEnvelope.AuthTicket != null?requestEnvelope.AuthTicket.ToByteArray() : requestEnvelope.AuthInfo.ToByteArray(); // Common device info var deviceInfo = new Signature.Types.DeviceInfo { DeviceId = _settings.DeviceId, DeviceBrand = _settings.DeviceBrand, DeviceModel = _settings.DeviceModel, DeviceModelBoot = _settings.DeviceModelBoot + "\0", HardwareManufacturer = _settings.HardwareManufacturer, HardwareModel = _settings.HardwareModel + "\0", FirmwareBrand = (_settings.DeviceModel == "iPhone" ? "iOS" : "iPhone OS"), FirmwareType = _settings.FirmwareType }; // Android if (_client.Platform == Platform.Android) { deviceInfo.AndroidBoardName = _settings.AndroidBoardName; deviceInfo.AndroidBootloader = _settings.AndroidBootloader; deviceInfo.DeviceModelIdentifier = _settings.DeviceModelIdentifier; deviceInfo.FirmwareTags = _settings.FirmwareTags; deviceInfo.FirmwareFingerprint = _settings.FirmwareFingerprint; } var sig = new Signature { SessionHash = _sessionHash, Unknown25 = _client.Unknown25, Timestamp = (ulong)Utils.GetTime(true), TimestampSinceStart = (ulong)(Utils.GetTime(true) - _client.StartTime), DeviceInfo = deviceInfo }; if (sig.TimestampSinceStart < 5000) { sig.TimestampSinceStart = (ulong)TRandomDevice.Next(5000, 8000); } var sen = new Signature.Types.SensorInfo() { LinearAccelerationX = TRandomDevice.Triangular(-3, 1, 0), LinearAccelerationY = TRandomDevice.Triangular(-2, 3, 0), LinearAccelerationZ = TRandomDevice.Triangular(-4, 2, 0), MagneticFieldX = TRandomDevice.Triangular(-50, 50, 0), MagneticFieldY = TRandomDevice.Triangular(-60, 50, -5), MagneticFieldZ = TRandomDevice.Triangular(-60, 40, -30), MagneticFieldAccuracy = TRandomDevice.Choice(new List <int>(new int[] { -1, 1, 1, 2, 2, 2, 2 })), AttitudePitch = TRandomDevice.Triangular(-1.5, 1.5, 0.2), AttitudeYaw = TRandomDevice.NextDouble(-3, 3), AttitudeRoll = TRandomDevice.Triangular(-2.8, 2.5, 0.25), RotationRateX = TRandomDevice.Triangular(-6, 4, 0), RotationRateY = TRandomDevice.Triangular(-5.5, 5, 0), RotationRateZ = TRandomDevice.Triangular(-5, 3, 0), GravityX = TRandomDevice.Triangular(-1, 1, 0.15), GravityY = TRandomDevice.Triangular(-1, 1, -.2), GravityZ = TRandomDevice.Triangular(-1, .7, -0.8), Status = 3 }; sen.TimestampSnapshot = (ulong)TRandomDevice.NextUInt((uint)(sig.TimestampSinceStart - 5000), (uint)(sig.TimestampSinceStart - 100)); sig.SensorInfo.Add(sen); var locationFix = new Signature.Types.LocationFix { Provider = TRandomDevice.Choice(new List <string>(new string[] { "network", "network", "network", "network", "fused" })), Latitude = (float)currentLocation.Latitude, Longitude = (float)currentLocation.Longitude, Altitude = (float)currentLocation.Altitude, ProviderStatus = 3, LocationType = 1 }; locationFix.TimestampSnapshot = (ulong)TRandomDevice.NextUInt((uint)(sig.TimestampSinceStart - 5000), (uint)(sig.TimestampSinceStart - 1000)); if (requestEnvelope.Accuracy >= 65) { locationFix.HorizontalAccuracy = TRandomDevice.Choice(new List <float>(new float[] { (float)requestEnvelope.Accuracy, 65, 65, TRandomDevice.Next(66, 80), 200 })); if (_client.Platform == Platform.Ios) { locationFix.VerticalAccuracy = (float)TRandomDevice.Triangular(35, 100, 65); } } else { locationFix.HorizontalAccuracy = (float)requestEnvelope.Accuracy; if (_client.Platform == Platform.Ios) { locationFix.VerticalAccuracy = requestEnvelope.Accuracy > 10 ? (float)TRandomDevice.Choice(new List <double>(new double[] { 24, 32, 48, 48, 64, 64, 96, 128 })) : (float)TRandomDevice.Choice(new List <double>(new double[] { 3, 4, 6, 6, 8, 12, 24 })); } } locationFix.HorizontalAccuracy = (float)Math.Round(locationFix.HorizontalAccuracy, GEOLOCATION_PRECISION); locationFix.VerticalAccuracy = (float)Math.Round(locationFix.VerticalAccuracy, GEOLOCATION_PRECISION); if (_client.Platform == Platform.Ios) { sig.ActivityStatus = new Signature.Types.ActivityStatus() { Stationary = true }; sig.ActivityStatus.Tilting |= TRandomDevice.NextDouble() > 0.50; if (TRandomDevice.NextDouble() > 0.95) { // No reading for roughly 1 in 20 updates locationFix.Course = -1; locationFix.Speed = -1; } else { // Course is iOS only. locationFix.Course = GetCourse(); // Speed is iOS only. locationFix.Speed = (float)TRandomDevice.Triangular(0.2, 4.25, 1); } } sig.LocationFix.Add(locationFix); string envelopString = JsonConvert.SerializeObject(requestEnvelope); var hashRequest = new HashRequestContent() { Latitude64 = BitConverter.DoubleToInt64Bits(currentLocation.Latitude), Longitude64 = BitConverter.DoubleToInt64Bits(currentLocation.Longitude), Accuracy64 = BitConverter.DoubleToInt64Bits(requestEnvelope.Accuracy), AuthTicket = ticketBytes, SessionData = _sessionHash.ToByteArray(), Requests = new List <byte[]>(), Timestamp = sig.Timestamp }; foreach (var request in requestEnvelope.Requests) { hashRequest.Requests.Add(request.ToByteArray()); } var res = await _client.Hasher.RequestHashesAsync(hashRequest).ConfigureAwait(false); foreach (var item in res.RequestHashes) { sig.RequestHash.Add(((ulong)item)); } sig.LocationHash1 = (int)res.LocationAuthHash; sig.LocationHash2 = (int)res.LocationHash; var encryptedSignature = new RequestEnvelope.Types.PlatformRequest { Type = PlatformRequestType.SendEncryptedSignature, RequestMessage = new SendEncryptedSignatureRequest { EncryptedSignature = ByteString.CopyFrom(_client.Cryptor.Encrypt(sig.ToByteArray(), (uint)_client.StartTime)) }.ToByteString() }; return(encryptedSignature); }
private RequestEnvelope.Types.PlatformRequest GenerateSignature(IEnumerable <IMessage> requests) { var ticketBytes = _authTicket.ToByteArray(); // Common device info Signature.Types.DeviceInfo deviceInfo = new Signature.Types.DeviceInfo { DeviceId = _settings.DeviceId, DeviceBrand = _settings.DeviceBrand, DeviceModel = _settings.DeviceModel, DeviceModelBoot = _settings.DeviceModelBoot, HardwareManufacturer = _settings.HardwareManufacturer, HardwareModel = _settings.HardwareModel, FirmwareBrand = _settings.FirmwareBrand, FirmwareType = _settings.FirmwareType }; // Android if (_client.Platform == Platform.Android) { deviceInfo.AndroidBoardName = _settings.AndroidBoardName; deviceInfo.AndroidBootloader = _settings.AndroidBootloader; deviceInfo.DeviceModelIdentifier = _settings.DeviceModelIdentifier; deviceInfo.FirmwareTags = _settings.FirmwareTags; deviceInfo.FirmwareFingerprint = _settings.FirmwareFingerprint; } var sig = new Signature { SessionHash = SessionHash, Unknown25 = Client_3500_Unknown25, Timestamp = (ulong)Utils.GetTime(true), TimestampSinceStart = (ulong)(Utils.GetTime(true) - _client.StartTime), LocationHash1 = Utils.GenerateLocation1(ticketBytes, _latitude, _longitude, _horizontalAccuracy), LocationHash2 = Utils.GenerateLocation2(_latitude, _longitude, _horizontalAccuracy), SensorInfo = new Signature.Types.SensorInfo { TimestampSnapshot = (ulong)(Utils.GetTime(true) - _client.StartTime - RandomDevice.Next(100, 500)), LinearAccelerationX = TRandomDevice.Triangular(-3, 1, 0), LinearAccelerationY = TRandomDevice.Triangular(-2, 3, 0), LinearAccelerationZ = TRandomDevice.Triangular(-4, 2, 0), MagneticFieldX = TRandomDevice.Triangular(-50, 50, 0), MagneticFieldY = TRandomDevice.Triangular(-60, 50, -5), MagneticFieldZ = TRandomDevice.Triangular(-60, 40, -30), RotationVectorX = GenRandom(-47.149471283, 61.8397789001), RotationVectorY = GenRandom(-47.149471283, 61.8397789001), RotationVectorZ = GenRandom(-47.149471283, 5), GyroscopeRawX = GenRandom(0.0729667818829, 0.0729667818829), GyroscopeRawY = GenRandom(-2.788630499244109, 3.0586791383810468), GyroscopeRawZ = GenRandom(-0.34825887123552773, 0.19347580173737935), GravityX = TRandomDevice.Triangular(-1, 1, 0.15), GravityY = TRandomDevice.Triangular(-1, 1, -.2), GravityZ = TRandomDevice.Triangular(-1, .7, -0.8), AccelerometerAxes = 3 }, DeviceInfo = deviceInfo }; Signature.Types.LocationFix locationFix = new Signature.Types.LocationFix { Provider = TRandomDevice.Choice(new List <string>(new string[] { "network", "network", "network", "network", "fused" })), Latitude = (float)_latitude, Longitude = (float)_longitude, Altitude = (float)_altitude, HorizontalAccuracy = (float)_horizontalAccuracy, TimestampSnapshot = (ulong)(Utils.GetTime(true) - _client.StartTime - RandomDevice.Next(100, 300)), ProviderStatus = 3, LocationType = 1 }; if (_horizontalAccuracy >= 65) { locationFix.HorizontalAccuracy = (float)TRandomDevice.Choice(new List <double>(new double[] { _horizontalAccuracy, 65, 65, GenRandom(66, 80), 200 })); if (_client.Platform == Platform.Ios) { locationFix.VerticalAccuracy = (float)TRandomDevice.Triangular(35, 100, 65); } } else { locationFix.HorizontalAccuracy = (float)_horizontalAccuracy; if (_client.Platform == Platform.Ios) { if (_horizontalAccuracy > 10) { locationFix.VerticalAccuracy = (float)TRandomDevice.Choice(new List <double>(new double[] { 24, 32, 48, 48, 64, 64, 96, 128 })); } else { locationFix.VerticalAccuracy = (float)TRandomDevice.Choice(new List <double>(new double[] { 3, 4, 6, 6, 8, 12, 24 })); } } } if (_client.Platform == Platform.Ios) { if (RandomDevice.NextDouble() > 0.95) { // No reading for roughly 1 in 20 updates locationFix.Course = -1; locationFix.Speed = -1; } else { _course = (float)TRandomDevice.Triangular(0, 360, _course); // Course is iOS only. locationFix.Course = _course; // Speed is iOS only. locationFix.Speed = _speed; } } sig.LocationFix.Add(locationFix); foreach (var request in requests) { sig.RequestHash.Add(Utils.GenerateRequestHash(ticketBytes, request.ToByteArray())); } var encryptedSignature = new RequestEnvelope.Types.PlatformRequest { Type = PlatformRequestType.SendEncryptedSignature, RequestMessage = new SendEncryptedSignatureRequest { EncryptedSignature = ByteString.CopyFrom(_crypt.Encrypt(sig.ToByteArray())) }.ToByteString() }; return(encryptedSignature); }