【发布时间】:2019-01-28 15:29:27
【问题描述】:
我想使用 azure-iot-sdk-csharp 在 azure iot dps 上使用 TPM 作为身份验证机制来配置基于 linux 的设备。
我在树莓板上添加了一个 TPM 模块并配置了内核/设备树。检测到 TPM 芯片并且 /dev/tpm0 设备出现在 linux 中。 此外,我在 linux 映像中包含了所有先决条件,以便在 linux (https://github.com/dotnet/core/blob/master/samples/YoctoInstructions.md) 上运行自包含的 .net-core 应用程序。可以运行 .net-core 应用程序...我使用 c# device-sdk 测试了一个简单的 Iot-Hub 连接。
接下来,我尝试从 .net 核心访问 TPM 模块。因此我编写了这个程序,使用 Microsoft.Azure.Devices.Provisioning.Security 中的 SecurityProviderTpmHsm 来读取 TPM endorsementKey。
using System;
using System.Text;
using Microsoft.Azure.Devices.Provisioning.Security;
using Microsoft.Azure.Devices.Shared;
namespace TPMTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var tpmProvider = new SecurityProviderTpmHsm("test");
var test = tpmProvider.GetEndorsementKey();
Console.WriteLine(BitConverter.ToString(test));
}
}
}
这在 Windows 机器上有效,但在带有自包含包 (dotnet publish -r linux-arm) 的 linux-arm 机器上失败。
Hello World!
Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'bcrypt.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libbcrypt.dll: cannot open shared object file: No such file or directory
at Tpm2Lib.Native.BCryptOpenAlgorithmProvider(UIntPtr& AlgProvider, String AlgId, String Implementation, UInt32 Flags)
at Tpm2Lib.BCryptAlgorithm.Open(String algName, UInt32 flags)
at Tpm2Lib.BCryptAlgorithm..ctor(String algName, UInt32 flags)
at Tpm2Lib.CryptoLib.Hmac(TpmAlgId hashAlgId, Byte[] key, Byte[] data)
at Tpm2Lib.KDF.KDFa(TpmAlgId hmacHash, Byte[] hmacKey, String label, Byte[] contextU, Byte[] contextV, Int32 numBitsRequired)
at Tpm2Lib.PRNG.FillRandBuf()
at Tpm2Lib.PRNG.SetRngRandomSeed()
at Tpm2Lib.PRNG.GetRandomBytes(Int32 numBytes)
at Tpm2Lib.Globs.GetRandomBytes(Int32 numBytes)
at Tpm2Lib.Tpm2.GetRandomBytes(Int32 numBytes)
at Tpm2Lib.Tpm2.CancelSafeStartAuthSession(TpmSe sessionType, TpmAlgId authHash, Int32 nonceCallerSize)
at Tpm2Lib.Tpm2.PrepareRequestSessions(CommandInfo commandInfo, TpmHandle[] inHandles)
at Tpm2Lib.Tpm2.DispatchMethod(TpmCc ordinal, TpmStructureBase inParms, Type expectedResponseType, TpmStructureBase& outParms, Int32 numInHandlesNotUsed, Int32 numOutHandlesNotUsed)
at Tpm2Lib.Tpm2.CreatePrimary(TpmHandle primaryHandle, SensitiveCreate inSensitive, TpmPublic inPublic, Byte[] outsideInfo, PcrSelection[] creationPCR, TpmPublic& outPublic, CreationData& creationData, Byte[]& creationHash, TkCreation& creationTicket)
at Microsoft.Azure.Devices.Provisioning.Security.SecurityProviderTpmHsm.ReadOrCreatePersistedKey(TpmHandle persHandle, TpmHandle hierarchy, TpmPublic template)
at Microsoft.Azure.Devices.Provisioning.Security.SecurityProviderTpmHsm.CacheEkAndSrk()
at Microsoft.Azure.Devices.Provisioning.Security.SecurityProviderTpmHsm..ctor(String registrationId, Tpm2Device tpm)
at Microsoft.Azure.Devices.Provisioning.Security.SecurityProviderTpmHsm..ctor(String registrationId)
at TPMTest.Program.Main(String[] args) in C:\Users\admin\source\repos\TPMTest\TPMTest\Program.cs:line 12
Aborted
我在 github 上阅读了一些关于缺少 bcrypted.dll 的问题。据我了解,一些加密功能没有移植到 .net core 2.x for linux 中。 https://github.com/dotnet/corefx/issues/7023 所以,我尝试了支持 AES-GCM 等的 .net-core 3.x 预览版……但我遇到了同样的错误。
不确定,如果这个问题与我的问题有关。
我的 linux 映像中是否缺少依赖项? 通常是否支持在基于 linux 的机器上使用 .net-core 中的 TPM 模块?
【问题讨论】:
-
您找到解决方案了吗?
标签: c# .net-core azure-iot-hub azure-iot-sdk tpm