有没有办法验证iPhone设备ID?我希望能够通过HTTP请求接受从iPhone用户提交的设备ID,并验证它们是否与合法设备绑定。
答案 0 :(得分:7)
如果这是一种验证Id的方法,那么这就是创建真假id的方法。
我同意Tyler的评论,有一种方法可以创建ID(简单)并验证它们(也很简单)但是要创建一个“假”ID需要扫描整个密钥空间(硬)或窃取私钥生成密钥(这就是TLS实际上是如何工作的)。 我的一些初步评论无效。
从来没有,这不是Apple设备Id的工作方式,AFAIK他们从硬件的各种值id生成id(例如MAC地址)
答案 1 :(得分:6)
要验证来自您的应用的请求,您可以发送UUID和散列,其中hash = SHA1(UUID + SECRET_KEY_STORED_IN_APP)。然后在服务器端执行相同的哈希函数并验证它们是否匹配。您可以将时间戳添加为nonce,您可以使用hash = SHA1(UUID + SECRET_KEY_STORED_IN_APP + TIMESTAMP)发送UUID,时间戳,哈希值。
这当然不是失败证明并且有许多限制,但它会使欺骗UUID变得更加困难。
答案 2 :(得分:2)
为了回应Martin Gorton,第三方图书馆不能信任UIDevice uniqueIdentifier-使用Objective C方法调整来欺骗它是微不足道的。
方法调配为类(UIDevice)交换两个选择器(uniqueIdentifier和spoofUniqueIdentifier)。在混合之后,对UIDevice uniqueIdentifier的后续调用将返回欺骗性UDID。这对于测试没有有效UDID的UDID密钥库非常有用。
以下是http://marccodes.posterous.com/method-swizzling-uidevice-to-spoof-udid的一些示例代码:
#import <objc/runtime.h>
// swap a class's instance method selectors, we do this to overload existing methods in category declarations
void swizzleMethodsForClass(Class c, SEL origMethodSel, SEL newMethodSel)
{
NSLog(@"swizzling %@ instance methods: %@ -> %@", NSStringFromClass(c),
NSStringFromSelector(origMethodSel), NSStringFromSelector(newMethodSel));
Method origMethod = class_getInstanceMethod(c, origMethodSel);
Method newMethod = class_getInstanceMethod(c, newMethodSel);
// check if method is inherited from superclass
if(class_addMethod(c, origMethodSel, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, newMethodSel, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
// exchange un-subclassed method
else
method_exchangeImplementations(origMethod, newMethod);
}
@interface UIDevice (SpoofUDID)
@end
#define UDID_TO_SPOOF @"e0101010d38bde8e6740011211af315301010223"
@implementation UIDevice (SpoofUDID)
// swizzle this instance method for UIDevice class
- (NSString *) spoofUniqueIdentifier
{
static NSString *spoofUDID = UDID_TO_SPOOF;
NSLog(@"spoofing %@ instead of %@", spoofUDID, [[UIDevice currentDevice]
spoofUniqueIdentifier]);
return spoofUDID;
}
@end
// call this from your app delegate
- (void) initUDID
{
NSString *UDID = [[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"this is my old udid: %@", UDID);
swizzleMethodsForClass([UIDevice class], @selector(uniqueIdentifier), @selector(spoofUniqueIdentifier));
NSString *UDID2 = [[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"this is my new udid: %@", UDID2);
}
答案 3 :(得分:0)
没有苹果文档或规范指定此字符串的布局。
AFAIK只有Apple知道哪个UDID是真实的,哪些是假的。
有根据的猜测是长度为40个字符,由字母数字字符组成。 (A-f0-9)
RegEx模式:
[a-z0-9]{40}
答案 4 :(得分:0)
验证UDID尝试关注正则表达式[[UIDevice currentDevice].identifierForVendor UUIDString]
或者你可以去here and just paste it。
如果你正在使用^([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})$
(你应该这样做) - 那么它只是一个guid,有a look at this
正则表达式是(if(isset($_FILES["img_post"]["tmp_name"]) && $_FILES["img_post"]["tmp_name"] != ''){
//uplode file
}
)
或者你可以paste it here。
希望这可以节省你一些时间。
答案 5 :(得分:-1)
如果您使用[[UIDevice currentDevice] uniqueIdentifier]
直接抓取它而不是提示用户,那么就没有理由说它不是合法的设备ID。