[asterisk-commits] mmichelson: branch mmichelson/conversion_script r398508 - /team/mmichelson/co...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 5 17:42:13 CDT 2013


Author: mmichelson
Date: Thu Sep  5 17:42:12 2013
New Revision: 398508

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398508
Log:
Get outbound authentication mapped.

The peer-defined outbound auth section will not actually
work correctly at the moment because of issue ASTERISK-22386.
However, a patch is waiting in issue ASTERISK-22471 that would
get the mapped peer outbound auth working properly.


Modified:
    team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py

Modified: team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py?view=diff&rev=398508&r1=398507&r2=398508
==============================================================================
--- team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py (original)
+++ team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py Thu Sep  5 17:42:12 2013
@@ -251,7 +251,7 @@
         subscribemwi = 'no'
 
     set_value('mailboxes', val, section, pjsip, nmapped, 'aor' if subscribemwi ==
-            'yes' else 'endpoint')
+              'yes' else 'endpoint')
 
 def setup_auth(key, val, section, pjsip, nmapped):
     """
@@ -269,7 +269,20 @@
     else:
         set_value('md5_cred', val, section, pjsip, nmapped, 'auth')
         set_value('auth_type', 'md5', section, pjsip, nmapped, 'auth')
-    set_value('auth', section, section, pjsip)
+
+    realms = [section]
+    try:
+        auths = sip.get('authentication', 'auth')
+        for i in auths:
+            user, at, realm = i.partition('@')
+            realms.append(realm)
+    except LookupError:
+        pass
+
+    realm_str = ','.join(realms)
+
+    set_value('auth', section, section, pjsip, nmapped)
+    set_value('outbound_auth', realm_str, section, pjsip, nmapped)
 
 ###############################################################################
 
@@ -446,8 +459,8 @@
     # IPv4 address or hostname
     host, sep, port = addr.rpartition(':')
 
-    if not host and not sep:
-        return port
+    if not sep and not port:
+        return (host, None)
     else:
         return (host, port)
 
@@ -672,6 +685,33 @@
     create_tcp(sip, pjsip, nmapped)
     create_tls(sip, pjsip, nmapped)
 
+def map_auth(sip, pjsip, nmapped):
+    try:
+        auths = sip.get('authentication', 'auth')
+    except LookupError:
+        return
+
+    for i in auths:
+        creds, at, realm = i.partition('@')
+        if not at and not realm:
+            # Invalid. Move on
+            continue
+        user, colon, secret = creds.partition(':')
+        if not secret:
+            user, sharp, md5 = creds.partition('#')
+            if not md5:
+                #Invalid. move on
+                continue
+        section = realm
+
+        set_value('realm', realm, section, pjsip, nmapped, 'auth')
+        set_value('username', user, section, pjsip, nmapped, 'auth')
+        if secret:
+            set_value('password', secret, section, pjsip, nmapped, 'auth')
+        else:
+            set_value('md5_cred', md5, section, pjsip, nmapped, 'auth')
+            set_value('auth_type', 'md5', section, pjsip, nmapped, 'auth')
+
 def map_peer(sip, section, pjsip, nmapped):
     for i in peer_map:
         try:
@@ -704,6 +744,7 @@
     nmapped = non_mapped(non_mappings[filename])
     # First thing we need to do is establish transports.
     map_transports(sip, pjsip, nmapped)
+    map_auth(sip, pjsip, nmapped)
     for section in sip.sections():
         if section == 'authentication':
             pass




More information about the asterisk-commits mailing list