Now works on mac, small build change for that

Plus does nothing for linux, but there's a comment.
This commit is contained in:
David Kelly 2016-12-05 11:11:30 -08:00
parent 643353a31e
commit 54716f70e5
3 changed files with 39 additions and 14 deletions

View file

@ -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})

View file

@ -12,8 +12,34 @@
#include "FingerprintUtils.h"
#include <QDebug>
#ifdef Q_OS_WIN
#include <comdef.h>
#include <Wbemidl.h>
#endif //Q_OS_WIN
#ifdef Q_OS_MAC
#include <IOKit/IOBSD.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/storage/IOMedia.h>
#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;
}

View file

@ -14,10 +14,6 @@
#include <QString>
#ifdef Q_OS_WIN
#include <comdef.h>
#include <Wbemidl.h>
#endif //Q_OS_WIN
class FingerprintUtils {
public: