public LinuxTpmDevice(string tpmDevicePath = null) { _tpmDevicePath = tpmDevicePath ?? "/dev/tpm0"; // _tpmDevicePath = tpmDevicePath ?? "/dev/tpmrm0"; try { Connect(); } catch (Exception) { //Console.WriteLine("Failed to connect to " + tpmDevicePath); try { TctiCtx = AbrmdWrapper.Load(out TctiCtxPtr); } catch (Exception e) { Console.WriteLine($"Exception while loading tpm2-abrmd: {e}"); } if (TctiCtx == null) { // If the first attempt to connect was to the kernel mode TRM, // then try to connect to the raw TPM device, and vice versa. _tpmDevicePath = _tpmDevicePath.Contains("/dev/tpmrm") ? _tpmDevicePath.Replace("/dev/tpmrm", "/dev/tpm") : "/dev/tpmrm0"; try { Connect(); } catch (Exception) { //Console.WriteLine("Failed to connect to " + tpmDevicePath); Debug.Assert(_tpmIO == null); TrmDevice = new TcpTpmDevice("127.0.0.1", 2323, false, true); TrmDevice.Connect(); } } } Close(); }
// Connect to TPM device public override void Connect() { if (TctiCtx != null && TctiCtxPtr == IntPtr.Zero) { try { TctiCtx = AbrmdWrapper.Load(out TctiCtxPtr); } catch (Exception e) { Console.WriteLine($"Exception while loading tpm2-abrmd: {e}"); } } else if (TrmDevice != null) { TrmDevice.Connect(); } else { _tpmIO = new FileStream(_tpmDevicePath, FileMode.Open, FileAccess.ReadWrite); } }