public static void Main(String[] args) { using (EzQuoteMain main = new EzQuoteMain()) { /*foreach (String tpm_name in main.ctx_.TPMClient.TPMDevices) * { * Console.WriteLine("TPM DEVICE {0}", tpm_name); * * }*/ TPMSession tpm0 = main.ctx_.TPMClient.SelectTPMDevice("ibm0"); IDictionary <string, string> opts = new Dictionary <string, string>(); opts.Add("file", "/tmp/mystore"); tpm0.Keystore = TPMKeystoreProviders.Create("SQLiteKeystore", opts); tpm0.SetRequestSecretCallback(mycallback); /* * ProtectedPasswordStorage pws = new ProtectedPasswordStorage(); * pws.AppendPasswordChar('i'); * pws.AppendPasswordChar('a'); * pws.AppendPasswordChar('i'); * pws.AppendPasswordChar('k'); * * tpm0.AdministrationClient.TakeOwnership(pws, pws); */ ClientKeyHandle kh_srk = tpm0.KeyClient.GetSrkKeyHandle(); ClientKeyHandle kh_sig1 = kh_srk.CreateKey("sigkey5" + tpm0.CreateRNG().Next(), 2048, TPMKeyUsage.TPM_KEY_SIGNING, TPMKeyFlags.None); TPMPCRSelection pcrs = tpm0.CreateEmptyPCRSelection(); pcrs.PcrSelection.SetBit(0, true); pcrs.PcrSelection.SetBit(1, true); pcrs.PcrSelection.SetBit(16, true); foreach (int pcr in pcrs.SelectedPCRs) { Console.Write(" PCR {0:D2}: 0x"); foreach (byte b in tpm0.IntegrityClient.PCRValue((uint)pcr)) { Console.Write("{0:X2}", b); } Console.WriteLine(); } ISigner signer = kh_sig1.CreateQuoter(pcrs); signer.Init(true, null); signer.Update((byte)'i'); signer.Update((byte)'a'); signer.Update((byte)'i'); signer.Update((byte)'k'); byte[] signature = signer.GenerateSignature(); Console.Write("QUOTE: "); foreach (byte b in signature) { Console.Write(" {0:X2}", b); } Console.WriteLine(); ISigner verifier = kh_sig1.CreateQuoter(pcrs); verifier.Init(false, null); verifier.Update((byte)'i'); verifier.Update((byte)'a'); verifier.Update((byte)'i'); verifier.Update((byte)'k'); if (verifier.VerifySignature(signature)) { Console.WriteLine("JO IT WORKED"); } else { Console.WriteLine("NA IT FAILED"); } } }
public static void Main(String[] args) { using (EzQuoteMain main = new EzQuoteMain()) { /*foreach (String tpm_name in main.ctx_.TPMClient.TPMDevices) { Console.WriteLine("TPM DEVICE {0}", tpm_name); }*/ TPMSession tpm0 = main.ctx_.TPMClient.SelectTPMDevice("ibm0"); IDictionary<string, string> opts = new Dictionary<string,string>(); opts.Add("file", "/tmp/mystore"); tpm0.Keystore = TPMKeystoreProviders.Create("SQLiteKeystore", opts); tpm0.SetRequestSecretCallback(mycallback); /* ProtectedPasswordStorage pws = new ProtectedPasswordStorage(); pws.AppendPasswordChar('i'); pws.AppendPasswordChar('a'); pws.AppendPasswordChar('i'); pws.AppendPasswordChar('k'); tpm0.AdministrationClient.TakeOwnership(pws, pws); */ ClientKeyHandle kh_srk = tpm0.KeyClient.GetSrkKeyHandle(); ClientKeyHandle kh_sig1 = kh_srk.CreateKey("sigkey5" + tpm0.CreateRNG().Next(), 2048, TPMKeyUsage.TPM_KEY_SIGNING, TPMKeyFlags.None); TPMPCRSelection pcrs = tpm0.CreateEmptyPCRSelection(); pcrs.PcrSelection.SetBit(0, true); pcrs.PcrSelection.SetBit(1, true); pcrs.PcrSelection.SetBit(16, true); foreach(int pcr in pcrs.SelectedPCRs) { Console.Write(" PCR {0:D2}: 0x"); foreach (byte b in tpm0.IntegrityClient.PCRValue((uint)pcr)) { Console.Write("{0:X2}", b); } Console.WriteLine(); } ISigner signer = kh_sig1.CreateQuoter(pcrs); signer.Init(true, null); signer.Update((byte)'i'); signer.Update((byte)'a'); signer.Update((byte)'i'); signer.Update((byte)'k'); byte[] signature = signer.GenerateSignature(); Console.Write("QUOTE: "); foreach (byte b in signature) { Console.Write(" {0:X2}", b); } Console.WriteLine(); ISigner verifier = kh_sig1.CreateQuoter(pcrs); verifier.Init(false, null); verifier.Update((byte)'i'); verifier.Update((byte)'a'); verifier.Update((byte)'i'); verifier.Update((byte)'k'); if (verifier.VerifySignature(signature)) { Console.WriteLine("JO IT WORKED"); } else { Console.WriteLine("NA IT FAILED"); } } }