summaryrefslogtreecommitdiff
path: root/python/samba/__init__.py
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2016-01-28 13:52:44 +0100
committerStefan Metzmacher <metze@samba.org>2016-02-03 08:33:11 +0100
commit078a7ae71081c24991bb34c818cc2c763eefad99 (patch)
tree3ce4b68ed2778d2b1e2f3d42b0a83a50056df273 /python/samba/__init__.py
parent65127d16744763d0865ca9ce4d039866785e3fc7 (diff)
downloadsamba-078a7ae71081c24991bb34c818cc2c763eefad99.tar.gz
python:samba: add a generic arcfour_encrypt() helper function
This works with Crypto.Cipher.ARC4 (from python*-crypto) and fallback to M2Crypto.RC4.RC4 (from [python*-]m2crypto). BUG: https://bugzilla.samba.org/show_bug.cgi?id=11699 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Alexander Bokovoy <ab@samba.org>
Diffstat (limited to 'python/samba/__init__.py')
-rw-r--r--python/samba/__init__.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/python/samba/__init__.py b/python/samba/__init__.py
index 59b6ebf5e61..7cfbc4c1088 100644
--- a/python/samba/__init__.py
+++ b/python/samba/__init__.py
@@ -370,6 +370,22 @@ def string_to_byte_array(string):
return blob
+def arcfour_encrypt(key, data):
+ try:
+ from Crypto.Cipher import ARC4
+ c = ARC4.new(key)
+ return c.encrypt(data)
+ except ImportError as e:
+ pass
+ try:
+ from M2Crypto.RC4 import RC4
+ c = RC4(key)
+ return c.update(data)
+ except ImportError as e:
+ pass
+ raise Exception("arcfour_encrypt() requires " +
+ "python*-crypto or python*-m2crypto or m2crypto")
+
import _glue
version = _glue.version
interface_ips = _glue.interface_ips