From 7bcd0dd97fe4f228bb19913aa89bf9a738606db8 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 6 Jan 2022 14:38:46 +1100 Subject: [PATCH] [client] main: if spice is in use check the guest uuid matches If the guest supports sending us it's UUID and PureSpice has also reported the guest's UUID, check them to see if the user has accidentially connected to the wrong spice socket. --- client/src/main.c | 46 ++++++++++++++++++++++++++++++++++++++++------ client/src/main.h | 5 +++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index d537d3c2..95091551 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -837,10 +837,43 @@ static void audioData(uint8_t * data, size_t size) g_state.audioDev->play(data, size); } +static void checkUUID(void) +{ + if (!g_state.spiceUUIDValid || !g_state.guestUUIDValid) + return; + + if (memcmp(g_state.spiceUUID, g_state.guestUUID, + sizeof(g_state.spiceUUID)) != 0) + return; + + DEBUG_ERROR("UUIDs do not match, you have connected SPICE to the wrong guest"); + DEBUG_ERROR("Shutting down"); + g_state.state = APP_STATE_SHUTDOWN; +} + void spiceReady(void) { // set the intial mouse mode purespice_mouseMode(true); + + PSServerInfo info; + if (!purespice_getServerInfo(&info)) + return; + + bool uuidValid = false; + for(int i = 0; i < sizeof(info.uuid); ++i) + if (info.uuid[i]) + { + uuidValid = true; + break; + } + + if (!uuidValid) + return; + + memcpy(g_state.spiceUUID, info.uuid, sizeof(g_state.spiceUUID)); + g_state.spiceUUIDValid = true; + checkUUID(); } int spiceThread(void * arg) @@ -1313,19 +1346,20 @@ restart: vmInfo->cores, vmInfo->cpus); DEBUG_INFO("Capture Device : %s", vmInfo->capture); - bool checkUUID = false; - for(int i = 0; i < 16; ++i) + bool uuidValid = false; + for(int i = 0; i < sizeof(vmInfo->uuid); ++i) if (vmInfo->uuid[i]) { - checkUUID = true; + uuidValid = true; break; } - if (!checkUUID) + if (!uuidValid) break; - //TODO: compare UUID with the one provided by SPICE if SPICE is in use - + memcpy(g_state.guestUUID, vmInfo->uuid, sizeof(g_state.guestUUID)); + g_state.guestUUIDValid = true; + checkUUID(); break; } diff --git a/client/src/main.h b/client/src/main.h index d48f1a32..6fc8c7fc 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -72,6 +72,11 @@ struct AppState bool dsInitialized; bool jitRender; + uint8_t spiceUUID[16]; + bool spiceUUIDValid; + uint8_t guestUUID[16]; + bool guestUUIDValid; + bool stopVideo; bool ignoreInput; bool escapeActive;