57726f
From eb38d2278937ec3fe45d0af30cd080953bbb5b54 Mon Sep 17 00:00:00 2001
57726f
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
57726f
Date: Tue, 2 Jan 2018 18:13:07 +0100
57726f
Subject: [PATCH] Fix pkcs11 variants atf tests
57726f
57726f
Add dns-pkcs11 tests Makefile to configure
57726f
57726f
Add pkcs11 Kyuafile, fix dh_test to pass in pkcs11 mode
57726f
---
57726f
 configure.ac                     |  1 +
57726f
 lib/Kyuafile                     |  2 ++
57726f
 lib/dns-pkcs11/tests/Makefile.in | 10 +++++-----
57726f
 lib/dns-pkcs11/tests/dh_test.c   |  3 ++-
57726f
 lib/isc-pkcs11/tests/Makefile.in |  6 +++---
57726f
 lib/isc-pkcs11/tests/hash_test.c | 32 +++++++++++++++++++++++++-------
57726f
 6 files changed, 38 insertions(+), 16 deletions(-)
57726f
57726f
diff --git a/configure.ac b/configure.ac
57726f
index 0532feb..a83ddd5 100644
57726f
--- a/configure.ac
57726f
+++ b/configure.ac
57726f
@@ -5578,6 +5578,7 @@ AC_CONFIG_FILES([
57726f
 	lib/dns-pkcs11/include/Makefile
57726f
 	lib/dns-pkcs11/include/dns/Makefile
57726f
 	lib/dns-pkcs11/include/dst/Makefile
57726f
+	lib/dns-pkcs11/tests/Makefile
57726f
 	lib/irs/Makefile
57726f
 	lib/irs/include/Makefile
57726f
 	lib/irs/include/irs/Makefile
57726f
diff --git a/lib/Kyuafile b/lib/Kyuafile
57726f
index 7c8bab0..eec9564 100644
57726f
--- a/lib/Kyuafile
57726f
+++ b/lib/Kyuafile
57726f
@@ -2,8 +2,10 @@ syntax(2)
57726f
 test_suite('bind9')
57726f
 
57726f
 include('dns/Kyuafile')
57726f
+include('dns-pkcs11/Kyuafile')
57726f
 include('irs/Kyuafile')
57726f
 include('isc/Kyuafile')
57726f
+include('isc-pkcs11/Kyuafile')
57726f
 include('isccc/Kyuafile')
57726f
 include('isccfg/Kyuafile')
57726f
 include('lwres/Kyuafile')
57726f
diff --git a/lib/dns-pkcs11/tests/Makefile.in b/lib/dns-pkcs11/tests/Makefile.in
57726f
index 7671e1d..e237d5c 100644
57726f
--- a/lib/dns-pkcs11/tests/Makefile.in
57726f
+++ b/lib/dns-pkcs11/tests/Makefile.in
57726f
@@ -17,12 +17,12 @@ VERSION=@BIND9_VERSION@
57726f
 
57726f
 CINCLUDES =	-I. -Iinclude ${DNS_INCLUDES} ${ISC_INCLUDES} \
57726f
 		@DST_OPENSSL_INC@
57726f
-CDEFINES =	@CRYPTO@ -DTESTS="\"${top_builddir}/lib/dns/tests/\""
57726f
+CDEFINES =	@CRYPTO_PK11@ -DTESTS="\"${top_builddir}/lib/dns-pkcs11/tests/\""
57726f
 
57726f
-ISCLIBS =	../../isc/libisc.@A@
57726f
-ISCDEPLIBS =	../../isc/libisc.@A@
57726f
-DNSLIBS =	../libdns.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
57726f
-DNSDEPLIBS =	../libdns.@A@
57726f
+ISCLIBS =	../../isc-pkcs11/libisc-pkcs11.@A@
57726f
+ISCDEPLIBS =	../../isc-pkcs11/libisc-pkcs11.@A@
57726f
+DNSLIBS =	../libdns-pkcs11.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
57726f
+DNSDEPLIBS =	../libdns-pkcs11.@A@
57726f
 
57726f
 LIBS =		@LIBS@ @CMOCKA_LIBS@
57726f
 CFLAGS =	@CFLAGS@ @CMOCKA_CFLAGS@
57726f
diff --git a/lib/dns-pkcs11/tests/dh_test.c b/lib/dns-pkcs11/tests/dh_test.c
57726f
index 4dbfd82..a383b8e 100644
57726f
--- a/lib/dns-pkcs11/tests/dh_test.c
57726f
+++ b/lib/dns-pkcs11/tests/dh_test.c
57726f
@@ -86,7 +86,8 @@ dh_computesecret(void **state) {
57726f
 	result = dst_key_computesecret(key, key, &buf;;
57726f
 	assert_int_equal(result, DST_R_NOTPRIVATEKEY);
57726f
 	result = key->func->computesecret(key, key, &buf;;
57726f
-	assert_int_equal(result, DST_R_COMPUTESECRETFAILURE);
57726f
+	/* PKCS11 variant gives different result, accept both */
57726f
+	assert_true(result == DST_R_COMPUTESECRETFAILURE || result == DST_R_INVALIDPRIVATEKEY);
57726f
 
57726f
 	dst_key_free(&key);
57726f
 }
57726f
diff --git a/lib/isc-pkcs11/tests/Makefile.in b/lib/isc-pkcs11/tests/Makefile.in
57726f
index 2fdee0b..a263b35 100644
57726f
--- a/lib/isc-pkcs11/tests/Makefile.in
57726f
+++ b/lib/isc-pkcs11/tests/Makefile.in
57726f
@@ -16,10 +16,10 @@ VERSION=@BIND9_VERSION@
57726f
 @BIND9_MAKE_INCLUDES@
57726f
 
57726f
 CINCLUDES =	-I. -Iinclude ${ISC_INCLUDES} @ISC_OPENSSL_INC@
57726f
-CDEFINES =	@CRYPTO@ -DTESTS="\"${top_builddir}/lib/isc/tests/\""
57726f
+CDEFINES =	@CRYPTO_PK11@ -DTESTS="\"${top_builddir}/lib/isc-pkcs11/tests/\""
57726f
 
57726f
-ISCLIBS =	../libisc.@A@ @ISC_OPENSSL_LIBS@
57726f
-ISCDEPLIBS =	../libisc.@A@
57726f
+ISCLIBS =	../libisc-pkcs11.@A@ @ISC_OPENSSL_LIBS@
57726f
+ISCDEPLIBS =	../libisc-pkcs11.@A@
57726f
 
57726f
 LIBS =		@LIBS@ @CMOCKA_LIBS@
57726f
 CFLAGS =	@CFLAGS@ @CMOCKA_CFLAGS@
57726f
diff --git a/lib/isc-pkcs11/tests/hash_test.c b/lib/isc-pkcs11/tests/hash_test.c
57726f
index 9c4d299..d9deba2 100644
57726f
--- a/lib/isc-pkcs11/tests/hash_test.c
57726f
+++ b/lib/isc-pkcs11/tests/hash_test.c
57726f
@@ -85,7 +85,7 @@ typedef struct hash_testcase {
57726f
 
57726f
 typedef struct hash_test_key {
57726f
 	const char *key;
57726f
-	const int len;
57726f
+	const unsigned len;
57726f
 } hash_test_key_t;
57726f
 
57726f
 /* non-hmac tests */
57726f
@@ -956,8 +956,11 @@ isc_hmacsha1_test(void **state) {
57726f
 	hash_test_key_t *test_key = test_keys;
57726f
 
57726f
 	while (testcase->input != NULL && testcase->result != NULL) {
57726f
+		int len = ISC_MAX(test_key->len, ISC_SHA1_DIGESTLENGTH);
57726f
+
57726f
+		memset(buffer, 0, ISC_SHA1_DIGESTLENGTH);
57726f
 		memmove(buffer, test_key->key, test_key->len);
57726f
-		isc_hmacsha1_init(&hmacsha1, buffer, test_key->len);
57726f
+		isc_hmacsha1_init(&hmacsha1, buffer, len);
57726f
 		isc_hmacsha1_update(&hmacsha1,
57726f
 				    (const uint8_t *) testcase->input,
57726f
 				    testcase->input_len);
57726f
@@ -1116,8 +1119,11 @@ isc_hmacsha224_test(void **state) {
57726f
 	hash_test_key_t *test_key = test_keys;
57726f
 
57726f
 	while (testcase->input != NULL && testcase->result != NULL) {
57726f
+		int len = ISC_MAX(test_key->len, ISC_SHA224_DIGESTLENGTH);
57726f
+
57726f
+		memset(buffer, 0, ISC_SHA224_DIGESTLENGTH);
57726f
 		memmove(buffer, test_key->key, test_key->len);
57726f
-		isc_hmacsha224_init(&hmacsha224, buffer, test_key->len);
57726f
+		isc_hmacsha224_init(&hmacsha224, buffer, len);
57726f
 		isc_hmacsha224_update(&hmacsha224,
57726f
 				      (const uint8_t *) testcase->input,
57726f
 				      testcase->input_len);
57726f
@@ -1277,8 +1283,11 @@ isc_hmacsha256_test(void **state) {
57726f
 	hash_test_key_t *test_key = test_keys;
57726f
 
57726f
 	while (testcase->input != NULL && testcase->result != NULL) {
57726f
+		int len = ISC_MAX(test_key->len, ISC_SHA256_DIGESTLENGTH);
57726f
+
57726f
+		memset(buffer, 0, ISC_SHA256_DIGESTLENGTH);
57726f
 		memmove(buffer, test_key->key, test_key->len);
57726f
-		isc_hmacsha256_init(&hmacsha256, buffer, test_key->len);
57726f
+		isc_hmacsha256_init(&hmacsha256, buffer, len);
57726f
 		isc_hmacsha256_update(&hmacsha256,
57726f
 				      (const uint8_t *) testcase->input,
57726f
 				      testcase->input_len);
57726f
@@ -1444,8 +1453,11 @@ isc_hmacsha384_test(void **state) {
57726f
 	hash_test_key_t *test_key = test_keys;
57726f
 
57726f
 	while (testcase->input != NULL && testcase->result != NULL) {
57726f
+		int len = ISC_MAX(test_key->len, ISC_SHA384_DIGESTLENGTH);
57726f
+
57726f
+		memset(buffer, 0, ISC_SHA384_DIGESTLENGTH);
57726f
 		memmove(buffer, test_key->key, test_key->len);
57726f
-		isc_hmacsha384_init(&hmacsha384, buffer, test_key->len);
57726f
+		isc_hmacsha384_init(&hmacsha384, buffer, len);
57726f
 		isc_hmacsha384_update(&hmacsha384,
57726f
 				      (const uint8_t *) testcase->input,
57726f
 				      testcase->input_len);
57726f
@@ -1611,8 +1623,11 @@ isc_hmacsha512_test(void **state) {
57726f
 	hash_test_key_t *test_key = test_keys;
57726f
 
57726f
 	while (testcase->input != NULL && testcase->result != NULL) {
57726f
+		int len = ISC_MAX(test_key->len, ISC_SHA512_DIGESTLENGTH);
57726f
+
57726f
+		memset(buffer, 0, ISC_SHA512_DIGESTLENGTH);
57726f
 		memmove(buffer, test_key->key, test_key->len);
57726f
-		isc_hmacsha512_init(&hmacsha512, buffer, test_key->len);
57726f
+		isc_hmacsha512_init(&hmacsha512, buffer, len);
57726f
 		isc_hmacsha512_update(&hmacsha512,
57726f
 				      (const uint8_t *) testcase->input,
57726f
 				      testcase->input_len);
57726f
@@ -1755,8 +1770,11 @@ isc_hmacmd5_test(void **state) {
57726f
 	hash_test_key_t *test_key = test_keys;
57726f
 
57726f
 	while (testcase->input != NULL && testcase->result != NULL) {
57726f
+		int len = ISC_MAX(test_key->len, ISC_MD5_DIGESTLENGTH);
57726f
+
57726f
+		memset(buffer, 0, ISC_MD5_DIGESTLENGTH);
57726f
 		memmove(buffer, test_key->key, test_key->len);
57726f
-		isc_hmacmd5_init(&hmacmd5, buffer, test_key->len);
57726f
+		isc_hmacmd5_init(&hmacmd5, buffer, len);
57726f
 		isc_hmacmd5_update(&hmacmd5,
57726f
 				   (const uint8_t *) testcase->input,
57726f
 				   testcase->input_len);
57726f
-- 
57726f
2.20.1
57726f