Ejemplo n.º 1
0
        private void ProcessAcceptedCall(TLPhoneCallAccepted phoneCallAccepted)
        {
            DispatchStateChanged(PhoneCallState.STATE_EXCHANGING_KEYS);

            if (!TLUtils.CheckGaAndGb(phoneCallAccepted.GB.Data, _secretP.Data))
            {
                CallFailed();
                return;
            }


            _authKey = MTProtoService.GetAuthKey(_aOrB, phoneCallAccepted.GB.ToBytes(), _secretP.ToBytes());
            var keyHash        = Utils.ComputeSHA1(_authKey);
            var keyFingerprint = new TLLong(BitConverter.ToInt64(keyHash, 12));

            var peer = new TLInputPhoneCall
            {
                Id         = phoneCallAccepted.Id,
                AccessHash = phoneCallAccepted.AccessHash
            };

            var protocol = new TLPhoneCallProtocol
            {
                Flags        = new TLInt(0),
                UdpP2P       = true,
                UdpReflector = true,
                MinLayer     = new TLInt(CALL_MIN_LAYER),
                MaxLayer     = new TLInt(CALL_MAX_LAYER)
            };

            _mtProtoService.ConfirmCallAsync(peer, TLString.FromBigEndianData(_ga), keyFingerprint, protocol,
                                             result =>
            {
                _call = result;
                InitiateActualEncryptedCall();
            },
                                             error =>
            {
                CallFailed();
            });
        }
Ejemplo n.º 2
0
        public void StartOutgoingCall(TLInputUserBase userId)
        {
            var salt   = new Byte[256];
            var random = new SecureRandom();

            random.NextBytes(salt);

            var version      = _lastVersion ?? new TLInt(0);
            var randomLength = new TLInt(256);

            _mtProtoService.GetDHConfigAsync(version, randomLength,
                                             result =>
            {
                ConfigureDeviceForCall();
                ShowNotifications();
                StartConnectionSound();
                DispatchStateChanged(PhoneCallState.STATE_REQUESTING);

                _eventAggregator.Publish(new PhoneCallEventArgs("NotificationCenter.didStartedCall"));

                var dhConfig = result as TLDHConfig;
                if (dhConfig != null)
                {
                    if (!TLUtils.CheckPrime(dhConfig.P.Data, dhConfig.G.Value))
                    {
                        CallFailed();
                        return;
                    }

                    _secretP      = dhConfig.P;
                    _secretG      = dhConfig.G;
                    _secretRandom = dhConfig.Random;
                }

                for (var i = 0; i < 256; i++)
                {
                    salt[i] = (byte)(salt[i] ^ _secretRandom.Data[i]);
                }

                var gaBytes = MTProtoService.GetGB(salt, _secretG, _secretP);

                var protocol = new TLPhoneCallProtocol
                {
                    Flags        = new TLInt(0),
                    UdpP2P       = true,
                    UdpReflector = true,
                    MinLayer     = new TLInt(CALL_MIN_LAYER),
                    MaxLayer     = new TLInt(CALL_MAX_LAYER)
                };
                _ga        = gaBytes;
                var gaHash = Utils.ComputeSHA256(_ga);

                _mtProtoService.RequestCallAsync(userId, TLInt.Random(), TLString.FromBigEndianData(gaHash), protocol,
                                                 result2 =>
                {
                    _call = result2;
                    _aOrB = salt;
                    DispatchStateChanged(PhoneCallState.STATE_WAITING);
                    //if (_endCallAfterRequest)
                    //{
                    //    Hangup();
                    //    return;
                    //}
                },
                                                 error2 =>
                {
                });
            },
                                             error =>
            {
                Helpers.Execute.ShowDebugMessage("messages.getDHConfig error " + error);
                CallFailed();
            });
        }