From 4e351b16a9913fd0368fbc4ea81fddd8c7f759ad Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 13 May 2021 09:49:08 -0700 Subject: [PATCH] Add support for `--with-wolfcrypt=/dir/`. Fix for build error with `--disable-wolfcrypt`. Fix for unused `auth` in store example. ZD 12204 --- configure.ac | 43 +++++++++++++++- examples/attestation/activate_credential.c | 4 +- examples/attestation/make_credential.c | 4 +- examples/nvram/store.c | 2 - m4/have_wolfssl.m4 | 57 ---------------------- 5 files changed, 48 insertions(+), 62 deletions(-) delete mode 100644 m4/have_wolfssl.m4 diff --git a/configure.ac b/configure.ac index 88bb648..b3a51d0 100644 --- a/configure.ac +++ b/configure.ac @@ -127,6 +127,26 @@ fi # wolfCrypt +AC_MSG_CHECKING([for wolfSSL]) +WOLFSSL_URL="http://www.wolfssl.com/download.html" +AC_ARG_WITH(wolfcrypt, + [AC_HELP_STRING([--with-wolfcrypt=PATH], [PATH to wolfssl install (default /usr/local)])], + [ + if test "x$withval" != "xno" ; then + if test -d "$withval/lib"; then + LDFLAGS="$LDFLAGS -L${withval}/lib" + fi + if test -d "$withval/include"; then + CPPFLAGS="$CPPFLAGS -I${withval}/include" + fi + fi + if test "x$withval" = "xyes" ; then + LDFLAGS="$LDFLAGS -L/usr/local/lib" + CPPFLAGS="$CPPFLAGS -I/usr/local/include" + fi + ] +) + AC_ARG_ENABLE([wolfcrypt], [AS_HELP_STRING([--enable-wolfcrypt],[Enable wolfCrypt hooks for RNG, Auth Sessions and Parameter encryption (default: enabled)])], [ ENABLED_WOLFCRYPT=$enableval ], @@ -135,12 +155,33 @@ AC_ARG_ENABLE([wolfcrypt], if test "x$ENABLED_WOLFCRYPT" = "xyes" then - TAO_REQUIRE_LIBWOLFSSL + LIBS="$LIBS -lwolfssl" + + AC_LIB_HAVE_LINKFLAGS(wolfssl,, + [ + #include + ],[ + wolfCrypt_Init(); + ]) + AM_CONDITIONAL(HAVE_LIBWOLFSSL, [test "x${ac_cv_libwolfssl}" = "xyes"]) + + AS_IF([test "x${ac_cv_libwolfssl}" = "xyes"],[ + save_LIBS="${LIBS}" + LIBS="${LIBS} ${LTLIBWOLFSSL}" + AC_CHECK_FUNCS(wolfCrypt_Cleanup) + LIBS="$save_LIBS" + ]) + + if test "x$ac_cv_libwolfssl" = "xno" && test "x$ENABLED_WOLFCRYPT" = "xno"; then + AC_MSG_ERROR([WolfSSL library not found. You can get it from $WOLFSSL_URL + If it's already installed, specify its path using --with-wolfcrypt=/dir/]) + fi else AM_CFLAGS="$AM_CFLAGS -DWOLFTPM2_NO_WOLFCRYPT" fi + # I2C Support AC_ARG_ENABLE([i2c], [AS_HELP_STRING([--enable-i2c],[Enable I2C TPM Support (default: disabled)])], diff --git a/examples/attestation/activate_credential.c b/examples/attestation/activate_credential.c index dc0ff46..199aaf4 100644 --- a/examples/attestation/activate_credential.c +++ b/examples/attestation/activate_credential.c @@ -54,10 +54,12 @@ int TPM2_ActivateCredential_Example(void* userCtx, int argc, char *argv[]) WOLFTPM2_KEY storage; WOLFTPM2_KEYBLOB akKey; WOLFTPM2_SESSION tpmSession; +#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_FILESYSTEM) FILE *fp; + int dataSize = 0; +#endif const char *input = "cred.blob"; const char *keyblob = "keyblob.bin"; - int dataSize = 0; union { ActivateCredential_In activCred; diff --git a/examples/attestation/make_credential.c b/examples/attestation/make_credential.c index f934f1e..3726df3 100644 --- a/examples/attestation/make_credential.c +++ b/examples/attestation/make_credential.c @@ -51,10 +51,12 @@ int TPM2_MakeCredential_Example(void* userCtx, int argc, char *argv[]) WOLFTPM2_DEV dev; WOLFTPM2_KEY storage; WOLFTPM2_KEYBLOB akKey; +#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_FILESYSTEM) FILE *fp; + int dataSize = 0; +#endif const char *output = "cred.blob"; const char *keyblob = "keyblob.bin"; - int dataSize = 0; union { MakeCredential_In makeCred; diff --git a/examples/nvram/store.c b/examples/nvram/store.c index bb14854..5be80ed 100644 --- a/examples/nvram/store.c +++ b/examples/nvram/store.c @@ -62,7 +62,6 @@ int TPM2_NVRAM_Store_Example(void* userCtx, int argc, char *argv[]) WOLFTPM2_SESSION tpmSession; WOLFTPM2_HANDLE parent; WOLFTPM2_NV nv; - TPM2B_AUTH auth; word32 nvAttributes; const char* filename = "keyblob.bin"; int paramEncAlg = TPM_ALG_NULL; @@ -112,7 +111,6 @@ int TPM2_NVRAM_Store_Example(void* userCtx, int argc, char *argv[]) XMEMSET(&keyBlob, 0, sizeof(keyBlob)); XMEMSET(&tpmSession, 0, sizeof(tpmSession)); XMEMSET(&parent, 0, sizeof(parent)); - XMEMSET(&auth, 0, sizeof(auth)); rc = wolfTPM2_Init(&dev, TPM2_IoCb, userCtx); if (rc != TPM_RC_SUCCESS) { diff --git a/m4/have_wolfssl.m4 b/m4/have_wolfssl.m4 deleted file mode 100644 index d9c5ae4..0000000 --- a/m4/have_wolfssl.m4 +++ /dev/null @@ -1,57 +0,0 @@ - -#-------------------------------------------------------------------- -# Check for libwolfssl -#-------------------------------------------------------------------- - - -AC_DEFUN([_TAO_SEARCH_LIBWOLFSSL],[ - AC_REQUIRE([AC_LIB_PREFIX]) - - LDFLAGS="$LDFLAGS -L/usr/local/lib" - LIBS="$LIBS -lwolfssl" - - AC_LIB_HAVE_LINKFLAGS(wolfssl,, - [ - #include - ],[ - wolfCrypt_Init(); - ]) - - AM_CONDITIONAL(HAVE_LIBWOLFSSL, [test "x${ac_cv_libwolfssl}" = "xyes"]) - - AS_IF([test "x${ac_cv_libwolfssl}" = "xyes"],[ - save_LIBS="${LIBS}" - LIBS="${LIBS} ${LTLIBWOLFSSL}" - AC_CHECK_FUNCS(wolfSSL_Cleanup) - LIBS="$save_LIBS" - ]) -]) - -AC_DEFUN([_TAO_HAVE_LIBWOLFSSL],[ - - AC_ARG_ENABLE([libwolfssl], - [AS_HELP_STRING([--disable-libwolfssl], - [Build with libwolfssl support @<:@default=on@:>@])], - [ac_enable_libwolfssl="$enableval"], - [ac_enable_libwolfssl="yes"]) - - _TAO_SEARCH_LIBWOLFSSL -]) - - -AC_DEFUN([TAO_HAVE_LIBWOLFSSL],[ - AC_REQUIRE([_TAO_HAVE_LIBWOLFSSL]) -]) - -AC_DEFUN([_TAO_REQUIRE_LIBWOLFSSL],[ - ac_enable_libwolfssl="yes" - _TAO_SEARCH_LIBWOLFSSL - - AS_IF([test x$ac_cv_libwolfssl = xno],[ - AC_MSG_ERROR([libwolfssl is required for ${PACKAGE}, It can be obtained from http://www.wolfssl.com/download.html/]) - ]) -]) - -AC_DEFUN([TAO_REQUIRE_LIBWOLFSSL],[ - AC_REQUIRE([_TAO_REQUIRE_LIBWOLFSSL]) -])