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