ezk
ezk copied to clipboard
How to handle unauthorized register and authorized register as a sip server
I have read send register and invite as a sip client, and accpet invite as a sip server. but how to accept unauthorized register and response 401, then accpet authorized register and validate auth data, if success response 200?
sip register request and response messages:
- => from sip client
REGISTER sip:44010200492000000001@4401020049 SIP/2.0
Via: SIP/2.0/UDP 192.168.3.139:57800;rport;branch=z9hG4bK24b96
From: <sip:34020000001110000001@4401020049>;tag=00000b9d
To: <sip:34020000001110000001@4401020049>
Contact: <sip:[email protected]:57800>
Call-ID: [email protected]
CSeq: 1 REGISTER
Max-Forwards: 70
Expires: 3600
X-GB-Ver: 2.0
User-Agent: Happytime GB28181 Device V7.0
Content-Length: 0
- => from sip server
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.3.139:57800;rport;branch=z9hG4bK24b96
From: <sip:34020000001110000001@4401020049>;tag=00000b9d
To: <sip:34020000001110000001@4401020049>;tag=1724123124
Call-ID: [email protected]
CSeq: 1 REGISTER
WWW-Authenticate: Digest realm="34020000", nonce="awer23sdfj123123", opaque="c3a02f1ecb122d255c4ae2266129d044", algorithm=MD5
User-Agent: General
Content-Length: 0
- => from sip client
REGISTER sip:44010200492000000001@4401020049 SIP/2.0
Via: SIP/2.0/UDP 192.168.3.139:57800;rport;branch=z9hG4bK24b97
From: <sip:34020000001110000001@4401020049>;tag=00000b9d
To: <sip:34020000001110000001@4401020049>
Contact: <sip:[email protected]:57800>
Call-ID: [email protected]
CSeq: 2 REGISTER
Max-Forwards: 70
Expires: 3600
X-GB-Ver: 2.0
User-Agent: Happytime GB28181 Device V7.0
Authorization: Digest username="34020000001110000001",realm="34020000",nonce="awer23sdfj123123",response="df5465996fd0eb332589debb8233bc6c",uri="sip:44010200492000000001@4401020049",opaque="c3a02f1ecb122d255c4ae2266129d044",algorithm=MD5
Content-Length: 0
- => from sip server
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.3.139:57800;rport;branch=z9hG4bK24b97
From: <sip:34020000001110000001@4401020049>;tag=00000b9d
To: <sip:34020000001110000001@4401020049>;tag=31243r3412
Call-ID: [email protected]
CSeq: 2 REGISTER
User-Agent: General
Date: 2024-08-09T10:46:08
Expires: 300
Content-Length: 0