示例#1
0
        internal async Task SetupAEkeysAsync()
        {
            if (Logger.WriteToLog_detail_enabled)
            {
                Logger.WriteToLog_detail(">> InviteSession.SetupAEkeysAsync()");
            }
            var ping     = CreatePing(true);
            var pingData = ping.Encode();


            var timeoutS = _localDrpPeer.Engine.Configuration.UdpLowLevelRequests_ExpirationTimeoutS;

            InitialPendingPingRequest = new PendingLowLevelUdpRequest("dmp pong 3186", RemoteSessionDescription.DirectChannelEndPoint,
                                                                      DmpPongPacket.GetScanner(LocalDirectChannelToken32, ping.PingRequestId32, this), // scanner also verifies HMAC
                                                                      _localDrpPeer.Engine.DateTimeNowUtc, timeoutS,
                                                                      pingData,
                                                                      _localDrpPeer.Engine.Configuration.UdpLowLevelRequests_InitialRetransmissionTimeoutS, _localDrpPeer.Engine.Configuration.UdpLowLevelRequests_RetransmissionTimeoutIncrement
                                                                      );
            var pongUdpData = await _localDrpPeer.Engine.SendUdpRequestAsync_Retransmit(InitialPendingPingRequest);

            if (pongUdpData == null)
            {
                string desc = $"no response to DC PING from {RemoteSessionDescription.DirectChannelEndPoint}  - timeout expired ({timeoutS}s)";
                throw new DrpTimeoutException(desc);
            }

            var pong = DmpPongPacket.Decode(pongUdpData);

            this.DeriveDirectChannelSharedDhSecret(pong.PublicEcdheKey.Ecdh25519PublicKey);
            if (Logger.WriteToLog_detail_enabled)
            {
                Logger.WriteToLog_detail("<< InviteSession.SetupAEkeysAsync()");
            }
        }
示例#2
0
        internal void OnReceivedDmpPing(IPEndPoint remoteEndpoint, byte[] udpData) // engine thread
        {
            WriteToLog_detail($">> OnReceivedDmpPing(remoteEndpoint={remoteEndpoint})");
            if (!remoteEndpoint.Equals(RemoteSessionDescription.DirectChannelEndPoint))
            {
                throw new PossibleAttackException();
            }
            if (SharedPingPongHmacKey == null)
            {
                WriteToLog_detail($"ignoring received DMP PING: SharedPingPongHmacKey is not initialized yet");
                return;
            }

            var ping = DmpPingPacket.DecodeAndVerify(udpData, this);

            var pong = new DmpPongPacket
            {
                DirectChannelToken32 = RemoteSessionDescription.DirectChannelToken32,
                PingRequestId32      = ping.PingRequestId32,
            };

            if (ping.PublicEcdheKey != null)
            {
                pong.PublicEcdheKey = new EcdhPublicKey {
                    Ecdh25519PublicKey = this.LocalDirectChannelEcdhePublicKey
                };
                this.DeriveDirectChannelSharedDhSecret(ping.PublicEcdheKey.Ecdh25519PublicKey);
            }
            pong.PingPongHMAC = GetPingPongHMAC(pong.GetSignedFieldsForPingPongHMAC);

            var pongUdpData = pong.Encode();

            _localDrpPeer.Engine.SendPacket(pongUdpData, remoteEndpoint);
        }
示例#3
0
        internal void OnReceivedDmpPing(IPEndPoint remoteEndpoint, byte[] udpData) // engine thread
        {
            WriteToLog_detail($">> OnReceivedDmpPing(remoteEndpoint={remoteEndpoint})");

            if (!remoteEndpoint.Address.Equals(RemoteSessionDescription.DirectChannelEndPoint.Address))
            {
                throw new PossibleAttackException($"receibed DMP PING from bad IP address {remoteEndpoint.Address}, expected from {RemoteSessionDescription.DirectChannelEndPoint.Address}");
            }

            if (SharedPingPongHmacKey == null)
            {
                WriteToLog_detail($"ignoring received DMP PING: SharedPingPongHmacKey is not initialized yet");
                return;
            }

            var ping = DmpPingPacket.DecodeAndVerify(udpData, this);


            if (this.RemoteSessionDescription.DirectChannelEndPoint.Port != remoteEndpoint.Port)
            {
                WriteToLog_detail($"updating remote peer DirectChannel port from {this.RemoteSessionDescription.DirectChannelEndPoint} to {remoteEndpoint} (when remote peer opens another port in NAT)");
                this.RemoteSessionDescription.DirectChannelEndPoint = remoteEndpoint;
                if (this.InitialPendingPingRequest != null)
                {
                    this.InitialPendingPingRequest.ResponderEndpoint = remoteEndpoint;
                }
            }


            var pong = new DmpPongPacket
            {
                DirectChannelToken32 = RemoteSessionDescription.DirectChannelToken32,
                PingRequestId32      = ping.PingRequestId32,
            };

            if (ping.PublicEcdheKey != null)
            {
                pong.PublicEcdheKey = new EcdhPublicKey {
                    Ecdh25519PublicKey = this.LocalDirectChannelEcdhePublicKey
                };
                this.DeriveDirectChannelSharedDhSecret(ping.PublicEcdheKey.Ecdh25519PublicKey);
            }
            pong.PingPongHMAC = GetPingPongHMAC(pong.GetSignedFieldsForPingPongHMAC);

            var pongUdpData = pong.Encode();

            _localDrpPeer.Engine.SendPacket(pongUdpData, remoteEndpoint);
        }
示例#4
0
        internal async Task SetupAEkeysAsync()
        {
            if (Logger.WriteToLog_detail_enabled)
            {
                Logger.WriteToLog_detail(">> InviteSession.SetupAEkeysAsync()");
            }
            var ping     = CreatePing(true);
            var pingData = ping.Encode();

            var pongUdpData = await _localDrpPeer.Engine.OptionallySendUdpRequestAsync_Retransmit_WaitForResponse("dmp pong 3186", "remote user", pingData, RemoteSessionDescription.DirectChannelEndPoint,
                                                                                                                  DmpPongPacket.GetScanner(LocalDirectChannelToken32, ping.PingRequestId32, this)); // scanner also verifies HMAC

            var pong = DmpPongPacket.Decode(pongUdpData);

            this.DeriveDirectChannelSharedDhSecret(pong.PublicEcdheKey.Ecdh25519PublicKey);
            if (Logger.WriteToLog_detail_enabled)
            {
                Logger.WriteToLog_detail("<< InviteSession.SetupAEkeysAsync()");
            }
        }