diff --git a/cmake/FindLibUUID.cmake b/cmake/FindLibUUID.cmake new file mode 100644 index 0000000..ab564b7 --- /dev/null +++ b/cmake/FindLibUUID.cmake @@ -0,0 +1,51 @@ +# - Try to find LIBUUID +# Find LIBUUID headers, libraries and the answer to all questions. +# +# LIBUUID_FOUND True if libuuid got found +# LIBUUID_INCLUDE_DIRS Location of libuuid headers +# LIBUUID_LIBRARIES List of libraries to use libuuid +# +# Copyright (c) 2008 Bjoern Ricks +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +INCLUDE( FindPkgConfig ) + +IF ( LibUuid_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "REQUIRED" ) +ELSE( LibUuid_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "" ) +ENDIF ( LibUuid_FIND_REQUIRED ) + +IF ( LIBUUID_MIN_VERSION ) + PKG_SEARCH_MODULE( LIBUUID ${_pkgconfig_REQUIRED} uuid>=${LIBUUID_MIN_VERSION} ) +ELSE ( LIBUUID_MIN_VERSION ) + PKG_SEARCH_MODULE( LIBUUID ${_pkgconfig_REQUIRED} uuid ) +ENDIF ( LIBUUID_MIN_VERSION ) + + +IF( NOT LIBUUID_FOUND AND NOT PKG_CONFIG_FOUND ) + FIND_PATH( LIBUUID_INCLUDE_DIRS uuid/uuid.h ) + FIND_LIBRARY( LIBUUID_LIBRARIES uuid) + + # Report results + IF ( LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS ) + SET( LIBUUID_FOUND 1 ) + IF ( NOT LIBUUID_FIND_QUIETLY ) + MESSAGE( STATUS "Found libuuid: ${LIBUUID_LIBRARIES}" ) + ENDIF ( NOT LIBUUID_FIND_QUIETLY ) + ELSE ( LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS ) + IF ( LIBUUID_FIND_REQUIRED ) + MESSAGE( SEND_ERROR "Could NOT find libuuid" ) + ELSE ( LIBUUID_FIND_REQUIRED ) + IF ( NOT LIBUUID_FIND_QUIETLY ) + MESSAGE( STATUS "Could NOT find libuuid" ) + ENDIF ( NOT LIBUUID_FIND_QUIETLY ) + ENDIF ( LIBUUID_FIND_REQUIRED ) + ENDIF ( LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS ) +ENDIF( NOT LIBUUID_FOUND AND NOT PKG_CONFIG_FOUND ) + +MARK_AS_ADVANCED( LIBUUID_LIBRARIES LIBUUID_INCLUDE_DIRS ) diff --git a/libgamestream/CMakeLists.txt b/libgamestream/CMakeLists.txt index fea8e5d..a7896a5 100644 --- a/libgamestream/CMakeLists.txt +++ b/libgamestream/CMakeLists.txt @@ -1,3 +1,4 @@ +find_package(LibUUID REQUIRED) find_package(Threads REQUIRED) find_package(CURL REQUIRED) find_package(OpenSSL REQUIRED) @@ -20,8 +21,8 @@ target_link_libraries(gamestream moonlight-common) set_target_properties(gamestream PROPERTIES SOVERSION 0 VERSION ${MOONLIGHT_VERSION}) set_target_properties(moonlight-common PROPERTIES SOVERSION 0 VERSION ${MOONLIGHT_VERSION}) -target_include_directories(gamestream PRIVATE ../third_party/moonlight-common-c ../third_party/h264bitstream ${AVAHI_INCLUDE_DIRS}) -target_link_libraries(gamestream ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${EXPAT_LIBRARIES} ${AVAHI_LIBRARIES}) +target_include_directories(gamestream PRIVATE ../third_party/moonlight-common-c ../third_party/h264bitstream ${AVAHI_INCLUDE_DIRS} ${LIBUUID_INCLUDE_DIRS}) +target_link_libraries(gamestream ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${EXPAT_LIBRARIES} ${AVAHI_LIBRARIES} ${LIBUUID_LIBRARIES}) target_link_libraries(gamestream ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) diff --git a/libgamestream/client.c b/libgamestream/client.c index 4913426..48204c3 100644 --- a/libgamestream/client.c +++ b/libgamestream/client.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -170,9 +171,14 @@ static int load_server_status(PSERVER_DATA server) { char *versionText = NULL; char *stateText = NULL; + uuid_t uuid; + char uuid_str[37]; + int ret = GS_INVALID; char url[4096]; - sprintf(url, "https://%s:47984/serverinfo?uniqueid=%s", server->address, unique_id); + uuid_generate_random(uuid); + uuid_unparse(uuid, uuid_str); + sprintf(url, "https://%s:47984/serverinfo?uniqueid=%s&uuid=%s", server->address, unique_id, uuid_str); PHTTP_DATA data = http_create_data(); if (data == NULL) { @@ -287,6 +293,8 @@ static int sign_it(const char *msg, size_t mlen, unsigned char **sig, size_t *sl int gs_pair(PSERVER_DATA server, char* pin) { int ret = GS_OK; char url[4096]; + uuid_t uuid; + char uuid_str[37]; if (server->paired) { gs_error = "Already paired"; @@ -303,7 +311,9 @@ int gs_pair(PSERVER_DATA server, char* pin) { RAND_bytes(salt_data, 16); bytes_to_hex(salt_data, salt_hex, 16); - sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&phrase=getservercert&salt=%s&clientcert=%s", server->address, unique_id, salt_hex, cert_hex); + uuid_generate_random(uuid); + uuid_unparse(uuid, uuid_str); + sprintf(url, "https://%s:47984/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&phrase=getservercert&salt=%s&clientcert=%s", server->address, unique_id, uuid_str, salt_hex, cert_hex); PHTTP_DATA data = http_create_data(); if (data == NULL) return GS_OUT_OF_MEMORY; @@ -325,7 +335,9 @@ int gs_pair(PSERVER_DATA server, char* pin) { AES_encrypt(challenge_data, challenge_enc, &aes_key); bytes_to_hex(challenge_enc, challenge_hex, 16); - sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&clientchallenge=%s", server->address, unique_id, challenge_hex); + uuid_generate_random(uuid); + uuid_unparse(uuid, uuid_str); + sprintf(url, "https://%s:47984/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&clientchallenge=%s", server->address, unique_id, uuid_str, challenge_hex); if ((ret = http_request(url, data)) != GS_OK) goto cleanup; @@ -363,7 +375,9 @@ int gs_pair(PSERVER_DATA server, char* pin) { } bytes_to_hex(challenge_response_hash_enc, challenge_response_hex, 32); - sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&serverchallengeresp=%s", server->address, unique_id, challenge_response_hex); + uuid_generate_random(uuid); + uuid_unparse(uuid, uuid_str); + sprintf(url, "https://%s:47984/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&serverchallengeresp=%s", server->address, unique_id, uuid_str, challenge_response_hex); if ((ret = http_request(url, data)) != GS_OK) goto cleanup; @@ -386,11 +400,15 @@ int gs_pair(PSERVER_DATA server, char* pin) { memcpy(client_pairing_secret + 16, signature, 256); bytes_to_hex(client_pairing_secret, client_pairing_secret_hex, 16 + 256); - sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&clientpairingsecret=%s", server->address, unique_id, client_pairing_secret_hex); + uuid_generate_random(uuid); + uuid_unparse(uuid, uuid_str); + sprintf(url, "https://%s:47984/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&clientpairingsecret=%s", server->address, unique_id, uuid_str, client_pairing_secret_hex); if ((ret = http_request(url, data)) != GS_OK) goto cleanup; - sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&phrase=pairchallenge", server->address, unique_id); + uuid_generate_random(uuid); + uuid_unparse(uuid, uuid_str); + sprintf(url, "https://%s:47984/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&phrase=pairchallenge", server->address, unique_id, uuid_str); if ((ret = http_request(url, data)) != GS_OK) goto cleanup; @@ -405,11 +423,15 @@ int gs_pair(PSERVER_DATA server, char* pin) { int gs_applist(PSERVER_DATA server, PAPP_LIST *list) { int ret = GS_OK; char url[4096]; + uuid_t uuid; + char uuid_str[37]; PHTTP_DATA data = http_create_data(); if (data == NULL) return GS_OUT_OF_MEMORY; - sprintf(url, "https://%s:47984/applist?uniqueid=%s", server->address, unique_id); + uuid_generate_random(uuid); + uuid_unparse(uuid, uuid_str); + sprintf(url, "https://%s:47984/applist?uniqueid=%s&uuid=%s", server->address, unique_id, uuid_str); if (http_request(url, data) != GS_OK) ret = GS_IO_ERROR; else if (xml_applist(data->memory, data->size, list) != GS_OK) @@ -420,6 +442,9 @@ int gs_applist(PSERVER_DATA server, PAPP_LIST *list) { } int gs_start_app(PSERVER_DATA server, STREAM_CONFIGURATION *config, int appId, bool sops, bool localaudio) { + uuid_t uuid; + char uuid_str[37]; + RAND_bytes(config->remoteInputAesKey, 16); memset(config->remoteInputAesIv, 0, 16); @@ -433,12 +458,14 @@ int gs_start_app(PSERVER_DATA server, STREAM_CONFIGURATION *config, int appId, b if (data == NULL) return GS_OUT_OF_MEMORY; + uuid_generate_random(uuid); + uuid_unparse(uuid, uuid_str); if (server->currentGame == 0) { int channelCounnt = config->audioConfiguration == AUDIO_CONFIGURATION_STEREO ? CHANNEL_COUNT_STEREO : CHANNEL_COUNT_51_SURROUND; int mask = config->audioConfiguration == AUDIO_CONFIGURATION_STEREO ? CHANNEL_MASK_STEREO : CHANNEL_MASK_51_SURROUND; - sprintf(url, "https://%s:47984/launch?uniqueid=%s&appid=%d&mode=%dx%dx%d&additionalStates=1&sops=%d&rikey=%s&rikeyid=%d&localAudioPlayMode=%d&surroundAudioInfo=%d", server->address, unique_id, appId, config->width, config->height, config->fps, sops, rikey_hex, rikeyid, localaudio, (mask << 16) + channelCounnt); + sprintf(url, "https://%s:47984/launch?uniqueid=%s&uuid=%s&appid=%d&mode=%dx%dx%d&additionalStates=1&sops=%d&rikey=%s&rikeyid=%d&localAudioPlayMode=%d&surroundAudioInfo=%d", server->address, unique_id, uuid_str, appId, config->width, config->height, config->fps, sops, rikey_hex, rikeyid, localaudio, (mask << 16) + channelCounnt); } else - sprintf(url, "https://%s:47984/resume?uniqueid=%s&rikey=%s&rikeyid=%d", server->address, unique_id, rikey_hex, rikeyid); + sprintf(url, "https://%s:47984/resume?uniqueid=%s&uuid=%s&rikey=%s&rikeyid=%d", server->address, unique_id, uuid_str, rikey_hex, rikeyid); int ret = http_request(url, data); if (ret == GS_OK) @@ -450,11 +477,15 @@ int gs_start_app(PSERVER_DATA server, STREAM_CONFIGURATION *config, int appId, b int gs_quit_app(PSERVER_DATA server) { char url[4096]; + uuid_t uuid; + char uuid_str[37]; PHTTP_DATA data = http_create_data(); if (data == NULL) return GS_OUT_OF_MEMORY; - sprintf(url, "https://%s:47984/cancel?uniqueid=%s", server->address, unique_id); + uuid_generate_random(uuid); + uuid_unparse(uuid, uuid_str); + sprintf(url, "https://%s:47984/cancel?uniqueid=%s&uuid=%s", server->address, unique_id, uuid_str); int ret = http_request(url, data); http_free_data(data);