Наследование: DeOps.Implementation.Protocol.G2Packet
Пример #1
0
        private static void DecodeKey(G2Header child, SettingsPacket settings)
        {
            G2Header key = new G2Header(child.Data);

            RSAParameters rsa = new RSAParameters();

            while (G2Protocol.ReadNextChild(child, key) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(key))
                {
                    continue;
                }

                switch (key.Name)
                {
                case Key_D:
                    rsa.D = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                    break;

                case Key_DP:
                    rsa.DP = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                    break;

                case Key_DQ:
                    rsa.DQ = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                    break;

                case Key_Exponent:
                    rsa.Exponent = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                    break;

                case Key_InverseQ:
                    rsa.InverseQ = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                    break;

                case Key_Modulus:
                    rsa.Modulus = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                    break;

                case Key_P:
                    rsa.P = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                    break;

                case Key_Q:
                    rsa.Q = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                    break;
                }
            }

            settings.KeyPair.ImportParameters(rsa);
            settings.KeyPublic = rsa.Modulus;
        }
Пример #2
0
        private static void DecodeKey(G2Header child, SettingsPacket settings)
        {
            G2Header key = new G2Header(child.Data);

            RSAParameters rsa = new RSAParameters();

            while (G2Protocol.ReadNextChild(child, key) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(key))
                    continue;

                switch (key.Name)
                {
                    case Key_D:
                        rsa.D = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                        break;

                    case Key_DP:
                        rsa.DP = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                        break;

                    case Key_DQ:
                        rsa.DQ = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                        break;

                    case Key_Exponent:
                        rsa.Exponent = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                        break;

                    case Key_InverseQ:
                        rsa.InverseQ = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                        break;

                    case Key_Modulus:
                        rsa.Modulus = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                        break;

                    case Key_P:
                        rsa.P = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                        break;

                    case Key_Q:
                        rsa.Q = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize);
                        break;
                }
            }

            settings.KeyPair.ImportParameters(rsa);
            settings.KeyPublic = rsa.Modulus;
        }
Пример #3
0
        public static SettingsPacket Decode(G2Header root)
        {
            SettingsPacket settings = new SettingsPacket();

            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (child.Name == Packet_KeyPair)
                {
                    DecodeKey(child, settings);
                    continue;
                }

                if (child.Name == Packet_GlobalIM)
                {
                    settings.GlobalIM = true;
                    continue;
                }

                if (child.Name == Packet_Invisible)
                {
                    settings.Invisible = true;
                    continue;
                }

                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_Operation:
                        settings.Operation = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_UserName:
                        settings.UserName = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_TcpPort:
                        settings.TcpPort = BitConverter.ToUInt16(child.Data, child.PayloadPos);
                        break;

                    case Packet_UdpPort:
                        settings.UdpPort = BitConverter.ToUInt16(child.Data, child.PayloadPos);
                        break;

                    case Packet_OpKey:
                        settings.OpKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);

                        byte[] pubID = new MD5CryptoServiceProvider().ComputeHash(settings.OpKey);
                        settings.PublicOpID = Utilities.ExtractBytes(pubID, 0, 8);
                        break;

                    case Packet_FileKey:
                        settings.FileKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_OpAccess:
                        settings.OpAccess = (AccessType)child.Data[child.PayloadPos];
                        break;

                    case Packet_SecurityLevel:
                        settings.Security = (SecurityLevel)BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_Location:
                        settings.Location = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_AwayMsg:
                        settings.AwayMessage = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;
                }
            }

            return settings;
        }
Пример #4
0
        public void Load(LoadModeType loadMode)
        {
            RijndaelManaged Password = new RijndaelManaged();
            Password.Key = PasswordKey;

            byte[] iv = new byte[16];
            byte[] salt = new byte[4];

            OpCore lookup = null;
            if (Core != null)
                lookup = Core.Context.Lookup;

            try
            {
                using (TaggedStream file = new TaggedStream(ProfilePath, Protocol, ProcessSplash)) // tagged with splash
                {
                    // first 16 bytes IV, next 4 bytes is salt
                    file.Read(iv, 0, 16);
                    file.Read(salt, 0, 4);
                    Password.IV = iv;

                    using (CryptoStream crypto = new CryptoStream(file, Password.CreateDecryptor(), CryptoStreamMode.Read))
                    {
                        PacketStream stream = new PacketStream(crypto, Protocol, FileAccess.Read);

                        G2Header root = null;
                        while (stream.ReadPacket(ref root))
                        {
                            if (loadMode == LoadModeType.Settings)
                            {
                                if (root.Name == IdentityPacket.OperationSettings)
                                    Settings = SettingsPacket.Decode(root);

                                if (root.Name == IdentityPacket.UserInfo && Core != null &&
                                    (Core.Sim == null || !Core.Sim.Internet.FreshStart))
                                    Core.IndexInfo(UserInfo.Decode(root));

                                // save icon to identity file because only root node saves icon/splash to link file
                                // to minimize link file size, but allow user to set custom icon/splash if there are not overrides
                                if (root.Name == IdentityPacket.Icon)
                                    OpIcon = IconPacket.Decode(root).OpIcon;
                            }

                            if (lookup != null && (loadMode == LoadModeType.AllCaches || loadMode == LoadModeType.LookupCache))
                            {
                                if (root.Name == IdentityPacket.LookupCachedIP)
                                    lookup.Network.Cache.AddSavedContact(CachedIP.Decode(root));

                                if (root.Name == IdentityPacket.LookupCachedWeb)
                                    lookup.Network.Cache.AddWebCache(WebCache.Decode(root));
                            }

                            if (loadMode == LoadModeType.AllCaches)
                            {
                                if (root.Name == IdentityPacket.OpCachedIP)
                                    Core.Network.Cache.AddSavedContact(CachedIP.Decode(root));

                                if (root.Name == IdentityPacket.OpCachedWeb)
                                    Core.Network.Cache.AddWebCache(WebCache.Decode(root));
                            }
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
Пример #5
0
        public static SettingsPacket Decode(G2Header root)
        {
            SettingsPacket settings = new SettingsPacket();

            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (child.Name == Packet_KeyPair)
                {
                    DecodeKey(child, settings);
                    continue;
                }

                if (child.Name == Packet_GlobalIM)
                {
                    settings.GlobalIM = true;
                    continue;
                }

                if (child.Name == Packet_Invisible)
                {
                    settings.Invisible = true;
                    continue;
                }

                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }


                switch (child.Name)
                {
                case Packet_Operation:
                    settings.Operation = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_UserName:
                    settings.UserName = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_TcpPort:
                    settings.TcpPort = BitConverter.ToUInt16(child.Data, child.PayloadPos);
                    break;

                case Packet_UdpPort:
                    settings.UdpPort = BitConverter.ToUInt16(child.Data, child.PayloadPos);
                    break;

                case Packet_OpKey:
                    settings.OpKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);

                    byte[] pubID = new MD5CryptoServiceProvider().ComputeHash(settings.OpKey);
                    settings.PublicOpID = Utilities.ExtractBytes(pubID, 0, 8);
                    break;

                case Packet_FileKey:
                    settings.FileKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_OpAccess:
                    settings.OpAccess = (AccessType)child.Data[child.PayloadPos];
                    break;

                case Packet_SecurityLevel:
                    settings.Security = (SecurityLevel)BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Location:
                    settings.Location = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_AwayMsg:
                    settings.AwayMessage = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(settings);
        }
Пример #6
0
        public void Load(LoadModeType loadMode)
        {
            RijndaelManaged Password = new RijndaelManaged();

            Password.Key = PasswordKey;

            byte[] iv   = new byte[16];
            byte[] salt = new byte[4];

            OpCore lookup = null;

            if (Core != null)
            {
                lookup = Core.Context.Lookup;
            }

            try
            {
                using (TaggedStream file = new TaggedStream(ProfilePath, Protocol, ProcessSplash)) // tagged with splash
                {
                    // first 16 bytes IV, next 4 bytes is salt
                    file.Read(iv, 0, 16);
                    file.Read(salt, 0, 4);
                    Password.IV = iv;

                    using (CryptoStream crypto = new CryptoStream(file, Password.CreateDecryptor(), CryptoStreamMode.Read))
                    {
                        PacketStream stream = new PacketStream(crypto, Protocol, FileAccess.Read);

                        G2Header root = null;
                        while (stream.ReadPacket(ref root))
                        {
                            if (loadMode == LoadModeType.Settings)
                            {
                                if (root.Name == IdentityPacket.OperationSettings)
                                {
                                    Settings = SettingsPacket.Decode(root);
                                }

                                if (root.Name == IdentityPacket.UserInfo && Core != null &&
                                    (Core.Sim == null || !Core.Sim.Internet.FreshStart))
                                {
                                    Core.IndexInfo(UserInfo.Decode(root));
                                }

                                // save icon to identity file because only root node saves icon/splash to link file
                                // to minimize link file size, but allow user to set custom icon/splash if there are not overrides
                                if (root.Name == IdentityPacket.Icon)
                                {
                                    OpIcon = IconPacket.Decode(root).OpIcon;
                                }
                            }

                            if (lookup != null && (loadMode == LoadModeType.AllCaches || loadMode == LoadModeType.LookupCache))
                            {
                                if (root.Name == IdentityPacket.LookupCachedIP)
                                {
                                    lookup.Network.Cache.AddSavedContact(CachedIP.Decode(root));
                                }

                                if (root.Name == IdentityPacket.LookupCachedWeb)
                                {
                                    lookup.Network.Cache.AddWebCache(WebCache.Decode(root));
                                }
                            }

                            if (loadMode == LoadModeType.AllCaches)
                            {
                                if (root.Name == IdentityPacket.OpCachedIP)
                                {
                                    Core.Network.Cache.AddSavedContact(CachedIP.Decode(root));
                                }

                                if (root.Name == IdentityPacket.OpCachedWeb)
                                {
                                    Core.Network.Cache.AddWebCache(WebCache.Decode(root));
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }