From e7d43983e8399ef9f95476fa0e99026f9be8a001 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sat, 5 Nov 2011 20:36:17 +0200 Subject: [PATCH] [mac] Added encryption for UDID --- platform/platform_mac.mm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/platform/platform_mac.mm b/platform/platform_mac.mm index ae406f3caa..1005472c29 100644 --- a/platform/platform_mac.mm +++ b/platform/platform_mac.mm @@ -2,6 +2,9 @@ #include "../base/logging.hpp" +#include "../coding/sha2.hpp" +#include "../coding/base64.hpp" + #include "../std/target_os.hpp" #include @@ -86,7 +89,16 @@ string Platform::UniqueClientId() const CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); IOObjectRelease(ioRegistryRoot); char buf[513]; - CFStringGetCString(uuidCf, buf, 512, kCFStringEncodingMacRoman); + CFStringGetCString(uuidCf, buf, 512, kCFStringEncodingUTF8); CFRelease(uuidCf); - return buf; + + // generate sha2 hash for UUID + string const hash = sha2::digest256(buf, false); + // xor it + size_t const offset = hash.size() / 4; + string xoredHash; + for (size_t i = 0; i < offset; ++i) + xoredHash.push_back(hash[i] ^ hash[i + offset] ^ hash[i + offset * 2] ^ hash[i + offset * 3]); + // and use base64 encoding + return base64::encode(xoredHash); }