Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Makefile
Makefile.in
aclocal.m4
ax_*.m4
pkg.m4
aminclude_static.am
autom4te.cache/
compile
Expand All @@ -16,6 +18,7 @@ install-sh
libtool
libtpm2.la
ltmain.sh
stamp-h1
m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
Expand All @@ -26,6 +29,7 @@ src/.dirstamp
src/.libs/
src/*.o
src/*.lo
src/config.h
tpm2tss-genkey
libtpm2tss.la
*.gcno
Expand All @@ -44,3 +48,5 @@ test/error_tpm2-tss-engine-common
test/*.o
config.h.in
VERSION
build/
.vscode/
15 changes: 10 additions & 5 deletions src/tpm2-tss-engine-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ tpm2tss_tpm2data_write(const TPM2_DATA *tpm2Data, const char *filename)
goto error;
}
tpk->type = OBJ_txt2obj(OID_loadableKey, 1);
tpk->parent = ASN1_INTEGER_new();
tpk->privkey = ASN1_OCTET_STRING_new();
tpk->pubkey = ASN1_OCTET_STRING_new();
if (!tpk->type || !tpk->privkey || !tpk->pubkey || !tpk->parent) {
if (!tpk->type) {
ERR(tpm2tss_tpm2data_write, ERR_R_MALLOC_FAILURE);
goto error;
}
Expand All @@ -182,6 +179,8 @@ tpm2tss_tpm2data_write(const TPM2_DATA *tpm2Data, const char *filename)
BN_set_word(bn_parent, TPM2_RH_OWNER);
}
BN_to_ASN1_INTEGER(bn_parent, tpk->parent);
BN_free(bn_parent);

ASN1_STRING_set(tpk->privkey, &privbuf[0], privbuf_len);
ASN1_STRING_set(tpk->pubkey, &pubbuf[0], pubbuf_len);

Expand All @@ -195,6 +194,8 @@ tpm2tss_tpm2data_write(const TPM2_DATA *tpm2Data, const char *filename)
BIO_free(bio);
if (tpk)
TSSPRIVKEY_free(tpk);
if (bn_parent)
BN_free(bn_parent);
return 0;
}

Expand Down Expand Up @@ -347,7 +348,7 @@ tpm2tss_tpm2data_read(const char *filename, TPM2_DATA **tpm2Datap)
TSSPRIVKEY *tpk = NULL;
TPM2_DATA *tpm2Data = NULL;
char type_oid[64];
BIGNUM *bn_parent;
BIGNUM *bn_parent = NULL;

if ((bio = BIO_new_file(filename, "r")) == NULL) {
ERR(tpm2tss_tpm2data_read, TPM2TSS_R_FILE_READ);
Expand Down Expand Up @@ -382,6 +383,8 @@ tpm2tss_tpm2data_read(const char *filename, TPM2_DATA **tpm2Datap)
} else {
tpm2Data->parent = BN_get_word(bn_parent);
}
BN_free(bn_parent);

if (tpm2Data->parent == 0)
tpm2Data->parent = TPM2_RH_OWNER;

Expand Down Expand Up @@ -415,6 +418,8 @@ tpm2tss_tpm2data_read(const char *filename, TPM2_DATA **tpm2Datap)
BIO_free(bio);
if (tpk)
TSSPRIVKEY_free(tpk);
if (bn_parent)
BN_free(bn_parent);

return 0;
}
Expand Down
9 changes: 1 addition & 8 deletions src/tpm2tss-genkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,7 @@ genkey_rsa()

VERB("Key generated\n");

TPM2_DATA *tpm2Data = OPENSSL_malloc(sizeof(*tpm2Data));
if (tpm2Data == NULL) {
ERR("out of memory\n");
BN_free(e);
RSA_free(rsa);
return NULL;
}
memcpy(tpm2Data, RSA_get_app_data(rsa), sizeof(*tpm2Data));
TPM2_DATA *tpm2Data = RSA_get_app_data(rsa);

BN_free(e);
RSA_free(rsa);
Expand Down
Loading