Ejemplo n.º 1
0
def test_inbound_and_outbound(tmpdir, fixtures, capture, material, expected):
    km = dsrtp.KeyingMaterial.unpack_encoded(
        fixtures.join(material).read()
    )
    decrypted_cap = tmpdir.join('decrypted.pcap')

    streams = [
        dsrtp.SRTPStream(km.remote, '192.168.121.234', 60401),
        dsrtp.SRTPStream(km.local, '192.168.121.234', 49686),
    ]

    with fixtures.join(capture).open('rb') as fo, \
            decrypted_cap.open('wb') as tfo:
        dec_pkts = dsrtp.decrypt_packets(
            streams,
            dsrtp.read_packets(fo),
            unknown='drop',
            malformed='raise',
        )
        dsrtp.write_packets(tfo, dec_pkts)

    count = 0
    with decrypted_cap.open('rb') as tfo:
        for _ in dsrtp.read_packets(tfo):
            count += 1
    assert count == expected
Ejemplo n.º 2
0
def test_decrypt_outbound_srtp(fixtures, capture, material, out_address,
                               out_port, expected):
    km = dsrtp.KeyingMaterial.unpack_encoded(fixtures.join(material).read())
    with fixtures.join(capture).open('rb') as fo:
        dec_pkts = dsrtp.decrypt_packets(
            dsrtp.SRTPStream(km.local, out_address, out_port),
            dsrtp.read_packets(fo),
            unknown='drop',
            malformed='raise',
        )
        count = 0
        for _, pkt in dec_pkts:
            assert (dsrtp.is_srtp_packet(pkt) or dsrtp.is_srtcp_packet(pkt))
            count += 1
        assert count == expected
Ejemplo n.º 3
0
def test_inbound_and_outbound(tmpdir, fixtures, capture, material, expected):
    km = dsrtp.KeyingMaterial.unpack_encoded(fixtures.join(material).read())
    decrypted_cap = tmpdir.join('decrypted.pcap')

    streams = [
        dsrtp.SRTPStream(km.remote, '192.168.121.234', 60401),
        dsrtp.SRTPStream(km.local, '192.168.121.234', 49686),
    ]

    with fixtures.join(capture).open('rb') as fo, \
            decrypted_cap.open('wb') as tfo:
        dec_pkts = dsrtp.decrypt_packets(
            streams,
            dsrtp.read_packets(fo),
            unknown='drop',
            malformed='raise',
        )
        dsrtp.write_packets(tfo, dec_pkts)

    count = 0
    with decrypted_cap.open('rb') as tfo:
        for _ in dsrtp.read_packets(tfo):
            count += 1
    assert count == expected
Ejemplo n.º 4
0
def test_decrypt_inbound_srtp(
        fixtures,
        capture,
        material,
        in_address,
        in_port,
        expected):
    km = dsrtp.KeyingMaterial.unpack_encoded(
        fixtures.join(material).read()
    )
    with fixtures.join(capture).open('rb') as fo:
        dec_pkts = dsrtp.decrypt_packets(
            dsrtp.SRTPStream(km.remote, in_address, in_port),
            dsrtp.read_packets(fo),
            unknown='drop',
            malformed='raise',
        )
        count = 0
        for _, pkt in dec_pkts:
            assert (
                dsrtp.is_srtp_packet(pkt) or dsrtp.is_srtcp_packet(pkt)
            )
            count += 1
        assert count == expected