Example #1
0
        public LinuxTpmDevice(string tpmDevicePath = null)
        {
            _tpmDevicePath = tpmDevicePath ?? "/dev/tpmrm0";
            //Tpm2Device dev = new LinuxTpmDevice("/dev/tpmrm0");
            try
            {
                Connect();
            }
            catch (Exception)
            {
                //Console.WriteLine("Failed to connect to " + tpmDevicePath);

                // 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();
        }
Example #2
0
 public Tbs(Tpm2Device theUnderlyingTpm, bool tpmHasRm)
 {
     TpmDevice      = theUnderlyingTpm;
     Tpm            = new Tpm2(TpmDevice);
     ContextManager = new ObjectContextManager();
     if (!tpmHasRm)
     {
         CleanTpm();
     }
 }
Example #3
0
 public Tbs(Tpm2Device theUnderlyingTpm, bool tpmHasRm)
 {
     TpmDevice = theUnderlyingTpm;
     Tpm = new Tpm2(TpmDevice);
     ContextManager = new ObjectContextManager();
     if (!tpmHasRm)
     {
         CleanTpm();
     }
 }
Example #4
0
 protected override void Dispose(bool disposing)
 {
     Close();
     if (disposing)
     {
         if (_tpmIO != null)
         {
             _tpmIO.Dispose();
             _tpmIO = null;
         }
         if (TrmDevice != null)
         {
             TrmDevice.Dispose();
             TrmDevice = null;
         }
     }
 }
Example #5
0
        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();
        }
Example #6
0
 public void DestroyContext(Tpm2Device tpmDevice)
 {
     throw new NotImplementedException("");
 }
Example #7
0
 public TpmPassThroughDevice(Tpm2Device underlyingDevice)
 {
     Device = underlyingDevice;
 }
Example #8
0
 public void DestroyContext(Tpm2Device tpmDevice)
 {
     throw new NotImplementedException("");
 }
Example #9
0
 /// <summary>
 /// A Tpm2 must be created attached to an underlying device
 /// </summary>
 /// <param name="device"></param>
 /// <param name="mode"></param>
 public Tpm2(Tpm2Device device, Behavior b = Behavior.Default)
 {
     Device = device;
     _Behavior = b;
     Sessions = new SessionBase[0];
     Helpers = new TpmHelpers(this);
 }
Example #10
0
 public void Dispose()
 {
     if (Device != null)
     {
         Device.Dispose();
     }
     Device = null;
 }