Skip to content

Instantly share code, notes, and snippets.

@anilgursel
Last active November 23, 2016 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anilgursel/bf53aa66f73ebfc2897bb107b8d24330 to your computer and use it in GitHub Desktop.
Save anilgursel/bf53aa66f73ebfc2897bb107b8d24330 to your computer and use it in GitHub Desktop.
Akka Http SSL Configuration

I have some confusion around how SSL settings are configured. By looking through the code, here is what I see happening:

Here is the API for ConnectionContext:

object ConnectionContext {
  //#https-context-creation
  // ConnectionContext
  def https(
    sslContext:          SSLContext,
    sslConfig:           Option[AkkaSSLConfig]         = None,
    enabledCipherSuites: Option[immutable.Seq[String]] = None,
    enabledProtocols:    Option[immutable.Seq[String]] = None,
    clientAuth:          Option[TLSClientAuth]         = None,
    sslParameters:       Option[SSLParameters]         = None) =
    new HttpsConnectionContext(sslContext, sslConfig, enabledCipherSuites, enabledProtocols, clientAuth, sslParameters)
  //#https-context-creation

  // for binary-compatibility, since 2.4.7
  def https(
    sslContext:          SSLContext,
    enabledCipherSuites: Option[immutable.Seq[String]],
    enabledProtocols:    Option[immutable.Seq[String]],
    clientAuth:          Option[TLSClientAuth],
    sslParameters:       Option[SSLParameters]) =
    new HttpsConnectionContext(sslContext, None, enabledCipherSuites, enabledProtocols, clientAuth, sslParameters)

  def noEncryption() = HttpConnectionContext
}

So, it looks like, the parameters of ConnectionContext.https are already in order of configuration override. To summarize, here is what seems to be happennig to find out the ultimate value of cipherSuites, for instance:

  • If cipherSuites is defined in sslParameters, that's the ultimate value. If not, go to next step.
  • If enabledCipherSuites parameter is not None, that's the ultimate value. If not, go to next step.
  • If sslConfig is None, use the singleton AkkaSSLConfig.
    • Create an SSLContext. If sslConfig.default is true, create from JVM default; otherwise from the configuration in sslConfig.
    • Get the enabledCipherSuites from SSLContext. Go to next step.
    • If sslConfig.enabledCipherSuites is not None, filter/order enabledCipherSuites from SSLContext accordingly, and this is the ultimate value. If not, go to the next step.
    • Filter/order enabledCipherSuites from SSLContext based on default recommended ciphers in Ciphers.recommendedCiphers of Typesafe SSLConfig project.

This many layers of configuration and fallback is quite confusing to me.

I probably miss something to understand the reasoning behind this. I will appreciate if you can please explain. Or is this issue filed to simplify it overall?

@akara
Copy link

akara commented Nov 23, 2016

I think this is a good way of summarizing it. There seems to be so many places doing the same thing, for instance the enabledCipherSuites to be configured. It is very confusing what takes precedence, until we invest the time into tracing down the code. Thanks!

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