简体   繁体   English

iOS:SocketRocket-如何实现SSL握手

[英]iOS: SocketRocket - How to implement SSL Handshake

just switched to Websockets in combination with Protobufs. 刚与Protobufs一起切换到Websockets。 Works like a charm on IOS but I am not sure how to implement SSL Handshake (like with NSURLConnection) via SocketRocket Lib. 在IOS上像魅惑一样工作,但是我不确定如何通过SocketRocket Lib实现SSL握手(与NSURLConnection一样)。 Has someone experience with that or is it just not yet supported. 有经验的人吗?还是不被支持。

TSL connection is already working and SSL pinning would also work - but how to implement the correct SSL handshake by validating the SSL chain correctly with web sockets via SocketRocket?! TSL连接已经可以使用,并且SSL固定也可以使用-但是如何通过SocketRocket通过Web套接字正确验证SSL链来实现正确的SSL握手?

BR BR

EDIT: Correcting error in my previous answer. 编辑:更正我以前的答案中的错误。

CFStream which is what Socket Rocket uses in the background will handle the handshake automatically assuming the certificate has been added to the keychain. 假设已将证书添加到钥匙串中,Socket Rocket在后台使用的CFStream将自动处理握手。 If you need to add a certificate, see answer to this question: iOS: Pre install SSL certificate in keychain - programmatically 如果您需要添加证书,请参见以下问题的答案: iOS:以编程方式在钥匙串中预安装SSL证书

If however, Pinning is what you are looking for, this is straightforward to do with Socket Rocket. 但是,如果您要寻找Pinning,那么直接使用Socket Rocket即可。 Use the initWithURLRequest initializer and everything else is handled automatically. 使用initWithURLRequest初始化程序,其他所有操作都会自动处理。 For pinned certificates, SocketRocket does not validate the certificate chain which is the behavior you want, because with pinning you are specifically saying trust this certificate or certificate signed by this certificate only. 对于固定的证书,SocketRocket不会验证您想要的行为的证书链,因为使用固定,您是在专门说信任此证书或仅由此证书签名的证书。 ie it does not rely on validating a chain. 即它不依赖于验证链。

    NSURL *url = [NSURL URLWithString: ServerSocketURLString];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"certificatefilename" ofType:@"cer"];
    NSData *certData = [[NSData alloc] initWithContentsOfFile:cerPath];
    CFDataRef certDataRef = (__bridge CFDataRef)certData;
    SecCertificateRef certRef = SecCertificateCreateWithData(NULL, certDataRef);
    id certificate = (__bridge id)certRef;

    [request setSR_SSLPinnedCertificates:@[certificate]];

    self.clientWebSocket = [[SRWebSocket alloc] initWithURLRequest:request];

    self.clientWebSocket.delegate = self;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM