コード例 #1
0
 public void BeginElement(
     string name,
     UnknownObjectReader value,
     string[] attributeNames,
     object[] attributeValues)
 {
     foreach (string resolvedElement in this._ResolvedElements)
     {
         this._Writer.WriteStartElement(resolvedElement);
     }
     this._ResolvedElements.Clear();
     this._Writer.WriteStartElement(name);
     if (attributeNames != null && attributeValues != null)
     {
         int num = 0;
         foreach (string attributeName in attributeNames)
         {
             this._Writer.WriteAttributeString(attributeName, attributeValues[num++].ToString());
         }
     }
     if (value == null)
     {
         return;
     }
     if (value.Value is string || value.Value is IPrimitive)
     {
         if (value.Value is PasswordFieldType)
         {
             this._Writer.WriteAttributeString("__encrypted", "yes");
             this._Writer.WriteCData(CryptUtil.Encrypt(value.Value.ToString()));
         }
         else
         {
             this._Writer.WriteCData(value.Value.ToString());
         }
     }
     else if (value.Value is EncryptedField)
     {
         this._Writer.WriteAttributeString("__encrypted", "yes");
         EncryptedField encryptedField = value.Value as EncryptedField;
         if (encryptedField.IsEncrypted)
         {
             this._Writer.WriteCData(encryptedField.Value);
         }
         else
         {
             this._Writer.WriteCData(CryptUtil.Encrypt(encryptedField.Value));
         }
     }
     else
     {
         this._Writer.WriteCData(value.Value.ToString().ToLower());
     }
 }
コード例 #2
0
ファイル: CookieSession.cs プロジェクト: jbinder/dragon
        private void SaveToCookie()
        {
            // set return cookie
            var cookie = new HttpCookie(CookieName);

            cookie.HttpOnly = false;
            cookie.Expires  = DateTime.UtcNow.AddYears(1);
            cookie.Secure   = SSLOnly;
            cookie.Value    = CryptUtil.Encrypt(ID.ToString());
            Debug.WriteLine(string.Format("Adding cookie '{0}' with value '{1}'", CookieName, cookie.Value));
            m_httpCtx.Response.Cookies.Add(cookie);
        }
コード例 #3
0
 public void Encrypt()
 {
     foreach (ADServerElement server in ADServers)
     {
         if (server.Password != null)
         {
             if (!server.Password.StartsWith(EncodePrefix))
             {
                 server.Password = EncodePrefix + CryptUtil.Encrypt(server.Password);
             }
         }
     }
 }
コード例 #4
0
        public byte[] Serialize <T>(T obj)
        {
            var json  = JsonUtility.ToJson(obj, prettyPrint: !compress && !ShouldCrypt);
            var bytes = System.Text.Encoding.UTF8.GetBytes(json);

            if (compress)
            {
                bytes = CompressUtil.Compress(bytes);
            }
            if (ShouldCrypt)
            {
                bytes = CryptUtil.Encrypt(bytes, password, salt, iterations);
            }
            return(bytes);
        }
コード例 #5
0
 public static EncryptedField CreateEncryptedField(string value)
 {
     return(new EncryptedField(CryptUtil.Encrypt(value), true));
 }
コード例 #6
0
 protected virtual string EncryptPassword(string document)
 {
   string str1 = document;
   XmlWriter xmlWriter = (XmlWriter) null;
   XmlReader reader = (XmlReader) null;
   bool flag1 = false;
   try
   {
     StringBuilder sb = new StringBuilder();
     xmlWriter = (XmlWriter) new XmlTextWriter((TextWriter) new StringWriter(sb));
     XmlReaderSettings settings = new XmlReaderSettings();
     settings.IgnoreWhitespace = true;
     reader = XmlReader.Create((TextReader) new StringReader(document), settings);
     if (reader.Read())
     {
       do
       {
         if (reader.NodeType == XmlNodeType.Element && (reader.LocalName == "__session" || reader.LocalName == "__connect"))
           reader.Read();
         else if (reader.NodeType == XmlNodeType.Element && (reader.LocalName == "password" || reader.LocalName == "sessionId"))
         {
           for (bool flag2 = reader.MoveToFirstAttribute(); flag2; flag2 = reader.MoveToNextAttribute())
           {
             if (reader.LocalName == "__encrypted" && string.Compare(reader.Value, "yes", true) == 0)
               flag1 = true;
           }
           reader.Close();
         }
         else
           reader.Read();
       }
       while (!reader.EOF && reader.ReadState != System.Xml.ReadState.Closed);
     }
     reader = XmlReader.Create((TextReader) new StringReader(document), settings);
     if (reader.Read())
     {
       do
       {
         if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "__InSite")
         {
           string str2 = (string) null;
           xmlWriter.WriteStartElement(reader.LocalName);
           for (bool flag2 = reader.MoveToFirstAttribute(); flag2; flag2 = reader.MoveToNextAttribute())
           {
             if (reader.LocalName == "__encryption")
               str2 = reader.Value;
             else
               xmlWriter.WriteAttributeString(reader.LocalName, reader.Value);
           }
           if (!flag1)
             str2 = "2";
           if (!string.IsNullOrEmpty(str2))
             xmlWriter.WriteAttributeString("__encryption", str2);
           reader.Read();
         }
         else if (reader.NodeType == XmlNodeType.Element && (reader.LocalName == "__session" || reader.LocalName == "__connect"))
         {
           xmlWriter.WriteStartElement(reader.LocalName);
           xmlWriter.WriteAttributes(reader, true);
           reader.Read();
         }
         else if (reader.NodeType == XmlNodeType.EndElement && (reader.LocalName == "__session" || reader.LocalName == "__connect"))
         {
           xmlWriter.WriteEndElement();
           reader.Read();
         }
         else if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "password")
         {
           if (!flag1)
           {
             xmlWriter.WriteStartElement(reader.LocalName);
             for (bool flag2 = reader.MoveToFirstAttribute(); flag2; flag2 = reader.MoveToNextAttribute())
             {
               if (reader.LocalName != "__encrypted")
                 xmlWriter.WriteAttributeString(reader.LocalName, reader.Value);
             }
             xmlWriter.WriteAttributeString("__encrypted", "yes");
             int content = (int) reader.MoveToContent();
             string fieldData = reader.ReadElementContentAsString();
             xmlWriter.WriteValue(CryptUtil.Encrypt(fieldData));
             xmlWriter.WriteEndElement();
           }
           else
             xmlWriter.WriteNode(reader, true);
         }
         else
           xmlWriter.WriteNode(reader, true);
       }
       while (!reader.EOF);
       str1 = sb.ToString();
     }
   }
   catch (Exception ex)
   {
     str1 = document;
     this.LogEntry(string.Format("Password encrypting error: {0}", (object) ex.Message), EventLogEntryType.Error);
   }
   finally
   {
     reader?.Close();
     xmlWriter?.Close();
   }
   return str1;
 }
コード例 #7
0
ファイル: RpcEncryption.cs プロジェクト: wertzui/POGOLib
        /// <summary>
        ///     Generates the encrypted signature which is required for the <see cref="RequestEnvelope"/>.
        /// </summary>
        /// <param name="requests">The requests of the <see cref="RequestEnvelope"/>.</param>
        /// <returns>The encrypted <see cref="Unknown6"/> (Signature).</returns>
        internal Unknown6 GenerateSignature(RequestEnvelope requestEnvelope)
        {
            var signature = new Signature
            {
                TimestampSinceStart = (ulong)_internalStopwatch.ElapsedMilliseconds,
                Timestamp           = (ulong)TimeUtil.GetCurrentTimestampInMilliseconds(),
                SensorInfo          = new SensorInfo()
                {
                    AccelNormalizedZ  = Randomize(9.8),
                    AccelNormalizedX  = Randomize(0.02),
                    AccelNormalizedY  = Randomize(0.3),
                    TimestampSnapshot = (ulong)_internalStopwatch.ElapsedMilliseconds - 230,
                    MagnetometerX     = Randomize(012271042913198471),
                    MagnetometerY     = Randomize(-0.015570580959320068),
                    MagnetometerZ     = Randomize(0.010850906372070313),
                    AngleNormalizedX  = Randomize(17.950439453125),
                    AngleNormalizedY  = Randomize(-23.36273193359375),
                    AngleNormalizedZ  = Randomize(-48.8250732421875),
                    AccelRawX         = Randomize(-0.0120010357350111),
                    AccelRawY         = Randomize(-0.04214850440621376),
                    AccelRawZ         = Randomize(0.94571763277053833),
                    GyroscopeRawX     = Randomize(7.62939453125e-005),
                    GyroscopeRawY     = Randomize(-0.00054931640625),
                    GyroscopeRawZ     = Randomize(0.0024566650390625),
                    AccelerometerAxes = 3
                },
                DeviceInfo = new DeviceInfo()
                {
                    DeviceId              = _session.Device.DeviceId,
                    AndroidBoardName      = _session.Device.AndroidBoardName,
                    AndroidBootloader     = _session.Device.AndroidBootloader,
                    DeviceBrand           = _session.Device.DeviceBrand,
                    DeviceModel           = _session.Device.DeviceModel,
                    DeviceModelIdentifier = _session.Device.DeviceModelIdentifier,
                    DeviceModelBoot       = _session.Device.DeviceModelBoot,
                    HardwareManufacturer  = _session.Device.HardwareManufacturer,
                    HardwareModel         = _session.Device.HardwareModel,
                    FirmwareBrand         = _session.Device.FirmwareBrand,
                    FirmwareTags          = _session.Device.FirmwareTags,
                    FirmwareType          = _session.Device.FirmwareType,
                    FirmwareFingerprint   = _session.Device.FirmwareFingerprint
                },
                LocationFix =
                {
                    new LocationFix
                    {
                        Provider = "network",
                        //Unk4 = 120,
                        Latitude            = (float)_session.Player.Coordinate.Latitude,
                        Longitude           = (float)_session.Player.Coordinate.Longitude,
                        Altitude            = (float)_session.Player.Coordinate.Altitude,
                        TimestampSinceStart = (ulong)_internalStopwatch.ElapsedMilliseconds - 200,
                        Floor        = 3,
                        LocationType = 1
                    }
                }
            };

            // Compute 10
            var serializedTicket = requestEnvelope.AuthTicket != null?requestEnvelope.AuthTicket.ToByteArray() : requestEnvelope.AuthInfo.ToByteArray();

            var firstHash     = CalculateHash32(serializedTicket, 0x1B845238);
            var locationBytes = BitConverter.GetBytes(_session.Player.Coordinate.Latitude).Reverse()
                                .Concat(BitConverter.GetBytes(_session.Player.Coordinate.Longitude).Reverse())
                                .Concat(BitConverter.GetBytes(_session.Player.Coordinate.Altitude).Reverse()).ToArray();

            signature.LocationHash1 = CalculateHash32(locationBytes, firstHash);
            // Compute 20
            signature.LocationHash2 = CalculateHash32(locationBytes, 0x1B845238);
            // Compute 24
            var seed = xxHash64.CalculateHash(serializedTicket, serializedTicket.Length, 0x1B845238);

            foreach (var req in requestEnvelope.Requests)
            {
                var reqBytes = req.ToByteArray();
                signature.RequestHash.Add(xxHash64.CalculateHash(reqBytes, reqBytes.Length, seed));
            }

            //static for now
            signature.Unknown22 = ByteString.CopyFrom(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F);

            var iv = new byte[32];

            _random.NextBytes(iv);

            var encryptedSignature = new Unknown6
            {
                RequestType = 6,
                Unknown2    = new Unknown6.Types.Unknown2
                {
                    EncryptedSignature = ByteString.CopyFrom(CryptUtil.Encrypt(signature.ToByteArray(), iv))
                }
            };

            return(encryptedSignature);
        }