diff options
author | Andreas Schneider <asn@samba.org> | 2021-08-19 11:29:04 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2022-07-28 11:51:28 +0000 |
commit | 1b142b72bd271ee19f493db60e49883cd0d31c3c (patch) | |
tree | 5fa2cdd7a45cd2aae96726667ce4ca708b083c98 /libcli | |
parent | 5da60573b5d3749292ca488b7dc1030679d6255b (diff) | |
download | samba-1b142b72bd271ee19f493db60e49883cd0d31c3c.tar.gz |
libcli:auth: Add encode_pw_buffer_from_str()
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'libcli')
-rw-r--r-- | libcli/auth/proto.h | 15 | ||||
-rw-r--r-- | libcli/auth/smbencrypt.c | 26 |
2 files changed, 41 insertions, 0 deletions
diff --git a/libcli/auth/proto.h b/libcli/auth/proto.h index 4d584d07f88..8a33e3b5c89 100644 --- a/libcli/auth/proto.h +++ b/libcli/auth/proto.h @@ -188,6 +188,21 @@ bool decode_pw_buffer(TALLOC_CTX *ctx, size_t *new_pw_len, charset_t string_charset); +/** + * @brief Encode an password buffer before we encrypt it. + * + * @param buffer[514] The buffer to encode into. + * + * @param password The password we want to encode into the buffer. + * + * @param string_flags String flags for encoding (e.g. STR_UNICODE). + * + * @return true on success, false otherwise. + */ +bool encode_pwd_buffer514_from_str(uint8_t buffer[514], + const char *password, + uint32_t string_flags); + /*********************************************************** Encode an arc4 password change buffer. ************************************************************/ diff --git a/libcli/auth/smbencrypt.c b/libcli/auth/smbencrypt.c index c89ac243ba4..934995c87fa 100644 --- a/libcli/auth/smbencrypt.c +++ b/libcli/auth/smbencrypt.c @@ -27,6 +27,7 @@ #include "../lib/crypto/crypto.h" #include "../libcli/auth/libcli_auth.h" #include "../librpc/gen_ndr/ndr_ntlmssp.h" +#include "lib/util/bytearray.h" #include "lib/crypto/gnutls_helpers.h" #include <gnutls/gnutls.h> @@ -989,6 +990,31 @@ bool decode_pw_buffer(TALLOC_CTX *ctx, return true; } +#define MAX_PASSWORD_LEN 256 + +/* + * [MS-SAMR] 2.2.6.32 This creates the buffer to be sent. It is of type + * SAMPR_USER_PASSWORD_AES. + */ +bool encode_pwd_buffer514_from_str(uint8_t buffer[514], + const char *password, + uint32_t string_flags) +{ + ssize_t pw_len; + + pw_len = _encode_pwd_buffer_from_str(buffer + 2, + password, + string_flags, + ENCODE_ORDER_PASSWORD_FIRST); + if (pw_len < 0) { + return false; + } + + PUSH_LE_U16(buffer, 0, pw_len); + + return true; +} + /*********************************************************** Encode an arc4 password change buffer. ************************************************************/ |