예제 #1
0
 public DialogModelEncrypted(TelegramSession session, EncryptedChat chat, byte[] key, long fingerprint, byte[] a) : base(session)
 {
     this.chat        = chat;
     this.key         = key;
     this.fingerprint = EncryptedChats.CalculateKeyFingerprint(key);//;fingerprint;
     this.a           = a;
 }
예제 #2
0
        public void read(BinaryReader reader)
        {
            logger.info("read session...");
            id         = reader.ReadUInt64();
            sequence   = reader.ReadInt32();
            mainDcId   = reader.ReadInt32();
            timeOffset = reader.ReadInt32();
            cachedSalt = reader.ReadUInt64();
            int count = reader.ReadInt32();

            // contacts sync marker
            ContactsStateMarker = Serializers.String.read(reader);

            dcs = new Dictionary <int, TelegramDC>(count);
            for (int i = 0; i < count; i++)
            {
                int endpointId = reader.ReadInt32();
                dcs.Add(endpointId, new TelegramDC(reader));
            }

            int authorizationExists = reader.ReadInt32();

            if (authorizationExists != 0)
            {
                authorization = (Auth_authorizationConstructor)TL.Parse <auth_Authorization>(reader);
            }


            int usersCount = reader.ReadInt32();

            users = new Dictionary <int, UserModel>(usersCount + 10);
            for (int i = 0; i < usersCount; i++)
            {
                users.Add(reader.ReadInt32(), new UserModel(TL.Parse <User>(reader)));
            }

            int chatsCount = reader.ReadInt32();

            chats = new Dictionary <int, ChatModel>(chatsCount + 10);
            for (int i = 0; i < chatsCount; i++)
            {
                chats.Add(reader.ReadInt32(), new ChatModel(TL.Parse <Chat>(reader)));
            }

            logger.info("reading updates state....");
            updates = new UpdatesProcessor(this, reader);

            logger.info("reading dialogs...");
            dialogs = new Dialogs(this, reader);

            files          = new Files(this);
            encryptedChats = new EncryptedChats(this, reader);

            logger.info("session readed complete");
        }
예제 #3
0
        public TelegramSession(ulong id, int sequence)
        {
            this.id        = id;
            this.sequence  = sequence;
            dcs            = new Dictionary <int, TelegramDC>();
            updates        = new UpdatesProcessor(this);
            dialogs        = new Dialogs(this);
            files          = new Files(this);
            encryptedChats = new EncryptedChats(this);
            users          = new Dictionary <int, UserModel>();
            chats          = new Dictionary <int, ChatModel>();

            SubscribeToUpdates();
        }
예제 #4
0
        public void SetEncryptedChat(EncryptedChatConstructor chat, byte[] a)
        {
            this.chat = chat;

            OnPropertyChanged("IsWaiting");

            if (a != null)
            {
                this.a = a;
            }

            if (this.a != null)
            {
                logger.info("computation key based on a: {0} and m: {1}", BitConverter.ToString(this.a).Replace("-", "").ToLower(), TelegramSession.Instance.EncryptedChats.Modulo);
                key         = new BigInteger(1, chat.g_a_or_b).ModPow(new BigInteger(1, this.a), TelegramSession.Instance.EncryptedChats.Modulo).ToByteArrayUnsigned();
                fingerprint = EncryptedChats.CalculateKeyFingerprint(key);
                this.a      = null;
                logger.info("new calculated key: {0}", BitConverter.ToString(key).Replace("-", "").ToLower());
            }
            // TODO: on property changed
        }