コード例 #1
0
ファイル: TbsDevice.cs プロジェクト: notfarfromorion/TSS.MSR
        private byte[] GetTpmAuth(TBS_AUTH_TYPE authType)
        {
#if false
            return(new byte[0]);
#else
            if (TbsHandle == UIntPtr.Zero)
            {
                throw new Exception("TBS context not created.");
            }

            //Console.WriteLine("GetTpmAuth: Retrieving auth value {0}", authType);
            var  resultBuf               = new byte[256];
            uint resultByteCount         = (uint)resultBuf.Length;
            TbsWrapper.TBS_RESULT result = TbsWrapper.NativeMethods.
                                           Tbsi_Get_OwnerAuth(TbsHandle,
                                                              (uint)authType,
                                                              resultBuf,
                                                              ref resultByteCount);
            if (result != TbsWrapper.TBS_RESULT.SUCCESS)
            {
                Console.WriteLine("GetTpmAuth({0}): error 0x{1:X} {2}", authType, result,
                                  result == TbsWrapper.TBS_RESULT.OWNERAUTH_NOT_FOUND ? " (OWNERAUTH_NOT_FOUND)" :
                                  result == TbsWrapper.TBS_RESULT.BAD_PARAMETER ? " (BAD_PARAMETER)" : "");
                return(new byte[0]);
            }

            return(Globs.CopyData(resultBuf, 0, (int)resultByteCount));
#endif
        }
コード例 #2
0
ファイル: TbsDevice.cs プロジェクト: israelfink/TSS.MSR
        private byte[] GetTpmAuth(TBS_AUTH_TYPE authType)
        {
#if false
            return(new byte[0]);
#else
            if (TbsHandle == UIntPtr.Zero)
            {
                throw new Exception("TBS context not created.");
            }

            //Console.WriteLine("GetTpmAuth: Retrieving auth value {0}", authType);
            var  resultBuf               = new byte[256];
            uint resultByteCount         = (uint)resultBuf.Length;
            TbsWrapper.TBS_RESULT result = TbsWrapper.NativeMethods.
                                           Tbsi_Get_OwnerAuth(TbsHandle,
                                                              (uint)authType,
                                                              resultBuf,
                                                              ref resultByteCount);
            if (result != TbsWrapper.TBS_RESULT.SUCCESS)
            {
#if !__NETCOREAPP2__ && false
                Console.WriteLine($"Trying to read LockoutAuth from the registry...");
                try
                {
                    string lockoutAuthBase64 = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TPM\WMI\Admin", "LockoutHash", null);
                    if (lockoutAuthBase64 != null)
                    {
                        resultBuf = Convert.FromBase64String(lockoutAuthBase64);
                        Console.WriteLine($"LockoutAuth: {lockoutAuthBase64} | len {resultBuf.Length} bytes | {Globs.HexFromByteArray(resultBuf)}");
                        return(resultBuf);
                    }
                }
                catch (Exception e) {
                    Console.WriteLine($"Exception: {e}");
                }
#endif
#if !WINDOWS_UWP
                Console.WriteLine("GetTpmAuth({0}): Windows TBS returned 0x{1:X} {2}", authType, result,
                                  result == TbsWrapper.TBS_RESULT.OWNERAUTH_NOT_FOUND ? " (OWNERAUTH_NOT_FOUND)" :
                                  result == TbsWrapper.TBS_RESULT.BAD_PARAMETER ? " (BAD_PARAMETER)" : "");
#endif
                return(new byte[0]);
            }

            return(Globs.CopyData(resultBuf, 0, (int)resultByteCount));
#endif
        }