3ce7d3
From d0433a314534e104f52acf2a0a96a68dd84305ae Mon Sep 17 00:00:00 2001
3ce7d3
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
3ce7d3
Date: Tue, 2 Jan 2018 18:13:07 +0100
3ce7d3
Subject: [PATCH] Fix pkcs11 variants atf tests
3ce7d3
3ce7d3
Add dns-pkcs11 tests Makefile to configure
3ce7d3
3ce7d3
Add pkcs11 Kyuafile, fix dh_test to pass in pkcs11 mode
3ce7d3
---
3ce7d3
 configure.in                     |  1 +
3ce7d3
 lib/Atffile                      |  2 ++
3ce7d3
 lib/Kyuafile                     |  2 ++
3ce7d3
 lib/dns-pkcs11/tests/Makefile.in | 10 +++++-----
3ce7d3
 lib/dns-pkcs11/tests/dh_test.c   |  3 ++-
3ce7d3
 lib/isc-pkcs11/tests/Makefile.in |  6 +++---
3ce7d3
 lib/isc-pkcs11/tests/hash_test.c | 32 +++++++++++++++++++++++++-------
3ce7d3
 7 files changed, 40 insertions(+), 16 deletions(-)
3ce7d3
3ce7d3
diff --git a/configure.in b/configure.in
3ce7d3
index 67b3aab..4767eeb 100644
3ce7d3
--- a/configure.in
3ce7d3
+++ b/configure.in
3ce7d3
@@ -5579,6 +5579,7 @@ AC_CONFIG_FILES([
3ce7d3
 	lib/dns-pkcs11/include/Makefile
3ce7d3
 	lib/dns-pkcs11/include/dns/Makefile
3ce7d3
 	lib/dns-pkcs11/include/dst/Makefile
3ce7d3
+	lib/dns-pkcs11/tests/Makefile
3ce7d3
 	lib/irs/Makefile
3ce7d3
 	lib/irs/include/Makefile
3ce7d3
 	lib/irs/include/irs/Makefile
3ce7d3
diff --git a/lib/Atffile b/lib/Atffile
3ce7d3
index 93bbb01..4db3dce 100644
3ce7d3
--- a/lib/Atffile
3ce7d3
+++ b/lib/Atffile
3ce7d3
@@ -3,7 +3,9 @@ Content-Type: application/X-atf-atffile; version="1"
3ce7d3
 prop: test-suite = bind9
3ce7d3
 
3ce7d3
 tp: dns
3ce7d3
+tp: dns-pkcs11
3ce7d3
 tp: irs
3ce7d3
 tp: isc
3ce7d3
+tp: isc-pkcs11
3ce7d3
 tp: isccfg
3ce7d3
 tp: lwres
3ce7d3
diff --git a/lib/Kyuafile b/lib/Kyuafile
3ce7d3
index ff9fc56..eaaf0dc 100644
3ce7d3
--- a/lib/Kyuafile
3ce7d3
+++ b/lib/Kyuafile
3ce7d3
@@ -2,7 +2,9 @@ syntax(2)
3ce7d3
 test_suite('bind9')
3ce7d3
 
3ce7d3
 include('dns/Kyuafile')
3ce7d3
+include('dns-pkcs11/Kyuafile')
3ce7d3
 include('irs/Kyuafile')
3ce7d3
 include('isc/Kyuafile')
3ce7d3
+include('isc-pkcs11/Kyuafile')
3ce7d3
 include('isccfg/Kyuafile')
3ce7d3
 include('lwres/Kyuafile')
3ce7d3
diff --git a/lib/dns-pkcs11/tests/Makefile.in b/lib/dns-pkcs11/tests/Makefile.in
3ce7d3
index 2a6571b..f25a784 100644
3ce7d3
--- a/lib/dns-pkcs11/tests/Makefile.in
3ce7d3
+++ b/lib/dns-pkcs11/tests/Makefile.in
3ce7d3
@@ -20,12 +20,12 @@ VERSION=@BIND9_VERSION@
3ce7d3
 
3ce7d3
 CINCLUDES =	-I. -Iinclude ${DNS_INCLUDES} ${ISC_INCLUDES} \
3ce7d3
 		@DST_OPENSSL_INC@
3ce7d3
-CDEFINES =	@CRYPTO@ -DTESTS="\"${top_builddir}/lib/dns/tests/\""
3ce7d3
+CDEFINES =	@CRYPTO@ -DTESTS="\"${top_builddir}/lib/dns-pkcs11/tests/\""
3ce7d3
 
3ce7d3
-ISCLIBS =	../../isc/libisc.@A@
3ce7d3
-ISCDEPLIBS =	../../isc/libisc.@A@
3ce7d3
-DNSLIBS =	../libdns.@A@ @DNS_CRYPTO_LIBS@
3ce7d3
-DNSDEPLIBS =	../libdns.@A@
3ce7d3
+ISCLIBS =	../../isc-pkcs11/libisc-pkcs11.@A@
3ce7d3
+ISCDEPLIBS =	../../isc-pkcs11/libisc-pkcs11.@A@
3ce7d3
+DNSLIBS =	../libdns-pkcs11.@A@ @DNS_CRYPTO_LIBS@
3ce7d3
+DNSDEPLIBS =	../libdns-pkcs11.@A@
3ce7d3
 
3ce7d3
 LIBS =		@LIBS@ @ATFLIBS@
3ce7d3
 
3ce7d3
diff --git a/lib/dns-pkcs11/tests/dh_test.c b/lib/dns-pkcs11/tests/dh_test.c
3ce7d3
index 036d27a..eb6554f 100644
3ce7d3
--- a/lib/dns-pkcs11/tests/dh_test.c
3ce7d3
+++ b/lib/dns-pkcs11/tests/dh_test.c
3ce7d3
@@ -63,7 +63,8 @@ ATF_TC_BODY(isc_dh_computesecret, tc) {
3ce7d3
 	ret = dst_key_computesecret(key, key, &buf;;
3ce7d3
 	ATF_REQUIRE_EQ(ret, DST_R_NOTPRIVATEKEY);
3ce7d3
 	ret = key->func->computesecret(key, key, &buf;;
3ce7d3
-	ATF_REQUIRE_EQ(ret, DST_R_COMPUTESECRETFAILURE);
3ce7d3
+	/* PKCS11 variant gives different result, accept both */
3ce7d3
+	ATF_REQUIRE(ret == DST_R_COMPUTESECRETFAILURE || ret == DST_R_INVALIDPRIVATEKEY);
3ce7d3
 
3ce7d3
 	dst_key_free(&key);
3ce7d3
 	dns_test_end();
3ce7d3
diff --git a/lib/isc-pkcs11/tests/Makefile.in b/lib/isc-pkcs11/tests/Makefile.in
3ce7d3
index f7fa538..818dae4 100644
3ce7d3
--- a/lib/isc-pkcs11/tests/Makefile.in
3ce7d3
+++ b/lib/isc-pkcs11/tests/Makefile.in
3ce7d3
@@ -17,10 +17,10 @@ VERSION=@BIND9_VERSION@
3ce7d3
 @BIND9_MAKE_INCLUDES@
3ce7d3
 
3ce7d3
 CINCLUDES =	-I. -Iinclude ${ISC_INCLUDES} @ISC_OPENSSL_INC@
3ce7d3
-CDEFINES =	@CRYPTO@ -DTESTS="\"${top_builddir}/lib/isc/tests/\""
3ce7d3
+CDEFINES =	@CRYPTO@ -DTESTS="\"${top_builddir}/lib/isc-pkcs11/tests/\""
3ce7d3
 
3ce7d3
-ISCLIBS =	../libisc.@A@ @ISC_OPENSSL_LIBS@
3ce7d3
-ISCDEPLIBS =	../libisc.@A@
3ce7d3
+ISCLIBS =	../libisc-pkcs11.@A@ @ISC_OPENSSL_LIBS@
3ce7d3
+ISCDEPLIBS =	../libisc-pkcs11.@A@
3ce7d3
 
3ce7d3
 LIBS =		@LIBS@ @ATFLIBS@
3ce7d3
 
3ce7d3
diff --git a/lib/isc-pkcs11/tests/hash_test.c b/lib/isc-pkcs11/tests/hash_test.c
3ce7d3
index 5b8a374..c1891c2 100644
3ce7d3
--- a/lib/isc-pkcs11/tests/hash_test.c
3ce7d3
+++ b/lib/isc-pkcs11/tests/hash_test.c
3ce7d3
@@ -74,7 +74,7 @@ typedef struct hash_testcase {
3ce7d3
 
3ce7d3
 typedef struct hash_test_key {
3ce7d3
 	const char *key;
3ce7d3
-	const int len;
3ce7d3
+	const unsigned len;
3ce7d3
 } hash_test_key_t;
3ce7d3
 
3ce7d3
 /* non-hmac tests */
3ce7d3
@@ -957,8 +957,11 @@ ATF_TC_BODY(isc_hmacsha1, tc) {
3ce7d3
 	hash_test_key_t *test_key = test_keys;
3ce7d3
 
3ce7d3
 	while (testcase->input != NULL && testcase->result != NULL) {
3ce7d3
+		int len = ISC_MAX(test_key->len, ISC_SHA1_DIGESTLENGTH);
3ce7d3
+
3ce7d3
+		memset(buffer, 0, ISC_SHA1_DIGESTLENGTH);
3ce7d3
 		memmove(buffer, test_key->key, test_key->len);
3ce7d3
-		isc_hmacsha1_init(&hmacsha1, buffer, test_key->len);
3ce7d3
+		isc_hmacsha1_init(&hmacsha1, buffer, len);
3ce7d3
 		isc_hmacsha1_update(&hmacsha1,
3ce7d3
 				    (const isc_uint8_t *) testcase->input,
3ce7d3
 				    testcase->input_len);
3ce7d3
@@ -1120,8 +1123,11 @@ ATF_TC_BODY(isc_hmacsha224, tc) {
3ce7d3
 	hash_test_key_t *test_key = test_keys;
3ce7d3
 
3ce7d3
 	while (testcase->input != NULL && testcase->result != NULL) {
3ce7d3
+		int len = ISC_MAX(test_key->len, ISC_SHA224_DIGESTLENGTH);
3ce7d3
+
3ce7d3
+		memset(buffer, 0, ISC_SHA224_DIGESTLENGTH);
3ce7d3
 		memmove(buffer, test_key->key, test_key->len);
3ce7d3
-		isc_hmacsha224_init(&hmacsha224, buffer, test_key->len);
3ce7d3
+		isc_hmacsha224_init(&hmacsha224, buffer, len);
3ce7d3
 		isc_hmacsha224_update(&hmacsha224,
3ce7d3
 				      (const isc_uint8_t *) testcase->input,
3ce7d3
 				      testcase->input_len);
3ce7d3
@@ -1283,8 +1289,11 @@ ATF_TC_BODY(isc_hmacsha256, tc) {
3ce7d3
 	hash_test_key_t *test_key = test_keys;
3ce7d3
 
3ce7d3
 	while (testcase->input != NULL && testcase->result != NULL) {
3ce7d3
+		int len = ISC_MAX(test_key->len, ISC_SHA256_DIGESTLENGTH);
3ce7d3
+
3ce7d3
+		memset(buffer, 0, ISC_SHA256_DIGESTLENGTH);
3ce7d3
 		memmove(buffer, test_key->key, test_key->len);
3ce7d3
-		isc_hmacsha256_init(&hmacsha256, buffer, test_key->len);
3ce7d3
+		isc_hmacsha256_init(&hmacsha256, buffer, len);
3ce7d3
 		isc_hmacsha256_update(&hmacsha256,
3ce7d3
 				      (const isc_uint8_t *) testcase->input,
3ce7d3
 				      testcase->input_len);
3ce7d3
@@ -1452,8 +1461,11 @@ ATF_TC_BODY(isc_hmacsha384, tc) {
3ce7d3
 	hash_test_key_t *test_key = test_keys;
3ce7d3
 
3ce7d3
 	while (testcase->input != NULL && testcase->result != NULL) {
3ce7d3
+		int len = ISC_MAX(test_key->len, ISC_SHA384_DIGESTLENGTH);
3ce7d3
+
3ce7d3
+		memset(buffer, 0, ISC_SHA384_DIGESTLENGTH);
3ce7d3
 		memmove(buffer, test_key->key, test_key->len);
3ce7d3
-		isc_hmacsha384_init(&hmacsha384, buffer, test_key->len);
3ce7d3
+		isc_hmacsha384_init(&hmacsha384, buffer, len);
3ce7d3
 		isc_hmacsha384_update(&hmacsha384,
3ce7d3
 				      (const isc_uint8_t *) testcase->input,
3ce7d3
 				      testcase->input_len);
3ce7d3
@@ -1621,8 +1633,11 @@ ATF_TC_BODY(isc_hmacsha512, tc) {
3ce7d3
 	hash_test_key_t *test_key = test_keys;
3ce7d3
 
3ce7d3
 	while (testcase->input != NULL && testcase->result != NULL) {
3ce7d3
+		int len = ISC_MAX(test_key->len, ISC_SHA512_DIGESTLENGTH);
3ce7d3
+
3ce7d3
+		memset(buffer, 0, ISC_SHA512_DIGESTLENGTH);
3ce7d3
 		memmove(buffer, test_key->key, test_key->len);
3ce7d3
-		isc_hmacsha512_init(&hmacsha512, buffer, test_key->len);
3ce7d3
+		isc_hmacsha512_init(&hmacsha512, buffer, len);
3ce7d3
 		isc_hmacsha512_update(&hmacsha512,
3ce7d3
 				      (const isc_uint8_t *) testcase->input,
3ce7d3
 				      testcase->input_len);
3ce7d3
@@ -1765,8 +1780,11 @@ ATF_TC_BODY(isc_hmacmd5, tc) {
3ce7d3
 	hash_test_key_t *test_key = test_keys;
3ce7d3
 
3ce7d3
 	while (testcase->input != NULL && testcase->result != NULL) {
3ce7d3
+		int len = ISC_MAX(test_key->len, ISC_MD5_DIGESTLENGTH);
3ce7d3
+
3ce7d3
+		memset(buffer, 0, ISC_MD5_DIGESTLENGTH);
3ce7d3
 		memmove(buffer, test_key->key, test_key->len);
3ce7d3
-		isc_hmacmd5_init(&hmacmd5, buffer, test_key->len);
3ce7d3
+		isc_hmacmd5_init(&hmacmd5, buffer, len);
3ce7d3
 		isc_hmacmd5_update(&hmacmd5,
3ce7d3
 				   (const isc_uint8_t *) testcase->input,
3ce7d3
 				   testcase->input_len);
3ce7d3
-- 
3ce7d3
2.14.3
3ce7d3