Permalink
Browse files

initial commit

  • Loading branch information...
1 parent 4acff79 commit 50ca96cd4d8db662eded237eedcad9274f7da3b8 @suvit committed Jan 3, 2013
Showing with 114 additions and 1 deletion.
  1. +1 −0 MANIFEST.in
  2. +27 −1 README.md
  3. +32 −0 setup.py
  4. +54 −0 suds_passworddigest/__init__.py
View
@@ -0,0 +1 @@
+include README.md
View
@@ -1,4 +1,30 @@
suds-passworddigest
===================
-adds Web Services Security PasswordDigest authentication to SUDS
+adds Web Services Security PasswordDigest authentication to SUDS
+
+Installation
+----------------
+
+installation is simple
+
+ pip install suds-passworddigest
+
+or
+
+ pip install git+https://github.com/suvit/suds-passworddigest
+
+
+Usage
+-------------------
+
+ from suds.client import Client
+ from suds.wsse import Security
+
+ from suds_passworddigest import UsernameDigestToken
+
+ client = Client()
+ security = Security()
+ token = UsernameDigestToken('my_username', 'my_pass')
+ security.tokens.append(token)
+ client.set_options(wsse=security)
View
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -
+#
+# This file is part of suds-passworddigest released under the MIT license.
+# See the NOTICE for more information.
+
+import os
+import sys
+from setuptools import setup, find_packages
+
+from suds_passworddigest import VERSION
+
+
+setup(
+ name='suds_passworddigest',
+ version=VERSION,
+ description='adds Web Services Security'
+ ' PasswordDigest authentication to SUDS',
+ long_description=file(
+ os.path.join(
+ os.path.dirname(__file__),
+ 'README.md'
+ )
+ ).read(),
+ author='Victor Safronovich',
+ author_email='vsafronovich@gmail.com',
+ license='MIT',
+ url='http://github.com/suvit/suds-passworddigest',
+ zip_safe=False,
+ packages=find_packages(exclude=['docs', 'examples', 'tests']),
+ install_requires=['suds'],
+ include_package_data=True,
+)
@@ -0,0 +1,54 @@
+
+import base64
+import datetime
+import hashlib
+from time import time, strftime, gmtime
+
+from suds.sax.element import Element
+from suds.sax.date import UTC
+from suds.wsse import UsernameToken, wssens
+
+
+VERSION = '0.1.0'
+
+
+wspassd = ('Type',
+ 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest')
+wsenctype = ('EncodingType',
+ 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary')
+
+
+class UsernameDigestToken(UsernameToken):
+ def xml(self):
+ """
+ Get xml representation of the object.
+ @return: The root node.
+ @rtype: L{Element}
+ """
+ root = Element('UsernameToken', ns=wssens)
+
+ u = Element('Username', ns=wssens)
+ u.setText(self.username)
+ root.append(u)
+
+ p = Element('Password', ns=wssens)
+ if self.nonce is None:
+ self.setnonce()
+ if self.created is None:
+ self.setcreated()
+ sha1 = hashlib.sha1(str(self.nonce) + \
+ str(UTC(self.created)) + self.password)
+ p.setText(base64.b64encode(sha1.digest()))
+ p.set(wspassd[0], wspassd[1])
+ root.append(p)
+
+ n = Element('Nonce', ns=wssens)
+ n.setText(base64.b64encode(self.nonce))
+ n.set(wsenctype[0], wsenctype[1])
+ root.append(n)
+
+ n = Element('Created', ns=wsuns)
+ n.setText(str(UTC(self.created)))
+ root.append(n)
+
+ return root

0 comments on commit 50ca96c

Please sign in to comment.