Skip to content

Commit e57f1dc

Browse files
authored
CBL-7468: Set kCFStreamSSLPeerName when using a network interface (#3456)
When a network interface is specified, CBLWebSocket resolves the hostname to an IP, creates the socket with that IP, and builds network streams from the socket. Because the original hostname isn’t set, the TLS ClientHello omits the Server Name Indication (SNI). The fix is to set the hostname via kCFStreamSSLPeerName (the same way we did when client-side proxy is specified), ensuring SNI is included for certificate validation and compatibility with carriers/ISPs that block connections without it.
1 parent f24d7b5 commit e57f1dc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Objective-C/Internal/Replicator/CBLWebSocket.mm

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ @implementation CBLWebSocket
110110
BOOL _closing;
111111

112112
NSString* _networkInterface;
113+
BOOL _useNetworkInterface;
113114
dispatch_queue_t _socketConnectQueue;
114115

115116
CBLDNSService* _dnsService;
@@ -217,9 +218,10 @@ - (instancetype) initWithURL: (NSURL*)url
217218

218219
_sockfd = -1;
219220
_networkInterface = [context networkInterfaceForWebsocket: self];
220-
if (_networkInterface) {
221+
if (_networkInterface.length > 0) {
221222
queueName = [NSString stringWithFormat: @"%@-SocketConnect", queueName];
222223
_socketConnectQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL);
224+
_useNetworkInterface = YES;
223225
}
224226
}
225227
return self;
@@ -353,7 +355,7 @@ - (void) _connect {
353355
_connectingToProxy = (_logic.proxyType == kCBLHTTPProxy);
354356
_connectedThruProxy = NO;
355357

356-
if (_networkInterface) {
358+
if (_useNetworkInterface) {
357359
[self connectToHostWithName: _logic.directHost
358360
port: _logic.directPort
359361
networkInterface: _networkInterface];
@@ -625,8 +627,14 @@ - (void) configureTLS {
625627
_shouldCheckSSLCert = true;
626628

627629
NSMutableDictionary* settings = [NSMutableDictionary dictionary];
628-
if (_connectedThruProxy) {
629-
[settings setObject: _logic.directHost forKey: (__bridge id)kCFStreamSSLPeerName];
630+
631+
// Set the actual hostname used for certificate verification during the TLS handshake
632+
// when connecting through a proxy or a specified network interface. The hostname will
633+
// appear in the Server Name Indication (SNI) field of the TLS ClientHello message.
634+
if (_connectedThruProxy || _useNetworkInterface) {
635+
NSString* hostName = _logic.directHost;
636+
CBLLogVerbose(WebSocket, @"%@ Setting TLS peer (SNI) hostname: %@", self, hostName);
637+
[settings setObject: hostName forKey: (__bridge id)kCFStreamSSLPeerName];
630638
}
631639

632640
// Disable the default certificate validation process using system's CA certs

0 commit comments

Comments
 (0)