microsoft / TSS.MSR

The TPM Software Stack from Microsoft Research
Other
428 stars 161 forks source link

M1 mac: Unable to load shared library 'bcrypt.dll' or one of its dependencies #148

Closed tdesmet closed 2 years ago

tdesmet commented 2 years ago

I am using an M1 macbook and trying to to simulate an iot device using the Microsoft.Azure.Devices packages. When I try to create the SecurityProviderTpmHsm I get an error Unable to load shared library 'bcrypt.dll' or one of its dependencies.

The Microsoft.Azure.Devices.Provisioning.Security.Tpm package has a dependency on this library and the error originates from this library.

It seems that this library uses bcrypt. I noticed that work has been done in https://github.com/microsoft/TSS.MSR/pull/105 to make this library cross platform compatible. But since then no new nuget package has been released.

Is it possible to release a new version? And hopefully that fixes the problem...

Stack trace

Unable to load shared library 'bcrypt.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libbcrypt.dll, 0x0001): tried: 'libbcrypt.dll' (no such file), '/usr/local/lib/libbcrypt.dll' (no such file), '/usr/lib/libbcrypt.dll' (no such file), '/Users/tom/Documents/GitHub/Geras.Cloud/src/Geras.DataGenerator/bin/Debug/net6.0/libbcrypt.dll' (no such file)
   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.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)

Code

var tpmDevice = new TcpTpmDevice("127.0.0.1", 2321);
    tpmDevice.Connect();
    tpmDevice.PowerCycle();
    using (var tpm2 = new Tpm2(tpmDevice))
    {
      tpm2.Startup(Su.Clear);
    }
    new SecurityProviderTpmHsm(GetRegistrationID(), tpmDevice);

Issue on azure iot sdk csharp: https://github.com/Azure/azure-iot-sdk-csharp/issues/2362