Blob Blame History Raw
From c1258172d502955442704264ec1c7ea926784b35 Mon Sep 17 00:00:00 2001
From: Isaac Boukris <iboukris@gmail.com>
Date: Sat, 9 Nov 2019 17:47:33 +0100
Subject: [PATCH 164/187] libcli/auth: test des_crypt56() and add test_gnutls
 to selftest

Signed-off-by: Isaac Boukris <iboukris@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit 07b4606f893fabd50c2685307d58e86f55defae5)
---
 libcli/auth/tests/test_gnutls.c | 24 ++++++++++++++++++++++++
 libcli/auth/wscript_build       |  1 +
 selftest/tests.py               |  2 ++
 3 files changed, 27 insertions(+)

diff --git a/libcli/auth/tests/test_gnutls.c b/libcli/auth/tests/test_gnutls.c
index 412a454b762..7847d01a4dc 100644
--- a/libcli/auth/tests/test_gnutls.c
+++ b/libcli/auth/tests/test_gnutls.c
@@ -24,6 +24,7 @@
 #include <cmocka.h>
 
 #include "includes.h"
+#include "libcli/auth/libcli_auth.h"
 
 #include "lib/crypto/gnutls_helpers.h"
 #include <gnutls/gnutls.h>
@@ -227,11 +228,34 @@ static void torture_gnutls_aes_128_cfb(void **state)
 #endif
 }
 
+static void torture_gnutls_des_crypt56(void **state)
+{
+	static const uint8_t key[7] = {
+		0x69, 0x88, 0x96, 0x8E, 0xB5, 0x3A, 0x24
+	};
+	static const uint8_t clear[8] = {
+		0x3F, 0x49, 0x5B, 0x20, 0xA7, 0x84, 0xC2, 0x34
+	};
+	static const uint8_t crypt_expected[8] = {
+		0x54, 0x86, 0xCF, 0x51, 0x49, 0x3A, 0x53, 0x5B
+	};
+
+	uint8_t crypt[8];
+	uint8_t decrypt[8];
+
+	des_crypt56(crypt, clear, key, 1);
+	assert_memory_equal(crypt, crypt_expected, 8);
+
+	des_crypt56(decrypt, crypt, key, 0);
+	assert_memory_equal(decrypt, clear, 8);
+}
+
 int main(int argc, char *argv[])
 {
 	int rc;
 	const struct CMUnitTest tests[] = {
 		cmocka_unit_test(torture_gnutls_aes_128_cfb),
+		cmocka_unit_test(torture_gnutls_des_crypt56),
 	};
 
 	if (argc == 2) {
diff --git a/libcli/auth/wscript_build b/libcli/auth/wscript_build
index 7b765cd9e43..8e856d07ddf 100644
--- a/libcli/auth/wscript_build
+++ b/libcli/auth/wscript_build
@@ -76,6 +76,7 @@ bld.SAMBA_BINARY('test_gnutls',
                  source='tests/test_gnutls.c',
                  deps='''
                       gnutls
+                      LIBCLI_AUTH
                       cmocka
                       samba-util
                       ''',
diff --git a/selftest/tests.py b/selftest/tests.py
index c91d9b445fe..20809678104 100644
--- a/selftest/tests.py
+++ b/selftest/tests.py
@@ -390,6 +390,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.gnutls", "none",
+              [os.path.join(bindir(), "default/libcli/auth/test_gnutls")])
 plantestsuite("samba.unittests.schannel", "none",
               [os.path.join(bindir(), "default/libcli/auth/test_schannel")])
 plantestsuite("samba.unittests.rc4_passwd_buffer", "none",
-- 
2.23.0