libcli:auth: Add test for decoding an RC4 password buffer
authorAndreas Schneider <asn@samba.org>
Fri, 5 Jul 2019 07:39:02 +0000 (09:39 +0200)
committerDavid Disseldorp <ddiss@samba.org>
Mon, 15 Jul 2019 08:54:15 +0000 (10:54 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14031

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
libcli/auth/tests/test_rc4_passwd_buffer.c [new file with mode: 0644]
libcli/auth/wscript_build
selftest/tests.py

diff --git a/libcli/auth/tests/test_rc4_passwd_buffer.c b/libcli/auth/tests/test_rc4_passwd_buffer.c
new file mode 100644 (file)
index 0000000..08f1cc7
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * Copyright (C) 2018-2019 Andreas Schneider <asn@samba.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include "includes.h"
+#include "libcli/auth/libcli_auth.h"
+#include "rpc_client/init_samr.h"
+
+#define PASSWORD "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
+
+static void torture_rc4_passwd_buffer(void **state)
+{
+       char *password_decoded = NULL;
+       size_t password_decoded_len = 0;
+       DATA_BLOB session_key = data_blob_const("SystemLibraryDTC", 16);
+       struct samr_CryptPasswordEx out_pwd_buf = {
+               .data = {0},
+       };
+       NTSTATUS status;
+       bool ok;
+
+       status = init_samr_CryptPasswordEx(PASSWORD,
+                                          &session_key,
+                                          &out_pwd_buf);
+       assert_true(NT_STATUS_IS_OK(status));
+
+       status = encode_or_decode_arc4_passwd_buffer(out_pwd_buf.data,
+                                                    &session_key);
+       assert_true(NT_STATUS_IS_OK(status));
+
+       ok = decode_pw_buffer(NULL,
+                             out_pwd_buf.data,
+                             &password_decoded,
+                             &password_decoded_len,
+                             CH_UTF16);
+       assert_true(ok);
+       assert_int_equal(password_decoded_len, strlen(PASSWORD));
+       assert_string_equal(password_decoded, PASSWORD);
+}
+
+int main(int argc, char *argv[])
+{
+       int rc;
+       const struct CMUnitTest tests[] = {
+               cmocka_unit_test(torture_rc4_passwd_buffer),
+       };
+
+       if (argc == 2) {
+               cmocka_set_test_filter(argv[1]);
+       }
+       cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
+
+       rc = cmocka_run_group_tests(tests, NULL, NULL);
+
+       return rc;
+}
index 39489c20b4e36e04a74847e10fe8aa45dd74b59b..5a4423e984e8594c682cb94c66226aa2e0f22d2b 100644 (file)
@@ -54,3 +54,12 @@ bld.SAMBA_BINARY(
         ''',
         install=False
     )
+
+bld.SAMBA_BINARY('test_rc4_passwd_buffer',
+                 source='tests/test_rc4_passwd_buffer.c',
+                 deps='''
+                      INIT_SAMR
+                      LIBCLI_AUTH
+                      cmocka
+                      ''',
+                 install=False)
index 1568f29b2128d4391e573b217b4d39178e7438b7..3377e7826bd903e532a1790bc4bda49c12e40719 100644 (file)
@@ -261,6 +261,8 @@ plantestsuite("samba.unittests.byteorder", "none",
               [os.path.join(bindir(), "default/lib/util/test_byteorder")])
 plantestsuite("samba.unittests.ntlm_check", "none",
               [os.path.join(bindir(), "default/libcli/auth/test_ntlm_check")])
+plantestsuite("samba.unittests.rc4_passwd_buffer", "none",
+              [os.path.join(bindir(), "default/libcli/auth/test_rc4_passwd_buffer")])
 plantestsuite("samba.unittests.test_registry_regfio", "none",
               [os.path.join(bindir(), "default/source3/test_registry_regfio")])
 plantestsuite("samba.unittests.test_oLschema2ldif", "none",