From 6c44fabcfd6fc4370a78854ab0ee9ac54f137a0e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 28 Jan 2016 14:00:38 +0100 Subject: s4:scripting/devel: make use of the generic arcfour_encrypt() and string_to_byte_array() functions BUG: https://bugzilla.samba.org/show_bug.cgi?id=11699 Signed-off-by: Stefan Metzmacher Reviewed-by: Alexander Bokovoy (cherry picked from commit 8841b1e641e1b950c2f36b26db982473b73b9d3b) --- source4/scripting/devel/createtrust | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/source4/scripting/devel/createtrust b/source4/scripting/devel/createtrust index 7f1ba33b85c..6c0de1c3ff1 100755 --- a/source4/scripting/devel/createtrust +++ b/source4/scripting/devel/createtrust @@ -11,21 +11,9 @@ import samba import samba.getopt as options from samba.dcerpc import lsa, security, drsblobs from samba.ndr import ndr_pack +from samba import arcfour_encrypt, string_to_byte_array import random -def arcfour_encrypt(key, data): - from Crypto.Cipher import ARC4 - c = ARC4.new(key) - return c.encrypt(data) - -def string_to_array(string): - blob = [0] * len(string) - - for i in range(len(string)): - blob[i] = ord(string[i]) - - return blob - ########### main code ########### if __name__ == "__main__": parser = OptionParser("createtrust [options] server") @@ -73,7 +61,7 @@ if __name__ == "__main__": info.trust_type = lsa.LSA_TRUST_TYPE_UPLEVEL info.trust_attributes = lsa.LSA_TRUST_ATTRIBUTE_WITHIN_FOREST - password_blob = string_to_array("password".encode('utf-16-le')) + password_blob = string_to_byte_array("password".encode('utf-16-le')) clear_value = drsblobs.AuthInfoClear() clear_value.size = len(password_blob) @@ -123,7 +111,7 @@ if __name__ == "__main__": auth_blob = lsa.DATA_BUF2() auth_blob.size = len(encrypted_trustpass) - auth_blob.data = string_to_array(encrypted_trustpass) + auth_blob.data = string_to_byte_array(encrypted_trustpass) auth_info = lsa.TrustDomainInfoAuthInfoInternal() auth_info.auth_blob = auth_blob -- cgit v1.2.1