Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            string quoteMe = "Hallo IAIK!";

            byte[] quoteMeBytes = System.Text.Encoding.ASCII.GetBytes(quoteMe);

            // 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);

            ClientKeyHandle myFirstSignKey =
                sessionToUse.KeyClient.GetSrkKeyHandle().CreateKey("my_first_sign_key", TPMKeyUsage.TPM_KEY_SIGNING);

            ISigner signer = myFirstSignKey.CreateSigner();

            signer.Init(true, null);
            signer.BlockUpdate(quoteMeBytes, 0, quoteMeBytes.Length);

            byte[] quote = signer.GenerateSignature();

            Console.WriteLine("Sign of \"Hallo IAIK\" is:\n" + ByteHelper.ByteArrayToHexString(quote));

            Console.WriteLine();
            Console.WriteLine("Now we would verify this sign.");

            signer.Reset();
            signer.Init(false, null);
            signer.BlockUpdate(quoteMeBytes, 0, quoteMeBytes.Length);

            if (signer.VerifySignature(quote) == true)
            {
                Console.WriteLine("Sign is OK!");
            }
            else
            {
                Console.WriteLine("UUUUPPPPSSS something went wrong!");
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);

            ProtectedPasswordStorage pws = new ProtectedPasswordStorage();

            pws.WellKnown();

            sessionToUse.AdministrationClient.TakeOwnership(ConsoleUtils.ReadPassword("Owner Password: "******"PCRS = " + sessionToUse.CapabilityClient.GetPCRCount());
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            string quoteMe = "Hallo IAIK!";

            byte[] quoteMeBytes = System.Text.Encoding.ASCII.GetBytes(quoteMe);

            // 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);

            ClientKeyHandle myFirstQuoteKey =
                sessionToUse.KeyClient.GetSrkKeyHandle().CreateKey("my_first_quote_key", TPMKeyUsage.TPM_KEY_SIGNING);

            sessionToUse.IntegrityClient.Extend(0, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });
            sessionToUse.IntegrityClient.Extend(1, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });
            sessionToUse.IntegrityClient.Extend(2, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });

            TPMPCRSelection pcrselect = sessionToUse.CreateEmptyPCRSelection();

            pcrselect.PcrSelection[0] = true;
            pcrselect.PcrSelection[1] = true;
            pcrselect.PcrSelection[2] = true;

            ISigner signer = myFirstQuoteKey.CreateQuoter(pcrselect);

            signer.Init(true, null);
            signer.BlockUpdate(quoteMeBytes, 0, quoteMeBytes.Length);

            byte[] quote = signer.GenerateSignature();

            Console.WriteLine("Quote of \"Hallo IAIK\" is:\n" + ByteHelper.ByteArrayToHexString(quote));

            Console.WriteLine();
            Console.WriteLine("Now we would verify this quote.");

            signer.Reset();
            signer.Init(false, null);
            signer.BlockUpdate(quoteMeBytes, 0, quoteMeBytes.Length);

            if (signer.VerifySignature(quote) == true)
            {
                Console.WriteLine("Quote is OK!");
            }
            else
            {
                Console.WriteLine("UUUUPPPPSSS something went wrong!");
            }


            Console.WriteLine("Extending PCRs, Quote should fail now!");

            sessionToUse.IntegrityClient.Extend(0, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });
            sessionToUse.IntegrityClient.Extend(1, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });
            sessionToUse.IntegrityClient.Extend(2, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });

            if (signer.VerifySignature(quote) == true)
            {
                Console.WriteLine("UUUUPPPPSSS something went wrong!");
            }
            else
            {
                Console.WriteLine("Quote is NOT OK, that's the way it should be.");
            }
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            string[] sealMe = { "Hallo", "IAIK!" };

            // 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("Create Cipher Key");

            ClientKeyHandle myFirstSealKey =
                sessionToUse.KeyClient.GetSrkKeyHandle().CreateKey("my_first_seal_key", TPMKeyUsage.TPM_KEY_STORAGE);

            Console.WriteLine("Key: {0}\n{1}", myFirstSealKey.FriendlyName, myFirstSealKey.PublicKey);
            Console.WriteLine("---------------------------------\n");


            sessionToUse.IntegrityClient.Extend(0, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });
            sessionToUse.IntegrityClient.Extend(1, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });
            sessionToUse.IntegrityClient.Extend(2, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });

            TPMPCRSelection pcrselect = sessionToUse.CreateEmptyPCRSelection();

            pcrselect.PcrSelection[0] = true;
            pcrselect.PcrSelection[1] = true;
            pcrselect.PcrSelection[2] = true;

            Console.WriteLine("Create Cipher, init and cipher");
            IAsymmetricBlockCipher cipher = myFirstSealKey.CreateSealBlockCipher(pcrselect);

            cipher.Init(true, null);

            byte[][] cipherText = new byte[sealMe.Length][];
            int      i          = 0;

            foreach (string msg in sealMe)
            {
                byte[] block = System.Text.ASCIIEncoding.ASCII.GetBytes(msg);
                cipherText[i] = cipher.ProcessBlock(block, 0, block.Length);
                i++;
            }

            Console.WriteLine("Original vs. CiperText:");
            for (i = 0; i < sealMe.Length; i++)
            {
                Console.WriteLine("{0} --> {1}", sealMe[i], ByteHelper.ByteArrayToHexString(cipherText[i]));
            }
            Console.WriteLine("---------------------------------\n");

            Console.WriteLine("Init and decode");
            cipher.Init(false, null);
            byte[][] decode = new byte[sealMe.Length][];
            i = 0;
            foreach (byte[] msg in cipherText)
            {
                decode[i] = cipher.ProcessBlock(msg, 0, msg.Length);
                i++;
            }

            Console.WriteLine("Does it work?:");
            for (i = 0; i < sealMe.Length; i++)
            {
                Console.WriteLine("{0}: {1}", sealMe[i] == System.Text.ASCIIEncoding.ASCII.GetString(decode[i])?"Y":"N", System.Text.ASCIIEncoding.ASCII.GetString(decode[i]));
            }
            Console.WriteLine("---------------------------------\n");

            Console.WriteLine("Changing PCR Values");
            sessionToUse.IntegrityClient.Extend(0, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });

            Console.WriteLine("Decode, now an TPMRequest Exception should be thrown, with Error Code (0x18): TPM_WRONGPCRVAL");
            decode = new byte[sealMe.Length][];
            i      = 0;
            foreach (byte[] msg in cipherText)
            {
                try
                {
                    decode[i] = cipher.ProcessBlock(msg, 0, msg.Length);
                    Console.WriteLine("UUUUUPPPPSSSS, something went wrong!");
                }
                catch (TPMRequestException e)
                {
                    Console.WriteLine(e.ToString());
                }
                i++;
            }
        }
Exemplo n.º 6
0
 private static void TestXmlConfig(string filename)
 {
     IDictionary <string, TPMSession> sessions = XMLConfiguration.EstablischConnection(filename);
 }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            string[] bindMe = { "Hallo", "IAIK!" };

            // 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("Create Cipher Key");

            ClientKeyHandle myFirstBindKey =
                sessionToUse.KeyClient.GetSrkKeyHandle().CreateKey("my_first_bind_key", TPMKeyUsage.TPM_KEY_BIND);

            Console.WriteLine("Key: {0}\n{1}", myFirstBindKey.FriendlyName, myFirstBindKey.PublicKey);
            Console.WriteLine("---------------------------------\n");


            Console.WriteLine("Create Cipher, init and cipher");
            IAsymmetricBlockCipher cipher = myFirstBindKey.CreateBindBlockCipher();

            cipher.Init(true, null);

            byte[][] cipherText = new byte[bindMe.Length][];
            int      i          = 0;

            foreach (string msg in bindMe)
            {
                byte[] block = System.Text.ASCIIEncoding.ASCII.GetBytes(msg);
                cipherText[i] = cipher.ProcessBlock(block, 0, block.Length);
                i++;
            }

            Console.WriteLine("Original vs. CiperText:");
            for (i = 0; i < bindMe.Length; i++)
            {
                Console.WriteLine("{0} --> {1}", bindMe[i], ByteHelper.ByteArrayToHexString(cipherText[i]));
            }
            Console.WriteLine("---------------------------------\n");

            Console.WriteLine("Init and decode");
            cipher.Init(false, null);
            byte[][] decode = new byte[bindMe.Length][];
            i = 0;
            foreach (byte[] msg in cipherText)
            {
                decode[i] = cipher.ProcessBlock(msg, 0, msg.Length);
                i++;
            }

            Console.WriteLine("Does it work?:");
            for (i = 0; i < bindMe.Length; i++)
            {
                Console.WriteLine("{0}: {1}", bindMe[i] == System.Text.ASCIIEncoding.ASCII.GetString(decode[i])?"Y":"N", System.Text.ASCIIEncoding.ASCII.GetString(decode[i]));
            }
            Console.WriteLine("---------------------------------\n");
        }