コード例 #1
0
# $Id$
import inc_sip as sip
import inc_sdp as sdp

pjsua = "--null-audio --id=tel:+12345 --registrar sip:127.0.0.1:$PORT"

req1 = sip.RecvfromTransaction(
    "",
    401,
    include=["REGISTER sip"],
    exclude=["Authorization"],
    resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"1234\""],
    expect="PJSIP_ENOCREDENTIAL")

recvfrom_cfg = sip.RecvfromCfg("Failed registration with tel: URI test", pjsua,
                               [req1])
コード例 #2
0
import inc_sip as sip
import inc_sdp as sdp

# In this test we simulate broken server, where it always sends
# stale=true with all 401 responses. We should expect pjsip to
# retry the authentication until PJSIP_MAX_STALE_COUNT is
# exceeded. When pjsip retries the authentication, it should
# use the new nonce from server


pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
	"--realm=python --user=username --password=password"

req1 = sip.RecvfromTransaction("Initial request", 401,
				include=["REGISTER sip"], 
				exclude=["Authorization"],
				resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"1\""]
			  	)

req2 = sip.RecvfromTransaction("First retry", 401,
				include=["REGISTER sip", "Authorization", "nonce=\"1\""], 
				exclude=["Authorization:[\\s\\S]+Authorization:"],
				resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"2\", stale=true"]
			  	)

req3 = sip.RecvfromTransaction("Second retry retry", 401,
				include=["REGISTER sip", "Authorization", "nonce=\"2\""], 
				exclude=["Authorization:[\\s\\S]+Authorization:"],
				resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"3\", stale=true"]
				)
コード例 #3
0
# $Id: 201_reg_good_ok.py 2110 2008-07-07 20:14:41Z bennylp $
import inc_sip as sip
import inc_sdp as sdp

pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
 "--username user --realm python --password passwd --auto-update-nat=0"

req1 = sip.RecvfromTransaction(
    "Initial registration",
    401,
    include=["REGISTER sip"],
    exclude=["Authorization"],
    resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"1234\""],
    expect="SIP/2.0 401")

req2 = sip.RecvfromTransaction("Registration retry with auth",
                               200,
                               include=[
                                   "REGISTER sip", "Authorization:",
                                   "realm=\"python\"", "username=\"user\"",
                                   "nonce=\"1234\"", "response="
                               ],
                               expect="registration success")

recvfrom_cfg = sip.RecvfromCfg("Successful registration test", pjsua,
                               [req1, req2])
コード例 #4
0
# $Id: 208_reg_good_retry_nonce_ok.py 2392 2008-12-22 18:54:58Z bennylp $
import inc_sip as sip
import inc_sdp as sdp

pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
 "--realm=python --user=username --password=password " + \
 "--auto-update-nat=0"

req1 = sip.RecvfromTransaction(
    "Initial request",
    401,
    include=["REGISTER sip"],
    exclude=["Authorization"],
    resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"1\""])

req2 = sip.RecvfromTransaction(
    "REGISTER first retry",
    401,
    include=["REGISTER sip", "Authorization", "nonce=\"1\""],
    exclude=["Authorization:[\\s\\S]+Authorization:"],
    resp_hdr=[
        "WWW-Authenticate: Digest realm=\"python\", nonce=\"2\", stale=true"
    ])

req3 = sip.RecvfromTransaction(
    "REGISTER retry with new nonce",
    200,
    include=["REGISTER sip", "Authorization", "nonce=\"2\""],
    exclude=["Authorization:[\\s\\S]+Authorization:"],
    expect="registration success")
コード例 #5
0
# $Id$
import inc_sip as sip
import inc_sdp as sdp

# INVITE session using session timer

pjsua = "--null-audio sip:127.0.0.1:$PORT --use-timer --timer-min-se 100 --timer-se 2000"

req = sip.RecvfromTransaction("INVITE with session timer", 200,
				include=["Session-Expires:\s*2000", "Min-SE:\s*100"], 
				exclude=[],
				resp_hdr=["Session-Expires: 1000;refresher=uac"]
			  	)

recvfrom_cfg = sip.RecvfromCfg("INVITE session using session timer",
			       pjsua, [req])

コード例 #6
0
# $Id: 206_reg_good_efailedcredential.py 2392 2008-12-22 18:54:58Z bennylp $
import inc_sip as sip
import inc_sdp as sdp

# Authentication failure test with same nonce


pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
 "--realm=python --user=username --password=password"

req1 = sip.RecvfromTransaction(
    "Initial request",
    401,
    include=["REGISTER sip"],
    exclude=["Authorization"],
    resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"1\""])

req2 = sip.RecvfromTransaction(
    "REGISTER retry",
    401,
    include=["REGISTER sip", "Authorization", "nonce=\"1\""],
    exclude=["Authorization:[\\s\\S]+Authorization:"],
    resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"1\""],
    expect="PJSIP_EFAILEDCREDENTIAL")

recvfrom_cfg = sip.RecvfromCfg("Authentication failure with same nonce", pjsua,
                               [req1, req2])
コード例 #7
0
ファイル: 100_simple.py プロジェクト: bra1nDump/pjsip-no-mic
# $Id: 100_simple.py 3284 2010-08-18 07:38:48Z bennylp $
import inc_sip as sip
import inc_sdp as sdp

pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
 "--auto-update-nat=0"

req1 = sip.RecvfromTransaction("Registration",
                               200,
                               include=["REGISTER sip"],
                               exclude=["Authorization"],
                               resp_hdr=[
                                   "Server: Snake Registrar", "Expires: 221",
                                   "Contact: sip:localhost"
                               ],
                               expect="registration success")

recvfrom_cfg = sip.RecvfromCfg("Simple registration test", pjsua, [req1])
コード例 #8
0
# $Id: 203_reg_good_empty_realm.py 3150 2010-04-29 00:23:43Z bennylp $
import inc_sip as sip
import inc_sdp as sdp

pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
 "--realm=* --user=username --password=password " + \
 "--auto-update-nat=0"

# 401 Response, missing realm value
req1 = sip.RecvfromTransaction("Initial request",
                               401,
                               include=["REGISTER sip"],
                               exclude=[],
                               resp_hdr=['WWW-Authenticate: Digest'])

# Client should retry, we giving it another 401 with empty realm
req2 = sip.RecvfromTransaction(
    "REGISTER retry #1 of 2",
    407,
    include=["REGISTER sip"],
    exclude=[],
    resp_hdr=['Proxy-Authenticate: Digest realm=""'])

# Client should retry
req3 = sip.RecvfromTransaction("REGISTER retry #2 of 2",
                               200,
                               include=[],
                               exclude=[],
                               expect="registration success")

recvfrom_cfg = sip.RecvfromCfg("Registration with empty realm", pjsua,
コード例 #9
0
# Offer with 2 media lines answered with only 1 media line

pjsua = "--null-audio sip:127.0.0.1:$PORT --id=sip:1000@localhost --extra-audio --use-srtp=0"

sdp = \
"""
v=0
o=- 0 0 IN IP4 127.0.0.1
s=pjmedia
c=IN IP4 127.0.0.1
t=0 0
m=audio 4000 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=sendrecv
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
"""

req = sip.RecvfromTransaction(
    "Receiving 2 media lines, answer with 1 media line",
    200,
    include=["m=audio \d+ RTP/AVP", "m=audio \d+ RTP/AVP"],
    exclude=[],
    resp_hdr=["Content-type: application/sdp"],
    resp_body=sdp,
)

recvfrom_cfg = sip.RecvfromCfg("Receiving answer with less media lines", pjsua,
                               [req])
コード例 #10
0
# $Id: 209c_reg_handle_423_bad_min_expires2.py 3105 2010-02-23 11:03:07Z bennylp $
import inc_sip as sip
import inc_sdp as sdp

pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
 "--realm=python --user=username --password=password " + \
 "--auto-update-nat=0 --reg-timeout 300"

# 423 without Min-Expires. PJSIP would retry with Expires: 3601
req1 = sip.RecvfromTransaction("Initial request",
                               423,
                               include=["REGISTER sip"],
                               exclude=[],
                               resp_hdr=[])

# Another 423, still without Min-Expires
req2 = sip.RecvfromTransaction("Retry with guessed Expires header",
                               423,
                               include=["REGISTER sip", "Expires: 3601"],
                               exclude=[],
                               resp_hdr=[],
                               expect="without Min-Expires header is invalid")

recvfrom_cfg = sip.RecvfromCfg("Invalid 423 response to REGISTER", pjsua,
                               [req1, req2])
コード例 #11
0
import inc_sdp as sdp

# In this test we simulate broken server, where it wants to
# change the nonce, but it fails to set stale to true. In this
# case, we should expect pjsip to retry the authentication until
# PJSIP_MAX_STALE_COUNT is exceeded as it should have detected
# that that nonce has changed


pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
 "--realm=python --user=username --password=password " + \
 "--auto-update-nat=0"

req1 = sip.RecvfromTransaction(
    "Initial request",
    401,
    include=["REGISTER sip"],
    exclude=["Authorization"],
    resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"1\""])

req2 = sip.RecvfromTransaction(
    "First retry",
    401,
    include=["REGISTER sip", "Authorization", "nonce=\"1\""],
    exclude=["Authorization:[\\s\\S]+Authorization:"],
    resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"2\""])

req3 = sip.RecvfromTransaction(
    "Second retry retry",
    401,
    include=["REGISTER sip", "Authorization", "nonce=\"2\""],
    exclude=["Authorization:[\\s\\S]+Authorization:"],
コード例 #12
0
# $Id: 209b_reg_handle_423_bad_min_expires1.py 3105 2010-02-23 11:03:07Z bennylp $
import inc_sip as sip
import inc_sdp as sdp

pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
 "--realm=python --user=username --password=password " + \
 "--auto-update-nat=0 --reg-timeout 300"

# 423 Response with Min-Expires header that is lower than what the client
# had requested
req1 = sip.RecvfromTransaction("Initial request",
                               423,
                               include=["REGISTER sip"],
                               exclude=[],
                               resp_hdr=["Min-Expires: 250"],
                               expect="invalid Min-Expires")

recvfrom_cfg = sip.RecvfromCfg("Invalid 423 response to REGISTER", pjsua,
                               [req1])
コード例 #13
0
# $Id$
import inc_sip as sip
import inc_sdp as sdp

# Several PUBLISH failure scenarios that should be handled automatically


pjsua = "--null-audio --id=sip:127.0.0.1:$PORT --registrar sip:127.0.0.1:$PORT " + \
 "--realm=python --user=username --password=password " + \
 "--auto-update-nat=0 --publish"
#pjsua = "--null-audio --local-port 0 --rtp-port 0"

# Handle REGISTER first
req1 = sip.RecvfromTransaction("Initial REGISTER",
                               200,
                               include=["REGISTER sip"],
                               exclude=[],
                               resp_hdr=["Expires: 1800"])

# First PUBLISH, reply with 412
req2 = sip.RecvfromTransaction("Initial PUBLISH, will be replied with 412",
                               412,
                               include=["PUBLISH sip"],
                               exclude=["Expires:"])

# Second PUBLISH
req3 = sip.RecvfromTransaction("Second PUBLISH, will be replied with 200",
                               200,
                               include=["PUBLISH sip"],
                               exclude=["Expires:"],
                               resp_hdr=["Expires: 60", "SIP-ETag: dx200xyz"])
コード例 #14
0
# $Id$
import inc_sip as sip
import inc_sdp as sdp

# Session timers retry after 422

pjsua = "--null-audio sip:127.0.0.1:$PORT --timer-min-se 100 --timer-se 1000"

# First INVITE with timer rejected with 422
req1 = sip.RecvfromTransaction("INVITE with SE too small",
                               422,
                               include=["Session-Expires:\s*1000"],
                               exclude=[],
                               resp_hdr=["Min-SE: 2000"])

# Wait for ACK
req2 = sip.RecvfromTransaction("Wait ACK", 0, include=["ACK sip"])

# New INVITE with SE >= Min-SE
req3 = sip.RecvfromTransaction(
    "Retrying with acceptable SE",
    200,
    include=["Session-Expires:\s*2000", "Min-SE:\s*2000"],
    exclude=[],
    resp_hdr=["Session-Expires: 2000;refresher=uac"])

recvfrom_cfg = sip.RecvfromCfg("Session timers retry after 422", pjsua,
                               [req1, req2, req3])
コード例 #15
0
# $Id: 209a_reg_handle_423_ok.py 369517 2012-07-01 17:28:57Z file $
import inc_sip as sip
import inc_sdp as sdp

pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
	"--realm=python --user=username --password=password " + \
	"--auto-update-nat=0"

# 423 Response without Min-Expires header
req1 = sip.RecvfromTransaction("Initial request", 423,
				include=["REGISTER sip"], 
				exclude=[],
				resp_hdr=[]
			  	)

# Client should retry with Expires header containing special value (pjsip specific)
req2 = sip.RecvfromTransaction("REGISTER retry after 423 response without Min-Expires header", 423,
				include=["REGISTER sip", "Expires: 3601"], 
				exclude=[],
				resp_hdr=["Min-Expires: 3612"]
			  	)

# Client should retry with proper Expires header now
req3 = sip.RecvfromTransaction("REGISTER retry after proper 423", 200,
				include=["Expires: 3612"], 
				exclude=[],
				expect="registration success"
			  	)

recvfrom_cfg = sip.RecvfromCfg("Reregistration after 423 response",
			       pjsua, [req1, req2, req3])
コード例 #16
0
# $Id: 215_reg_good_multi_ok.py 369517 2012-07-01 17:28:57Z file $
import inc_sip as sip
import inc_sdp as sdp

pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
 "--username theuser1 --realm python1 --password passwd --next-cred " + \
 "--username theuser2 --realm python2 --password passwd " + \
 "--auto-update-nat=0"

req1 = sip.RecvfromTransaction(
    "Initial registration",
    401,
    include=["REGISTER sip"],
    resp_hdr=[
        "WWW-Authenticate: Digest realm=\"python1\", nonce=\"1234\"",
        "WWW-Authenticate: Digest realm=\"python2\", nonce=\"6789\""
    ],
    expect="SIP/2.0 401")

req2 = sip.RecvfromTransaction(
    "Registration retry with auth",
    200,
    include=[
        "REGISTER sip",
        "Authorization:[\\s\\S]+Authorization:",  # Must have 2 Auth hdrs
        "realm=\"python1\"",
        "realm=\"python2\"",
        "username=\"theuser1\"",
        "username=\"theuser2\"",
        "nonce=\"1234\"",
        "nonce=\"6789\"",
コード例 #17
0
# $Id$
import inc_sip as sip
import inc_sdp as sdp

pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
	"--username theuser1 --realm python1 --password passwd --next-cred " + \
	"--username theuser2 --realm python2 --password passwd " + \
	"--auto-update-nat=0"

req1 = sip.RecvfromTransaction("Initial registration", 401,
				include=["REGISTER sip"], 
				resp_hdr=["WWW-Authenticate: Digest realm=\"python1\", nonce=\"1234\"",
					  "WWW-Authenticate: Digest realm=\"python2\", nonce=\"6789\""],
				expect="SIP/2.0 401"
			  )

req2 = sip.RecvfromTransaction("Registration retry with auth (not allowed multiple auth)", 200,
				include=["REGISTER sip", 
					 "Authorization:", # [\\s\\S]+Authorization:"
					 "realm=\"python1\"", # "realm=\"python2\"", 
					 "username=\"theuser1\"", # "username=\"theuser2\"", 
					 "nonce=\"1234\"", # "nonce=\"6789\"", 
					 "response="],
				expect="registration success",
				pj_config="PJSIP_AUTH_ALLOW_MULTIPLE_AUTH_HEADER.*: 0"
			  )

req3 = sip.RecvfromTransaction("Registration retry with auth (allowed multiple auth)", 200,
				include=["REGISTER sip", 
					 "Authorization:[\\s\\S]+Authorization:", # Must have 2 Auth hdrs
					 "realm=\"python1\"", "realm=\"python2\"",