Fix for building with wolfTPM without wolfCrypt `--disable-wolfcrypt`. Added test.

pull/264/head
David Garske 2023-04-12 15:00:55 -07:00
parent ee2f766554
commit af0668eafd
3 changed files with 35 additions and 15 deletions

View File

@ -44,4 +44,11 @@ jobs:
- name: make test
run: |
./ibmswtpm2/src/tpm_server &
sleep 10 && make test && ./examples/native/native_test && ./examples/wrap/wrap_test
sleep 2 && make check && ./examples/native/native_test && ./examples/wrap/wrap_test
#test wolfTPM without wolfCrypt
- name: configure no wolfCrypt
run: ./configure --enable-swtpm --disable-wolfcrypt
- name: make test no wolfCrypt
run: |
make check && ./examples/native/native_test && ./examples/wrap/wrap_test

View File

@ -61,9 +61,11 @@ int TPM2_Keyimport_Example(void* userCtx, int argc, char *argv[])
#if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
byte pemEncode = 0;
FILE* pemFile = NULL;
const char* pemName = "./certs/example-rsa-key.pem";
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_RSA)
FILE* pemFile = NULL;
char pemBuf[WOLFTPM2_MAX_BUFFER];
#endif
#endif
if (argc >= 2) {
@ -158,28 +160,35 @@ int TPM2_Keyimport_Example(void* userCtx, int argc, char *argv[])
if (alg == TPM_ALG_RSA) {
if (derEncode == 1) {
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_RSA)
rc = wolfTPM2_RsaPrivateKeyImportDer(&dev, &storage, &impKey,
kRsaKeyPrivDer, sizeof(kRsaKeyPrivDer), TPM_ALG_NULL,
TPM_ALG_NULL);
#else
rc = NOT_COMPILED_IN;
#endif
}
#if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
#if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
else if (pemEncode == 1) {
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_RSA)
pemFile = XFOPEN(pemName, "r");
if (pemFile == NULL)
printf("Failed to read pem file %s\n", pemName);
if (rc == 0)
if (pemFile != XBADFILE) {
rc = (int)XFREAD(pemBuf, 1, sizeof(pemBuf), pemFile);
if (rc > 0) {
rc = wolfTPM2_RsaPrivateKeyImportPem(&dev, &storage, &impKey,
pemBuf, rc, NULL, TPM_ALG_NULL, TPM_ALG_NULL);
}
XFCLOSE(pemFile);
}
#endif
else {
printf("Failed to read pem file %s\n", pemName);
rc = BUFFER_E;
}
#else
rc = NOT_COMPILED_IN;
#endif
}
#endif
else {
/* Import raw RSA private key into TPM */
rc = wolfTPM2_ImportRsaPrivateKey(&dev, &storage, &impKey,

View File

@ -115,6 +115,9 @@ typedef int64_t INT64;
#ifndef XFEOF
#define XFEOF feof
#endif
#ifndef XREWIND
#define XREWIND rewind
#endif
#else
@ -148,6 +151,7 @@ typedef int64_t INT64;
#define XSTRLEN(s1) strlen((s1))
#define XSTRCMP(s1,s2) strcmp((s1),(s2))
#define XSTRSTR(s1,s2) strstr((s1),(s2))
#define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
#endif /* !WOLFTPM_CUSTOM_TYPES */
/* Endianess */