代码之家  ›  专栏  ›  技术社区  ›  bpapa

验证iPhone设备ID?

  •  9
  • bpapa  · 技术社区  · 16 年前

    6 回复  |  直到 16 年前
        1
  •  7
  •   Shay Erlichmen    15 年前

    如果有一种方法可以验证Id,那么就有一种方法可以创建一个真实的假Id。


    我同意泰勒的意见,有一种方法可以创建id(简单)和验证id(也很简单),但创建“假”id需要扫描整个密钥空间(硬)或窃取生成密钥的私钥(TLS实际上就是这样工作的)。 我最初的一些评论是无效的。

    尽管如此,苹果设备Id不是这样工作的,因为他们从硬件的不同Id值(例如MAC地址)生成Id

        2
  •  6
  •   baalexander    16 年前

    要验证来自应用程序的请求,您可以发送UUID和散列,其中散列=SHA1(UUID+密钥存储在应用程序中)。然后在服务器端执行相同的哈希函数,并验证它们是否匹配。您可以将时间戳添加为nonce,在其中发送UUID、timestamp、hash,hash=SHA1(UUID+SECRET\u KEY\u存储在\u APP+timestamp中)。

    这当然不是防失败的,并且有很多限制,但这是否会使欺骗UUID变得更加困难。

        3
  •  2
  •   mr_marc    14 年前

    作为对Martin Gorton的回应,第三方库不能信任UIDevice uniqueIdentifier——使用Objective C方法swizzling欺骗它是微不足道的。

    下面是来自的一些示例代码 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);
            }
    
        4
  •  0
  •   Durai Amuthan.H    11 年前

    没有apple文档或规范指定此字符串的布局。

    一个有根据的猜测是,它们的长度为40个字符,由字母数字字符组成。(a-f0-9)

    正则表达式模式:

    [a-z0-9]{40}
    
        5
  •  -1
  •   Martin Gordon    16 年前

    如果你直接使用 [[UIDevice currentDevice] uniqueIdentifier] 没有理由不提示用户输入合法的设备ID。

        6
  •  -1
  •   Community CDub    8 年前

    ^([A-F0-9]{40})$ 或者你可以去 here and just paste it .

    如果您正在使用 [[UIDevice currentDevice].identifierForVendor UUIDString] (你应该这么做)-那么它只是一个guid,对吗 a look at this 正则表达式是( ^([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})$ ) 或者你可以 paste it here .

    希望这能为您节省一些时间。