public static LowLevelUdpResponseScanner GetScanner(DirectChannelToken32 senderToken32, uint pingRequestId32, InviteSession session) { BinaryProcedures.CreateBinaryWriter(out var ms, out var w); GetHeaderFields(w, senderToken32, pingRequestId32); return(new LowLevelUdpResponseScanner { ResponseFirstBytes = ms.ToArray(), OptionalFilter = (udpData) => { var pong = Decode(udpData); if (pong.PingPongHMAC.Equals( session.GetPingPongHMAC(pong.GetSignedFieldsForPingPongHMAC) ) == false) { return false; } return true; } }); }
public static DmpPingPacket DecodeAndVerify(byte[] udpData, InviteSession session) { var reader = BinaryProcedures.CreateBinaryReader(udpData, 1); var r = new DmpPingPacket(); r.DirectChannelToken32 = DirectChannelToken32.Decode(reader); r.PingRequestId32 = reader.ReadUInt32(); var flags = reader.ReadByte(); if ((flags & FlagsMask_MustBeZero) != 0) { throw new NotImplementedException(); } if ((flags & Flags_PublicEcdheKeySet) != 0) { r.PublicEcdheKey = EcdhPublicKey.Decode(reader); } r.PingPongHMAC = HMAC.Decode(reader); // verify DirectChannelToken32 if (!r.DirectChannelToken32.Equals(session.LocalSessionDescription.DirectChannelToken32)) { throw new BadSignatureException("invalid DMP PING DirectChannelToken32 136"); } // verify PingPongHMAC if (r.PingPongHMAC.Equals( session.GetPingPongHMAC(r.GetSignedFieldsForPingPongHMAC) ) == false) { throw new BadSignatureException("invalid DMP PING PingPongHMAC 1237"); } return(r); }