Package pyxmpp :: Package sasl |
[hide private]

# Source Code for Package pyxmpp.sasl

     1  #
     2  # (C) Copyright 2003-2004 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  __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 # Kerberos not available
    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
    48 -def client_authenticator_factory(mechanism,password_manager):
    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
    65 -def server_authenticator_factory(mechanism,password_manager):
    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  # vi: sts=4 et sw=4
    83