1   
 2   
 3   
 4   
 5   
 6   
 7   
 8   
 9   
10   
11   
12   
13   
14   
15   
16   
17  """SASL authentication implementaion for PyXMPP. 
18   
19  Normative reference: 
20    - `RFC 2222 <http://www.ietf.org/rfc/rfc2222.txt>`__ 
21  """ 
22   
23  __revision__="$Id: __init__.py 678 2008-08-08 11:22:14Z jajcus $" 
24  __docformat__="restructuredtext en" 
25   
26  import random 
27   
28  from pyxmpp.sasl.core import Reply,Response,Challenge,Success,Failure,PasswordManager 
29   
30  from pyxmpp.sasl.plain import PlainClientAuthenticator,PlainServerAuthenticator 
31  from pyxmpp.sasl.digest_md5 import DigestMD5ClientAuthenticator,DigestMD5ServerAuthenticator 
32   
33  safe_mechanisms_dict={"DIGEST-MD5":(DigestMD5ClientAuthenticator,DigestMD5ServerAuthenticator)} 
34  try: 
35      from pyxmpp.sasl.gssapi import GSSAPIClientAuthenticator 
36  except ImportError: 
37      pass  
38  else: 
39      safe_mechanisms_dict["GSSAPI"] = (GSSAPIClientAuthenticator,None) 
40  unsafe_mechanisms_dict={"PLAIN":(PlainClientAuthenticator,PlainServerAuthenticator)} 
41  all_mechanisms_dict=safe_mechanisms_dict.copy() 
42  all_mechanisms_dict.update(unsafe_mechanisms_dict) 
43   
44  safe_mechanisms=safe_mechanisms_dict.keys() 
45  unsafe_mechanisms=unsafe_mechanisms_dict.keys() 
46  all_mechanisms=safe_mechanisms+unsafe_mechanisms 
47   
49      """Create a client authenticator object for given SASL mechanism and 
50      password manager. 
51   
52      :Parameters: 
53          - `mechanism`: name of the SASL mechanism ("PLAIN", "DIGEST-MD5" or "GSSAPI"). 
54          - `password_manager`: name of the password manager object providing 
55            authentication credentials. 
56      :Types: 
57          - `mechanism`: `str` 
58          - `password_manager`: `PasswordManager` 
59   
60      :return: new authenticator. 
61      :returntype: `sasl.core.ClientAuthenticator`""" 
62      authenticator=all_mechanisms_dict[mechanism][0] 
63      return authenticator(password_manager) 
 64   
66      """Create a server authenticator object for given SASL mechanism and 
67      password manager. 
68   
69      :Parameters: 
70          - `mechanism`: name of the SASL mechanism ("PLAIN", "DIGEST-MD5" or "GSSAPI"). 
71          - `password_manager`: name of the password manager object to be used 
72            for authentication credentials verification. 
73      :Types: 
74          - `mechanism`: `str` 
75          - `password_manager`: `PasswordManager` 
76   
77      :return: new authenticator. 
78      :returntype: `sasl.core.ServerAuthenticator`""" 
79      authenticator=all_mechanisms_dict[mechanism][1] 
80      return authenticator(password_manager) 
 81   
82   
83