Example #1
0
        public void CreateServerInstanceUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            DtlsSrtpTransport dtlsTransport = new DtlsSrtpTransport(new DtlsSrtpServer());

            Assert.NotNull(dtlsTransport);
        }
Example #2
0
        public void CreateClientInstanceUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            (var tlsCert, var pvtKey) = DtlsUtils.CreateSelfSignedTlsCert();
            DtlsSrtpTransport dtlsTransport = new DtlsSrtpTransport(new DtlsSrtpClient(tlsCert, pvtKey));

            Assert.NotNull(dtlsTransport);
        }
Example #3
0
        public async void DoHandshakeServerTimeoutUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            DtlsSrtpTransport dtlsServerTransport = new DtlsSrtpTransport(new DtlsSrtpServer());

            dtlsServerTransport.TimeoutMilliseconds = 2000;

            var result = await Task.Run <bool>(dtlsServerTransport.DoHandshake);

            Assert.False(result);
        }
Example #4
0
        public void DoHandshakeUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var dtlsClient = new DtlsSrtpClient();
            var dtlsServer = new DtlsSrtpServer();

            DtlsSrtpTransport dtlsClientTransport = new DtlsSrtpTransport(dtlsClient);

            dtlsClientTransport.TimeoutMilliseconds = 5000;
            DtlsSrtpTransport dtlsServerTransport = new DtlsSrtpTransport(dtlsServer);

            dtlsServerTransport.TimeoutMilliseconds = 5000;

            dtlsClientTransport.OnDataReady += (buf) =>
            {
                logger.LogDebug($"DTLS client transport sending {buf.Length} bytes to server.");
                dtlsServerTransport.WriteToRecvStream(buf);
            };
            dtlsServerTransport.OnDataReady += (buf) =>
            {
                logger.LogDebug($"DTLS server transport sending {buf.Length} bytes to client.");
                dtlsClientTransport.WriteToRecvStream(buf);
            };

            var serverTask = Task.Run <bool>(dtlsServerTransport.DoHandshake);
            var clientTask = Task.Run <bool>(dtlsClientTransport.DoHandshake);

            bool didComplete = Task.WaitAll(new Task[] { serverTask, clientTask }, 5000);

            Assert.True(didComplete);
            Assert.True(serverTask.Result);
            Assert.True(clientTask.Result);

            logger.LogDebug($"DTLS client fingerprint       : {dtlsClient.Fingerprint}.");
            //logger.LogDebug($"DTLS client server fingerprint: {dtlsClient.ServerFingerprint}.");
            logger.LogDebug($"DTLS server fingerprint       : {dtlsServer.Fingerprint}.");
            //logger.LogDebug($"DTLS server client fingerprint: {dtlsServer.ClientFingerprint}.");

            Assert.NotNull(dtlsClient.GetRemoteCertificate());
            Assert.NotNull(dtlsServer.GetRemoteCertificate());
            //Assert.Equal(dtlsServer.Fingerprint.algorithm, dtlsClient.ServerFingerprint.algorithm);
            //Assert.Equal(dtlsServer.Fingerprint.value, dtlsClient.ServerFingerprint.value);
            //Assert.Equal(dtlsClient.Fingerprint.algorithm, dtlsServer.ClientFingerprint.algorithm);
            //Assert.Equal(dtlsClient.Fingerprint.value, dtlsServer.ClientFingerprint.value);
        }