Skip to content

HTTP client incorrectly passes IP to SSL_set_tlsext_host_name #1161

Open
@helgoboss

Description

@helgoboss

#52118 fixes the call to X509_VERIFY_PARAM_set1_host (it uses X509_VERIFY_PARAM_set1_ip_asc instead, if we have an IP address). But it still calls SSL_set_tlsext_host_name, even if we have an IP address. This seems wrong. In fact, OpenSSL should reject this already on the client side, but because of this OpenSSL bug it doesn't. Instead, the server will be confronted with the invalid value. And depending on its standard conformance it will reject the request or accept it. Mine rejects it.

The SSL_set_tlsext_host_name problem was brought up and fixed already in PR #52707, but @mount33 couldn't seem to reproduce the practical issue later, therefore the PR was closed without merging.

This is not just of theoretical nature. I'm affected by this issue when trying to use TLS with an IP address. Here's what happens when I send a HTTP request using TLS with the host being an IP address (192.1678.178.182):

  1. My server (using Rustls, apparently a quite strict TLS implementation) detects the error during the handshake and rejects the request: [2024-03-05T10:26:43Z WARN rustls::msgs::handshake] Illegal SNI hostname received "192.168.178.182". Because Dart has fed SSL_set_tlsext_host_name with an IP address. Here is the code in Rustls which rejects the hostname.
  2. Flutter in return gives me below stacktrace.
I/flutter (23684): Connecting to URI https://192.168.178.182:39443...
E/flutter (23684): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error: 
E/flutter (23684): 	TLSV1_ALERT_DECODE_ERROR(tls_record.cc:592))
E/flutter (23684): #0      _SecureFilterImpl._handshake (dart:io-patch/secure_socket_patch.dart:99:46)
E/flutter (23684): #1      _SecureFilterImpl.handshake (dart:io-patch/secure_socket_patch.dart:143:25)
E/flutter (23684): #2      _RawSecureSocket._secureHandshake (dart:io/secure_socket.dart:920:54)
E/flutter (23684): #3      _RawSecureSocket._closeHandler (dart:io/secure_socket.dart:913:15)
E/flutter (23684): #4      _RawSecureSocket._eventDispatcher (dart:io/secure_socket.dart:856:9)
E/flutter (23684): #5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (23684): #6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (23684): #7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (23684): #8      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
E/flutter (23684): #9      _StreamController._add (dart:async/stream_controller.dart:658:7)
E/flutter (23684): #10     _StreamController.add (dart:async/stream_controller.dart:606:5)
E/flutter (23684): #11     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1943:35)
E/flutter (23684): #12     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1372:18)
E/flutter (23684): #13     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (23684): #14     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Originally posted by @helgoboss in dart-lang/sdk#49183 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions