镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

ALPNProtocols option of TLSSocket constructor is broken. #16643

Closed

Description

@qubyte
  • Version: v8.8.1
  • Platform: Darwin sprite.local 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64
  • Subsystem: _tls_wrap.js

Documentation for the ALPNProtocols option (found here) indicates that an array of strings should be acceptable:

\\ Broken
var socket = new tls.TLSSocket(null, { ALPNProtocols: ['http/1.1'] });

However, the example above produces this error:

TypeError: Must give a Buffer as first argument
    at TLSSocket._init (_tls_wrap.js:516:9)
    at new TLSSocket (_tls_wrap.js:304:8)
    at repl:1:14
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:441:10)
    at emitOne (events.js:120:20)
    at REPLServer.emit (events.js:210:7)

From which I inferred that I had to use a buffer:

\\ Working
var buffer = Buffer.from([8, ...Buffer.from('http/1.1')]);
var socket = new tls.TLSSocket(null, { ALPNProtocols: buffer });

If this is indeed a documentation bug, I'd be happy to open a pull request. I'll take a shot at a code bug if the issue is determined to be there instead.

Activity

  1. added
    tlsIssues and PRs related to the tls subsystem.
    on Oct 31, 2017
  2. bnoordhuis commented on Oct 31, 2017

    @bnoordhuis
    Member

    It sounds like the constructor should call tls.convertALPNProtocols() and tls.convertNPNProtocols() instead of letting tls.connect() and tls.createServer() do that before passing it on to new TLSSocket().

  3. qubyte commented on Oct 31, 2017

    @qubyte
    ContributorAuthor

    I wasn't aware of these methods, thanks for the tip. I'll probably have to apply them within the TLSSocket constructor though. Do you mean these should be applied before calling the Socket constructor?

  4. addaleax commented on Oct 31, 2017

    @addaleax
    Member

    @qubyte I think it’s more like, the TLSSocket constructor should call them, not userland code.

    But for now calling them yourself should be fine as a workaround.

  5. qubyte commented on Oct 31, 2017

    @qubyte
    ContributorAuthor

    @addaleax Hmm. I think I wasn't making myself clear. I mean to call these within the TLSSocket constructor, as you say. I think we're on the same page though. Do you mind if I assign myself? It'll be a nice way to ease myself into the codebase.

  6. addaleax commented on Oct 31, 2017

    @addaleax
    Member

    @qubyte Yes, I think we’re on the same page. Go for it if you like!

  7. qubyte commented on Oct 31, 2017

    @qubyte
    ContributorAuthor

    Thanks! Looks like I can't self-assign though. Would you mind doing that for me please?

  8. removed
    good first issueIssues that are suitable for first-time contributors.
    on Oct 31, 2017
  9. apapirovski commented on Nov 4, 2017

    @apapirovski
    Contributor

    Fixed by 291ff72

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

Metadata

Metadata

Assignees

Labels

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