How to use the aiortc.rtcdtlstransport.RTCDtlsTransport function in aiortc

To help you get started, we’ve selected a few aiortc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aiortc / aiortc / tests / test_rtcdtlstransport.py View on Github external
def test_broken_ssl(self, mock_use_certificate):
        mock_use_certificate.return_value = 0

        transport1, transport2 = dummy_ice_transport_pair()

        certificate = RTCCertificate.generateCertificate()
        with self.assertRaises(DtlsError):
            RTCDtlsTransport(transport1, [certificate])
github aiortc / aiortc / tests / test_rtcdtlstransport.py View on Github external
def test_rtp_malformed(self):
        transport1, transport2 = dummy_ice_transport_pair()

        certificate1 = RTCCertificate.generateCertificate()
        session1 = RTCDtlsTransport(transport1, [certificate1])

        # receive truncated RTP
        run(session1._handle_rtp_data(RTP[0:8], 0))

        # receive truncated RTCP
        run(session1._handle_rtcp_data(RTCP[0:8]))
github aiortc / aiortc / tests / test_rtcdtlstransport.py View on Github external
def test_handshake_error(
        self, mock_err_get_error, mock_ssl_get_error, mock_do_handshake
    ):
        mock_err_get_error.side_effect = [0x2006D080, 0, 0]
        mock_ssl_get_error.return_value = 1
        mock_do_handshake.return_value = -1

        transport1, transport2 = dummy_ice_transport_pair()

        certificate1 = RTCCertificate.generateCertificate()
        session1 = RTCDtlsTransport(transport1, [certificate1])

        certificate2 = RTCCertificate.generateCertificate()
        session2 = RTCDtlsTransport(transport2, [certificate2])

        run(
            asyncio.gather(
                session1.start(session2.getLocalParameters()),
                session2.start(session1.getLocalParameters()),
            )
        )
        self.assertEqual(session1.state, "failed")
        self.assertEqual(session2.state, "failed")

        run(session1.stop())
        run(session2.stop())
github aiortc / aiortc / tests / test_rtcdtlstransport.py View on Github external
session1 = RTCDtlsTransport(transport1, [certificate1])
        receiver1 = DummyRtpReceiver()
        session1._register_rtp_receiver(
            receiver1,
            RTCRtpReceiveParameters(
                codecs=[
                    RTCRtpCodecParameters(
                        mimeType="audio/PCMU", clockRate=8000, payloadType=0
                    )
                ],
                encodings=[RTCRtpDecodingParameters(ssrc=1831097322, payloadType=0)],
            ),
        )

        certificate2 = RTCCertificate.generateCertificate()
        session2 = RTCDtlsTransport(transport2, [certificate2])
        receiver2 = DummyRtpReceiver()
        session2._register_rtp_receiver(
            receiver2,
            RTCRtpReceiveParameters(
                codecs=[
                    RTCRtpCodecParameters(
                        mimeType="audio/PCMU", clockRate=8000, payloadType=0
                    )
                ],
                encodings=[RTCRtpDecodingParameters(ssrc=4028317929, payloadType=0)],
            ),
        )

        run(
            asyncio.gather(
                session1.start(session2.getLocalParameters()),
github aiortc / aiortc / tests / test_rtcdtlstransport.py View on Github external
def test_handshake_error(
        self, mock_err_get_error, mock_ssl_get_error, mock_do_handshake
    ):
        mock_err_get_error.side_effect = [0x2006D080, 0, 0]
        mock_ssl_get_error.return_value = 1
        mock_do_handshake.return_value = -1

        transport1, transport2 = dummy_ice_transport_pair()

        certificate1 = RTCCertificate.generateCertificate()
        session1 = RTCDtlsTransport(transport1, [certificate1])

        certificate2 = RTCCertificate.generateCertificate()
        session2 = RTCDtlsTransport(transport2, [certificate2])

        run(
            asyncio.gather(
                session1.start(session2.getLocalParameters()),
                session2.start(session1.getLocalParameters()),
            )
        )
        self.assertEqual(session1.state, "failed")
        self.assertEqual(session2.state, "failed")

        run(session1.stop())
        run(session2.stop())
github aiortc / aiortc / tests / test_rtcdtlstransport.py View on Github external
def test_data(self):
        transport1, transport2 = dummy_ice_transport_pair()

        certificate1 = RTCCertificate.generateCertificate()
        session1 = RTCDtlsTransport(transport1, [certificate1])
        receiver1 = DummyDataReceiver()
        session1._register_data_receiver(receiver1)

        certificate2 = RTCCertificate.generateCertificate()
        session2 = RTCDtlsTransport(transport2, [certificate2])
        receiver2 = DummyDataReceiver()
        session2._register_data_receiver(receiver2)

        run(
            asyncio.gather(
                session1.start(session2.getLocalParameters()),
                session2.start(session1.getLocalParameters()),
            )
        )

        # send encypted data
github aiortc / aiortc / tests / test_rtcdtlstransport.py View on Github external
def test_bad_client_fingerprint(self):
        transport1, transport2 = dummy_ice_transport_pair()

        certificate1 = RTCCertificate.generateCertificate()
        session1 = RTCDtlsTransport(transport1, [certificate1])

        certificate2 = RTCCertificate.generateCertificate()
        session2 = RTCDtlsTransport(transport2, [certificate2])

        bogus_parameters = RTCDtlsParameters(
            fingerprints=[
                RTCDtlsFingerprint(algorithm="sha-256", value="bogus_fingerprint")
            ]
        )
        run(
            asyncio.gather(
                session1.start(bogus_parameters),
                session2.start(session1.getLocalParameters()),
            )
        )
        self.assertEqual(session1.state, "failed")
github aiortc / aiortc / tests / test_rtcdtlstransport.py View on Github external
def test_bad_client_fingerprint(self):
        transport1, transport2 = dummy_ice_transport_pair()

        certificate1 = RTCCertificate.generateCertificate()
        session1 = RTCDtlsTransport(transport1, [certificate1])

        certificate2 = RTCCertificate.generateCertificate()
        session2 = RTCDtlsTransport(transport2, [certificate2])

        bogus_parameters = RTCDtlsParameters(
            fingerprints=[
                RTCDtlsFingerprint(algorithm="sha-256", value="bogus_fingerprint")
            ]
        )
        run(
            asyncio.gather(
                session1.start(bogus_parameters),
                session2.start(session1.getLocalParameters()),
            )
        )
        self.assertEqual(session1.state, "failed")
        self.assertEqual(session2.state, "connected")

        run(session1.stop())
github aiortc / aiortc / tests / test_rtcdtlstransport.py View on Github external
def test_data_handler_error(self):
        transport1, transport2 = dummy_ice_transport_pair()

        certificate1 = RTCCertificate.generateCertificate()
        session1 = RTCDtlsTransport(transport1, [certificate1])
        receiver1 = DummyDataReceiver()
        session1._register_data_receiver(receiver1)

        certificate2 = RTCCertificate.generateCertificate()
        session2 = RTCDtlsTransport(transport2, [certificate2])
        session2._register_data_receiver(BrokenDataReceiver())

        run(
            asyncio.gather(
                session1.start(session2.getLocalParameters()),
                session2.start(session1.getLocalParameters()),
            )
        )

        # send encypted data
        run(session1._send_data(b"ping"))
        run(asyncio.sleep(0.1))

        # shutdown
        run(session1.stop())
        run(session2.stop())
github aiortc / aiortc / tests / test_rtcdtlstransport.py View on Github external
def test_abrupt_disconnect(self):
        transport1, transport2 = dummy_ice_transport_pair()

        certificate1 = RTCCertificate.generateCertificate()
        session1 = RTCDtlsTransport(transport1, [certificate1])

        certificate2 = RTCCertificate.generateCertificate()
        session2 = RTCDtlsTransport(transport2, [certificate2])

        run(
            asyncio.gather(
                session1.start(session2.getLocalParameters()),
                session2.start(session1.getLocalParameters()),
            )
        )

        # break connections -> tasks exits
        run(transport1.stop())
        run(transport2.stop())

        # close DTLS