s4-test: added a test for E_deshash()
authorAndrew Tridgell <tridge@samba.org>
Wed, 13 Apr 2011 04:40:27 +0000 (14:40 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 13 Apr 2011 05:31:55 +0000 (07:31 +0200)
this particularly checks the boundary conditions near passwords of
length 14 characters

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Wed Apr 13 07:31:55 CEST 2011 on sn-devel-104

source4/torture/auth/smbencrypt.c [new file with mode: 0644]
source4/torture/local/local.c
source4/torture/wscript_build

diff --git a/source4/torture/auth/smbencrypt.c b/source4/torture/auth/smbencrypt.c
new file mode 100644 (file)
index 0000000..79c90eb
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   tests for smbencrypt code
+
+   Copyright (C) Andrew Tridgell 2011
+   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2011
+
+   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 "includes.h"
+#include "libcli/auth/libcli_auth.h"
+#include "torture/torture.h"
+#include "torture/auth/proto.h"
+
+static bool torture_deshash(struct torture_context *tctx)
+{
+       struct {
+               const char *input;
+               uint8_t output[16];
+               bool should_pass;
+       } testcases[] = {
+               { "",
+                 { 0xAA, 0xD3, 0xB4, 0x35, 0xB5, 0x14, 0x04, 0xEE,
+                   0xAA, 0xD3, 0xB4, 0x35, 0xB5, 0x14, 0x04, 0xEE }, true},
+               { "abcdefgh",
+                 { 0xE0, 0xC5, 0x10, 0x19, 0x9C, 0xC6, 0x6A, 0xBD,
+                   0x5A, 0xCD, 0xCD, 0x7C, 0x24, 0x7F, 0xA8, 0x3A }, true},
+               { "0123456789abc",
+                 { 0x56, 0x45, 0xF1, 0x3F, 0x50, 0x08, 0x82, 0xB2,
+                   0x50, 0x79, 0x8A, 0xE6, 0x33, 0x38, 0xAF, 0xE9 }, true},
+               { "0123456789abcd",
+                 { 0x56, 0x45, 0xF1, 0x3F, 0x50, 0x08, 0x82, 0xB2,
+                   0x1A, 0xC3, 0x88, 0x4B, 0x83, 0x32, 0x45, 0x40 }, true},
+               { "0123456789abcde",
+                 { 0x56, 0x45, 0xF1, 0x3F, 0x50, 0x08, 0x82, 0xB2,
+                   0x1A, 0xC3, 0x88, 0x4B, 0x83, 0x32, 0x45, 0x40 }, false},
+       };
+       int i;
+       for (i=0; i<ARRAY_SIZE(testcases); i++) {
+               uint8_t res[16];
+               bool ret;
+               ret = E_deshash(testcases[i].input, res);
+               torture_assert(tctx, ret == testcases[i].should_pass,
+                              "E_deshash bad result");
+               torture_assert_mem_equal(tctx, res, testcases[i].output, 16, "E_deshash bad return data");
+       }
+       return true;
+}
+
+struct torture_suite *torture_smbencrypt(TALLOC_CTX *mem_ctx)
+{
+       struct torture_suite *suite = torture_suite_create(mem_ctx, "smbencrypt");
+
+       torture_suite_add_simple_test(suite, "deshash check", torture_deshash);
+
+       return suite;
+}
index 6452bd6e896fa5dfa89d919c7b3b84c54f0506c7..b11d3387cb022b78eb223a2ecf9dbf7d1f70c578 100644 (file)
@@ -31,6 +31,7 @@
 { 
        torture_local_binding_string, 
        torture_ntlmssp, 
+       torture_smbencrypt,
        torture_local_messaging, 
        torture_local_irpc, 
        torture_local_util_strlist, 
index babe5f19e676050148d997de67bfaee292b1464b..68ec4e622095c89e9322c1d9b98b98e07fc3071f 100644 (file)
@@ -70,7 +70,7 @@ bld.SAMBA_MODULE('TORTURE_DFS',
 
 
 bld.SAMBA_MODULE('TORTURE_AUTH',
-       source='auth/ntlmssp.c auth/pac.c',
+       source='auth/ntlmssp.c auth/pac.c auth/smbencrypt.c',
        autoproto='auth/proto.h',
        subsystem='smbtorture',
        deps='LIBCLI_SMB gensec auth4 authkrb5 POPT_CREDENTIALS smbpasswdparser torture com_err gensec_ntlmssp',