Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSharp support for setting the auth on a key blob #237

Merged
merged 1 commit into from
Aug 11, 2022
Merged
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
3 changes: 3 additions & 0 deletions wrapper/CSharp/wolfTPM-tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ private void LoadGeneratedKey(string algorithm)
rc = device.LoadKey(blob, parent_key);
Assert.AreEqual((int)Status.TPM_RC_SUCCESS, rc);

rc = blob.SetKeyAuthPassword("ThisIsMyKeyAuth");
Assert.AreEqual((int)Status.TPM_RC_SUCCESS, rc);

rc = device.UnloadHandle(blob);
Assert.AreEqual((int)Status.TPM_RC_SUCCESS, rc);
}
Expand Down
25 changes: 22 additions & 3 deletions wrapper/CSharp/wolfTPM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ private static extern int wolfTPM2_SetKeyBlobFromBuffer(IntPtr key,
[DllImport(DLLNAME, EntryPoint = "wolfTPM2_GetHandleRefFromKeyBlob")]
private static extern IntPtr wolfTPM2_GetHandleRefFromKeyBlob(IntPtr keyBlob);

[DllImport(DLLNAME, EntryPoint = "wolfTPM2_SetKeyAuthPassword")]
private static extern int wolfTPM2_SetKeyAuthPassword(
IntPtr keyBlob, string auth, int authSz);

internal IntPtr keyblob;

public KeyBlob()
Expand Down Expand Up @@ -282,6 +286,23 @@ public IntPtr GetHandle()
{
return wolfTPM2_GetHandleRefFromKeyBlob(keyblob);
}

/// <summary>
/// Set the authentication data for a key
/// </summary>
/// <param name="auth">pointer to auth data</param>
/// <returns>Success: 0</returns>
public int SetKeyAuthPassword(string auth)
{
int rc = wolfTPM2_SetKeyAuthPassword(keyblob,
auth,
auth.Length);
if (rc != (int)Status.TPM_RC_SUCCESS) {
throw new WolfTpm2Exception(
"wolfTPM2_SetKeyAuthPassword", rc);
}
return rc;
}
}

public class Key : IDisposable
Expand All @@ -300,9 +321,7 @@ public class Key : IDisposable

[DllImport(DLLNAME, EntryPoint = "wolfTPM2_SetKeyAuthPassword")]
private static extern int wolfTPM2_SetKeyAuthPassword(
IntPtr key,
string auth,
int authSz);
IntPtr key, string auth, int authSz);

[DllImport(DLLNAME, EntryPoint = "wolfTPM2_GetHandleRefFromKey")]
private static extern IntPtr wolfTPM2_GetHandleRefFromKey(IntPtr key);
Expand Down