python:samba/netcmd/domain: make use of the generic arcfour_encrypt() and string_to_b...
authorStefan Metzmacher <metze@samba.org>
Thu, 28 Jan 2016 13:00:38 +0000 (14:00 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 3 Feb 2016 07:33:11 +0000 (08:33 +0100)
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>
python/samba/netcmd/domain.py

index 8802803c01564e34caa46d608549e472f0fb6e69..635714472549f5262230ec963f82a07f1e2fcf97 100644 (file)
@@ -60,7 +60,7 @@ from samba.upgrade import upgrade_from_samba3
 from samba.drs_utils import (
                             sendDsReplicaSync, drsuapi_connect, drsException,
                             sendRemoveDsServer)
-from samba import remove_dc
+from samba import remove_dc, arcfour_encrypt, string_to_byte_array
 
 from samba.dsdb import (
     DS_DOMAIN_FUNCTION_2000,
@@ -2230,24 +2230,16 @@ class cmd_domain_trust_create(DomainTrustCommand):
                     password = None
                     self.outf.write("Sorry, passwords do not match.\n")
 
-        def string_to_array(string):
-            blob = [0] * len(string)
-
-            for i in range(len(string)):
-                blob[i] = ord(string[i])
-
-            return blob
-
         incoming_secret = None
         outgoing_secret = None
         remote_policy_access = lsa.LSA_POLICY_VIEW_LOCAL_INFORMATION
         if create_location == "local":
             if local_trust_info.trust_direction & lsa.LSA_TRUST_DIRECTION_INBOUND:
                 incoming_password = get_password("Incoming Trust")
-                incoming_secret = string_to_array(incoming_password.encode('utf-16-le'))
+                incoming_secret = string_to_byte_array(incoming_password.encode('utf-16-le'))
             if local_trust_info.trust_direction & lsa.LSA_TRUST_DIRECTION_OUTBOUND:
                 outgoing_password = get_password("Outgoing Trust")
-                outgoing_secret = string_to_array(outgoing_password.encode('utf-16-le'))
+                outgoing_secret = string_to_byte_array(outgoing_password.encode('utf-16-le'))
 
             remote_trust_info = None
         else:
@@ -2272,7 +2264,7 @@ class cmd_domain_trust_create(DomainTrustCommand):
                     #
                     # We can remove this once our client libraries
                     # support using the correct NTHASH.
-                    return string_to_array(pw1.encode('utf-16-le'))
+                    return string_to_byte_array(pw1.encode('utf-16-le'))
 
                 # We mix characters from generate_random_password
                 # with random numbers from random.randint()
@@ -2425,11 +2417,6 @@ class cmd_domain_trust_create(DomainTrustCommand):
             except RuntimeError as error:
                 raise self.RemoteRuntimeError(self, error, "failed to get netlogon dc info")
 
-        def arcfour_encrypt(key, data):
-            from Crypto.Cipher import ARC4
-            c = ARC4.new(key)
-            return c.encrypt(data)
-
         def generate_AuthInOutBlob(secret, update_time):
             if secret is None:
                 blob = drsblobs.trustAuthInOutBlob()
@@ -2473,7 +2460,7 @@ class cmd_domain_trust_create(DomainTrustCommand):
 
             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