问题描述
我一直在寻找一种将值安全地存储到受信任的执行环境中的方法,然后我从Microsoft找到了一个名为Tpm2Lib的库。 我正在使用下面的代码,它实际上可以正常工作,但是我对安全性有些担心。 众所周知,数据已安全地存储在TPM中,但是从代码中看,AuthValue byte []初始化在这里很容易分解。 如果攻击者反汇编了我的代码,则他可以轻松地编写具有相同AuthValue的软件来从TPM中获取机密。
public static AuthValue _authValue = new AuthValue(new byte[] { 22,123,22,1,33 });
public static void SaveValueIntoTpm(int address,byte[] data,int length,AuthValue authValue)
{
Tpm2Device tpmDevice;
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
{
tpmDevice = new TbsDevice();
}
else
{
tpmDevice = new LinuxTpmDevice();
}
tpmDevice.Connect();
var tpm = new Tpm2(tpmDevice);
var ownerAuth = new AuthValue();
TpmHandle nvHandle = TpmHandle.NV(address);
tpm[ownerAuth]._AllowErrors().NvUndefineSpace(TpmHandle.RhOwner,nvHandle);
AuthValue nvAuth = authValue;
var nvPublic = new NvPublic(nvHandle,TpmAlgId.Sha1,NvAttr.Authwrite | NvAttr.Authread,new byte[0],(ushort)length);
tpm[ownerAuth].NvDefineSpace(TpmHandle.RhOwner,nvAuth,nvPublic);
tpm[nvAuth].NvWrite(nvHandle,nvHandle,data,0);
tpm.Dispose();
}
public static byte[] ReadValueFromTpm(int address,AuthValue authValue)
{
Tpm2Device tpmDevice;
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
{
tpmDevice = new TbsDevice();
}
else
{
tpmDevice = new LinuxTpmDevice();
}
tpmDevice.Connect();
var tpm = new Tpm2(tpmDevice);
TpmHandle nvHandle = TpmHandle.NV(address);
AuthValue nvAuth = authValue;
byte[] newData = tpm[nvAuth].NvRead(nvHandle,(ushort)length,0);
tpm.Dispose();
return newData;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)