Package pyxmpp :: Package sasl
[hide private]

Source Code for Package pyxmpp.sasl

 1  # 
 2  # (C) Copyright 2003-2010 Jacek Konieczny <jajcus@jajcus.net> 
 3  # 
 4  # This program is free software; you can redistribute it and/or modify 
 5  # it under the terms of the GNU Lesser General Public License Version 
 6  # 2.1 as published by the Free Software Foundation. 
 7  # 
 8  # This program is distributed in the hope that it will be useful, 
 9  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
11  # GNU Lesser General Public License for more details. 
12  # 
13  # You should have received a copy of the GNU Lesser General Public 
14  # License along with this program; if not, write to the Free Software 
15  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
16  # 
17  """SASL authentication implementaion for PyXMPP. 
18   
19  Normative reference: 
20    - `RFC 2222 <http://www.ietf.org/rfc/rfc2222.txt>`__ 
21  """ 
22   
23  __docformat__="restructuredtext en" 
24   
25  import random 
26   
27  from pyxmpp.sasl.core import Reply,Response,Challenge,Success,Failure,PasswordManager 
28   
29  from pyxmpp.sasl.plain import PlainClientAuthenticator,PlainServerAuthenticator 
30  from pyxmpp.sasl.digest_md5 import DigestMD5ClientAuthenticator,DigestMD5ServerAuthenticator 
31  from pyxmpp.sasl.external import ExternalClientAuthenticator 
32   
33  safe_mechanisms_dict={"DIGEST-MD5":(DigestMD5ClientAuthenticator,DigestMD5ServerAuthenticator), 
34                        "EXTERNAL":(ExternalClientAuthenticator, None)} 
35  try: 
36      from pyxmpp.sasl.gssapi import GSSAPIClientAuthenticator 
37  except ImportError: 
38      pass # Kerberos not available 
39  else: 
40      safe_mechanisms_dict["GSSAPI"] = (GSSAPIClientAuthenticator,None) 
41  unsafe_mechanisms_dict={"PLAIN":(PlainClientAuthenticator,PlainServerAuthenticator)} 
42  all_mechanisms_dict=safe_mechanisms_dict.copy() 
43  all_mechanisms_dict.update(unsafe_mechanisms_dict) 
44   
45  safe_mechanisms=safe_mechanisms_dict.keys() 
46  unsafe_mechanisms=unsafe_mechanisms_dict.keys() 
47  all_mechanisms=safe_mechanisms+unsafe_mechanisms 
48   
49 -def client_authenticator_factory(mechanism,password_manager):
50 """Create a client authenticator object for given SASL mechanism and 51 password manager. 52 53 :Parameters: 54 - `mechanism`: name of the SASL mechanism ("PLAIN", "DIGEST-MD5" or "GSSAPI"). 55 - `password_manager`: name of the password manager object providing 56 authentication credentials. 57 :Types: 58 - `mechanism`: `str` 59 - `password_manager`: `PasswordManager` 60 61 :return: new authenticator. 62 :returntype: `sasl.core.ClientAuthenticator`""" 63 authenticator=all_mechanisms_dict[mechanism][0] 64 return authenticator(password_manager)
65
66 -def server_authenticator_factory(mechanism,password_manager):
67 """Create a server authenticator object for given SASL mechanism and 68 password manager. 69 70 :Parameters: 71 - `mechanism`: name of the SASL mechanism ("PLAIN", "DIGEST-MD5" or "GSSAPI"). 72 - `password_manager`: name of the password manager object to be used 73 for authentication credentials verification. 74 :Types: 75 - `mechanism`: `str` 76 - `password_manager`: `PasswordManager` 77 78 :return: new authenticator. 79 :returntype: `sasl.core.ServerAuthenticator`""" 80 authenticator=all_mechanisms_dict[mechanism][1] 81 return authenticator(password_manager)
82 83 # vi: sts=4 et sw=4 84