]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libcli:auth: Add extract_pwd_blob_from_buffer514()
authorAndreas Schneider <asn@samba.org>
Fri, 20 Aug 2021 07:45:27 +0000 (09:45 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 28 Jul 2022 11:51:29 +0000 (11:51 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
libcli/auth/proto.h
libcli/auth/smbencrypt.c

index 8a33e3b5c89c7f3f35de35cd2aa09ea1fe1024a2..c787ac2d7125b56fe99e27b41c1afc882ee7fc25 100644 (file)
@@ -203,6 +203,24 @@ bool encode_pwd_buffer514_from_str(uint8_t buffer[514],
                                   const char *password,
                                   uint32_t string_flags);
 
+/**
+ * @brief Extract AES password blob from buffer.
+ *
+ * This extracts the password from the in_buffer as a data blob. It should
+ * then contain an UTF-16 encoded password.
+ *
+ * @param mem_ctx       The memory context to allowcate the password on.
+ *
+ * @param in_buffer[514] The input buffer to extract the password from.
+ *
+ * @param new_password  A pointer to the store the extracted password blob.
+ *
+ * @return true on success, false otherwise.
+ */
+bool extract_pwd_blob_from_buffer514(TALLOC_CTX *mem_ctx,
+                                    const uint8_t in_buffer[514],
+                                    DATA_BLOB *new_password);
+
 /***********************************************************
  Encode an arc4 password change buffer.
 ************************************************************/
index 666ff3145239381b7e4c8d3bdf94674d95019bc7..cf141a9891f43bb8e02a358c60dad7767e5f0378 100644 (file)
@@ -1011,6 +1011,36 @@ bool encode_pwd_buffer514_from_str(uint8_t buffer[514],
        return true;
 }
 
+bool extract_pwd_blob_from_buffer514(TALLOC_CTX *mem_ctx,
+                                    const uint8_t in_buffer[514],
+                                    DATA_BLOB *new_password)
+{
+#ifdef DEBUG_PASSWORD
+       DEBUG(100, ("in_buffer: "));
+       dump_data(100, in_buffer, 514);
+#endif
+
+       new_password->length = PULL_LE_U16(in_buffer, 0);
+       if (new_password->length == 0 || new_password->length > 512) {
+               return false;
+       }
+
+       new_password->data =
+               talloc_memdup(mem_ctx, in_buffer + 2, new_password->length);
+       if (new_password->data == NULL) {
+               return false;
+       }
+       talloc_keep_secret(new_password->data);
+
+#ifdef DEBUG_PASSWORD
+       DEBUG(100, ("new_pwd_len: %zu\n", new_password->length));
+       DEBUG(100, ("new_pwd: "));
+       dump_data(100, new_password->data, new_password->length);
+#endif
+
+       return true;
+}
+
 /***********************************************************
  Encode an arc4 password change buffer.
 ************************************************************/