level7systems / php-sip

PHP SIP User Agent class
MIT License
51 stars 39 forks source link

Error: "Can't find nonce in www-auth" -cause regex defined not correctly #12

Open Carsak opened 1 year ago

Carsak commented 1 year ago

I cant auth to sip server, cause class PhpSip cant parse "nonce"

in code we have line line if (!preg_match('/^WWW-Authenticate: .* nonce="(.*)"/imU',$this->rx_msg, $m))

But I got this string in rx_msg

SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.56.1:52619;rport=52619;received=192.168.56.1;branch=z9hG4bK400475
Call-ID: bd83da2e3b1bea8bd05a0d4f86a95651@192.168.56.1
From: <sip:demo-bob@192.168.56.1>;tag=29476
To: <sip:demo-bob@192.168.56.101>;tag=z9hG4bK400475
CSeq: 20 INVITE
WWW-Authenticate: Digest realm="asterisk",nonce="1674462773/ed4af0596a23a091b977b82551037698",opaque="5c230e6a1b3ca71a",algorithm=MD5,qop="auth"
Server: Asterisk PBX 20.1.0
Content-Length:  0

So the regexp pattern must be /.*WWW-Authenticate: .* nonce="(.*)"/imU not /^WWW-Authenticate: .* nonce="(.*)"/imU

Carsak commented 1 year ago

I was wrong

Carsak commented 1 year ago

I cant figure out, why I got error if regexp is correct. I checked this on regexOnline it is correct: image

But in php i got error: image

the text is same

Carsak commented 1 year ago

could somebody explain why this regexp dont work? https://onlinephp.io/c/221e2

livetechPT commented 1 year ago

Is the spaces in the expression. Remove spaces!

if (!preg_match('/^WWW-Authenti*cate*:.n*once="(.*)"/miU',$x, $m)) {

Às 09:37 de 2023/01/23, Alma Z escreveu:

could somebody explain why this regexp dont work? https://onlinephp.io/c/221e2

— Reply to this email directly, view it on GitHub https://github.com/level7systems/php-sip/issues/12#issuecomment-1400043548, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEZETTMNJ67S377DWCAWR4TWTZGMHANCNFSM6AAAAAAUDR4CV4. You are receiving this because you are subscribed to this thread.Message ID: @.***>

Carsak commented 1 year ago

OMG. yes. So, correct pattern should be /^WWW-Authenticate:.*nonce="(.*)"/imU not /^WWW-Authenticate: .* nonce="(.*)"/imU