예제 #1
0
        private async Task CreateChatResponse(EncryptedChatRequestedConstructor chat)
        {
            try {
                messages_DhConfig dhConfig = await session.Api.messages_getDhConfig(version, 256);

                byte[] randomSalt;
                if (dhConfig.Constructor == Constructor.messages_dhConfig)
                {
                    Messages_dhConfigConstructor conf = (Messages_dhConfigConstructor)dhConfig;
                    version    = conf.version;
                    g          = conf.g;
                    p          = new BigInteger(1, conf.p);
                    randomSalt = conf.random;
                }
                else if (dhConfig.Constructor == Constructor.messages_dhConfigNotModified)
                {
                    Messages_dhConfigNotModifiedConstructor conf = (Messages_dhConfigNotModifiedConstructor)dhConfig;
                    randomSalt = conf.random;
                }
                else
                {
                    throw new InvalidDataException("invalid constructor");
                }

                byte[]     b           = GetSaltedRandomBytes(256, randomSalt, 0);
                BigInteger bInt        = new BigInteger(1, b);
                byte[]     gb          = BigInteger.ValueOf(g).ModPow(bInt, p).ToByteArrayUnsigned();
                byte[]     key         = new BigInteger(1, chat.g_a).ModPow(bInt, p).ToByteArrayUnsigned();
                long       fingerprint = CalculateKeyFingerprint(key);

                EncryptedChat acceptedChat = await session.Api.messages_acceptEncryption(TL.inputEncryptedChat(chat.id, chat.access_hash), gb, fingerprint);


                Deployment.Current.Dispatcher.BeginInvoke(() => {
                    var echats = from dialog in session.Dialogs.Model.Dialogs where dialog is DialogModelEncrypted && ((DialogModelEncrypted)dialog).Id == chat.id select dialog;
                    if (echats.Any())
                    {
                        // ???
                    }
                    else
                    {
                        session.Dialogs.Model.Dialogs.Insert(0, new DialogModelEncrypted(session, acceptedChat, key, fingerprint, b));
                    }
                });
            } catch (Exception e) {
                logger.error("response create chat error: {0}", e);
            }
        }
예제 #2
0
        private async Task CreateChatResponse(EncryptedChatRequestedConstructor chat) {
            try {
                messages_DhConfig dhConfig = await session.Api.messages_getDhConfig(version, 256);
                byte[] randomSalt;
                if(dhConfig.Constructor == Constructor.messages_dhConfig) {
                    Messages_dhConfigConstructor conf = (Messages_dhConfigConstructor) dhConfig;
                    version = conf.version;
                    g = conf.g;
                    p = new BigInteger(1, conf.p);
                    randomSalt = conf.random;
                } else if(dhConfig.Constructor == Constructor.messages_dhConfigNotModified) {
                    Messages_dhConfigNotModifiedConstructor conf = (Messages_dhConfigNotModifiedConstructor) dhConfig;
                    randomSalt = conf.random;
                } else {
                    throw new InvalidDataException("invalid constructor");
                }

                byte[] b = GetSaltedRandomBytes(256, randomSalt, 0);
                BigInteger bInt = new BigInteger(1, b);
                byte[] gb = BigInteger.ValueOf(g).ModPow(bInt, p).ToByteArrayUnsigned();
                byte[] key = new BigInteger(1, chat.g_a).ModPow(bInt, p).ToByteArrayUnsigned();
                long fingerprint = CalculateKeyFingerprint(key);

                EncryptedChat acceptedChat = await session.Api.messages_acceptEncryption(TL.inputEncryptedChat(chat.id, chat.access_hash), gb, fingerprint);


                Deployment.Current.Dispatcher.BeginInvoke(() => {
                    var echats = from dialog in session.Dialogs.Model.Dialogs where dialog is DialogModelEncrypted && ((DialogModelEncrypted) dialog).Id == chat.id select dialog;
                    if(echats.Any()) {
                        // ???
                    } else {
                        session.Dialogs.Model.Dialogs.Insert(0, new DialogModelEncrypted(session, acceptedChat, key, fingerprint, b));
                    }
                });
            } catch(Exception e) {
                logger.error("response create chat error: {0}", e);
            }
        }
예제 #3
0
 public void UpdateChat(EncryptedChatRequestedConstructor chat, byte[] a)
 {
     Task.Run(() => CreateChatResponse(chat));
 }
예제 #4
0
 public void UpdateChat(EncryptedChatRequestedConstructor chat, byte[] a) {
     Task.Run(() => CreateChatResponse(chat));
 }