我想使用azure- iot -sdk-csharp在azure iot dps上配置一个基于linux的设备,使用TPM作为身份验证机制。
我在一个树莓板上添加了一个TPM模块,并配置了内核/ deviceTree。检测到TPM芯片,并在linux中显示/dev/tpm0设备。另外,我在linux镜像中包含了在linux上运行一个自包含的.net-core应用程序的所有先决条件(https://github.com/dotnet/core/blob/master/samples/YoctoInstructions.md)。可以运行.Net核心应用程序...我使用c#设备开发工具包测试了一个简单的物联网集线器连接。
接下来,我尝试从.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机器上可以工作,但在具有自包含包的linux-arm机器上失败(dotnet发布-r 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丢失的问题。据我所知,一些加密函数没有移植到linux的.net核心2.x中。所以,我尝试了.net- https://github.com/dotnet/corefx/issues/7023 3.x预览版,它支持AES-GCM等...但我也遇到了同样的错误。
不确定这个问题是否与我的问题有关。
我的linux镜像中是否缺少我需要的依赖项?在基于linux的机器上使用.net-core中的TPM模块通常受支持吗?
发布于 2019-02-08 00:53:30
Microsoft.Azure.Devices.Provisioning.Security.Tpm依赖于Microsoft.TSS 2.0.1 NuGet包,该包只包含linux-x64的二进制文件。
为了让它工作:
<PropertyGroup Condition=" '$(RuntimeIdentifier)' == 'linux-x64' Or '$(OS)' == 'Unix'  Or '$(OS)' == 'Linux'">到这个
<PropertyGroup Condition=" '$(RuntimeIdentifier)' == 'linux-x64' Or '$(RuntimeIdentifier)' == 'linux-arm' Or '$(OS)' == 'Unix'  Or '$(OS)' == 'Linux'">arm在项目中引用Microsoft.Azure.Devices.Provisioning.Security.Tpm
https://stackoverflow.com/questions/54405230
复制相似问题