TT#88750 add SRTP test script

Change-Id: I352f24cc6cc229ffd0635adafe89aa20b5f9ef31
pull/1072/head
Richard Fuchs 5 years ago
parent 4d2291846c
commit 1537eddff6

@ -20,7 +20,8 @@ BEGIN {
require Exporter;
@ISA = qw(Exporter);
our @EXPORT = qw(autotest_start new_call offer answer ft tt snd srtp_snd rtp rcv srtp_rcv
srtp_dec escape rtpm rtpmre reverse_tags new_tt crlf sdp_split rtpe_req offer_answer);
srtp_dec escape rtpm rtpmre reverse_tags new_tt crlf sdp_split rtpe_req offer_answer
autotest_init);
};
@ -50,6 +51,10 @@ sub autotest_start {
ok $rtpe_pid, 'daemon launched in background';
}
return autotest_init();
}
sub autotest_init {
# keep trying to connect to the control socket while daemon is starting up
for (1 .. 300) {
$c = NGCP::Rtpengine->new($ENV{RTPENGINE_HOST} // '127.0.0.1', $ENV{RTPENGINE_PORT} // 2223);
@ -135,11 +140,11 @@ sub answer {
return offer_answer('answer', $name, $req, $sdps);
}
sub snd {
my ($sock, $dest, $packet) = @_;
$sock->send($packet, 0, pack_sockaddr_in($dest, inet_aton('203.0.113.1'))) or die;
my ($sock, $dest, $packet, $addr) = @_;
$sock->send($packet, 0, pack_sockaddr_in($dest, inet_aton($addr // '203.0.113.1'))) or die;
}
sub srtp_snd {
my ($sock, $dest, $packet, $srtp_ctx) = @_;
my ($sock, $dest, $packet, $srtp_ctx, $addr) = @_;
if (!$srtp_ctx->{skey}) {
my ($key, $salt) = NGCP::Rtpclient::SRTP::decode_inline_base64($srtp_ctx->{key}, $srtp_ctx->{cs});
@$srtp_ctx{qw(skey sauth ssalt)} = NGCP::Rtpclient::SRTP::gen_rtp_session_keys($key, $salt);
@ -147,7 +152,7 @@ sub srtp_snd {
my ($enc, $out_roc) = NGCP::Rtpclient::SRTP::encrypt_rtp(@$srtp_ctx{qw(cs skey ssalt sauth roc)},
'', 0, 0, 0, $packet);
$srtp_ctx->{roc} = $out_roc;
$sock->send($enc, 0, pack_sockaddr_in($dest, inet_aton('203.0.113.1'))) or die;
$sock->send($enc, 0, pack_sockaddr_in($dest, inet_aton($addr // '203.0.113.1'))) or die;
}
sub rtp {
my ($pt, $seq, $ts, $ssrc, $payload) = @_;

@ -0,0 +1,98 @@
#!/usr/bin/perl
use strict;
use warnings;
use NGCP::Rtpengine::Test;
use NGCP::Rtpclient::SRTP;
use NGCP::Rtpengine::AutoTest;
use Test::More;
autotest_init() or die;
my ($sock_a, $sock_b, $port_a, $port_b, $ssrc, $resp, $srtp_ctx_a, $srtp_ctx_b, $crypto);
# SDES in
($sock_a, $sock_b) = new_call([qw(192.168.1.149 20010)], [qw(192.168.1.149 20012)]);
($port_a) = offer('SDES in', { ICE => 'remove',
replace => ['origin'],
'transport-protocol' => 'RTP/AVP',
}, <<SDP);
v=0
o=- 1545997027 1 IN IP4 192.168.1.149
s=tester
t=0 0
m=audio 20010 RTP/SAVP 0 8
c=IN IP4 192.168.1.149
a=sendrecv
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:zC6Ea9EK/7YmDM79CK+TAnNXTI1pVmZuCMjUPMph
----------------------------------
v=0
o=- 1545997027 1 IN IP4 192.168.1.149
s=tester
t=0 0
m=audio PORT RTP/AVP 0 8
c=IN IP4 192.168.1.149
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=sendrecv
a=rtcp:PORT
SDP
($port_b, undef, $crypto) = answer('SDES in', { ICE => 'remove',
replace => ['origin'],
DTLS => 'off',
}, <<SDP);
v=0
o=- 1545997027 1 IN IP4 192.168.1.149
s=tester
t=0 0
m=audio 20012 RTP/AVP 0 8
c=IN IP4 192.168.1.149
a=sendrecv
--------------------------------------
v=0
o=- 1545997027 1 IN IP4 192.168.1.149
s=tester
t=0 0
m=audio PORT RTP/SAVP 0 8
c=IN IP4 192.168.1.149
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=sendrecv
a=rtcp:PORT
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:CRYPTO128
SDP
$srtp_ctx_a = {
cs => $NGCP::Rtpclient::SRTP::crypto_suites{AES_CM_128_HMAC_SHA1_80},
key => 'zC6Ea9EK/7YmDM79CK+TAnNXTI1pVmZuCMjUPMph',
};
$srtp_ctx_b = {
cs => $NGCP::Rtpclient::SRTP::crypto_suites{AES_CM_128_HMAC_SHA1_80},
key => $crypto,
};
snd($sock_b, $port_a, rtp(0, 1000, 3000, 0x1234, "\x00" x 160), '192.168.1.149');
srtp_rcv($sock_a, $port_b, rtpm(0, 1000, 3000, 0x1234, "\x00" x 160), $srtp_ctx_b);
srtp_snd($sock_a, $port_b, rtp(0, 2000, 4000, 0x3456, "\x00" x 160), $srtp_ctx_a, '192.168.1.149');
rcv($sock_b, $port_a, rtpm(0, 2000, 4000, 0x3456, "\x00" x 160));
print("wait for restart...\n");
sleep(10);
snd($sock_b, $port_a, rtp(0, 1000, 3000, 0x1234, "\x00" x 160), '192.168.1.149');
srtp_rcv($sock_a, $port_b, rtpm(0, 1000, 3000, 0x1234, "\x00" x 160), $srtp_ctx_b);
srtp_snd($sock_a, $port_b, rtp(0, 2000, 4000, 0x3456, "\x00" x 160), $srtp_ctx_a, '192.168.1.149');
rcv($sock_b, $port_a, rtpm(0, 2000, 4000, 0x3456, "\x00" x 160));
done_testing();
Loading…
Cancel
Save