[mac] Added encryption for UDID

This commit is contained in:
Alex Zolotarev 2011-11-05 20:36:17 +02:00 committed by Alex Zolotarev
parent a2f4f7995c
commit e7d43983e8

View file

@ -2,6 +2,9 @@
#include "../base/logging.hpp"
#include "../coding/sha2.hpp"
#include "../coding/base64.hpp"
#include "../std/target_os.hpp"
#include <IOKit/IOKitLib.h>
@ -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);
}