Asterisk的SIP type和身份认证
《Asterisk 使用资料》

Asterisk目录及配置文件/etc/asterisk/Asterisk主目录,包含其它关于Asterisk的配置文件;*zaptel.conf这个配置文件放在/etc,因为其它软件也可以使用Zaptel这个硬件及其驱动,所以不是放在/etc/asterisk里./usr/lib/asterisk/modules/这个目录包含所有可以加载Asterisk模块(应用程序\编辑器\格式和有用通道),在Asterisk启运时会加载这些模块(可以编辑modules.conf)./var/lib/asterisk/比较重要的是astdb文件与agi-bin目录;astdb包含Asterisk当地数据库信息.sounds/所有声音提示的文件在里面,包括Asterisk原代码中的sounds.txt文件mohmp3/如果配置了音乐保持,应用程序会在这个目录下查找mp3(用CBR从文件中去除身份标签).keys/使用公钥和私钥系统认证与一个由RSA数字签名形成的一对等连接.公钥和私钥的扩展名分别为.pub和.keyfirmware/这个目录含了很多Asterisk相兼容的设备固件,它只有iax/这个子目录,其中有Digium的IAXy的二进制固件镜像.images/只有在较多的支持并且利用图解式的图像设备被发布,这个目录将会与相应的目录有更大的关联./var/lib/asterisk/agi-bin agi-bin包含所有脚本,可以通过许多已经建立的AGI应用程序与Asterisk连接./var/spool/asteriskoutgoing/gcall/tmp/voicemail/================配置文件================/etc/asterisk/asterisk.conf主要配置文件,/etc/zaptel.conf硬件接口的基本层.修改这个配置文件要用modprobe装载Linux Kernel使用模块./etc/asterisk/zapata.conf为硬件配置Asterisk的接口./etc/asterisk/extensions.conf拨号方案./etc/asterisk/sip.conf SIP协议配置文件/etc/asterisk/iax.conf呼入和呼出IAX通道/etc/asterisk/extensions.conf拨号方案配置文件/etc/asterisk/moduprobe.conf加载模块配置文件Asterisk developer\'s documentation 翻译计划by serva今天,Asterisk已经成为一个VOIP业界使用最广泛的一个集成电信级别P BX的工具,IPPBX如今已经成为VOIP商家争夺的一块重要市场,在我们越来越熟悉使用Asterisk的同时,我们希望能够越来越深入的了解asterisk,特别是对于开发人员,如果有自己特定的需求,在复杂的asterisk文件夹和asteri sk的源代码文件中迷失了方向,不知所措。
asterisk使用SIP相互对接

asterisk使⽤SIP相互对接当⽤户数量上去,单凭⼀台asterisk是很能⽀持庞⼤的⽤户群体,所以要根据⽤户量来部署多台asterisk来应付实际情况的需求.但部署多台asterisk所带来的⼀个问题就是A服务器的⽤户如果Call B服务器的⽤户呢?其实asterisk的设计者早已帮我们解决问题,以下是通过SIP把两台asterisk对接起来(不过官⽅推荐asterisk的对接⽤AIX).分别在192.168.1.21 和192.168.1.22两台服务器上装上asterisk,然后配置各⾃的⽤户,TRUNK和转发规则。
配置192.168.1.21打开/etc/asterisk/sip.conf在[general]组下添加注册到22的命令register=>AST22:123456@192.168.1.22然后在⽂件尾添加相关组信息[AST21]type=friendsecret=123456host=dynamicusername=AST21disallow=allallow=ulaw;alawcontext=FROMSIP[22TRUNK]type=friendusername=AST22secret=123456host=192.168.1.22dtmfmode=rfc2833context=FROMSIPfromuser=AST22insecure=very打开/etc/asterisk/extensions.conf 添加下⾯内容[FROMSIP]Exten => _90.,1,dila(sip/91${exten:2}@22TRUNK,40,m(default))拔打90开头的号码,把91代替90后转发192.168.1.22,拔打等待40秒,等待的时候播放default这个采铃。
Exten => _91.,1,dial(sip/${exten:2},40,m(default))当接收到91开头的号码,把91后⾯的号码进⾏内部呼叫。
asterisk常用调试监测命令

asterisk常用调试监测命令asterisk是开源的VOIP系统。
是目前最流行的VOIP开源软件。
在使用过程中可以使用下述的命令,对系统进行监控调试。
下文来自网络,非本人原创1. 运行调试常用命令./asterisk & 在后台启动asterisk./asterisk –vvvc 启动asterisk并尽量多的在控制台显示调试信息./asterisk –r 连接asterisk控制台set verbose 9999 设置打印详细信息2.asterisk控制台下常用命令sip reload 重新加载sip配置信息sip set debug on 设置显示更多的sip信息sip set debug off关闭显示更多的sip信息sip show channels 显示所有活动的SIP通道sip show peers 显示所有已定义的SIP peerdialplan show 显示拨号方案dialplan reload重新加载拨打方案stop gracefully 优雅地停止asteriskstop now 立即停止运行asteriskmodule show 显示所有已加载模块module load cdr_radius.so 加载模块cdr_radius.somodule reload cdr_radius.so 重新加载模块cdr_radius.somodule unload cdr_radius.so 卸载模块cdr_radius.socore show applications 显示所有的应用,比如Dial, Radius, Hangup, Answer等core show channels 显示所有的通话频道core show codecs 显示所有支持的编解码器core show functions 显示所有的功能函数ps -aux :显示进程命令。
asterisk -rvc 进入到asterisk。
Asterisk-相关知识与应用

DialPlan (拨号方案)
dial : 它是Asterisk 很有价值的一功能,当来电者使用不同的通信方式时,它可以进行转换并进 行呼叫连接,如SIP电话到PSTN呼叫
Contexts : 拨号方案(DialPlan)进入部分我我们称为Contexts,每个Contexts 有一些extensions(扩展)构成,来实现一系列相关服务。
举一个例子如下: [default]
在extensions.conf 配制文件中, [default]上下文是拨号方案默认的进入部分
DialPlan (拨号方案)
goto 功能是发送呼叫到拨号方案中的其它context部分.
语法: goto(context,extension,priority)
[default] exten => 123,1,Answer() exten => 123,n,Background(main-menu) exten => 1,1,Playback(digits/1)
支持一条线路,只需要增32KB 的带宽,但是需要网络 质量良好。 Asterisk可支持成千的客户端(需要板卡与带宽支持)
asterisk 安装与启动
1从官方网站下载 asterisk-1.2.26.tar包,拷备到LINUX 下的用户目录. 2 用tar xzvf asterisk-1.2.26.tar 解压到当目录. 3 进入 asterisk 目录 执行如下命令
/usr/lib/asterisk/modules/ 这个目录包含所有可以加载Asterisk模块(应用程序\ 编辑器\格式和有用 通道),在Asterisk启运时会加载这些模块(可以编辑 modules.conf).
/var/lib/asterisk 比较重要的是astdb文件与agi-bin目录;astdb包含Asterisk当地数 据库信息. sounds/ 所有声音提示的文件在里面 mohmp3/ 如果配置了音乐保持,应用程序会在这个目录下查找mp3 keys/ 使用公钥和私钥系统认证与一个由RSA数字签名形成的一对等 连接.公钥和私钥的扩展名分别为.pub和.key
基于Twilio弹性SIP网关配置Asterisk指南说明书

Asterisk with Twilio Elastic SIP Trunking Configuration Guide This guide shows one way of configuring Asterisk to work with Twilio’s Elastic SIP Trunking product.Asterisk is a hugely flexible piece of software and it is quite possible to depart,significantly,from the instructions provided here and still bring up a fully working trunk. I’ve tried to highlight the essential concepts that you will need to follow.If you have any feedback on this or any of our other configuration guides,please do email us at s***********************************Contents:Installing AsteriskSetting up your Twilio Elastic SIP TrunkTermination URIACLCredentialsOrigination URIPhone NumbersConfiguring your Asterisksip.confpjsip.confextensions.confUsing Secure TrunkingTwilio account portalchan_sipPJSIP Channel DriverInstalling AsteriskThe first thing to do is to set up a server and install Asterisk.I installed Asterisk on an Amazon EC2instance running Redhat.Wherever you build your Asterisk,remember to configure firewall or security settings so that you can receive SIP and RTP from Twilioand any other SIP devices(like phones)you will be using.Please see https:///docs/api/sip-trunking/getting-started#whitelist for all the IP addresses you will need to whitelist.NB:If you know that you want to use TLS and SRTP on this trunk,please read Using Secure Trunking, below.There’s a pretty good guide for how to install Asterisk at /sample-device-configurations/41-asterisk/179-asterisk-13-on-ce ntos.We found that we had to install two extra packages before we could install asterisk: ncurses-devel and libuuid-devel.Setting up your Twilio Elastic SIP TrunkWe have a pretty comprehensive guide on how to configure an Elastic SIP Trunk through your Twilio account portal at https:///docs/sip-trunking/getting-started. I will highlight 5 aspects here.Termination URIThis is where you configure a unique URI that identifies your trunk.You will need to remember this when configuring your Asterisk because we need it to reference this URI in its SIP requests.The termination URI I’ve chosen here is .It’s too long to fit neatly into the text box in the screenshot.ACLYou can add an ACL that contains the public IP address of your Asterisk.This tells Twilio to ignore SIP from anywhere except for your PBX,reducing the chance of anyone making fraudulent calls on your trunk.You will need to add either an ACL or SIP credentials to your trunk.CredentialsYou can add credentials to your trunk.If you do,we will expect any server that sends SIP requests to Twilio on this trunk to authenticate using these credentials.Again,this is a way of reducing the chance of someone making fraudulent calls on your trunk.If you do not add credentials to your trunk, you will need to add an ACL.Origination URIThe easiest way to configure the Origination URI is using“sip:”followed by the public IP address of your Asterisk.In my case,that would be“sip:52.23.233.7”.Although I have used an IP address here, you can also use an FQDN.Phone NumbersIf you want to receive calls from the PSTN,across your new trunk,you will need to add a phone number to it.If someone calls this number,Twilio will contact your PBX using the Origination URI, above.Configuring your AsteriskIn this section we’re going to walk through a minimal configuration to use your Asterisk system for inbound and outbound calls over a Twilio SIP Trunk.sip.confIf you are using the default SIP driver,chan_sip,you will need to edit sip.conf.First,set up some global parameters.Because I was building on an AWS EC2instance,my asterisk server was behind NAT so I needed to account for this:[general]udpenable=yestcpenable=yespreferred_codec_only=yesdisallow=allallow=ulaw ;Twilio does G.711 onlysipdebug=yeslocalnet=172.31.0.0/16;My EC2instance had a private IP in this rangeexternaddr=52.23.233.7 ;The public IP of my EC2 instance Then, we need to build a trunk to Twilio.[twilio-trunk](!)type=peercontext=from-twilio ;Which dialplan to use for incoming calls dtmfmode=rfc4733canreinivite=noinsecure=port,invite[twilio0](twilio-trunk)host= ;Our Termination URI remotesecret=nottelling;password,if you are using credentialsdefaultuser=myuser;username,if you are using credentials[twilio1](twilio-trunk)host=54.172.60.2[twilio2](twilio-trunk)host=54.172.60.0[twilio3](twilio-trunk)host=54.172.60.1[twilio4](twilio-trunk)host=54.172.60.3In the US,Twilio has4different IP addresses that it uses for SIP signaling.We need the Asterisk server to recognize a SIP INVITE coming from any of these addresses as coming over this trunk.That means we need to build a trunk for each address.We then need to build another trunk for outgoing calls to Twilio,one that uses the Termination URI we configured earlier.When you are building multiple objects with similar configuration objects on Asterisk,using templates makes life easier.A template is denoted by putting a(!)at the end of the object name.We then use that template by putting its name in () at the end of a new object’s name.If you want to use non-US numbers on your trunk,you will need to authorize other Twilio Regional IP addresses.The full list can be found at https:///docs/api/sip-trunking/getting-started#whitelistThen, build objects for the SIP phones you will register with the Asterisk.[office-phone](!)type=friendcontext=from-phoneshost=dynamicsecret=Asterisk15dtmfmode=autodisallow=allallow=ulaw[1001](office-phone)pjsip.confIf you have installed,and are using pjsip,instead of chan_sip,you will need to edit pjsip.conf.First,we need to build a transport.Again,I had to account for the fact that my EC2 instance is behind NAT.[transport-udp-nat]type=transportprotocol=udpbind=0.0.0.0local_net=172.31.0.0/16external_media_address=52.23.233.7external_signaling_address=52.23.233.7Then, we set up our trunk. Again, I will use templates to make life easier.[twilio-trunks](!)type=endpointtransport=transport-udp-natcontext=from-twiliodisallow=allallow=ulaw[auth-out](!)type=authauth_type=userpass[twilio0](twilio-trunks)aors=twilio0-aorsoutbound_auth=twilio0-auth;if we are using credentials[twilio0-aors]type=aorcontact=sip::5060[twilio0-ident]type=identifyendpoint=twilio0match=54.172.60.0match=54.172.60.1match=54.172.60.2match=54.172.60.3[twilio0-auth](auth-out)password=nottelling;password on our credentialsusername=myuser;username on our credentialsAnd then we build objects for our SIP phones.[endpoint-basic](!)type=endpointtransport=transport-udp-natcontext=from-phonesdisallow=allallow=ulaw[auth-userpass](!)type=authauth_type=userpass[aor-single-reg](!)type=aormax_contacts=1[1001](endpoint-basic)auth=auth1001aors=1001[auth1001](auth-userpass)password=ImNotTellingYouusername=1001[1001](aor-single-reg)extensions.confThis is where we tell the Asterisk how to handle incoming calls.The examples here are for very, very basic North American dialing.We’ll start with calls coming in from the Twilio SIP trunk.We’re just going to send all incoming calls to the one SIP phone registered as1001.This is enough for testing but you will want to end up with something more complicated that this,probably.This example assumes you are using chan_sip.I f you are using PJSIP,replace the“SIP”with “PJSIP”[from-twilio]exten => _+1NXXXXXXXXX,1,Dial(SIP/1001)Then,for calls from our SIP phones,we’ll just worry about ones that are to go out over the trunk. If you are using chan_sip:[from-phones]exten => _NXXNXXXXXX,1,Set(CALLERID(all)="David" <7845551234>) same => n,Dial(SIP/twilio0/+1${EXTEN})If you are using pjsip, the second line should be:same => n,Dial(PJSIP/+1${EXTEN}@twilio0)Using Secure TrunkingTwilio account portalIn the General Settings section for your trunk, you will need to enable secure trunking.chan_sipBefore you can use secure trunking with chan_sip,you need to install srtp.Before you can install srtp, you need to install words!$cd /usr/src$sudo yum install -y wordsThe SRTP module uses words for self testing$wgethttps:///project/srtp/srtp/1.4.4/srtp-1.4.4.tgz$tar zxvf srtp-1.4.4.tgz$cd /usr/src/srtp$./configure CFLAGS=-fPIC --prefix=/usr/local/lib$makehere, you’re going to have to fix up one of the install scripts.cd testvi rtpw_test.shchange line 7 from “R TPW=rtpw” to “R TPW=./rtpw”save and exit (<esc>followed by :wq)cd ..$make runtest$make installNow,when you configure Asterisk,replace the“./configure”command with “./configure--with-srtp=/usr/local/lib”This tells asterisk to include the SRTP module and where to find the linkable libraries(note that we told the SRTP module to use /usr/local/lib when configuring it, above).Then,you can follow the instructions in https:///wiki/display/AST/Secure+Calling+Tutorial to enable TLS and SRTP on your asterisk.Using TLS with Twilio requires a couple more settings,too.On the transport object for TLS, you should settlsdontverifyserver=yesOn the peer object for the SIP trunk, you should setencryption=yesmedia_encryption=sdesPJSIP Channel DriverAsterisk ships by default with c han_sip driver and works well with Twilio.However,if you have some reason to run p jsip driver with Asterisk, please note the following:●Asterisk13.8cert2defaults to P JSIP 2.5and it does not work with Twilio forTLS/SRTP purposes. Non-encrypted calls do work.●Asterisk13.8cert2can also use the latest P JSIP driver,which at this time is2.5.5.Twilio works well with it despite the following message appearing in yourlog:Sep 27 13:03:56] ERROR[10886]: pjproject:0 <?>:tlsc0x7f217c03RFC5922(section7.2)does not allow TLS wildcard certificates. Advise your SIP provider, please!The following link is a guide to installing a non-bundled version of P JSIP.Change the version to 2.5.5 in the steps.Installing PJSIP channel driver。
如何将SIP网关注册到Asterisk

前面是我写给我喜欢的女孩的东北二人转荷子香染衣, 不拘世人前月淡树影寒, 车远客行单雨洒千楼小, 风入九窍曲未闲终成句, 疏散始期许正文开始:布:exten => _1NXXNXXXXXX,1,Dial,H323/${EXTEN}@ip.or.hostnameszmzsm:我装的是TRIXBOX 1。
1就是后面多了个IP?布:你先编译usr/src/asterisk/channels/h323(路径根据你的来)然后拷贝h323.conf.sample到/etc/asterisk配置帐号.然后配置规则.szmzsm:请问SIP gateway怎样连接到ASTERISK上,我用下面的设置在asterisk里的sip show peers 里看到2002 为unspecified.请问怎样解决?我的SIP。
CONF的设置是[2002]type=friendusername=2002secret=2002host=dynamiccontext=outgoingextensions.conf里的设置是[outgoing]exten => _2002,1,Dial(SIP/ ${EXTEN}@192.168.1.46,20,rt)gateway的ip 为192.168.1.46请问哪里有问题呢?布:你这是自己给自己打?需要开两个帐号帐号1 打帐号2szmzsm:我的sip.conf[2001]type=friendusername=2001host=dynamiccontext=outgoing[2002]type=friendusername=2002secret=2002host=dynamiccontext=outgoing[2004]type=friendusername=2004secret=2004host=dynamiccontext=outgoing其中2001,2002为软电话,2004为sip gateway我的extensions.conf[outgoing]exten => _2001,1,Dial(SIP/ ${EXTEN},20,rt)exten => _2002,1,Dial(SIP/ ${EXTEN},20,rt)exten => _1NXXNXXXXXX,1,Dial,SIP/ ${EXTEN}@192.168.1.46 布:你想用SIP 打到H323上?szmzsm不是,是SIP软电话打到sip gateway上请问extensions.conf中最后的改为[outgoing]exten => _2004,1,Dial,SIP/ ${EXTEN}@192.168.1.46szmzsm(624047449) 13:29:55但是现在好象连sip gateway用2004注册到asterisk都不行布:[outgoing]sip.conf[general]port = 5063bindaddr = 0.0.0.0context = default在extensions.conf[2002]type=friendusername=2002secret=2002host=192.168.xx.xx(根据你的情况而定)port=5065szmzsm:我的general是用他默认的,是[general]port = 5060bindaddr = 0.0.0.0disallow=allallow=ulawallow=alawcontext = from-sip-externalcallerid = Unknowntos=0x68是不是把其他的注释掉啊只用port disallow context还有bindaddrport是用5063吗??布:enszmzsm我现在的2002是软电话2004是gateway布你网关能注册到asterisk上不?szmzsm现在不行就是SIP.CONF里怎么加才能注册上布:type=peerport = 5060host=XXX.XXX.XXX.XXXbindaddr=XXX.XXX.XXX.XXX ; Local interface insecure=veryqualify=nocanreinvite=nodisallow=allallow=alawallow=ulawregister=>:@XXX.XXX.XXX.XXX ; Local interface在outgoing中exten => _2XXX,1,Dial(SIP/${EXTEN}@2004,60)试试.szmzsm请问bindaddr=XXX.XXX.XXX.XXX 用的是哪个IP是gateway 的吗?布对szmzsm现在可以call sip gateway了但是他不能call回来我把上面的peer改成friend也是一样,还是只能接,不能打出去布:把sip gateway的context设置成outgoing1[ougoing1]exten => _2XXX,1,Dial(SIP/${EXTEN}@2002,60)。
AsteriskConfig(Asterisk配置)

配置AsteriskSiSky企业版为Asterisk提供多达16路的Skype通道!方法1:配置Asterisk(例如:Asterisk不带有freePBX) --> 请点击这儿。
方法2:配置 Asterisk(例如: Asterisk+freePBX 或 Trixbox )。
下列以16个通道为例,您可以创建从501到516这16个SIP帐号作为SiSky的SIP 端口。
1. 将下面的内容添加到extensions_custom.conf的[from-internal-custom]中: exten => _500.,1,Dial(SIP/${EXTEN:0}@501)exten => _501.,1,Dial(SIP/${EXTEN:0}@501)exten => _502.,1,Dial(SIP/${EXTEN:0}@502)exten => _503.,1,Dial(SIP/${EXTEN:0}@503)exten => _504.,1,Dial(SIP/${EXTEN:0}@504)exten => _505.,1,Dial(SIP/${EXTEN:0}@505)exten => _506.,1,Dial(SIP/${EXTEN:0}@506)exten => _507.,1,Dial(SIP/${EXTEN:0}@507)exten => _508.,1,Dial(SIP/${EXTEN:0}@508)exten => _509.,1,Dial(SIP/${EXTEN:0}@509)exten => _510.,1,Dial(SIP/${EXTEN:0}@510)exten => _511.,1,Dial(SIP/${EXTEN:0}@511)exten => _512.,1,Dial(SIP/${EXTEN:0}@512)exten => _513.,1,Dial(SIP/${EXTEN:0}@513)exten => _514.,1,Dial(SIP/${EXTEN:0}@514)exten => _515.,1,Dial(SIP/${EXTEN:0}@515)exten => _516.,1,Dial(SIP/${EXTEN:0}@516)注意:exten => _500.,1,Dial (SIP/${EXTEN:0}@501)---表示自动从第1个到第16个Skype通道中,寻找空闲的通道进行呼出。
Asterisk配置文件说明

关于AsteriskAsterisk是一款实现用户电话交换机(PBX)功能的自由软件、开源软件。
Asterisk提供完善PBX 功能,可以连接多种不同的电话终端,包括普通电话机,IP电话机,软电话等,支持多种主流的IP电话协议和系统接口。
软件名称Asterisk-星号(*),在Unix(包括Linux)和DOS操作系统中是通配符,用来在查找中适配任何字符,寓意该软件广泛的适用性。
Asterisk软件提供很多以前只有昂贵的专业PBX系统才支持的功能,比如:语音信箱,会议电话,交互式语音提示和自动电话转接等。
由于该软件开放的性质,用户可以灵活的配置方便的扩展系统的功能,甚至编程开发自己所需功能的模块。
Asterisk通常都运行在Linux操作系统下,当然它也可以在其他系统,如BSD, Windows或OS X下编译并安装。
Asterisk服务器不需要任何特殊的硬件即可提供VoIP的服务,只需服务器有网络连接即可。
它支持主流VoIP协议,包括会话发起协议(SIP)、H.323,既可作为IP电话服务器也可以作IP 电话和PSTN之间的转接。
Asterisk系统还设计了一个新协议,IAX,用于在Asterisk服务器之间维护话路通道。
如果需要连接普通电话或PSTN中继线,运行Asterisk的服务器则需要安装相应的硬件接口板。
许多厂商都生产用于连接普通电话、T1、E1中继线、ISDN等的接口板。
由于是自由软件且具有丰富的系统功能,Asterisk提供给用户一个廉价并功能强大的PBX解决方案。
它被越来越多的用于代替传统专用的PBX,或被用于跨国VoIP电话以节省长途费用。
一些国家的VoIP电话公司已经开始支持Asterisk,提供IAX2接口或允许用户的Asterisk 服务器使用SIP协议连接。
截止2008年4月22日,Asterisk的最新版本是1.4.19.1版。
Asterisk功能说明及基本呼叫流程1.Asterisk内部核心:共分为6个部分A.PBX核心交换模块B.调度和IO管理模块C.应用调用模块D.编码转换模块E.动态模块加载器模块F.CDR生成模块(即时呼叫详细记录报告)2.Asterisk基本呼叫流程(1)通过Asterisk的一个电话呼叫在一个通道驱动接口上到达,如SIP通道。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Asterisk的SIP type和身份认证
在Asterisk中对某个peer的类型分为3种:peer, user和friend
看看voip-info对这三种类型的解释
∙peer: A SIP entity to which Asterisk sends calls (a SIP provider for example). If you want a user (extension) to have multiple phones, define an extension that calls two
SIP peers. The peer authenticates at registration.
∙user: A SIP entity which places calls through Asterisk (A phone which can place calls only). Users authenticate to reach services with their context.
∙friend: An entity which is both a user and a peer. This make sense for most desk handsets and other devices. Asterisk will create two objects, one peer and one user,
with the same name.
where it can be found (IP address/host name) and that it is reachable from now on.
简单的说,在这篇文档里, type=peer定义对方是一个服务提供者, 它允许你的Asterisk通过这里定义的服务商打电话; 而user则定义对方是你的一个客户端, 允许对方通过你的Asterisk打电话. friend就是两者兼有.
但是实际情况是什么? 试试这样的定义:
[1001]
username=1001
secret=xxxxx
host=dynamic
port=5060
type=peer
context=from-extensions
然后用一个SIP客户端来尝试注册到你的Asterisk上, what happened?
你会发现客户端也能注册上!
其实type的真正意义在于Asterisk怎么去处理发往外部和来自外部的请求.
type=peer
如果type是peer,有两层含义.
1. 可以将对方作为一个SIP Service Provider, 允许你的Asterisk通过对方进行呼出.
2. 如果对方在逻辑上是一个客户端, asterisk将根据传入的Invite请求来对对方进行身份验证, 但需要注意的是这里的验证不是通过username和secret, 而是通过对方的address和port. 这里分两种情况:
* 对方的address和port没有匹配到你在sip.conf中对任何一个peer的设置, 如果你的Asterisk 允许匿名呼入(allowguest=yes), 那么, 该呼入将被传到在sip.conf的general配置中的context 上. 如果不允许匿名呼入, 直接拒绝该呼入.
* 对方的address和port匹配到了任何一个sip.conf种的peer设置, 那么改呼入将被传到该peer 指定的context上.
Asterisk还提供了一个insecure参数来配置对peer呼入的身份验证方式.
insecure=port|invite
port: Asterisk忽略对方的port, 只根据对方的address来验证某个peer, Asterisk收到对方的Invite后, 会发送SIP/2.0 401 Unauthorized到对方, 要求对方发送认证信息, 但事实上对方返回回来的认证信息不会被真正使用.
invite: Asterisk对初始Invite不进行验证. 这意味着Asterisk直接使用客户端传入的Invite包中的信息尝试进行验证而不会发送SIP/2.0 401 Unauthorized包到对方
type=user
根据来源Invite包中的用户和密码信息来认证,所以对方不能也不需要Register到你的Asterisk 服务器上.
需要额外说明一点的是Register, 如果某个peer的host设置为dynamic, 那么Asterisk允许客户端通过Register的方式来告诉Asterisk对方的地址和端口.。