public GetQuoteResponse(UInt32 i_error_code, RSACryptoServiceProvider i_public_key) { error_code = i_error_code; public_key = i_public_key; pcr_info = new byte[25]; pcr_info[0] = 0; pcr_info[1] = 3; pcr_info[2] = 0; pcr_info[3] = 0; pcr_info[4] = 14; if (CommonParams.loaderHash.Length == 40 && CommonParams.appHash.Length == 40) { SHA1Managed hasher = new SHA1Managed(); byte[] encoded_public_key = CommonRoutines.EncodePublicKey(public_key); byte[] pcr17 = GetExpectedPCR17(); byte[] pcr18 = GetZeroPCR(); byte[] pcr19 = GetExpectedPCR19(hasher, encoded_public_key); byte[] tpm_pcr_composite = CommonRoutines.CombineByteArrays(pcr_info.Take(5).ToArray(), BitConverter.GetBytes((UInt32)60), pcr17, pcr18, pcr19); byte[] h1 = hasher.ComputeHash(tpm_pcr_composite); Array.Copy(h1, 0, pcr_info, 5, 20); } sig = new byte[1]; sig[0] = 0; }
private void CheckPCRInfo(byte[] pcr_info, byte[] encoded_public_key) { if (pcr_info[0] != 0 || pcr_info[1] != 3 || pcr_info[2] != 0 || pcr_info[3] != 0 || pcr_info[4] != 14) { throw new Exception("Invalid PCR selection in PCR info"); } if (CommonParams.loaderHash.Length != 40 || CommonParams.appHash.Length != 40) { Console.Error.WriteLine("Skipping TPM composite hash check because loader hash and app hash weren't supplied"); return; } SHA1Managed hasher = new SHA1Managed(); byte[] pcr17 = GetExpectedPCR17(); byte[] pcr18 = GetZeroPCR(); byte[] pcr19 = GetExpectedPCR19(hasher, encoded_public_key); byte[] tpm_pcr_composite = CommonRoutines.CombineByteArrays(pcr_info.Take(5).ToArray(), BitConverter.GetBytes((UInt32)60), pcr17, pcr18, pcr19); byte[] h1 = hasher.ComputeHash(tpm_pcr_composite); byte[] received_h1 = pcr_info.Skip(5).Take(20).ToArray(); if (!h1.SequenceEqual(received_h1)) { throw new Exception("Composite hash in received PCR info not what was expected"); } }
public byte[] Encode() { byte[] header = new byte[1]; header[0] = 1; byte[] error_code = CommonRoutines.EncodeBEWord(0); byte[] encoded_public_key = CommonRoutines.EncodePublicKey(public_key); byte[] encoded_public_key_length = CommonRoutines.EncodeBEWord((uint)encoded_public_key.Length); byte[] pcr_info_length = CommonRoutines.EncodeBEWord((uint)pcr_info.Length); byte[] sig_length = CommonRoutines.EncodeBEWord((uint)sig.Length); return(CommonRoutines.CombineByteArrays(header, error_code, encoded_public_key_length, pcr_info_length, sig_length, encoded_public_key, pcr_info, sig)); }
private byte[] ExtendPCR(SHA1Managed hasher, byte[] currentValue, byte[] valueToExtendBy) { return(hasher.ComputeHash(CommonRoutines.CombineByteArrays(currentValue, valueToExtendBy))); }