Fixed hostname for wrapped ssl connections
@@ -58,6 +58,7 @@ static NSDictionary *protocolMapping;
}
- (JavaIoInputStream *)plainInputStream;
- (JavaIoOutputStream *)plainOutputStream;
+- (NSString *)getHostname;
@end
// An input stream that uses Apple's SSLRead.
@@ -213,6 +214,10 @@ static NSDictionary *protocolMapping;
return [super getOutputStream];
}
+- (NSString *)getHostname {
+ return [[self getInetAddress] getHostName];
+}
+
- (void)dealloc {
tearDownContext(self);
[_sslInputStream release];
@@ -397,7 +402,7 @@ static void setUpContext(ComGoogleJ2objcNetSslIosSslSocket *self) {
self->_sslContext = SSLCreateContext(nil, kSSLClientSide, kSSLStreamType);
checkStatus(SSLSetIOFuncs(self->_sslContext, SslReadCallback, SslWriteCallback));
checkStatus(SSLSetConnection(self->_sslContext, self));
- NSString *hostName = [[self getInetAddress] getHostName];
+ NSString *hostName = [self getHostname];
checkStatus(SSLSetPeerDomainName(self->_sslContext, [hostName UTF8String], [hostName length]));
SSLProtocol protocol = [protocolMapping[[self->enabledProtocols objectAtIndex:0]] intValue];
checkStatus(SSLSetProtocolVersionMin(self->_sslContext, protocol));
@@ -518,6 +523,7 @@ ComGoogleJ2objcNetSslIosSslSocket *create_ComGoogleJ2objcNetSslIosSslSocket_init
@interface WrapperSocket : ComGoogleJ2objcNetSslIosSslSocket {
@public
JavaNetSocket *underlyingSocket;
+ NSString *hostname;
BOOL autoClose;
}
@end
@@ -527,6 +533,7 @@ ComGoogleJ2objcNetSslIosSslSocket *create_ComGoogleJ2objcNetSslIosSslSocket_init
- (void)dealloc {
[super dealloc];
[underlyingSocket release];
+ [hostname release];
}
#pragma mark ComGoogleJ2objcNetSslIosSslSocket methods
@@ -548,6 +555,10 @@ ComGoogleJ2objcNetSslIosSslSocket *create_ComGoogleJ2objcNetSslIosSslSocket_init
return [underlyingSocket getOutputStream];
}
+- (NSString *)getHostname {
+ return hostname;
+}
+
#pragma mark JavaNetSocket methods
- (void)bindWithJavaNetSocketAddress:(JavaNetSocketAddress *)bindpoint {
@@ -750,6 +761,7 @@ void WrapperSocket_initWithJavaNetSocket_initWithNSString_withInt_withBoolean_(
}
init(self);
JreStrongAssign(&self->underlyingSocket, socket);
+ JreStrongAssign(&self->hostname, host);
self->autoClose = autoClose;
}
