Skip to content

Commit

Permalink
Fix race condition when setting up client https connection akka#20228
Browse files Browse the repository at this point in the history
  • Loading branch information
markvandertol committed Apr 5, 2016
1 parent 770c216 commit 993d4e1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions akka-stream/src/main/scala/akka/stream/impl/io/TLSActor.scala
Expand Up @@ -165,6 +165,22 @@ private[akka] class TLSActor(settings: ActorMaterializerSettings,
params.setServerNames(Collections.singletonList(serverName))
}

private def cloneSSLParameters(parameters: SSLParameters): SSLParameters = {
val clone = new SSLParameters()

clone.setCipherSuites(parameters.getCipherSuites)
clone.setProtocols(parameters.getProtocols)
clone.setWantClientAuth(parameters.getWantClientAuth)
clone.setNeedClientAuth(parameters.getNeedClientAuth)
clone.setEndpointIdentificationAlgorithm(parameters.getEndpointIdentificationAlgorithm)
clone.setAlgorithmConstraints(parameters.getAlgorithmConstraints)
clone.setServerNames(parameters.getServerNames)
clone.setSNIMatchers(parameters.getSNIMatchers)
clone.setUseCipherSuitesOrder(parameters.getUseCipherSuitesOrder)

clone
}

var currentSession = engine.getSession
applySessionParameters(firstSession)

Expand All @@ -178,8 +194,10 @@ private[akka] class TLSActor(settings: ActorMaterializerSettings,
case _ // do nothing
}
params.sslParameters foreach { p
hostInfo foreach { case (host, _) applySNI(host, p) }
engine.setSSLParameters(p)
//first copy the mutable SLLParameters before modifying to prevent race condition
val parameters = cloneSSLParameters(p)
hostInfo foreach { case (host, _) applySNI(host, parameters) }
engine.setSSLParameters(parameters)
}

engine.beginHandshake()
Expand Down

0 comments on commit 993d4e1

Please sign in to comment.