From 54716f70e5194feeb84d6357fdecdccaa1baf7d8 Mon Sep 17 00:00:00 2001 From: David Kelly Date: Mon, 5 Dec 2016 11:11:30 -0800 Subject: [PATCH] Now works on mac, small build change for that Plus does nothing for linux, but there's a comment. --- libraries/networking/CMakeLists.txt | 9 +++++ libraries/networking/src/FingerprintUtils.cpp | 40 ++++++++++++++----- libraries/networking/src/FingerprintUtils.h | 4 -- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/libraries/networking/CMakeLists.txt b/libraries/networking/CMakeLists.txt index 53ebb86b83..8ef67cb2a4 100644 --- a/libraries/networking/CMakeLists.txt +++ b/libraries/networking/CMakeLists.txt @@ -15,6 +15,10 @@ add_dependency_external_projects(tbb) find_package(OpenSSL REQUIRED) find_package(TBB REQUIRED) +if (APPLE) + find_library(FRAMEWORK_IOKIT IOKit) +endif () + if (APPLE AND ${OPENSSL_INCLUDE_DIR} STREQUAL "/usr/include") # this is a user on OS X using system OpenSSL, which is going to throw warnings since they're deprecating for their common crypto message(WARNING "The found version of OpenSSL is the OS X system version. This will produce deprecation warnings." @@ -26,6 +30,11 @@ include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}") # append OpenSSL to our list of libraries to link target_link_libraries(${TARGET_NAME} ${OPENSSL_LIBRARIES} ${TBB_LIBRARIES}) +# IOKit is needed for getting machine fingerprint +if (APPLE) + target_link_libraries(${TARGET_NAME} ${FRAMEWORK_IOKIT}) +endif (APPLE) + # libcrypto uses dlopen in libdl if (UNIX) target_link_libraries(${TARGET_NAME} ${CMAKE_DL_LIBS}) diff --git a/libraries/networking/src/FingerprintUtils.cpp b/libraries/networking/src/FingerprintUtils.cpp index 6aa35dd2b6..7f18ccd276 100644 --- a/libraries/networking/src/FingerprintUtils.cpp +++ b/libraries/networking/src/FingerprintUtils.cpp @@ -12,8 +12,34 @@ #include "FingerprintUtils.h" #include +#ifdef Q_OS_WIN +#include +#include +#endif //Q_OS_WIN + +#ifdef Q_OS_MAC +#include +#include +#include +#endif //Q_OS_MAC + QString FingerprintUtils::getMachineFingerprint() { QString retval; + +#ifdef Q_OS_LINUX + // sadly need to be root to get smbios guid from linux, so + // for now lets do nothing. +#endif //Q_OS_LINUX + +#ifdef Q_OS_MAC + io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/"); + CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); + IOObjectRelease(ioRegistryRoot); + retval = QString::fromCFString(uuidCf); + CFRelease(uuidCf); + qDebug() << "Mac serial number: " << retval; +#endif //Q_OS_MAC + #ifdef Q_OS_WIN HRESULT hres; IWbemLocator *pLoc = NULL; @@ -125,16 +151,10 @@ QString FingerprintUtils::getMachineFingerprint() { qDebug() << "Windows BIOS UUID: " << retval; #endif //Q_OS_WIN -#ifdef Q_OS_MAC - - io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/"); - CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); - IOObjectRelease(ioRegistryRoot); - retval = QString::fromCFString(uuidCf); - CFRelease(uuidCf); - qDebug() << "Mac serial number: " << retval; -#endif //Q_OS_MAC - + // TODO: should we have a fallback for cases where this failed, + // leaving us with an empty string or something that isn't a + // guid? For now keeping this a string, but maybe best to return + // a QUuid? return retval; } diff --git a/libraries/networking/src/FingerprintUtils.h b/libraries/networking/src/FingerprintUtils.h index 84a94f0abc..cad198789c 100644 --- a/libraries/networking/src/FingerprintUtils.h +++ b/libraries/networking/src/FingerprintUtils.h @@ -14,10 +14,6 @@ #include -#ifdef Q_OS_WIN -#include -#include -#endif //Q_OS_WIN class FingerprintUtils { public: