ad7b3b8
From 3474d13bbf08c441783bd72afbc8cec8857baf46 Mon Sep 17 00:00:00 2001
e5f6b89
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
e5f6b89
Date: Tue, 2 Jan 2018 18:13:07 +0100
e5f6b89
Subject: [PATCH] Fix pkcs11 variants atf tests
e5f6b89
e5f6b89
Add dns-pkcs11 tests Makefile to configure
e5f6b89
e5f6b89
Add pkcs11 Kyuafile, fix dh_test to pass in pkcs11 mode
e5f6b89
---
e5f6b89
 configure.in                     |  1 +
f3f402d
 lib/Atffile                      |  2 ++
e5f6b89
 lib/Kyuafile                     |  2 ++
e5f6b89
 lib/dns-pkcs11/tests/Makefile.in | 10 +++++-----
e5f6b89
 lib/dns-pkcs11/tests/dh_test.c   |  3 ++-
e5f6b89
 lib/isc-pkcs11/tests/Makefile.in |  6 +++---
e5f6b89
 lib/isc-pkcs11/tests/hash_test.c | 32 +++++++++++++++++++++++++-------
f3f402d
 7 files changed, 40 insertions(+), 16 deletions(-)
e5f6b89
e5f6b89
diff --git a/configure.in b/configure.in
ad7b3b8
index 1edafd1..5466de1 100644
e5f6b89
--- a/configure.in
e5f6b89
+++ b/configure.in
ad7b3b8
@@ -5489,6 +5489,7 @@ AC_CONFIG_FILES([
e5f6b89
 	lib/dns-pkcs11/include/Makefile
e5f6b89
 	lib/dns-pkcs11/include/dns/Makefile
e5f6b89
 	lib/dns-pkcs11/include/dst/Makefile
e5f6b89
+	lib/dns-pkcs11/tests/Makefile
e5f6b89
 	lib/irs/Makefile
e5f6b89
 	lib/irs/include/Makefile
e5f6b89
 	lib/irs/include/irs/Makefile
f3f402d
diff --git a/lib/Atffile b/lib/Atffile
f3f402d
index 93bbb01..4db3dce 100644
f3f402d
--- a/lib/Atffile
f3f402d
+++ b/lib/Atffile
f3f402d
@@ -3,7 +3,9 @@ Content-Type: application/X-atf-atffile; version="1"
f3f402d
 prop: test-suite = bind9
f3f402d
 
f3f402d
 tp: dns
f3f402d
+tp: dns-pkcs11
f3f402d
 tp: irs
f3f402d
 tp: isc
f3f402d
+tp: isc-pkcs11
f3f402d
 tp: isccfg
f3f402d
 tp: lwres
e5f6b89
diff --git a/lib/Kyuafile b/lib/Kyuafile
e5f6b89
index ff9fc56..eaaf0dc 100644
e5f6b89
--- a/lib/Kyuafile
e5f6b89
+++ b/lib/Kyuafile
e5f6b89
@@ -2,7 +2,9 @@ syntax(2)
e5f6b89
 test_suite('bind9')
e5f6b89
 
e5f6b89
 include('dns/Kyuafile')
e5f6b89
+include('dns-pkcs11/Kyuafile')
e5f6b89
 include('irs/Kyuafile')
e5f6b89
 include('isc/Kyuafile')
e5f6b89
+include('isc-pkcs11/Kyuafile')
e5f6b89
 include('isccfg/Kyuafile')
e5f6b89
 include('lwres/Kyuafile')
e5f6b89
diff --git a/lib/dns-pkcs11/tests/Makefile.in b/lib/dns-pkcs11/tests/Makefile.in
ad7b3b8
index 625e809..6fd4e36 100644
e5f6b89
--- a/lib/dns-pkcs11/tests/Makefile.in
e5f6b89
+++ b/lib/dns-pkcs11/tests/Makefile.in
ad7b3b8
@@ -21,12 +21,12 @@ VERSION=@BIND9_VERSION@
e5f6b89
 
e5f6b89
 CINCLUDES =	-I. -Iinclude ${DNS_INCLUDES} ${ISC_INCLUDES} \
e5f6b89
 		@DST_OPENSSL_INC@
e5f6b89
-CDEFINES =	@CRYPTO@ -DTESTS="\"${top_builddir}/lib/dns/tests/\""
e5f6b89
+CDEFINES =	@CRYPTO@ -DTESTS="\"${top_builddir}/lib/dns-pkcs11/tests/\""
e5f6b89
 
e5f6b89
-ISCLIBS =	../../isc/libisc.@A@
e5f6b89
-ISCDEPLIBS =	../../isc/libisc.@A@
e5f6b89
-DNSLIBS =	../libdns.@A@ @DNS_CRYPTO_LIBS@
e5f6b89
-DNSDEPLIBS =	../libdns.@A@
e5f6b89
+ISCLIBS =	../../isc-pkcs11/libisc-pkcs11.@A@
e5f6b89
+ISCDEPLIBS =	../../isc-pkcs11/libisc-pkcs11.@A@
e5f6b89
+DNSLIBS =	../libdns-pkcs11.@A@ @DNS_CRYPTO_LIBS@
e5f6b89
+DNSDEPLIBS =	../libdns-pkcs11.@A@
e5f6b89
 
e5f6b89
 LIBS =		@LIBS@ @ATFLIBS@
e5f6b89
 
e5f6b89
diff --git a/lib/dns-pkcs11/tests/dh_test.c b/lib/dns-pkcs11/tests/dh_test.c
ad7b3b8
index 6216b4e..dd74e58 100644
e5f6b89
--- a/lib/dns-pkcs11/tests/dh_test.c
e5f6b89
+++ b/lib/dns-pkcs11/tests/dh_test.c
ad7b3b8
@@ -64,7 +64,8 @@ ATF_TC_BODY(isc_dh_computesecret, tc) {
e5f6b89
 	ret = dst_key_computesecret(key, key, &buf;;
e5f6b89
 	ATF_REQUIRE_EQ(ret, DST_R_NOTPRIVATEKEY);
e5f6b89
 	ret = key->func->computesecret(key, key, &buf;;
e5f6b89
-	ATF_REQUIRE_EQ(ret, DST_R_COMPUTESECRETFAILURE);
e5f6b89
+	/* PKCS11 variant gives different result, accept both */
e5f6b89
+	ATF_REQUIRE(ret == DST_R_COMPUTESECRETFAILURE || ret == DST_R_INVALIDPRIVATEKEY);
e5f6b89
 
e5f6b89
 	dst_key_free(&key);
e5f6b89
 	dns_test_end();
e5f6b89
diff --git a/lib/isc-pkcs11/tests/Makefile.in b/lib/isc-pkcs11/tests/Makefile.in
ad7b3b8
index add8068..a928dcf 100644
e5f6b89
--- a/lib/isc-pkcs11/tests/Makefile.in
e5f6b89
+++ b/lib/isc-pkcs11/tests/Makefile.in
ad7b3b8
@@ -20,10 +20,10 @@ VERSION=@BIND9_VERSION@
e5f6b89
 @BIND9_MAKE_INCLUDES@
e5f6b89
 
e5f6b89
 CINCLUDES =	-I. -Iinclude ${ISC_INCLUDES} @ISC_OPENSSL_INC@
e5f6b89
-CDEFINES =	@CRYPTO@ -DTESTS="\"${top_builddir}/lib/isc/tests/\""
e5f6b89
+CDEFINES =	@CRYPTO@ -DTESTS="\"${top_builddir}/lib/isc-pkcs11/tests/\""
e5f6b89
 
e5f6b89
-ISCLIBS =	../libisc.@A@ @ISC_OPENSSL_LIBS@
e5f6b89
-ISCDEPLIBS =	../libisc.@A@
e5f6b89
+ISCLIBS =	../libisc-pkcs11.@A@ @ISC_OPENSSL_LIBS@
e5f6b89
+ISCDEPLIBS =	../libisc-pkcs11.@A@
e5f6b89
 
e5f6b89
 LIBS =		@LIBS@ @ATFLIBS@
e5f6b89
 
e5f6b89
diff --git a/lib/isc-pkcs11/tests/hash_test.c b/lib/isc-pkcs11/tests/hash_test.c
ad7b3b8
index 7eb1552..048ae9d 100644
e5f6b89
--- a/lib/isc-pkcs11/tests/hash_test.c
e5f6b89
+++ b/lib/isc-pkcs11/tests/hash_test.c
ad7b3b8
@@ -78,7 +78,7 @@ typedef struct hash_testcase {
e5f6b89
 
e5f6b89
 typedef struct hash_test_key {
e5f6b89
 	const char *key;
e5f6b89
-	const int len;
e5f6b89
+	const unsigned len;
e5f6b89
 } hash_test_key_t;
e5f6b89
 
e5f6b89
 /* non-hmac tests */
ad7b3b8
@@ -961,8 +961,11 @@ ATF_TC_BODY(isc_hmacsha1, tc) {
e5f6b89
 	hash_test_key_t *test_key = test_keys;
e5f6b89
 
e5f6b89
 	while (testcase->input != NULL && testcase->result != NULL) {
e5f6b89
+		int len = ISC_MAX(test_key->len, ISC_SHA1_DIGESTLENGTH);
e5f6b89
+
e5f6b89
+		memset(buffer, 0, ISC_SHA1_DIGESTLENGTH);
e5f6b89
 		memmove(buffer, test_key->key, test_key->len);
e5f6b89
-		isc_hmacsha1_init(&hmacsha1, buffer, test_key->len);
e5f6b89
+		isc_hmacsha1_init(&hmacsha1, buffer, len);
e5f6b89
 		isc_hmacsha1_update(&hmacsha1,
ad7b3b8
 				    (const uint8_t *) testcase->input,
e5f6b89
 				    testcase->input_len);
ad7b3b8
@@ -1124,8 +1127,11 @@ ATF_TC_BODY(isc_hmacsha224, tc) {
e5f6b89
 	hash_test_key_t *test_key = test_keys;
e5f6b89
 
e5f6b89
 	while (testcase->input != NULL && testcase->result != NULL) {
e5f6b89
+		int len = ISC_MAX(test_key->len, ISC_SHA224_DIGESTLENGTH);
e5f6b89
+
e5f6b89
+		memset(buffer, 0, ISC_SHA224_DIGESTLENGTH);
e5f6b89
 		memmove(buffer, test_key->key, test_key->len);
e5f6b89
-		isc_hmacsha224_init(&hmacsha224, buffer, test_key->len);
e5f6b89
+		isc_hmacsha224_init(&hmacsha224, buffer, len);
e5f6b89
 		isc_hmacsha224_update(&hmacsha224,
ad7b3b8
 				      (const uint8_t *) testcase->input,
e5f6b89
 				      testcase->input_len);
ad7b3b8
@@ -1287,8 +1293,11 @@ ATF_TC_BODY(isc_hmacsha256, tc) {
e5f6b89
 	hash_test_key_t *test_key = test_keys;
e5f6b89
 
e5f6b89
 	while (testcase->input != NULL && testcase->result != NULL) {
e5f6b89
+		int len = ISC_MAX(test_key->len, ISC_SHA256_DIGESTLENGTH);
e5f6b89
+
e5f6b89
+		memset(buffer, 0, ISC_SHA256_DIGESTLENGTH);
e5f6b89
 		memmove(buffer, test_key->key, test_key->len);
e5f6b89
-		isc_hmacsha256_init(&hmacsha256, buffer, test_key->len);
e5f6b89
+		isc_hmacsha256_init(&hmacsha256, buffer, len);
e5f6b89
 		isc_hmacsha256_update(&hmacsha256,
ad7b3b8
 				      (const uint8_t *) testcase->input,
e5f6b89
 				      testcase->input_len);
ad7b3b8
@@ -1456,8 +1465,11 @@ ATF_TC_BODY(isc_hmacsha384, tc) {
e5f6b89
 	hash_test_key_t *test_key = test_keys;
e5f6b89
 
e5f6b89
 	while (testcase->input != NULL && testcase->result != NULL) {
e5f6b89
+		int len = ISC_MAX(test_key->len, ISC_SHA384_DIGESTLENGTH);
e5f6b89
+
e5f6b89
+		memset(buffer, 0, ISC_SHA384_DIGESTLENGTH);
e5f6b89
 		memmove(buffer, test_key->key, test_key->len);
e5f6b89
-		isc_hmacsha384_init(&hmacsha384, buffer, test_key->len);
e5f6b89
+		isc_hmacsha384_init(&hmacsha384, buffer, len);
e5f6b89
 		isc_hmacsha384_update(&hmacsha384,
ad7b3b8
 				      (const uint8_t *) testcase->input,
e5f6b89
 				      testcase->input_len);
ad7b3b8
@@ -1625,8 +1637,11 @@ ATF_TC_BODY(isc_hmacsha512, tc) {
e5f6b89
 	hash_test_key_t *test_key = test_keys;
e5f6b89
 
e5f6b89
 	while (testcase->input != NULL && testcase->result != NULL) {
e5f6b89
+		int len = ISC_MAX(test_key->len, ISC_SHA512_DIGESTLENGTH);
e5f6b89
+
e5f6b89
+		memset(buffer, 0, ISC_SHA512_DIGESTLENGTH);
e5f6b89
 		memmove(buffer, test_key->key, test_key->len);
e5f6b89
-		isc_hmacsha512_init(&hmacsha512, buffer, test_key->len);
e5f6b89
+		isc_hmacsha512_init(&hmacsha512, buffer, len);
e5f6b89
 		isc_hmacsha512_update(&hmacsha512,
ad7b3b8
 				      (const uint8_t *) testcase->input,
e5f6b89
 				      testcase->input_len);
ad7b3b8
@@ -1769,8 +1784,11 @@ ATF_TC_BODY(isc_hmacmd5, tc) {
e5f6b89
 	hash_test_key_t *test_key = test_keys;
e5f6b89
 
e5f6b89
 	while (testcase->input != NULL && testcase->result != NULL) {
e5f6b89
+		int len = ISC_MAX(test_key->len, ISC_MD5_DIGESTLENGTH);
e5f6b89
+
e5f6b89
+		memset(buffer, 0, ISC_MD5_DIGESTLENGTH);
e5f6b89
 		memmove(buffer, test_key->key, test_key->len);
e5f6b89
-		isc_hmacmd5_init(&hmacmd5, buffer, test_key->len);
e5f6b89
+		isc_hmacmd5_init(&hmacmd5, buffer, len);
e5f6b89
 		isc_hmacmd5_update(&hmacmd5,
ad7b3b8
 				   (const uint8_t *) testcase->input,
e5f6b89
 				   testcase->input_len);
e5f6b89
-- 
ad7b3b8
2.14.4
e5f6b89