在连接(到FTP,首先没有SSL)时,我运行:
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];
同样适用于iStream。这允许我通过socks5代理成功连接。 如果我继续没有setProperty:proxyDictionary ...(socks5禁用)我会告诉服务器切换到SSL,然后成功将这些设置应用到输入/输出流,从而给我一个SSL连接:
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]; <-- needs to be default or unset, then it works.
对于oStream也一样。如果我禁用socks5,所有这些都可以正常工作。如果我将其打开(第一个snippit中的第7行),则在应用SSL设置时会失去联系。
如果我不得不猜测,我认为在应用(ssl)“设置”时会失去一些属性?
请帮助:)