public static byte[] getBytes(TimeStampRequest_t str) { int size = Marshal.SizeOf(str); Console.WriteLine("Size of str: " + size); byte[] arr = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(str, ptr, true); Marshal.Copy(ptr, arr, 0, size); Marshal.FreeHGlobal(ptr); return(arr); }
public static void Main(string[] args) { UDPServer server = new UDPServer(11000, 5000); // timeout for recv = 5 secs Console.WriteLine("Verifier"); Key_t k = new Key_t(); FileMeta_t fm = new FileMeta_t(); TargetRequest_t tr = new TargetRequest_t(); RootRequest_t rr = new RootRequest_t(); SnapshotRequest_t sr = new SnapshotRequest_t(); TimeStampRequest_t tsr = new TimeStampRequest_t(); Console.WriteLine("Size: " + Marshal.SizeOf(tr) + " " + Marshal.SizeOf(rr) + " " + Marshal.SizeOf(sr) + " " + Marshal.SizeOf(tsr)); Console.WriteLine("Size: " + sizeof(byte)); while (true) { Console.Write("Select task: (1) Software Update, (2) Remote Attestation: "); String task = Console.ReadLine(); Console.Write("Select a target process: (1) Fuel Level, (2) Speed: "); Image_t image = default(Image_t); image.processId = Convert.ToUInt32(Console.ReadLine()); String fp = "../../"; String image_name = ""; if (image.processId == 1) { image_name = "fuel-level-app"; fp += "fuel-level-app"; image.start_cpio_addr = 0; image.start_disk_addr = 0; } else if (image.processId == 2) { image_name = "speedometer-app"; fp += "speedometer-app"; image.start_cpio_addr = 0;// 477876; image.start_disk_addr = 0; } else { Console.WriteLine("Invalid Process: " + image.processId); continue; } Console.Write("Select a version: (0), (1), (2) or (10) for fake request: "); image.version = Convert.ToUInt32(Console.ReadLine()); if (image.version == 10) { sendFakeRequest(server); continue; } if (image.version > 2) { Console.WriteLine("Invalid Version: " + image.version); continue; } fp += "-v" + image.version; //Console.WriteLine("Loading file at: " + fp); image.img = System.IO.File.ReadAllBytes(fp); image.imgSize = image.img.Length; if (task == "1") // software update { //if(sendUpdateRequest(image, server)) sendImage(image.img, image.imgSize, server); sendTufRequest(server); } else if (task == "2") { Console.WriteLine("Attestation Result: " + performRemoteAttestation(image, server)); //Console.WriteLine("Attestation Result: Prover is "+ (performRemoteAttestation(image, server) ? "" : "NOT") + " running "+image_name+" version "+image.version); //if (!performRemoteAttestation(image, server)) Console.WriteLine("Prover does not run the correct software"); //else Console.WriteLine("Prover is healthy"); } } }