gpt4 book ai didi

perl ssl tls 与 net::sip 的连接

转载 作者:行者123 更新时间:2023-12-04 22:41:16 24 4
gpt4 key购买 nike

我尝试在 perl 中创建 tls net::sip 连接

i have a good ssl connection

this is my sub


start_connection("2.50.44.55:5061", "100", "100");
sub start_connection{
my @parms = @_;
my $host = $parms[0];
my $user = $parms[1];
my $pass = $parms[2];

$sock = IO::Socket::SSL->new(
PeerAddr => $host,
SSL_fingerprint => 'sha1$CE68626830EAF46482F55CB7FBF4DA1B77889FDD',
) or die $SSL_ERROR;

$sock->connect_SSL() or die $SSL_ERROR;

my $leg = Net::SIP::Leg->new(sock => $sock , proto => 'tls' , host => $host )|| exit ;


my $ua = Net::SIP::Simple->new(
registrar => $host,
domain => $host,
from => $user,
auth => [ $user,$pass ],
leg => $leg,
)|| exit;
$ua->register;
my $err = $ua->error;
print $err;
}

这是我的 IO::Socket::SSL 调试
DEBUG: .../IO/Socket/SSL.pm:3010: new ctx 37429024
DEBUG: .../IO/Socket/SSL.pm:762: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:764: socket connected
DEBUG: .../IO/Socket/SSL.pm:787: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:832: not using SNI because hostname is unknown
DEBUG: .../IO/Socket/SSL.pm:864: request OCSP stapling
DEBUG: .../IO/Socket/SSL.pm:894: call Net::SSLeay::connect
DEBUG: .../IO/Socket/SSL.pm:2864: ok=0 [1] /CN=Asterisk Private CA/O=asterisk/CN=Asterisk Private CA/O=asterisk
DEBUG: .../IO/Socket/SSL.pm:2864: ok=0 [1] /CN=Asterisk Private CA/O=asterisk/CN=Asterisk Private CA/O=asterisk
DEBUG: .../IO/Socket/SSL.pm:2864: ok=1 [1] /CN=Asterisk Private CA/O=asterisk/CN=Asterisk Private CA/O=asterisk
DEBUG: .../IO/Socket/SSL.pm:2864: ok=0 [0] /CN=Asterisk Private CA/O=asterisk/CN=localhost/O=asterisk
DEBUG: .../IO/Socket/SSL.pm:2864: ok=1 [0] /CN=Asterisk Private CA/O=asterisk/CN=localhost/O=asterisk
DEBUG: .../IO/Socket/SSL.pm:897: done Net::SSLeay::connect -> 1
DEBUG: .../IO/Socket/SSL.pm:952: ssl handshake done
DEBUG: .../IO/Socket/SSL.pm:3010: new ctx 45515568
DEBUG: .../IO/Socket/SSL.pm:3010: new ctx 46461040
Failed with error 113DEBUG: .../IO/Socket/SSL.pm:3059: free ctx 46461040 open=46461040 45515568 37429024
DEBUG: .../IO/Socket/SSL.pm:3063: free ctx 46461040 callback
DEBUG: .../IO/Socket/SSL.pm:3070: OK free ctx 46461040
DEBUG: .../IO/Socket/SSL.pm:3059: free ctx 45515568 open=45515568 37429024
DEBUG: .../IO/Socket/SSL.pm:3070: OK free ctx 45515568
DEBUG: .../IO/Socket/SSL.pm:3059: free ctx 37429024 open=37429024
DEBUG: .../IO/Socket/SSL.pm:3063: free ctx 37429024 callback
DEBUG: .../IO/Socket/SSL.pm:3070: OK free ctx 37429024

it is a good connnection

and this is my net::sip debug

When printing $ err; Be the output Failed with error 113

It is supposed to be at Print $ err; The result She is Failed with error 404 or Failed with error 403 But I think there is a problem with the leg connection


1590637618.9245 DEBUG:<99> Net::SIP::Dispatcher::Eventloop::addFD[61]: Net::SIP::Dispatcher::Eventloop=HASH(0x18f29c0) added fn=3 rw(0) sock=103.145.12.104:60188
1590637618.9249 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::addFD[64]: maxfd=4
1590637618.9257 DEBUG:<100> Net::SIP::Endpoint::Context::new[84]: CREATE context Net::SIP::Endpoint::Context=HASH(0x18f67f8) callid=16c05c388bcb952fd738fd5aeb9dbcd2
1590637618.9260 DEBUG:<10> Net::SIP::Endpoint::new_request[156]: create new request for REGISTER within new call 16c05c388bcb952fd738fd5aeb9dbcd2
1590637618.9270 DEBUG:<50> Net::SIP::Endpoint::new_request[164]: request=REGISTER sip:2.50.44.55:5061 SIP/2.0
1590637618.9270 DEBUG:<50> Call-id: 16c05c388bcb952fd738fd5aeb9dbcd2
1590637618.9270 DEBUG:<50> Contact: 100 <sips:100@[2.50.44.55:5061]:60188>
1590637618.9270 DEBUG:<50> Cseq: 1 REGISTER
1590637618.9270 DEBUG:<50> Expires: 900
1590637618.9270 DEBUG:<50> From: 100 <sips:100@2.50.44.55:5061>;tag=8a2c944e529b5155822a25c60e8b8865
1590637618.9270 DEBUG:<50> Max-forwards: 70
1590637618.9270 DEBUG:<50> To: 100 <sips:100@2.50.44.55:5061>
1590637618.9270 DEBUG:<50> Content-length: 0
1590637618.9270 DEBUG:<50>
1590637618.9270 DEBUG:<50>
1590637618.9295 DEBUG:<100> Net::SIP::Dispatcher::deliver[392]: deliver Net::SIP::Request=HASH(0x18fbb80)
1590637618.9300 DEBUG:<100> Net::SIP::Dispatcher::Packet::prepare_retransmits[1318]: retransmits 1590637618 + 0.5 1.5 3.5 7.5 11.5 15.5 19.5 23.5 27.5 31.5
1590637618.9303 DEBUG:<100> Net::SIP::Dispatcher::__deliver[607]: no dst_addr or leg yet, uri='sip:2.50.44.55:5061'
1590637618.9307 DEBUG:<100> Net::SIP::Dispatcher::resolve_uri[736]: domain=55.44.50.2.in-addr.arpa
1590637618.9309 DEBUG:<50> Net::SIP::Dispatcher::resolve_uri[766]: setting dst_addr from URI because IP address given
1590637618.9317 DEBUG:<100> Net::SIP::Dispatcher::__resolve_uri_final[837]: $VAR1 = [
1590637618.9317 DEBUG:<100> {
1590637618.9317 DEBUG:<100> 'proto' => 'udp',
1590637618.9317 DEBUG:<100> 'prio' => 65536,
1590637618.9317 DEBUG:<100> 'addr' => '2.50.44.55',
1590637618.9317 DEBUG:<100> 'port' => '5061',
1590637618.9317 DEBUG:<100> 'host' => '2.50.44.55',
1590637618.9317 DEBUG:<100> 'family' => 2
1590637618.9317 DEBUG:<100> },
1590637618.9317 DEBUG:<100> {
1590637618.9317 DEBUG:<100> 'proto' => 'tcp',
1590637618.9317 DEBUG:<100> 'prio' => 65536,
1590637618.9317 DEBUG:<100> 'addr' => '2.50.44.55',
1590637618.9317 DEBUG:<100> 'port' => '5061',
1590637618.9317 DEBUG:<100> 'host' => '2.50.44.55',
1590637618.9317 DEBUG:<100> 'family' => 2
1590637618.9317 DEBUG:<100> }
1590637618.9317 DEBUG:<100> ];
1590637618.9317 DEBUG:<100>
1590637618.9357 DEBUG:<50> Net::SIP::Dispatcher::__resolve_uri_final[864]: no leg with udp to 2.50.44.55:5061
1590637618.9360 DEBUG:<50> Net::SIP::Dispatcher::__resolve_uri_final[864]: no leg with tcp to 2.50.44.55:5061
1590637618.9679 DEBUG:<100> Net::SIP::Simple::error[244]: 1590637618.9364 DEBUG: Net::SIP::Debug::stacktrace[194]: set error to Failed with error 113 at /root/perl5/lib/perl5/Net/SIP/Simple.pm line 244.
1590637618.9679 DEBUG:<100> Net::SIP::Simple::error('Net::SIP::Simple=HASH(0x18f2948)', 'Failed with error 113') called at /root/perl5/lib/perl5/Net/SIP/Simple.pm line 377
1590637618.9679 DEBUG:<100> Net::SIP::Simple::__ANON__('Net::SIP::Simple=HASH(0x18f2948)', 'SCALAR(0x15dc8b8)', 'SCALAR(0x15dc9d8)', 'Net::SIP::Endpoint=HASH(0x18f6078)', 'Net::SIP::Endpoint::Context=HASH(0x18f67f8)', 113) called at /root/perl5/lib/perl5/Net/SIP/Util.pm line 474
1590637618.9679 DEBUG:<100> Net::SIP::Util::invoke_callback('ARRAY(0x18f6570)', 'Net::SIP::Endpoint=HASH(0x18f6078)', 'Net::SIP::Endpoint::Context=HASH(0x18f67f8)', 113) called at /root/perl5/lib/perl5/Net/SIP/Endpoint/Context.pm line 258
1590637618.9679 DEBUG:<100> Net::SIP::Endpoint::Context::request_delivery_done('Net::SIP::Endpoint::Context=HASH(0x18f67f8)', 'Net::SIP::Endpoint=HASH(0x18f6078)', '16c05c388bcb952fd738fd5aeb9dbcd2 1', 113) called at /root/perl5/lib/perl5/Net/SIP/Endpoint.pm line 218
1590637618.9679 DEBUG:<100> Net::SIP::Endpoint::_request_delivery_callback('Net::SIP::Endpoint=HASH(0x18f6078)', 'Net::SIP::Endpoint::Context=HASH(0x18f67f8)', 113, 'Net::SIP::Dispatcher::Packet=HASH(0x18fbd48)') called at /root/perl5/lib/perl5/Net/SIP/Util.pm line 474
1590637618.9679 DEBUG:<100> Net::SIP::Util::invoke_callback('ARRAY(0x18f6708)', 113, 'Net::SIP::Dispatcher::Packet=HASH(0x18fbd48)') called at /root/perl5/lib/perl5/Net/SIP/Dispatcher.pm line 1351
1590637618.9679 DEBUG:<100> Net::SIP::Dispatcher::Packet::trigger_callback('Net::SIP::Dispatcher::Packet=HASH(0x18fbd48)', 113) called at /root/perl5/lib/perl5/Net/SIP/Dispatcher.pm line 612
1590637618.9679 DEBUG:<100> Net::SIP::Dispatcher::__ANON__('Net::SIP::Dispatcher=HASH(0x18f2c30)', 'Net::SIP::Dispatcher::Packet=HASH(0x18fbd48)', 113) called at /root/perl5/lib/perl5/Net/SIP/Util.pm line 474
1590637618.9679 DEBUG:<100> Net::SIP::Util::invoke_callback('ARRAY(0x18fc7b0)', 113) called at /root/perl5/lib/perl5/Net/SIP/Dispatcher.pm line 868
1590637618.9679 DEBUG:<100> Net::SIP::Dispatcher::__resolve_uri_final('ARRAY(0x18fc330)', 'ARRAY(0x18fc168)', 'ARRAY(0x18fc7e0)', 5061, 'ARRAY(0x18fc7b0)', 'ARRAY(0x1406e38)') called at /root/perl5/lib/perl5/Net/SIP/Dispatcher.pm line 820
1590637618.9679 DEBUG:<100> Net::SIP::Dispatcher::resolve_uri('Net::SIP::Dispatcher=HASH(0x18f2c30)', 'sip:2.50.44.55:5061', 'ARRAY(0x18fc330)', 'ARRAY(0x18fc168)', 'ARRAY(0x18fc7b0)', undef) called at /root/perl5/lib/perl5/Net/SIP/Dispatcher.pm line 618
1590637618.9679 DEBUG:<100> Net::SIP::Dispatcher::__deliver('Net::SIP::Dispatcher=HASH(0x18f2c30)', 'Net::SIP::Dispatcher::Packet=HASH(0x18fbd48)') called at /root/perl5/lib/perl5/Net/SIP/Dispatcher.pm line 416
1590637618.9679 DEBUG:<100> Net::SIP::Dispatcher::deliver('Net::SIP::Dispatcher=HASH(0x18f2c30)', 'Net::SIP::Request=HASH(0x18fbb80)', 'id', '16c05c388bcb952fd738fd5aeb9dbcd2 1', 'callback', 'ARRAY(0x18f6708)', 'leg', undef, 'dst_addr', ...) called at /root/perl5/lib/perl5/Net/SIP/Endpoint.pm line 167
1590637618.9679 DEBUG:<100> Net::SIP::Endpoint::new_request('Net::SIP::Endpoint=HASH(0x18f6078)', 'REGISTER', 'HASH(0x144a3d0)', 'ARRAY(0x18f6570)', undef, 'uri', 'sip:2.50.44.55:5061', 'expires', 900, ...) called at /root/perl5/lib/perl5/Net/SIP/Endpoint.pm line 114
1590637618.9679 DEBUG:<100> Net::SIP::Endpoint::register('Net::SIP::Endpoint=HASH(0x18f6078)', 'auth', 'ARRAY(0x18f2930)', 'registrar', 'sip:2.50.44.55:5061', 'from', '100 <sips:100@2.50.44.55:5061>', 'contact', '100 <sips:100@[2.50.44.55:5061]:60188>', ...) called at /root/perl5/lib/perl5/Net/SIP/Simple.pm line 386
1590637618.9679 DEBUG:<100> Net::SIP::Simple::register('Net::SIP::Simple=HASH(0x18f2948)') called at dd.pl line 37
1590637618.9679 DEBUG:<100> main::start_connection('2.50.44.55:5061', 100, 100) called at dd.pl line 13
1590637618.9679 DEBUG:<100>
1590637618.9731 DEBUG:<100> Net::SIP::Dispatcher::cancel_delivery[449]: cancel packet id: 16c05c388bcb952fd738fd5aeb9dbcd2 1
1590637618.9734 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[156]: timeout = <undef>
1590637618.9737 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[188]: timeout = 0.950617074966431
1590637618.9739 DEBUG:<50> Net::SIP::Dispatcher::Eventloop::loop[191]: stopvar triggered

最佳答案

在 SIP 中,底层 SIP session 独立于实际的 TCP/UDP 连接。这意味着在客户端创建分支时不应使用已连接的套接字。相反,应该只提供创建套接字或提供未连接套接字的必要信息。后者在客户端仅对可以从未连接的套接字发送的 UDP 有意义。使用 TCP,未连接的套接字将不起作用,因为它需要连接以进行发送,但不能多次连接以防连接中断。

基于此,代码应如下所示:

use strict;
use warnings;
use Net::SIP;

start_connection("2.50.44.55","5061","100", "100");

sub start_connection{
my ($host,$port,$user,$pass) = @_;

my $ua = Net::SIP::Simple->new(
registrar => "sips:$host:$port",
domain => $host,
from => $user,
auth => [ $user,$pass ],
tls => {
SSL_fingerprint => 'sha1$CE68626830EAF46482F55CB7FBF4DA1B77889FDD',
},
) or die "failed to create UA";
$ua->register or die $ua->error;
print "ok\n";
}

这里只给出了创建套接字的必要信息,但连接的套接字本身将在内部创建。确保注册商的 URL 具有明确的 sips:...在前面指定应如何联系注册商。

请注意,因为它是代码似乎挂起。更深入地观察(使用 perl -MNet::SIP::Debug=50 ... )可以看到使用给定凭据的身份验证失败,并且服务器一次又一次地请求身份验证,使用相同的 realm但不同 opaque范围。 Net::SIP 使用两个参数的组合来检查这是否是相同的身份验证目标,因此它使用新的不透明重试身份验证而不是失败。这已在 908f5c8a0 中修复所以请在尝试时查看最新版本。

关于perl ssl tls 与 net::sip 的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62056763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com