Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: TLSSocket options not initialized #2614

Closed

Conversation

jhamhader
Copy link
Contributor

Upon creating a TLSSocket object without options, default options will be used, which
set the socket as isServer: false
Updated tls docs and added test-tls-socket-default-options

See issue #2394

@targos targos added the tls Issues and PRs related to the tls subsystem. label Aug 29, 2015
@@ -460,7 +460,7 @@ Construct a new TLSSocket object from existing TCP socket.
- `secureContext`: An optional TLS context object from
`tls.createSecureContext( ... )`

- `isServer`: If true - TLS socket will be instantiated in server-mode
- `isServer`: If true - TLS socket will be instantiated in server-mode. Default: `false`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The true here should include backticks also for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@thefourtheye
Copy link
Contributor

If isServer is not set explicitly then it will be undefined. Does the code really check if the value is false anywhere?

Edit: I see that the code relies only on the truthiness/falsiness of isServer.

@indutny
Copy link
Member

indutny commented Sep 24, 2015

cc @nodejs/crypto

@@ -228,7 +228,7 @@ function initRead(tls, wrapped) {
*/

function TLSSocket(socket, options) {
this._tlsOptions = options;
this._tlsOptions = options || { isServer: false };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this can possibly suffice. There are also context and various other things that needs to be specified. It can't be possible to omit them, so I don't think that there is any point in providing this default values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you would like to make isServer false by default - let's do it explicitly!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make isServer: false by default (set to false if options is undefined or options.isServer is undefined).
Regarding the context - TLS API says the rest of the options (besides isServer) are optional and seems like _wrapHandle() creates a secureContext if such is not provided.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... sorry then!

@jhamhader
Copy link
Contributor Author

  • Changed isServer to be false by default
  • Updated test to include two kinds of arguments of TLSSocket()

@jhamhader
Copy link
Contributor Author

@indutny can you confirm?

@indutny
Copy link
Member

indutny commented Oct 13, 2015

Why is it needed? Would it be enough to do !!isServer when passing it to the C++ layer?

@jhamhader
Copy link
Contributor Author

Well, it is not only passed to the C++ layer - it is also used extensively in _tls_wrap.js.
Instead of the current change, we could do in TLSSocket():

this._tlsOptions.isServer = !!options.isServer

but initializing this value with a default boolean (in either way) seems like a harmless and safe thing to do.

@indutny
Copy link
Member

indutny commented Oct 18, 2015

@jhamhader It feels like doing !! in one place is simpler.

@jhamhader
Copy link
Contributor Author

Done


- `secureContext`: An optional TLS context object from
`tls.createSecureContext( ... )`

- `isServer`: If true - TLS socket will be instantiated in server-mode
- `isServer`: If `true` - TLS socket will be instantiated in server-mode. Default: `false`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this over 80 column limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the thorough review. Fixed that

Upon creating a TLSSocket object, set the default isServer option to false
Updated tls docs and added test-tls-socket-default-options
@indutny
Copy link
Member

indutny commented Oct 20, 2015

LGTM

@indutny
Copy link
Member

indutny commented Oct 20, 2015

@indutny
Copy link
Member

indutny commented Oct 20, 2015

Landed in adfd20b, thank you!

@indutny indutny closed this Oct 20, 2015
indutny pushed a commit that referenced this pull request Oct 20, 2015
Upon creating a TLSSocket object, set the default isServer option to false
Updated tls docs and added test-tls-socket-default-options

PR-URL: #2614
Reviewed-By: Fedor Indutny <[email protected]>
rvagg pushed a commit that referenced this pull request Oct 21, 2015
Upon creating a TLSSocket object, set the default isServer option to false
Updated tls docs and added test-tls-socket-default-options

PR-URL: #2614
Reviewed-By: Fedor Indutny <[email protected]>
@rvagg rvagg mentioned this pull request Oct 21, 2015
@MylesBorins
Copy link
Contributor

LTS?

@MylesBorins
Copy link
Contributor

/cc @jasnell

jasnell pushed a commit to jasnell/node that referenced this pull request Oct 26, 2015
Upon creating a TLSSocket object, set the default isServer option to false
Updated tls docs and added test-tls-socket-default-options

PR-URL: nodejs#2614
Reviewed-By: Fedor Indutny <[email protected]>
@jasnell
Copy link
Member

jasnell commented Oct 26, 2015

Landed in v4.x-staging in 590378c

jasnell pushed a commit that referenced this pull request Oct 26, 2015
Upon creating a TLSSocket object, set the default isServer option to false
Updated tls docs and added test-tls-socket-default-options

PR-URL: #2614
Reviewed-By: Fedor Indutny <[email protected]>
jasnell pushed a commit that referenced this pull request Oct 29, 2015
Upon creating a TLSSocket object, set the default isServer option to false
Updated tls docs and added test-tls-socket-default-options

PR-URL: #2614
Reviewed-By: Fedor Indutny <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants