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

Fix race condition when setting up client https connection #20228 #20243

Merged
merged 1 commit into from Apr 6, 2016

Conversation

markvandertol
Copy link
Contributor

As discussed in #20228

Fixes a race condition when multiple connections are setup simultaneously that could result in an error when setting up a https connection or sending the wrong SNI to the server.

A better fix would have been to not pass around a mutable SSLParameters object between actors, but that cannot be done without breaking the public api.

@akka-ci
Copy link

akka-ci commented Apr 6, 2016

Can one of the repo owners verify this patch?

@ktoso
Copy link
Member

ktoso commented Apr 6, 2016

OK TO TEST

@akka-ci akka-ci added the validating PR is currently being validated by Jenkins label Apr 6, 2016
@ktoso
Copy link
Member

ktoso commented Apr 6, 2016

LGTM – Thanks for the fix (and finding it in the first place)!

The better fix mentioned is tricky to pull off, I wonder if we really would be able to do it in a nice way.
On one hand, letting users set "the usual things" on SSLContext is "known territory" for many, so it's a nice api to expose; but the mutability is a pain as seen here... We'd have to otherwise expose our own immutable APIs for passing in more config, that we apply to the context in the actual Actor I guess.

clone.setUseCipherSuitesOrder(parameters.getUseCipherSuitesOrder)

clone
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be done in one go without cloning the params if hostInfo is None:

private def applySNI(params: NegotiateNewSession): Unit = for {
  sslParams <- params.sslParameters
  (hostname, _) <- hostInfo
} yield {
  //first copy the mutable SLLParameters before modifying to prevent race condition in `setServerNames`
  val clone = new SSLParameters()
  clone.setCipherSuites(sslParams.getCipherSuites)
  clone.setProtocols(sslParams.getProtocols)
  clone.setWantClientAuth(sslParams.getWantClientAuth)
  clone.setNeedClientAuth(sslParams.getNeedClientAuth)
  clone.setEndpointIdentificationAlgorithm(sslParams.getEndpointIdentificationAlgorithm)
  clone.setAlgorithmConstraints(sslParams.getAlgorithmConstraints)
  clone.setSNIMatchers(sslParams.getSNIMatchers)
  clone.setUseCipherSuitesOrder(sslParams.getUseCipherSuitesOrder)

  // apply the changes
  clone.setServerNames(Collections.singletonList(new SNIHostName(hostname)))
  engine.setSSLParameters(clone)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

setServerNames is called only once here.

Copy link
Member

Choose a reason for hiding this comment

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

I'll be touching this area in a PR in the next hour or so, will apply this idea – thanks @2Beaucoup!

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@akka-ci akka-ci added tested PR that was successfully built and tested by Jenkins and removed validating PR is currently being validated by Jenkins labels Apr 6, 2016
@akka-ci
Copy link

akka-ci commented Apr 6, 2016

Test PASSed.

@ktoso ktoso merged commit 0a1431e into akka:master Apr 6, 2016
@ktoso
Copy link
Member

ktoso commented Apr 6, 2016

Thanks again @markvandertol 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR that was successfully built and tested by Jenkins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants