Cocoa NSStream works with SSL, with socks5, but not at the same time

Posted by Evan D on Stack Overflow See other posts from Stack Overflow or by Evan D
Published on 2010-04-07T20:30:40Z Indexed on 2010/04/07 20:33 UTC
Read the original article Hit count: 610

Filed under:
|
|
|

Upon connecting (to an FTP, at first without SSL) I run:

NSArray *objects = [NSArray arrayWithObjects:@"proxy.ip", [NSNumber numberWithInt:1080], NSStreamSOCKSProxyVersion5, @"user", @"pass", nil];
NSArray *keys = [NSArray arrayWithObjects:NSStreamSOCKSProxyHostKey, NSStreamSOCKSProxyPortKey, NSStreamSOCKSProxyVersionKey, NSStreamSOCKSProxyUserKey, NSStreamSOCKSProxyPasswordKey, nil];
NSDictionary *proxyDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

[iStream retain];
[iStream setDelegate:self];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[iStream setProperty:proxyDictionary forKey:NSStreamSOCKSProxyConfigurationKey];
[iStream open];

same for iStream. This allows me to connect succesfully through a socks5 proxy. If I continue without setProperty:proxyDictionary... (socks5 disabled) I would tell the server to switch to SSL, and then successfully apply these settings to the in/output streams, thus giving me a SSL connection:

NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithCapacity:1];
[settings setObject:(NSString *)NSStreamSocketSecurityLevelTLSv1 forKey:(NSString *)kCFStreamSSLLevel];
// to allow selfsigned certificates:
[settings setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsAnyRoot];
[iStream retain];   
[iStream setDelegate:self];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
CFReadStreamSetProperty((CFReadStreamRef)iStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);
[iStream setProperty:NSStreamSocketSecurityLevelTLSv1 forKey:NSStreamSocketSecurityLevelKey];

same for oStream. All of which works fine if I disable socks5. If I turn it on (line 7 in the first snippit) I lose contact when applying the SSL settings.

If I had to guess, I'd think it's losing some properties when applying (ssl) "settings"?

Please help :)

  • Evan

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about nsstream