Skip to content

Commit fb42349

Browse files
committed
Fixes for loading TPM based key. Requires wolfSSL/wolfTPM#428
1 parent c135a29 commit fb42349

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/internal.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8294,6 +8294,11 @@ static int WP11_Object_LoadTpmKey(WP11_Object* object)
82948294
return BAD_FUNC_ARG;
82958295
}
82968296

8297+
if (object->opFlag & WP11_FLAG_TPM) {
8298+
return wolfTPM2_LoadKey(&object->slot->tpmDev, &object->tpmKey,
8299+
&object->slot->tpmCtx.storageKey->handle);
8300+
}
8301+
82978302
switch (object->type) {
82988303
#ifndef NO_RSA
82998304
case CKK_RSA:
@@ -8449,6 +8454,9 @@ int WP11_Rsa_GenerateKeyPair(WP11_Object* pub, WP11_Object* priv,
84498454
ret = wc_MakeRsaKey(&priv->data.rsaKey, pub->size, e, &rng);
84508455
#ifdef WOLFPKCS11_TPM
84518456
if (ret == 0) {
8457+
/* set flag indicating this is TPM based key */
8458+
priv->opFlag |= WP11_FLAG_TPM;
8459+
84528460
/* unload handle and reload when used */
84538461
wolfTPM2_UnloadHandle(&priv->slot->tpmDev, &priv->tpmKey.handle);
84548462
}
@@ -9182,7 +9190,7 @@ int WP11_Ec_GenerateKeyPair(WP11_Object* pub, WP11_Object* priv,
91829190
CK_ULONG len = sizeof(isSign);
91839191
ret = WP11_Object_GetAttr(priv, CKA_SIGN, &isSign, &len);
91849192
if (ret == 0 && isSign)
9185-
priv->slot->tpmCtx.eccKey = (WOLFTPM2_KEY*)&priv->tpmKey;
9193+
priv->slot->tpmCtx.ecdsaKey = &priv->tpmKey;
91869194
else
91879195
priv->slot->tpmCtx.ecdhKey = (WOLFTPM2_KEY*)&priv->tpmKey;
91889196
#endif
@@ -9197,6 +9205,9 @@ int WP11_Ec_GenerateKeyPair(WP11_Object* pub, WP11_Object* priv,
91979205
&priv->data.ecKey, priv->data.ecKey.dp->id);
91989206
#ifdef WOLFPKCS11_TPM
91999207
if (ret == 0) {
9208+
/* set flag indicating this is TPM based key */
9209+
priv->opFlag |= WP11_FLAG_TPM;
9210+
92009211
/* unload handle and reload when used */
92019212
wolfTPM2_UnloadHandle(&slot->tpmDev, &priv->tpmKey.handle);
92029213
}

0 commit comments

Comments
 (0)