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