Skip to content

Commit

Permalink
Adding EXTERNAL mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Shafer authored Mar 9, 2018
1 parent e9831d8 commit 3ee25a9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pure-sasl

pure-sasl is a pure python client-side SASL implementation.

At the moment, it supports the following mechanisms: ANONYMOUS, PLAIN,
At the moment, it supports the following mechanisms: ANONYMOUS, PLAIN, EXTERNAL,
CRAM-MD5, DIGEST-MD5, and GSSAPI. Support for other mechanisms may be added in the
future. Only GSSAPI supports a QOP higher than auth. Always use TLS!

Expand Down
20 changes: 20 additions & 0 deletions puresasl/mechanisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ def dispose(self):
self.password = None


class ExternalMechanism(Mechanism):
"""
The EXTERNAL mechanism allows a client to request the server to use
credentials established by means external to the mechanism to
authenticate the client.
"""
name = 'EXTERNAL'
score = 10

def wrap(self, outgoing):
return outgoing

def unwrap(self, incoming):
return incoming

def process(self, challenge=None):
return b''


class CramMD5Mechanism(PlainMechanism):
name = "CRAM-MD5"
score = 20
Expand Down Expand Up @@ -530,6 +549,7 @@ def dispose(self):
mechanisms = dict((m.name, m) for m in (
AnonymousMechanism,
PlainMechanism,
ExternalMechanism,
CramMD5Mechanism,
DigestMD5Mechanism))

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
long_description=
"""This package provides a reasonably high-level SASL client written
in pure Python. New mechanisms may be integrated easily, but by default,
support for PLAIN, ANONYMOUS, CRAM-MD5, DIGEST-MD5, and GSSAPI are
support for PLAIN, ANONYMOUS, EXTERNAL, CRAM-MD5, DIGEST-MD5, and GSSAPI are
provided.""",
license='MIT',
url='http://github.com/thobbs/pure-sasl',
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/test_mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from puresasl import SASLProtocolException, QOP
from puresasl.client import SASLClient
from puresasl.mechanisms import AnonymousMechanism, PlainMechanism, GSSAPIMechanism, DigestMD5Mechanism, CramMD5Mechanism
from puresasl.mechanisms import AnonymousMechanism, PlainMechanism, GSSAPIMechanism, DigestMD5Mechanism, CramMD5Mechanism, ExternalMechanism


class _BaseMechanismTests(unittest.TestCase):
Expand Down Expand Up @@ -91,6 +91,20 @@ def test_wrap_unwrap(self):
self.assertIs(self.sasl.wrap(msg), msg)
self.assertIs(self.sasl.unwrap(msg), msg)


class ExternalMechanismTest(_BaseMechanismTests):

mechanism_class = ExternalMechanism

def test_process(self):
self.assertIs(self.sasl.process(), b'')

def test_wrap_unwrap(self):
msg = 'msg'
self.assertIs(self.sasl.wrap(msg), msg)
self.assertIs(self.sasl.unwrap(msg), msg)


@patch('puresasl.mechanisms.kerberos.authGSSClientStep')
@patch('puresasl.mechanisms.kerberos.authGSSClientResponse', return_value=base64.b64encode(six.b('some\x00 response')))
class GSSAPIMechanismTest(_BaseMechanismTests):
Expand Down

0 comments on commit 3ee25a9

Please sign in to comment.