示例#1
0
        public static Signature.Types.DeviceInfo GetRandomIosDevice()
        {
            var deviceInfo = new Signature.Types.DeviceInfo();

            // iOS device id (UDID) are 16 bytes long. <<-- WRONG see that https://www.theiphonewiki.com/wiki/UDID
            // Must have 40 hex digits.
            // var deviceId = new Random().NextHexNumber(40).ToLower();
            // but pogodev says 32 hex digits.
            var deviceId = new Random().NextHexNumber(32).ToLower();

            deviceInfo.DeviceId = deviceId;
            //PokemonGo.RocketAPI kernel emulated is lasted Darwin/17.2.0 according iOS 11.1.0
            //deviceInfo.FirmwareType = IosVersions[new Random().Next(IosVersions.Length)];
            deviceInfo.FirmwareType = "11.1.0"; // force use lasted iOS
            string[] device = IosDeviceInfo[(new Random()).Next(IosDeviceInfo.Length)];
            deviceInfo.DeviceModelBoot = device[0];
            deviceInfo.DeviceModel     = device[1];

            deviceInfo.HardwareModel        = device[2];
            deviceInfo.FirmwareBrand        = (device[1] == "iPhone" ? "iOS" : "iPhone OS");
            deviceInfo.DeviceBrand          = "Apple";
            deviceInfo.HardwareManufacturer = "Apple";

            return(deviceInfo);
        }
        public Signature.Types.DeviceInfo GetDeviceInfo()
        {
            if (deviceInfo != null)
            {
                return(deviceInfo);
            }
            var devicePackageName = _client.Settings.DevicePackageName;

            if (!DeviceInfoHelper.DeviceInfoSets.ContainsKey(devicePackageName))
            {
                devicePackageName = DeviceInfoHelper.DeviceInfoSets.Keys.ElementAt(0);
                var deviceList = String.Join(",", DeviceInfoHelper.DeviceInfoSets.Select(x => x.Key).ToArray());
                Logger.Write($"You must provide a valid DevicePackageName in the Configs/Settings.xml file. We are going to use the default '{devicePackageName}'. The currently supported values are: {deviceList}", LogLevel.Warning);
            }

            deviceInfo = new Signature.Types.DeviceInfo();
            deviceInfo.AndroidBoardName      = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["AndroidBoardName"];
            deviceInfo.AndroidBootloader     = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["AndroidBootloader"];
            deviceInfo.DeviceBrand           = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["DeviceBrand"];
            deviceInfo.DeviceId              = string.IsNullOrEmpty(_client.Settings.DeviceId) ? DeviceInfoHelper.DeviceInfoSets[devicePackageName]["DeviceId"] : _client.Settings.DeviceId;
            deviceInfo.DeviceModel           = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["DeviceModel"];
            deviceInfo.DeviceModelBoot       = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["DeviceModelBoot"];
            deviceInfo.DeviceModelIdentifier = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["DeviceModelIdentifier"];
            deviceInfo.FirmwareBrand         = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["FirmwareBrand"];
            deviceInfo.FirmwareFingerprint   = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["FirmwareFingerprint"];
            deviceInfo.FirmwareTags          = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["FirmwareTags"];
            deviceInfo.FirmwareType          = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["FirmwareType"];
            deviceInfo.HardwareManufacturer  = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["HardwareManufacturer"];
            deviceInfo.HardwareModel         = DeviceInfoHelper.DeviceInfoSets[devicePackageName]["HardwareModel"];

            return(deviceInfo);
        }
示例#3
0
        public static Signature.Types.DeviceInfo GetRandomIosDevice()
        {
            var deviceInfo = new Signature.Types.DeviceInfo();

            deviceInfo.DeviceId = RandomDeviceId();
            deviceInfo.FirmwareType = DeviceInfoHelper.IosVersions[new Random().Next(DeviceInfoHelper.IosVersions.Length)];
            string[] device = DeviceInfoHelper.IosDeviceInfo[new Random().Next(DeviceInfoHelper.IosDeviceInfo.Length)];
            deviceInfo.DeviceModelBoot = device[0];
            deviceInfo.DeviceModel = device[1];

            deviceInfo.HardwareModel = device[2];
            deviceInfo.FirmwareBrand = "iPhone OS";
            deviceInfo.DeviceBrand = "Apple";
            deviceInfo.HardwareManufacturer = "Apple";

            return deviceInfo;
        }
示例#4
0
        public static Signature.Types.DeviceInfo GetRandomIosDevice()
        {
            var deviceInfo = new Signature.Types.DeviceInfo();

            // iOS device id (UDID) are 16 bytes long. <<-- WRONG see that https://www.theiphonewiki.com/wiki/UDID
            // Must have 40 hex digits.
            var deviceId = new Random().NextHexNumber(40).ToLower();

            deviceInfo.DeviceId     = deviceId;
            deviceInfo.FirmwareType = IosVersions[new Random().Next(IosVersions.Length)];
            string[] device = IosDeviceInfo[(new Random()).Next(IosDeviceInfo.Length)];
            deviceInfo.DeviceModelBoot = device[0];
            deviceInfo.DeviceModel     = device[1];

            deviceInfo.HardwareModel        = device[2];
            deviceInfo.FirmwareBrand        = (device[1] == "iPhone" ? "iOS" : "iPhone OS");
            deviceInfo.DeviceBrand          = "Apple";
            deviceInfo.HardwareManufacturer = "Apple";

            return(deviceInfo);
        }
        public RequestBuilder(Client client, string authToken, AuthType authType, double latitude, double longitude, double altitude, AuthTicket authTicket = null)
        {
            if (!setupdevicedone)
            {
                _DeviceInfo     = DeviceSetup.SelectedDevice.DeviceInfo;
                setupdevicedone = true;
            }

            _client     = client;
            _authToken  = authToken;
            _authType   = authType;
            _latitude   = latitude;
            _longitude  = longitude;
            _altitude   = altitude;
            _authTicket = authTicket;

            // Add small variance to speed.
            _speed = _speed + ((float)Math.Round(GenRandom(-1, 1), 7));

            if (_sessionHash == null)
            {
                _sessionHash = GenerateNewHash();
            }
        }
        private Unknown6 GenerateSignature(IEnumerable <IMessage> requests)
        {
            var ticketBytes = _authTicket.ToByteArray();

            Signature.Types.DeviceInfo deviceInfo;
            if (settings.HardwareManufacturer.Equals("Apple", StringComparison.Ordinal))
            {
                // iOS
                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,
                };
            }
            else
            {
                // Android
                deviceInfo = new Signature.Types.DeviceInfo()
                {
                    DeviceId              = settings.DeviceId,
                    AndroidBoardName      = settings.AndroidBoardName,
                    AndroidBootloader     = settings.AndroidBootloader,
                    DeviceBrand           = settings.DeviceBrand,
                    DeviceModel           = settings.DeviceModel,
                    DeviceModelIdentifier = settings.DeviceModelIdentifier,
                    DeviceModelBoot       = settings.DeviceModelBoot,
                    HardwareManufacturer  = settings.HardwareManufacturer,
                    HardwareModel         = settings.HardwareModel,
                    FirmwareBrand         = settings.FirmwareBrand,
                    FirmwareTags          = settings.FirmwareTags,
                    FirmwareType          = settings.FirmwareType,
                    FirmwareFingerprint   = settings.FirmwareFingerprint
                };
            }

            var sig = new Signature()
            {
                Timestamp           = (ulong)Utils.GetTime(true),
                TimestampSinceStart = (ulong)(Utils.GetTime(true) - _startTime),
                LocationHash1       = Utils.GenerateLocation1(ticketBytes, _latitude, _longitude, _altitude),
                LocationHash2       = Utils.GenerateLocation2(_latitude, _longitude, _altitude),
                SensorInfo          = new Signature.Types.SensorInfo()
                {
                    AccelNormalizedX  = GenRandom(-0.31110161542892456, 0.1681540310382843),
                    AccelNormalizedY  = GenRandom(-0.6574847102165222, -0.07290205359458923),
                    AccelNormalizedZ  = GenRandom(-0.9943905472755432, -0.7463029026985168),
                    TimestampSnapshot = (ulong)(Utils.GetTime(true) - _startTime - RandomDevice.Next(100, 400)),
                    MagnetometerX     = GenRandom(-0.139084026217, 0.138112977147),
                    MagnetometerY     = GenRandom(-0.2, 0.19),
                    MagnetometerZ     = GenRandom(-0.2, 0.4),
                    AngleNormalizedX  = GenRandom(-47.149471283, 61.8397789001),
                    AngleNormalizedY  = GenRandom(-47.149471283, 61.8397789001),
                    AngleNormalizedZ  = GenRandom(-47.149471283, 5),
                    AccelRawX         = GenRandom(0.0729667818829, 0.0729667818829),
                    AccelRawY         = GenRandom(-2.788630499244109, 3.0586791383810468),
                    AccelRawZ         = GenRandom(-0.34825887123552773, 0.19347580173737935),
                    GyroscopeRawX     = GenRandom(-0.9703824520111084, 0.8556089401245117),
                    GyroscopeRawY     = GenRandom(-1.7470258474349976, 1.4218578338623047),
                    GyroscopeRawZ     = GenRandom(-0.9681901931762695, 0.8396636843681335),
                    AccelerometerAxes = 3
                },
                DeviceInfo = deviceInfo
            };

            sig.LocationFix.Add(new Signature.Types.LocationFix()
            {
                Provider           = "fused",
                Latitude           = (float)_latitude,
                Longitude          = (float)_longitude,
                Altitude           = (float)_altitude,
                HorizontalAccuracy = (float)Math.Round(GenRandom(50, 250), 7),
                VerticalAccuracy   = RandomDevice.Next(2, 5),
                TimestampSnapshot  = (ulong)(Utils.GetTime(true) - _startTime - RandomDevice.Next(100, 300)),
                ProviderStatus     = 3,
                LocationType       = 1
            });

            foreach (var request in requests)
            {
                sig.RequestHash.Add(Utils.GenerateRequestHash(ticketBytes, request.ToByteArray()));
            }

            sig.SessionHash = SessionHash;
            //sig.Unknown25 = -8537042734809897855; // For 0.33
            sig.Unknown25 = 7363665268261373700; // For 0.35

            Unknown6 val = new Unknown6()
            {
                RequestType = 6,
                Unknown2    = new Unknown6.Types.Unknown2()
                {
                    EncryptedSignature = ByteString.CopyFrom(crypt.Encrypt(sig.ToByteArray()))
                }
            };

            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);
        }
示例#8
0
        public Client(ISettings settings)
        {
            if (settings.UsePogoDevHashServer)
            {
                if (string.IsNullOrEmpty(settings.AuthAPIKey))
                {
                    throw new AuthConfigException("You have selected Pogodev API but not provide proper API Key");
                }

                Cryptor = new Cipher();          // 0.61.0, 0.63.1

                ApiEndPoint = "api/v133_1/hash"; // 0.63.1

                Hasher = new PokefarmerHasher(settings.AuthAPIKey, settings.DisplayVerboseLog, ApiEndPoint);

                // These 4 constants below need to change if we update the hashing server API version
                // that is used.
                Unknown25 = 0x4A3889A251CCAD52; // 0.63.1

                // WARNING! IF YOU CHANGE THE APPVERSION BELOW ALSO UPDATE THE API_VERSION AT THE TOP
                // OF THE FILE!
                AppVersion = 6301; // 0.63.1

                CurrentApiEmulationVersion = new Version(API_VERSION);
                UnknownPlat8Field          = "15c79df0558009a4242518d2ab65de2a59e09499";
            }

            /*
             * else
             * if (settings.UseLegacyAPI)
             * {
             *  Hasher = new LegacyHashser();
             *  Cryptor = new LegacyCrypt();
             *
             *  Unknown25 = -816976800928766045;// - 816976800928766045;// - 1553869577012279119;
             *  AppVersion = 4500;
             *  CurrentApiEmulationVersion = new Version("0.45.0");
             * }
             */
            else
            {
                throw new AuthConfigException("No API method was selected in auth.json");
            }

            Settings          = settings;
            Proxy             = InitProxy();
            PokemonHttpClient = new PokemonHttpClient();
            Login             = new Login(this);
            Player            = new Player(this);
            Download          = new Download(this);
            Inventory         = new Inventory(this);
            Map            = new Map(this);
            Fort           = new Fort(this);
            Encounter      = new Encounter(this);
            Misc           = new Misc(this);
            KillswitchTask = new KillSwitchTask(this);

            Player.SetCoordinates(Settings.DefaultLatitude, Settings.DefaultLongitude, Settings.DefaultAltitude);
            Platform = settings.DevicePlatform.Equals("ios", StringComparison.Ordinal) ? Platform.Ios : Platform.Android;

            // We can no longer emulate Android so for now just overwrite settings with randomly
            // generated iOS device info.
            if (Platform == Platform.Android)
            {
                Signature.Types.DeviceInfo iosInfo = DeviceInfoHelper.GetRandomIosDevice();
                settings.DeviceId             = iosInfo.DeviceId;
                settings.DeviceBrand          = iosInfo.DeviceBrand;
                settings.DeviceModel          = iosInfo.DeviceModel;
                settings.DeviceModelBoot      = iosInfo.DeviceModelBoot;
                settings.HardwareManufacturer = iosInfo.HardwareManufacturer;
                settings.HardwareModel        = iosInfo.HardwareModel;
                settings.FirmwareBrand        = iosInfo.FirmwareBrand;
                settings.FirmwareType         = iosInfo.FirmwareType;

                // Clear out the android fields.
                settings.AndroidBoardName      = "";
                settings.AndroidBootloader     = "";
                settings.DeviceModelIdentifier = "";
                settings.FirmwareTags          = "";
                settings.FirmwareFingerprint   = "";

                // Now set the client platform to ios
                Platform = Platform.Ios;
            }
        }
示例#9
0
        /// <summary>
        /// Stores data like assets and item templates. Defaults to an in-memory cache, but can be implemented as writing to disk by the platform
        /// </summary>
        // public IDataCache DataCache { get; set; } = new MemoryDataCache();
        // public Templates Templates { get; private set; }

        internal Session(ILoginProvider loginProvider, AccessToken accessToken, GeoCoordinate geoCoordinate, Signature.Types.DeviceInfo deviceInfo = null)
        {
            if (!ValidLoginProviders.Contains(loginProvider.ProviderId))
            {
                throw new ArgumentException($"LoginProvider ID must be one of the following: {string.Join(", ", ValidLoginProviders)}");
            }

            HttpClient    = new PokemonHttpClient();
            DeviceInfo    = deviceInfo ?? DeviceInfoHelper.GetRandomIosDevice();
            AccessToken   = accessToken;
            LoginProvider = loginProvider;
            // Player = new Player(geoCoordinate);
            //Map = new Map(this);
            //RpcClient = new RpcClient(this);
            //_heartbeat = new HeartbeatDispatcher(this);
        }
示例#10
0
        public Client(ISettings settings)
        {
            if (settings.UsePogoDevHashServer)
            {
                if (string.IsNullOrEmpty(settings.AuthAPIKey))
                {
                    throw new AuthConfigException("You have selected Pogodev API but not provide proper API Key");
                }

                Cryptor = new Crypto(); // 0.61.0

                // This value will determine which version of the hashing service you will receive.
                // Currently supported versions:
                // v119   -> Pogo iOS 1.19
                // v121   -> Pogo iOS 1.21
                // v121_2 -> Pogo iOS 1.22
                // v125   -> Pogo iOS 1.25
                // v127_2 -> Pogo iOS 1.27.2
                // v127_3 -> Pogo iOS 1.27.3
                // v127_4 -> Pogo iOS 1.27.4
                // v129_1 -> Pogo iOS 1.29.1
                // v131_0 -> Pogo iOS 1.31.0

                ApiEndPoint = "api/v131_0/hash"; // 0.61.0

                Hasher = new PokefamerHasher(settings.AuthAPIKey, settings.DisplayVerboseLog, ApiEndPoint);

                // These 4 constants below need to change if we update the hashing server API version that is used.

                //Unknown25 = -816976800928766045; // 0.59.1
                Unknown25 = 1296456256998993698; // 0.61.0


                // WARNING! IF YOU CHANGE THE APPVERSION BELOW ALSO UPDATE THE API_VERSION AT THE TOP OF THE FILE!
                //AppVersion = 5704;
                AppVersion = 6100; // 0.61.0

                CurrentApiEmulationVersion = new Version(API_VERSION);
                UnknownPlat8Field          = "90f6a704505bccac73cec99b07794993e6fd5a12";
            }

            /*
             * else
             * if (settings.UseLegacyAPI)
             * {
             *  Hasher = new LegacyHashser();
             *  Cryptor = new LegacyCrypt();
             *
             *  Unknown25 = -816976800928766045;// - 816976800928766045;// - 1553869577012279119;
             *  AppVersion = 4500;
             *  CurrentApiEmulationVersion = new Version("0.45.0");
             * }
             */
            else
            {
                throw new AuthConfigException("No API method being select in your auth.json");
            }

            Settings          = settings;
            Proxy             = InitProxy();
            PokemonHttpClient = new PokemonHttpClient();
            Login             = new Login(this);
            Player            = new Player(this);
            Download          = new Download(this);
            Inventory         = new Inventory(this);
            Map            = new Map(this);
            Fort           = new Fort(this);
            Encounter      = new Encounter(this);
            Misc           = new Misc(this);
            KillswitchTask = new KillSwitchTask(this);

            Player.SetCoordinates(Settings.DefaultLatitude, Settings.DefaultLongitude, Settings.DefaultAltitude);
            Platform = settings.DevicePlatform.Equals("ios", StringComparison.Ordinal) ? Platform.Ios : Platform.Android;

            // We can no longer emulate Android so for now just overwrite settings with randomly generated iOS device info.
            if (Platform == Platform.Android)
            {
                Signature.Types.DeviceInfo iosInfo = DeviceInfoHelper.GetRandomIosDevice();
                settings.DeviceId             = iosInfo.DeviceId;
                settings.DeviceBrand          = iosInfo.DeviceBrand;
                settings.DeviceModel          = iosInfo.DeviceModel;
                settings.DeviceModelBoot      = iosInfo.DeviceModelBoot;
                settings.HardwareManufacturer = iosInfo.HardwareManufacturer;
                settings.HardwareModel        = iosInfo.HardwareModel;
                settings.FirmwareBrand        = iosInfo.FirmwareBrand;
                settings.FirmwareType         = iosInfo.FirmwareType;

                // Clear out the android fields.
                settings.AndroidBoardName      = "";
                settings.AndroidBootloader     = "";
                settings.DeviceModelIdentifier = "";
                settings.FirmwareTags          = "";
                settings.FirmwareFingerprint   = "";

                // Now set the client platform to ios
                Platform = Platform.Ios;
            }
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }