コード例 #1
0
        public void CreateTransactionUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipRequestStr =
                "INVITE sip:[email protected];switchtag=902888 SIP/2.0" + m_CRLF +
                "Record-Route: <sip:2.3.4.5;ftag=9307C640-33C;lr=on>" + m_CRLF +
                "Via: SIP/2.0/UDP  5.6.7.2:5060" + m_CRLF +
                "Via: SIP/2.0/UDP 1.2.3.4;branch=z9hG4bKa7ac.2bfad091.0" + m_CRLF +
                "From: \"unknown\" <sip:00.000.00.0>;tag=9307C640-33C" + m_CRLF +
                "To: <sip:[email protected]>" + m_CRLF +
                "Date: Thu, 21 Feb 2008 01:46:30 GMT" + m_CRLF +
                "Call-ID: A8706191-DF5511DC-B886ED7B-395C3F7E" + m_CRLF +
                "Supported: timer,100rel" + m_CRLF +
                "Min-SE:  1800" + m_CRLF +
                "Cisco-Guid: 2825897321-3746894300-3095653755-962346878" + m_CRLF +
                "User-Agent: Cisco-SIPGateway/IOS-12.x" + m_CRLF +
                "Allow: INVITE, OPTIONS, BYE, CANCEL, ACK, PRACK, COMET, REFER, SUBSCRIBE, NOTIFY, INFO" + m_CRLF +
                "CSeq: 101 INVITE" + m_CRLF +
                "Max-Forwards: 5" + m_CRLF +
                "Timestamp: 1203558390" + m_CRLF +
                "Contact: <sip:1.2.3.4:5060>" + m_CRLF +
                "Expires: 180" + m_CRLF +
                "Allow-Events: telephone-event" + m_CRLF +
                "Content-Type: application/sdp" + m_CRLF +
                "Content-Length: 370" + m_CRLF +
                m_CRLF +
                "v=0" + m_CRLF +
                "o=CiscoSystemsSIP-GW-UserAgent 9312 7567 IN IP4 00.00.00.0" + m_CRLF +
                "s=SIP Call" + m_CRLF +
                "c=IN IP4 00.000.00.0" + m_CRLF +
                "t=0 0" + m_CRLF +
                "m=audio 16434 RTP/AVP 8 0 4 18 3 101" + m_CRLF +
                "c=IN IP4 00.000.00.0" + m_CRLF +
                "a=rtpmap:8 PCMA/8000" + m_CRLF +
                "a=rtpmap:0 PCMU/8000" + m_CRLF +
                "a=rtpmap:4 G723/8000" + m_CRLF +
                "a=fmtp:4 annexa=no" + m_CRLF +
                "a=rtpmap:18 G729/8000" + m_CRLF +
                "a=fmtp:18 annexb=no" + m_CRLF +
                "a=rtpmap:3 GSM/8000" + m_CRLF +
                "a=rtpmap:101 telepho";

            SIPRequest           request           = SIPRequest.ParseSIPRequest(sipRequestStr);
            SIPTransport         sipTransport      = new SIPTransport();
            SIPTransactionEngine transactionEngine = sipTransport.m_transactionEngine;
            SIPEndPoint          dummySIPEndPoint  = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234));
            SIPTransaction       transaction       = new UACInviteTransaction(sipTransport, request, null);

            Assert.True(transaction.TransactionRequest.URI.ToString() == "sip:[email protected];switchtag=902888", "Transaction request URI was incorrect.");
        }
コード例 #2
0
        public async Task BlindTransferUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPTransport transport = new SIPTransport();

            transport.AddSIPChannel(new MockSIPChannel(new System.Net.IPEndPoint(IPAddress.Any, 0)));

            SIPUserAgent userAgent = new SIPUserAgent(transport, null);

            string inviteReqStr = "INVITE sip:192.168.11.50:5060 SIP/2.0" + m_CRLF +
                                  "Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691" + m_CRLF +
                                  "To: <sip:[email protected]>;tag=ZUJSXRRGXQ" + m_CRLF +
                                  "From: <sip:[email protected]>;tag=4a60ce364b774258873ff199e5e39938" + m_CRLF +
                                  "Call-ID: 17324d6df8744d978008c8997bfd208d" + m_CRLF +
                                  "CSeq: 3532 INVITE" + m_CRLF +
                                  "Contact: <sip:[email protected]:60163;ob>" + m_CRLF +
                                  "Max-Forwards: 70" + m_CRLF +
                                  "User-Agent: MicroSIP/3.19.22" + m_CRLF +
                                  "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS" + m_CRLF +
                                  "Supported: replaces, 100rel, timer, norefersub" + m_CRLF +
                                  "Content-Length: 343" + m_CRLF +
                                  "Content-Type: application/sdp" + m_CRLF +
                                  "Session-Expires: 1800" + m_CRLF +
                                  "Min-SE: 90" + m_CRLF +
                                  "" + m_CRLF +
                                  "v=0" + m_CRLF +
                                  "o=- 3785527268 3785527269 IN IP4 192.168.11.50" + m_CRLF +
                                  "s=pjmedia" + m_CRLF +
                                  "t=0 0" + m_CRLF +
                                  "m=audio 4032 RTP/AVP 0 101" + m_CRLF +
                                  "c=IN IP4 192.168.11.50" + m_CRLF +
                                  "a=rtpmap:0 PCMU/8000" + m_CRLF +
                                  "a=rtpmap:101 telephone-event/8000" + m_CRLF +
                                  "a=fmtp:101 0-16" + m_CRLF +
                                  "a=sendrecv";

            SIPEndPoint      dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 0));
            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint);
            SIPRequest       inviteReq        = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            UASInviteTransaction uasTx   = new UASInviteTransaction(transport, inviteReq, null);
            SIPServerUserAgent   mockUas = new SIPServerUserAgent(transport, null, null, null, SIPCallDirection.In, null, null, null, uasTx);
            await userAgent.Answer(mockUas, CreateMediaSession());

            CancellationTokenSource cts = new CancellationTokenSource();
            bool result = await userAgent.BlindTransfer(SIPURI.ParseSIPURIRelaxed("127.0.0.1"), TimeSpan.FromSeconds(2), cts.Token);

            Assert.False(result);
        }
コード例 #3
0
        public void TestMethod1()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                @"INVITE sip:[email protected];unknownparam SIP/2.0
        TO :
        sip:[email protected] ;   tag    = 1918181833n
        from   : ""J Rosenberg \\\""""       <sip:[email protected]>
        ;
        tag = 98asjd8
        MaX-fOrWaRdS: 0068
        Call-ID: [email protected]
        Content-Length   : 150
        cseq: 0009
        INVITE
        Via  : SIP  /   2.0
        /UDP
        192.0.2.2;branch=390skdjuw
        s :
        NewFangledHeader:   newfangled value
        continued newfangled value
        UnknownHeaderWithUnusualValue: ;;,,;;,;
        Content-Type: application/sdp
        Route:
        <sip:services.example.com;lr;unknownwith=value;unknown-no-value>
        v:  SIP  / 2.0  / TCP     spindle.example.com   ;
        branch  =   z9hG4bK9ikj8  ,
        SIP  /    2.0   / UDP  192.168.255.111   ; branch=
        z9hG4bK30239
        m:""Quoted string \""\"""" <sip:[email protected]> ; newparam =
        newvalue ;
        secondparam ; q = 0.33

        v=0
      o=mhandley 29739 7272939 IN IP4 192.0.2.3
      s=-
      c=IN IP4 192.0.2.4
      t=0 0
      m=audio 49217 RTP/AVP 0 12
      m=video 3227 RTP/AVP 31
      a=rtpmap:31 LPC";

            SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPRequest inviteReq  = SIPRequest.ParseSIPRequest(sipMessage);

            Console.WriteLine(inviteReq.ToString());

            Console.WriteLine("-----------------------------------------");
        }
コード例 #4
0
        public void AckRecognitionIIUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPTransport         sipTransport = new SIPTransport();
            SIPTransactionEngine engine       = sipTransport.m_transactionEngine; // Client side of the INVITE.

            string inviteRequestStr =
                "INVITE sip:[email protected] SIP/2.0" + m_CRLF +
                "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
                "From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF +
                "To: <sip:[email protected]>" + m_CRLF +
                "Contact: <sip:[email protected]:5065>" + m_CRLF +
                "Call-ID: [email protected]" + m_CRLF +
                "CSeq: 49429 INVITE" + m_CRLF +
                "Max-Forwards: 70" + m_CRLF +
                "Content-Type: application/sdp" + m_CRLF +
                "User-Agent: Dummy" + m_CRLF +
                m_CRLF;

            SIPRequest inviteRequest = SIPRequest.ParseSIPRequest(inviteRequestStr);

            // Server has received the invite.
            SIPEndPoint          dummySIPEndPoint  = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234));
            UASInviteTransaction serverTransaction = new UASInviteTransaction(sipTransport, inviteRequest, null, true);

            engine.AddTransaction(serverTransaction);

            string ackRequestStr =
                "ACK sip:[email protected] SIP/2.0" + m_CRLF +
                "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
                "From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF +
                "To: <sip:[email protected]>" + m_CRLF +
                "Contact: <sip:[email protected]:5065>" + m_CRLF +
                "Call-ID: [email protected]" + m_CRLF +
                "CSeq: 49429 ACK" + m_CRLF +
                "Max-Forwards: 70" + m_CRLF +
                "User-Agent: Dummy" + m_CRLF +
                m_CRLF;

            SIPRequest ackRequest = SIPRequest.ParseSIPRequest(ackRequestStr);

            SIPTransaction matchingTransaction = engine.GetTransaction(ackRequest);

            Assert.True(matchingTransaction.TransactionId == serverTransaction.TransactionId, "ACK transaction did not match INVITE transaction.");
        }
コード例 #5
0
        public async Task HandleInvalidSdpPortOnAnswerUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPTransport transport = new SIPTransport();
            SIPUserAgent userAgent = new SIPUserAgent(transport, null);

            string inviteReqStr = @"INVITE sip:[email protected] SIP/2.0
Via: SIP/2.0/UDP 0.0.0.0;branch=z9hG4bK57441c4980b94e1686a06ae080be2935;rport
To: <sip:[email protected]>
From: <sip:0.0.0.0:0>;tag=MYILIYPHQD 
Call-ID: ddf0e5a9687b4745925438da9000445d
CSeq: 1 INVITE
Max-Forwards: 70
Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, PRACK, REFER, REGISTER, SUBSCRIBE
Content-Length: 0

v=0
o=- 1838015445 0 IN IP4 127.0.0.1
s=-
c=IN IP4 127.0.0.1
t=0 0
m=audio 79762 RTP/AVP 0
a=rtpmap:0 PCMU/8000
a=sendrecv";

            SIPEndPoint      dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 0));
            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint);
            SIPRequest       inviteReq        = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            var uas = userAgent.AcceptCall(inviteReq);

            RTPSession       rtpSession = new RTPSession(false, false, false);
            MediaStreamTrack audioTrack = new MediaStreamTrack(SDPMediaTypesEnum.audio, false, new List <SDPMediaFormat> {
                new SDPMediaFormat(SDPMediaFormatsEnum.PCMU)
            });

            rtpSession.addTrack(audioTrack);

            var result = await userAgent.Answer(uas, rtpSession);

            Assert.False(result);

            rtpSession.Close("normal");
        }
コード例 #6
0
            public void AckRecognitionIIUnitTest()
            {
                SIPTransactionEngine engine = new SIPTransactionEngine();     // Client side of the INVITE.

                string inviteRequestStr =
                    "INVITE sip:[email protected] SIP/2.0" + m_CRLF +
                    "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
                    "From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF +
                    "To: <sip:[email protected]>" + m_CRLF +
                    "Contact: <sip:[email protected]:5065>" + m_CRLF +
                    "Call-ID: [email protected]" + m_CRLF +
                    "CSeq: 49429 INVITE" + m_CRLF +
                    "Max-Forwards: 70" + m_CRLF +
                    "Content-Type: application/sdp" + m_CRLF +
                    "User-Agent: Dummy" + m_CRLF +
                    m_CRLF;

                SIPRequest inviteRequest = SIPRequest.ParseSIPRequest(inviteRequestStr);

                // Server has received the invite.
                SIPEndPoint          dummySIPEndPoint  = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234));
                UASInviteTransaction serverTransaction = new UASInviteTransaction(new SIPTransport(MockSIPDNSManager.Resolve, null), inviteRequest, dummySIPEndPoint, dummySIPEndPoint, null);

                engine.AddTransaction(serverTransaction);

                //SIPResponse errorResponse = SIPTransport.GetResponse(inviteRequest.Header, SIPResponseStatusCodesEnum.Decline, "Unit Test", null, null);

                string ackRequestStr =
                    "ACK sip:[email protected] SIP/2.0" + m_CRLF +
                    "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
                    "From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF +
                    "To: <sip:[email protected]>" + m_CRLF +
                    "Contact: <sip:[email protected]:5065>" + m_CRLF +
                    "Call-ID: [email protected]" + m_CRLF +
                    "CSeq: 49429 ACK" + m_CRLF +
                    "Max-Forwards: 70" + m_CRLF +
                    "User-Agent: Dummy" + m_CRLF +
                    m_CRLF;

                SIPRequest ackRequest = SIPRequest.ParseSIPRequest(ackRequestStr);

                SIPTransaction matchingTransaction = engine.GetTransaction(ackRequest);

                Assert.IsTrue(matchingTransaction.TransactionId == serverTransaction.TransactionId, "ACK transaction did not match INVITE transaction.");
            }
コード例 #7
0
        public void RFC5118_4_7()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "BYE sip:[email protected] SIP/2.0" + CRLF +
                "Via: SIP/2.0/UDP [2001:db8::9:1]:6050;branch=z9hG4bKas3-111" + CRLF +
                "Via: SIP/2.0/UDP 192.0.2.1;branch=z9hG4bKjhja8781hjuaij65144" + CRLF +
                "Via: SIP/2.0/TCP [2001:db8::9:255];branch=z9hG4bK451jj;received=192.0.2.200" + CRLF +
                "Call-ID: 997077@lau_4100" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "CSeq: 89187 BYE" + CRLF +
                "To: sip:[email protected];tag=9817--94" + CRLF +
                "From: sip:[email protected];tag=81x2" + CRLF +
                "Content-Length: 0";


            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);

            Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly.");
            SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            Assert.Equal(SIPMethodsEnum.BYE, sipRequest.Method);
            IPAddress ip6, ip4;

            Assert.NotEmpty(sipRequest.Header.Vias.Via);
            Assert.True(sipRequest.Header.Vias.Length == 3);
            Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);
            Assert.Equal(SIPProtocolsEnum.udp, sipRequest.Header.Vias.TopViaHeader.Transport);
            Assert.Equal(6050, sipRequest.Header.Vias.TopViaHeader.Port);
            Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.BottomViaHeader.Host, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);
            Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.BottomViaHeader.ReceivedFromIPAddress, out ip4));
            Assert.Equal(AddressFamily.InterNetwork, ip4.AddressFamily);
            Assert.Equal(SIPProtocolsEnum.tcp, sipRequest.Header.Vias.BottomViaHeader.Transport);
            sipRequest.Header.Vias.PopTopViaHeader();
            Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromAddress, out ip4));
            Assert.Equal(AddressFamily.InterNetwork, ip4.AddressFamily);
            Assert.Equal(SIPProtocolsEnum.udp, sipRequest.Header.Vias.TopViaHeader.Transport);
            Assert.False(IPAddress.TryParse(sipRequest.URI.HostAddress, out ip6));

            logger.LogDebug("-----------------------------------------");
        }
コード例 #8
0
        public void ShortTorturousInvite()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            Assert.True(File.Exists("wsinv.dat"), "The wsinv.dat torture test input file was missing.");

            string raw = File.ReadAllText("wsinv.dat");

            logger.LogDebug(raw);

            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(raw), null, null);
            SIPRequest       inviteReq        = SIPRequest.ParseSIPRequest(raw);

            Assert.NotNull(sipMessageBuffer);
            Assert.NotNull(inviteReq);

            logger.LogDebug("-----------------------------------------");
        }
コード例 #9
0
        public async Task TestSetRequestCustomHeaderFuncUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPEndPoint dummyEP = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 5060));

            string inviteReqStr =
                @"INVITE sip:[email protected]:12014 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27
To: <sip:[email protected]:12014>
From: <sip:[email protected]>;tag=2062917371
Call-ID: 8ae45c15425040179a4285d774ccbaf6
CSeq: 1 INVITE
Contact: <sip:127.0.0.1:1234>
Max-Forwards: 70
User-Agent: unittest
Content-Length: 5
Content-Type: application/sdp

dummy";
            var        sipReqBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummyEP, dummyEP);
            SIPRequest inviteReq    = SIPRequest.ParseSIPRequest(sipReqBuffer);

            using (var transport = new SIPTransport())
            {
                transport.AddSIPChannel(new MockSIPChannel(dummyEP.GetIPEndPoint()));

                string contactHost = "devcall.sipsorcery.com";
                transport.CustomiseRequestHeader = (local, dst, req) =>
                {
                    var hdr = req.Header.Copy();
                    hdr.Contact[0].ContactURI.Host = contactHost;
                    return(hdr);
                };

                await transport.SendRequestAsync(inviteReq);

                logger.LogDebug(inviteReq.ToString());

                Assert.Equal(contactHost, inviteReq.Header.Contact[0].ContactURI.Host);
            }
        }
コード例 #10
0
        public void RFC5118_4_3()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "REGISTER sip:[2001:db8::10:5070] SIP/2.0" + CRLF +
                "To: sip:[email protected]" + CRLF +
                "From: sip:[email protected];tag=81x2" + CRLF +
                "Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111" + CRLF +
                "Call-ID: SSG9559905523997077@hlau_4100" + CRLF +
                "Contact: \"Caller\" <sip:caller@[2001:db8::1]>" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "CSeq: 98176 REGISTER" + CRLF +
                "Content-Length: 0";

            //parsing is correct, but port is ambiguous,
            //intention was to target port 5070
            //but that's nothing a program can find out

            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);

            Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly.");
            SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            Assert.Equal(SIPMethodsEnum.REGISTER, sipRequest.Method);
            IPAddress ip6;

            Assert.NotEmpty(sipRequest.Header.Vias.Via);
            Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);
            Assert.NotEmpty(sipRequest.Header.Contact);
            Assert.True(IPAddress.TryParse(sipRequest.Header.Contact[0].ContactURI.HostAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);
            Assert.True(IPAddress.TryParse(sipRequest.URI.HostAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);

            logger.LogDebug("-----------------------------------------");
        }
コード例 #11
0
        public void RFC5118_4_2()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "REGISTER sip:2001:db8::10 SIP/2.0" + CRLF +
                "To: sip:[email protected]" + CRLF +
                "From: sip:[email protected];tag=81x2" + CRLF +
                "Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111" + CRLF +
                "Call-ID: SSG9559905523997077@hlau_4100" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "Contact: \"Caller\" <sip:caller@[2001:db8::1]>" + CRLF +
                "CSeq: 98176 REGISTER" + CRLF +
                "Content-Length: 0";

            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);

            Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly.");
            Assert.Throws <SIPValidationException>(() => SIPRequest.ParseSIPRequest(sipMessageBuffer));

            logger.LogDebug("-----------------------------------------");
        }
コード例 #12
0
        public void ParseRAckHeaderTest()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string prackRequest =
                "PRACK sip:127.0.0.1 SIP/2.0" + m_CRLF +
                "Via: SIP/2.0/UDP 0.0.0.0:6060;branch=z9hG4bKed0553cb6e4b476990a34d7c98f58a14;rport" + m_CRLF +
                "To: <sip:127.0.0.1>" + m_CRLF +
                "From: <sip:[email protected]>;tag=YPACUCOFBG" + m_CRLF +
                "Call-ID: c22e9dc218a1423695b1f5ef33020b84" + m_CRLF +
                "CSeq: 1 ACK" + m_CRLF +
                "Max-Forwards: 70" + m_CRLF +
                "Content-Length: 0" + m_CRLF +
                "RAck: 423501656 1 INVITE" + m_CRLF + m_CRLF;

            var sipRequest = SIPRequest.ParseSIPRequest(prackRequest);

            Assert.AreEqual(423501656, sipRequest.Header.RAckRSeq, "The RAck sequence header value was not parsed correctly.");
            Assert.AreEqual(1, sipRequest.Header.RAckCSeq, "The RAck cseq header value was not parsed correctly.");
            Assert.AreEqual(SIPMethodsEnum.INVITE, sipRequest.Header.RAckCSeqMethod, "The RAck method header value was not parsed correctly.");

            Console.WriteLine("---------------------------------------------------");
        }
コード例 #13
0
        public void RFC5118_4_5_2()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "OPTIONS sip:[2001:db8::10] SIP/2.0" + CRLF +
                "To: sip:user @example.com" + CRLF +
                "From: sip:user @example.com; tag=81x2" + CRLF +
                "Via: SIP/2.0/UDP [2001:db8::9:1];received=2001:db8::9:255;branch=z9hG4bKas3" + CRLF +
                "Call-ID: SSG95523997077 @hlau_4100" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "Contact: \"Caller\" <sip:caller@[2001:db8::9:1]>" + CRLF +
                "CSeq: 921 OPTIONS" + CRLF +
                "Content-Length: 0";

            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);

            Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly.");
            SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            Assert.Equal(SIPMethodsEnum.OPTIONS, sipRequest.Method);
            IPAddress ip6;

            Assert.NotEmpty(sipRequest.Header.Vias.Via);
            Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);
            Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromIPAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);
            Assert.NotEmpty(sipRequest.Header.Contact);
            Assert.True(IPAddress.TryParse(sipRequest.Header.Contact[0].ContactURI.HostAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);
            Assert.True(IPAddress.TryParse(sipRequest.URI.HostAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);

            logger.LogDebug("-----------------------------------------");
        }
コード例 #14
0
        public void MatchOnRequestAndResponseTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPTransport         sipTransport      = new SIPTransport();
            SIPTransactionEngine transactionEngine = sipTransport.m_transactionEngine;

            SIPRequest inviteRequest = SIPRequest.ParseSIPRequest("INVITE sip:[email protected]:12014 SIP/2.0" + m_CRLF +
                                                                  "Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27" + m_CRLF +
                                                                  "To: <sip:[email protected]:12014>" + m_CRLF +
                                                                  "From: <sip:[email protected]>;tag=2062917371" + m_CRLF +
                                                                  "Call-ID: 8ae45c15425040179a4285d774ccbaf6" + m_CRLF +
                                                                  "CSeq: 1 INVITE" + m_CRLF +
                                                                  "Contact: <sip:127.0.0.1:1234>" + m_CRLF +
                                                                  "Max-Forwards: 70" + m_CRLF +
                                                                  "User-Agent: unittest" + m_CRLF +
                                                                  "Content-Length: 5" + m_CRLF +
                                                                  "Content-Type: application/sdp" + m_CRLF +
                                                                  m_CRLF +
                                                                  "dummy");

            SIPTransaction tx = new UACInviteTransaction(sipTransport, inviteRequest, null);

            transactionEngine.AddTransaction(tx);

            SIPResponse sipResponse = SIPResponse.ParseSIPResponse("SIP/2.0 603 Nothing listening" + m_CRLF +
                                                                   "Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27;rport=12013" + m_CRLF +
                                                                   "To: <sip:[email protected]:12014>" + m_CRLF +
                                                                   "From: <sip:[email protected]>;tag=2062917371" + m_CRLF +
                                                                   "Call-ID: 8ae45c15425040179a4285d774ccbaf6" + m_CRLF +
                                                                   "CSeq: 1 INVITE" + m_CRLF +
                                                                   "Content-Length: 0" + m_CRLF +
                                                                   m_CRLF);

            Assert.True(transactionEngine.GetTransaction(sipResponse) != null, "Transaction should have matched, check the hashing mechanism.");
        }
コード例 #15
0
        public async Task AnswerAudioOnlyUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPTransport transport = new SIPTransport();
            SIPUserAgent userAgent = new SIPUserAgent(transport, null);

            string inviteReqStr = @"INVITE sip:[email protected] SIP/2.0
Via: SIP/2.0/UDP 0.0.0.0;branch=z9hG4bK57441c4980b94e1686a06ae080be2935;rport
To: <sip:[email protected]>
From: <sip:0.0.0.0:0>;tag=MYILIYPHQD
Call-ID: ddf0e5a9687b4745925438da9000445d
CSeq: 1 INVITE
Max-Forwards: 70
Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, PRACK, REFER, REGISTER, SUBSCRIBE
Content-Length: 0

v=0
o=- 1838015445 0 IN IP4 127.0.0.1
s=-
c=IN IP4 127.0.0.1
t=0 0
m=audio 19762 RTP/AVP 0
a=rtpmap:0 PCMU/8000
a=sendrecv";

            SIPEndPoint      dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 0));
            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint);
            SIPRequest       inviteReq        = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            var uas    = userAgent.AcceptCall(inviteReq);
            var result = await userAgent.Answer(uas, CreateMediaSession());

            Assert.True(result);
        }
コード例 #16
0
        public async Task IncomingCallNoSdpUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPTransport transport = new SIPTransport();

            transport.AddSIPChannel(new MockSIPChannel(new System.Net.IPEndPoint(IPAddress.Any, 0)));

            SIPUserAgent userAgent = new SIPUserAgent(transport, null);

            string inviteReqStr = "INVITE sip:192.168.11.50:5060 SIP/2.0" + m_CRLF +
                                  "Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691" + m_CRLF +
                                  "To: <sip:[email protected]>;tag=ZUJSXRRGXQ" + m_CRLF +
                                  "From: <sip:[email protected]>;tag=4a60ce364b774258873ff199e5e39938" + m_CRLF +
                                  "Call-ID: 17324d6df8744d978008c8997bfd208d" + m_CRLF +
                                  "CSeq: 3532 INVITE" + m_CRLF +
                                  "Contact: <sip:[email protected]:60163;ob>" + m_CRLF +
                                  "Max-Forwards: 70" + m_CRLF +
                                  "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS" + m_CRLF +
                                  "Supported: replaces, 100rel, timer, norefersub" + m_CRLF +
                                  "Content-Length: 0" + m_CRLF +
                                  "Content-Type: application/sdp" + m_CRLF +
                                  "Session-Expires: 1800" + m_CRLF + m_CRLF;

            SIPEndPoint      dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 0));
            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint);
            SIPRequest       inviteReq        = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            var uas          = userAgent.AcceptCall(inviteReq);
            var mediaSession = CreateMediaSession();
            await userAgent.Answer(uas, mediaSession);

            // The call attempt should timeout while waiting for the ACK request with the SDP answer.
            Assert.False(userAgent.IsCallActive);
        }
コード例 #17
0
        public async Task IncomingCallNoSdpWithACKUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPTransport transport = new SIPTransport();

            transport.AddSIPChannel(new MockSIPChannel(new System.Net.IPEndPoint(IPAddress.Any, 0)));
            var dummySep = SIPEndPoint.ParseSIPEndPoint("udp:127.0.0.1:5060");

            SIPUserAgent userAgent = new SIPUserAgent(transport, null);

            string inviteReqStr = @"INVITE sip:[email protected] SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:51200;branch=z9hG4bKbeed9b0cde8d43cc8a2aae91526b6a1d;rport
To: <sip:[email protected]>
From: <sip:[email protected]>;tag=GCLNRILCDU
Call-ID: 7265e19f53a146a1bacdf4f4f8ea70b2
CSeq: 1 INVITE
Contact: <sip:127.0.0.1:51200>
Max-Forwards: 70
User-Agent: www.sipsorcery.com
Content-Length: 0
Content-Type: application/sdp" + m_CRLF + m_CRLF;

            SIPEndPoint      dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 0));
            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint);
            SIPRequest       inviteReq        = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            var uas          = userAgent.AcceptCall(inviteReq);
            var mediaSession = CreateMediaSession();

            _ = Task.Run(() =>
            {
                Task.Delay(2000).Wait();

                string ackReqStr = @"ACK sip:127.0.0.1:5060 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:51200;branch=z9hG4bK76dfb1480ea14f778bd24afed1c8ded0;rport
To: <sip:[email protected]>;tag=YWPNZPMLPB
From: <sip:[email protected]>;tag=GCLNRILCDU
Call-ID: 7265e19f53a146a1bacdf4f4f8ea70b2
CSeq: 1 ACK
Max-Forwards: 70
Content-Length: 160

v=0
o=- 67424 0 IN IP4 127.0.0.1
s=-
c=IN IP4 127.0.0.1
t=0 0
m=audio 16976 RTP/AVP 8 101
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=sendrecv" + m_CRLF + m_CRLF;


                uas.ClientTransaction.ACKReceived(dummySep, dummySep, SIPRequest.ParseSIPRequest(ackReqStr));
            });

            await userAgent.Answer(uas, mediaSession);

            Assert.True(userAgent.IsCallActive);
        }
コード例 #18
0
        public async Task HangupUserAgentUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPTransport   transport   = new SIPTransport(false, MockSIPDNSManager.Resolve);
            MockSIPChannel mockChannel = new MockSIPChannel(new System.Net.IPEndPoint(IPAddress.Any, 0));

            transport.AddSIPChannel(mockChannel);

            SIPUserAgent userAgent = new SIPUserAgent(transport, null);

            string inviteReqStr = "INVITE sip:192.168.11.50:5060 SIP/2.0" + m_CRLF +
                                  "Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691" + m_CRLF +
                                  "To: <sip:[email protected]>;tag=ZUJSXRRGXQ" + m_CRLF +
                                  "From: <sip:[email protected]>;tag=4a60ce364b774258873ff199e5e39938" + m_CRLF +
                                  "Call-ID: 17324d6df8744d978008c8997bfd208d" + m_CRLF +
                                  "CSeq: 3532 INVITE" + m_CRLF +
                                  "Contact: <sip:[email protected]:60163;ob>" + m_CRLF +
                                  "Max-Forwards: 70" + m_CRLF +
                                  "User-Agent: MicroSIP/3.19.22" + m_CRLF +
                                  "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS" + m_CRLF +
                                  "Supported: replaces, 100rel, timer, norefersub" + m_CRLF +
                                  "Content-Length: 343" + m_CRLF +
                                  "Content-Type: application/sdp" + m_CRLF +
                                  "Session-Expires: 1800" + m_CRLF +
                                  "Min-SE: 90" + m_CRLF +
                                  "" + m_CRLF +
                                  "v=0" + m_CRLF +
                                  "o=- 3785527268 3785527269 IN IP4 192.168.11.50" + m_CRLF +
                                  "s=pjmedia" + m_CRLF +
                                  "t=0 0" + m_CRLF +
                                  "m=audio 4032 RTP/AVP 0 101" + m_CRLF +
                                  "c=IN IP4 192.168.11.50" + m_CRLF +
                                  "a=rtpmap:0 PCMU/8000" + m_CRLF +
                                  "a=rtpmap:101 telephone-event/8000" + m_CRLF +
                                  "a=fmtp:101 0-16" + m_CRLF +
                                  "a=sendrecv";

            SIPEndPoint      dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 0));
            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint);
            SIPRequest       inviteReq        = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            UASInviteTransaction uasTx   = new UASInviteTransaction(transport, inviteReq, null);
            SIPServerUserAgent   mockUas = new SIPServerUserAgent(transport, null, null, null, SIPCallDirection.In, null, null, null, uasTx);
            await userAgent.Answer(mockUas, CreateMediaSession());

            // Incremented Cseq and modified Via header from original request. Means the request is the same dialog but different tx.
            string inviteReqStr2 = "BYE sip:192.168.11.50:5060 SIP/2.0" + m_CRLF +
                                   "Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3700" + m_CRLF +
                                   "To: <sip:[email protected]>;tag=ZUJSXRRGXQ" + m_CRLF +
                                   "From: <sip:[email protected]>;tag=4a60ce364b774258873ff199e5e39938" + m_CRLF +
                                   "Call-ID: 17324d6df8744d978008c8997bfd208d" + m_CRLF +
                                   "CSeq: 3533 BYE" + m_CRLF +
                                   "Contact: <sip:[email protected]:60163;ob>" + m_CRLF +
                                   "Max-Forwards: 70" + m_CRLF +
                                   "User-Agent: MicroSIP/3.19.22" + m_CRLF +
                                   "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS" + m_CRLF +
                                   "Supported: replaces, 100rel, timer, norefersub" + m_CRLF +
                                   "";

            mockChannel.FireMessageReceived(dummySipEndPoint, dummySipEndPoint, Encoding.UTF8.GetBytes(inviteReqStr2));
        }
コード例 #19
0
 private SIPRequest TryDecodeSipRequest(UdpPacket udpPacket)
 {
     return(SIPRequest.ParseSIPRequest(Encoding.UTF8.GetString(udpPacket.Data)));
 }
コード例 #20
0
        public void ParseCryptoSIPMessage()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "INVITE sip:[email protected]:5061;transport=tls SIP/2.0" + CRLF +
                "Via: SIP/2.0/TLS 10.2.19.102:58179;rport;branch=z9hG4bKPj9893426a070f4c26ab494ceb746836a6" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "From: <sip:[email protected]>;tag=b0d60b9dda9043818dea1f0e8ff9667c" + CRLF +
                "To: <sip:[email protected]>" + CRLF +
                "Contact: <sip:[email protected]:58179;ob>" + CRLF +
                "Call-ID: 6410bc5eb6724efd8717831ac2af5c35" + CRLF +
                "CSeq: 9941 INVITE" + CRLF +
                "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS" + CRLF +
                "Supported: replaces, 100rel, timer, norefersub" + CRLF +
                "Session-Expires: 1800" + CRLF +
                "Min-SE: 90" + CRLF +
                "User-Agent: MicroSIP/3.19.8" + CRLF +
                "Content-Type: application/sdp" + CRLF +
                "Content-Length:   720" + CRLF +
                "" + CRLF +
                "v=0" + CRLF +
                "o=- 3784977145 3784977145 IN IP4 10.2.19.102" + CRLF +
                "s=pjmedia" + CRLF +
                "b=AS:84" + CRLF +
                "t=0 0" + CRLF +
                "a=X-nat:0" + CRLF +
                "m=audio 4000 RTP/AVP 8 0 101" + CRLF +
                "c=IN IP4 10.2.19.102" + CRLF +
                "b=TIAS:64000" + CRLF +
                "a=rtcp:4001 IN IP4 10.2.19.102" + CRLF +
                "a=sendrecv" + CRLF +
                "a=rtpmap:8 PCMA/8000" + CRLF +
                "a=rtpmap:0 PCMU/8000" + CRLF +
                "a=rtpmap:101 telephone-event/8000" + CRLF +
                "a=fmtp:101 0-16" + CRLF +
                "a=ssrc:370289018 cname:089912e5446c1847" + CRLF +
                "a=crypto:1 AES_256_CM_HMAC_SHA1_80 inline:i/aQZXuTQXF8NcIPG/8ClKLXjzJZiZkFqNerJJaWtX9ShjuamMQgFocXUEkWCQ==" + CRLF +
                "a=crypto:2 AES_256_CM_HMAC_SHA1_32 inline:WEXYOzOomH16+KpVRc8RKHkGUEW6DdvYHWSFKePVy9RzC5DB2Ciw+4t9huV8KA==" + CRLF +
                "a=crypto:3 AES_CM_128_HMAC_SHA1_80 inline:6wGxadTFLGO9iKPSC8XfRQsOFDRFgJdmpBfdWp9r" + CRLF +
                "a=crypto:4 AES_CM_128_HMAC_SHA1_32 inline:SdihJallj5frjwWc5yeXbMZlJSLlS+o2bkH3Jsle"
            ;

            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);

            Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly.");
            SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            Assert.Equal(SIPMethodsEnum.INVITE, sipRequest.Method);
            Assert.Equal(SIPProtocolsEnum.tls, sipRequest.URI.Protocol);

            SDP sdp = SDP.ParseSDPDescription(sipRequest.Body);

            Assert.NotNull(sdp);
            Assert.Equal("10.2.19.102", sdp.Connection.ConnectionAddress);
            Assert.Equal("-", sdp.Username);
            Assert.Equal("pjmedia", sdp.SessionName);
            Assert.Equal(SDPMediaTypesEnum.audio, sdp.Media[0].Media);
            Assert.Equal(MediaStreamStatusEnum.SendRecv, sdp.Media[0].MediaStreamStatus);

            Assert.NotEmpty(sdp.Media[0].SecurityDescriptions);
            Assert.Equal(SDPSecurityDescription.CryptoSuites.AES_256_CM_HMAC_SHA1_80, sdp.Media[0].SecurityDescriptions[0].CryptoSuite);
            Assert.NotEmpty(sdp.Media[0].SecurityDescriptions[0].KeyParams);
            Assert.Null(sdp.Media[0].SecurityDescriptions[0].SessionParam);
            Assert.Equal(SDPSecurityDescription.CryptoSuites.AES_256_CM_HMAC_SHA1_32, sdp.Media[0].SecurityDescriptions[1].CryptoSuite);
            Assert.Equal(2u, sdp.Media[0].SecurityDescriptions[1].Tag);
            Assert.Equal(SDPSecurityDescription.CryptoSuites.AES_CM_128_HMAC_SHA1_80, sdp.Media[0].SecurityDescriptions[2].CryptoSuite);
            Assert.Equal("6wGxadTFLGO9iKPSC8XfRQsOFDRFgJdmpBfdWp9r", sdp.Media[0].SecurityDescriptions[2].KeyParams[0].KeySaltBase64);
            Assert.Equal(SDPSecurityDescription.CryptoSuites.AES_CM_128_HMAC_SHA1_32, sdp.Media[0].SecurityDescriptions[3].CryptoSuite);
            Assert.Equal("SdihJallj5frjwWc5yeXbMZlJSLlS+o2bkH3Jsle", sdp.Media[0].SecurityDescriptions[3].KeyParams[0].KeySaltBase64);
        }
コード例 #21
0
        public void RFC5118_4_8()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "INVITE sip:user@[2001:db8::10] SIP/2.0" + CRLF +
                "To: sip:user@[2001:db8::10]" + CRLF +
                "From: sip:[email protected];tag=81x2" + CRLF +
                "Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111" + CRLF +
                "Call-ID: SSG9559905523997077@hlau_4100" + CRLF +
                "Contact: \"Caller\" <sip:caller@[2001:db8::9:1]>" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "CSeq: 8912 INVITE" + CRLF +
                "Content-Type: application/sdp" + CRLF +
                "Content-Length: 181" + CRLF +
                CRLF +
                "v=0" + CRLF +
                "o=bob 280744730 28977631 IN IP4 host.example.com" + CRLF +
                "s=" + CRLF +
                "t=0 0" + CRLF +
                "m=audio 22334 RTP/AVP 0" + CRLF +
                "c=IN IP4 192.0.2.1" + CRLF +
                "m=video 6024 RTP/AVP 107" + CRLF +
                "c=IN IP6 2001:db8::1" + CRLF +
                "a=rtpmap:107 H263-1998/90000";


            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);

            Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly.");
            SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            Assert.Equal(SIPMethodsEnum.INVITE, sipRequest.Method);
            IPAddress ip6, ip4;

            Assert.NotEmpty(sipRequest.Header.Vias.Via);
            Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);
            Assert.NotEmpty(sipRequest.Header.Contact);
            Assert.True(IPAddress.TryParse(sipRequest.Header.Contact[0].ContactURI.HostAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);
            Assert.True(IPAddress.TryParse(sipRequest.URI.HostAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);
            Assert.False(string.IsNullOrWhiteSpace(sipRequest.Body));
            SDP sdp = SDP.ParseSDPDescription(sipRequest.Body);

            Assert.NotNull(sdp);
            Assert.NotNull(sdp.Connection);
            Assert.True(IPAddress.TryParse(sdp.Connection.ConnectionAddress, out ip4));
            Assert.Equal(AddressFamily.InterNetwork, ip4.AddressFamily);
            Assert.NotEmpty(sdp.Media);
            Assert.NotNull(sdp.Media[0].Connection);
            Assert.True(IPAddress.TryParse(sdp.Media[0].Connection.ConnectionAddress, out ip4));
            Assert.Equal(AddressFamily.InterNetwork, ip4.AddressFamily);
            Assert.NotNull(sdp.Media[1].Connection);
            Assert.True(IPAddress.TryParse(sdp.Media[1].Connection.ConnectionAddress, out ip6));
            Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily);

            logger.LogDebug("-----------------------------------------");
        }