Example #1
0
        public static void Main(string[] args)
        {
            // Establish Connections
            IDictionary <string, TPMSession> sessions =
                XMLConfiguration.EstablischConnection(base_path + "ClientConfigXml/UnixSocketDeviceLin.xml");

            // Create one keystore per opened session
            foreach (TPMSession tpmSes in sessions.Values)
            {
                tpmSes.Keystore = new InMemoryKeystore();
            }


            TPMSession sessionToUse = sessions["local0"];

            sessionToUse.SetRequestSecretCallback(RequestSecret);


            Console.WriteLine("Creating key 'my_first_storage_key'");
            ClientKeyHandle myFirstStorageKey =
                sessionToUse.KeyClient.GetSrkKeyHandle().CreateKey("my_first_storage_key", TPMKeyUsage.TPM_KEY_STORAGE);

            Console.WriteLine("Created key 'my_first_storage_key' with public key: {0}", myFirstStorageKey.PublicKey.PublicKey);
            Console.WriteLine("------------------------\n\n");

            Console.WriteLine("Creating key 'my_second_storage_key'");
            ClientKeyHandle mySecondStorageKey = myFirstStorageKey.CreateKey("my_second_storage_key", TPMKeyUsage.TPM_KEY_STORAGE);

            Console.WriteLine("Created key 'my_second_storage_key' with public key: {0}", mySecondStorageKey.PublicKey.PublicKey);
            Console.WriteLine("------------------------\n\n");


            Console.WriteLine("Creating key 'binding_key'");
            ClientKeyHandle bindingKey = mySecondStorageKey.CreateKey("binding_key", TPMKeyUsage.TPM_KEY_BIND);

            Console.WriteLine("Created key 'binding_key' with public key: {0}", bindingKey.PublicKey.PublicKey);
            Console.WriteLine("------------------------\n\n");

            Console.WriteLine("Keystore now contains {0} keys", sessionToUse.Keystore.EnumerateFriendlyNames().Length);

            foreach (String keyFriendlyName in sessionToUse.Keystore.EnumerateFriendlyNames())
            {
                KeyValuePair <string, string>?parent = sessionToUse.Keystore.FindParentKeyByFriendlyName(keyFriendlyName);
                Console.WriteLine("Key: '{0}' with parent '{1}'", keyFriendlyName,
                                  parent == null?"srk":parent.Value.Key);
            }
        }
Example #2
0
        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");
                }
            }
        }