Add `wolfTPM2_SetAuthSession` and `wolfTPM2_NVStoreKey`.

pull/209/head
David Garske 2022-05-23 13:37:45 -07:00
parent f3c8b6cc12
commit 0ce7038863
3 changed files with 54 additions and 8 deletions

6
.gitignore vendored
View File

@ -29,6 +29,8 @@ RemoteSystemsTempFiles
*.dep
*.deps
*.libs
*.dSYM
.vs
IDE/IAR-EWARM/settings
wolftpm/options.h
@ -96,3 +98,7 @@ ek.pem
# Generated Documentation
docs/html
# Wrapper
wrapper/CSharp/obj
wrapper/CSharp/bin

View File

@ -1509,7 +1509,7 @@ WOLFTPM_API int wolfTPM2_NVCreateAuth(WOLFTPM2_DEV* dev, WOLFTPM2_HANDLE* parent
/*!
\ingroup wolfTPM2_Wrappers
\brief Stores user data to a NV Index, at a given offest
\brief Stores user data to a NV Index, at a given offset
\note User data size should be less or equal to the NV Index maxSize specified using wolfTPM2_CreateAuth
\return TPM_RC_SUCCESS: successful
@ -2248,7 +2248,7 @@ WOLFTPM_API int wolfTPM2_CreateAndLoadAIK(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* aikKe
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param aikKey pointer to a WOLFTPM2_KEY structure, containign valid TPM handle of a loaded attestation key
\param aikKey pointer to a WOLFTPM2_KEY structure, containing valid TPM handle of a loaded attestation key
\param getTimeOut pointer to an empty structure of GetTime_Out type, to store the output of the command
\sa wolfTPM2_CreateSRK

View File

@ -72,6 +72,16 @@ namespace wolfTPM
TRIAL = 0x03,
}
public enum SESSION_mask : byte
{
continueSession = 0x01,
auditExclusive = 0x02,
auditReset = 0x04,
decrypt = 0x20,
encrypt = 0x40,
audit = 0x80,
}
public class KeyBlob
{
const string DLLNAME = "wolftpm";
@ -320,13 +330,17 @@ namespace wolfTPM
}
[DllImport(DLLNAME, EntryPoint = "wolfTPM2_StartSession")]
private static extern int wolfTPM2_StartSession(IntPtr dev, IntPtr session,
IntPtr tmpKey, IntPtr bind, byte sesType, int encDecAlg);
private static extern int wolfTPM2_StartSession(IntPtr dev,
IntPtr session,
IntPtr tmpKey,
IntPtr bind,
byte sesType,
int encDecAlg);
public int StartSession(IntPtr session,
Key tmpKey,
IntPtr bind,
byte sesType,
int encDecAlg)
Key tmpKey,
IntPtr bind,
byte sesType,
int encDecAlg)
{
return wolfTPM2_StartSession(device,
session,
@ -336,6 +350,21 @@ namespace wolfTPM
encDecAlg);
}
[DllImport(DLLNAME, EntryPoint = "wolfTPM2_SetAuthSession")]
private static extern int wolfTPM2_SetAuthSession(IntPtr dev,
int index,
IntPtr tpmSession,
byte sessionAttributes);
public int SetAuthSession(IntPtr session,
int index,
byte sessionAttributes)
{
/* For sessionAttributes suggest using:
* (byte)(SESSION_mask.decrypt | SESSION_mask.encrypt | SESSION_mask.continueSession)
*/
return wolfTPM2_SetAuthSession(device, index, session, sessionAttributes);
}
[DllImport(DLLNAME, EntryPoint = "wolfTPM2_ReadPublicKey")]
private static extern int wolfTPM2_ReadPublicKey(IntPtr dev,
@ -382,6 +411,17 @@ namespace wolfTPM
return wolfTPM2_LoadKey(device, keyBlob.keyblob, parent.GetHandleRefFromKey());
}
[DllImport(DLLNAME, EntryPoint = "wolfTPM2_NVStoreKey")]
private static extern int wolfTPM2_NVStoreKey(IntPtr dev,
IntPtr primaryHandle, IntPtr key, IntPtr persistentHandle);
public int StoreKey(Key key, IntPtr primaryHandle, IntPtr persistentHandle)
{
return wolfTPM2_NVStoreKey(device, primaryHandle, key.GetHandleRefFromKey(),
persistentHandle);
}
[DllImport(DLLNAME, EntryPoint = "wolfTPM2_ImportRsaPrivateKey")]
private static extern int wolfTPM2_ImportRsaPrivateKey(
IntPtr dev,