| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/ios/device_util.h" | 5 #include "base/ios/device_util.h" |
| 6 | 6 |
| 7 #include <CommonCrypto/CommonDigest.h> | 7 #include <CommonCrypto/CommonDigest.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include <ifaddrs.h> | 10 #include <ifaddrs.h> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 // Try to migrate from legacy client id. | 40 // Try to migrate from legacy client id. |
| 41 NSString* client_id = [defaults stringForKey:kLegacyClientIdPreferenceKey]; | 41 NSString* client_id = [defaults stringForKey:kLegacyClientIdPreferenceKey]; |
| 42 | 42 |
| 43 // Some iOS6 devices return a buggy identifierForVendor: | 43 // Some iOS6 devices return a buggy identifierForVendor: |
| 44 // http://openradar.appspot.com/12377282. If this is the case, revert to | 44 // http://openradar.appspot.com/12377282. If this is the case, revert to |
| 45 // generating a new one. | 45 // generating a new one. |
| 46 if (!client_id || [client_id isEqualToString:kZeroUUID]) { | 46 if (!client_id || [client_id isEqualToString:kZeroUUID]) { |
| 47 if (base::ios::IsRunningOnIOS6OrLater()) { | 47 if (base::ios::IsRunningOnIOS6OrLater()) { |
| 48 client_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; | 48 client_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; |
| 49 if (!client_id || [client_id isEqualToString:kZeroUUID]) | 49 if ([client_id isEqualToString:kZeroUUID]) |
| 50 client_id = base::SysUTF8ToNSString(ios::device_util::GetRandomId()); | 50 client_id = base::SysUTF8ToNSString(ios::device_util::GetRandomId()); |
| 51 } else { | 51 } else { |
| 52 client_id = base::SysUTF8ToNSString(ios::device_util::GetRandomId()); | 52 client_id = base::SysUTF8ToNSString(ios::device_util::GetRandomId()); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 return client_id; | 55 return client_id; |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 [defaults setObject:current_hardware forKey:kHardwareTypePreferenceKey]; | 156 [defaults setObject:current_hardware forKey:kHardwareTypePreferenceKey]; |
| 157 [defaults synchronize]; | 157 [defaults synchronize]; |
| 158 } | 158 } |
| 159 | 159 |
| 160 return GetSaltedString(base::SysNSStringToUTF8(client_id), | 160 return GetSaltedString(base::SysNSStringToUTF8(client_id), |
| 161 salt ? salt : kDefaultSalt); | 161 salt ? salt : kDefaultSalt); |
| 162 } | 162 } |
| 163 | 163 |
| 164 std::string GetSaltedString(const std::string& in_string, | 164 std::string GetSaltedString(const std::string& in_string, |
| 165 const std::string& salt) { | 165 const std::string& salt) { |
| 166 DCHECK(in_string.length()); | |
| 167 DCHECK(salt.length()); | 166 DCHECK(salt.length()); |
| 168 NSData* hash_data = [base::SysUTF8ToNSString(in_string + salt) | 167 NSData* hash_data = [base::SysUTF8ToNSString(in_string + salt) |
| 169 dataUsingEncoding:NSUTF8StringEncoding]; | 168 dataUsingEncoding:NSUTF8StringEncoding]; |
| 170 | 169 |
| 171 unsigned char hash[CC_SHA256_DIGEST_LENGTH]; | 170 unsigned char hash[CC_SHA256_DIGEST_LENGTH]; |
| 172 CC_SHA256([hash_data bytes], [hash_data length], hash); | 171 CC_SHA256([hash_data bytes], [hash_data length], hash); |
| 173 CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash); | 172 CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash); |
| 174 | 173 |
| 175 base::ScopedCFTypeRef<CFUUIDRef> uuid_object( | 174 base::ScopedCFTypeRef<CFUUIDRef> uuid_object( |
| 176 CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes)); | 175 CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes)); |
| 177 base::ScopedCFTypeRef<CFStringRef> device_id( | 176 base::ScopedCFTypeRef<CFStringRef> device_id( |
| 178 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); | 177 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); |
| 179 return base::SysCFStringRefToUTF8(device_id); | 178 return base::SysCFStringRefToUTF8(device_id); |
| 180 } | 179 } |
| 181 | 180 |
| 182 } // namespace device_util | 181 } // namespace device_util |
| 183 } // namespace ios | 182 } // namespace ios |
| OLD | NEW |