Skip to content

autoSelectFamily: true breaks TLS #46679

Closed

Description

@addaleax

Version

v19.6.0

Platform

x64 macOS 13.2.1; x64 Ubuntu 22.04

Subsystem

tls

What steps will reproduce the bug?

const socket = tls.connect({ host: 'google.com', port: 443, servername: 'google.com', autoSelectFamily: true }); 
socket.on('secureConnect', () => (console.log('secure connect'), socket.end()))

Results in Error: self-signed certificate with autoSelectFamily: true, works with autoSelectFamily: false.

How often does it reproduce? Is there a required condition?

Consistently.

What is the expected behavior?

Same as autoSelectFamily: false / same as when specifying IP addresses directly (with servername set).

What do you see instead?

TLS certificate validation errors.

Additional information

No response

Activity

  1. added
    tlsIssues and PRs related to the tls subsystem.
    netIssues and PRs related to the net subsystem.
    on Feb 16, 2023
  2. targos commented on Feb 16, 2023

    @targos
    Member

    Also note that specifying family: 4 or family: 6 both work without error.

  3. bnoordhuis commented on Feb 17, 2023

    @bnoordhuis
    Member

    With { autoSelectFamily: true }, SSL_get_servername(TLSEXT_NAMETYPE_host_name) returns NULL.

    That is, openssl thinks there's no SNI record and therefore this line returns false instead of 'google.com':

    this.servername = this._handle.getServername();

    I noticed TLSSocket.prototype._init() gets called when autoSelectFamily is set. There's also an extra call to Socket.prototype._read() that wasn't there before. This block seems responsible.

    node/lib/net.js

    Lines 1547 to 1550 in a2bbe5f

    if (self[kWrapConnectedHandle]) {
    self[kWrapConnectedHandle](handle);
    initSocketHandle(self); // This is called again to initialize the TLSWrap
    }

    I suspect this line (possibly other init stuff as well) needs to be reapplied in TLSSocket.prototype._init(), otherwise node "forgets" relevant TLS context state:

    tlssock.setServername(options.servername);

    An interesting question is if { autoSelectFamily: true, secureContext: context } works and if not, what to do about it.

  4. mcollina commented on Feb 18, 2023

    @mcollina
    SponsorMember
  5. ShogunPanda commented on Feb 18, 2023

    @ShogunPanda
    Contributor

    Thanks! I'll take a look on Mon when I'll tackle all related problems forever.

  6. ShogunPanda commented on Feb 21, 2023

    @ShogunPanda
    Contributor

    I found the issue. This will be fixed once #46587 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.netIssues and PRs related to the net subsystem.tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions