zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

Redesign SSL for Server

Open tusharmath opened this issue 2 years ago • 5 comments

Is your feature request related to a problem? Please describe. The current SSL API isn't inline with the rest of ZIO Http. It's a bit awkward to use, specially if you are a beginner.

Describe the solution you'd like Re-look at how HTTPs server is created. There should just be a one line configuration to enable SSL, which starts with some default certificates / keys etc. Customization should be allowed but not necessary.

Additional context Design of SSL module isn't such that it can be tested easily and the existing tests are also a bit flaky.

tusharmath avatar Sep 14 '22 02:09 tusharmath

I suggest pure data as a representation for the SSL configuration, having both options to load the SSL key / certs from resources (local file, resource, etc.), as well as options to pass it directly ("in memory", having already been loaded from, e.g., a secret server), and options to generate fresh keys & self-certify (for testing / developer-mode).

Something like:

sealed trait SSLConfig
object SSLConfig {
  sealed trait SSLProvider
  object SSLProvider { .. }

  /** A new public/private key pair will be generated and self-signed: */
  case object Generate extends SSLConfig 
  final case class FromFile(certPath: String, keyPath: String) extends SSLConfig
  final case class FromResource(certPath: String, keyPath: String) extends SSLConfig 
  ...
}

Then this pure data which is independent of JVM / Netty can be placed into ServerConfig as Option[SSLConfig], and SSL will be turned on if and only if such SSL Config is present.

jdegoes avatar Sep 15 '22 15:09 jdegoes

I'll take this one

ghidei avatar Sep 16 '22 09:09 ghidei

@ghidei Thank you!

Generating a key pair and self-signing (for SSLConfig.Generate) is a bit painful due to API design and best searching on Stack Overflow or elsewhere for pre-canned answers.

image

jdegoes avatar Sep 16 '22 10:09 jdegoes

Thanks! I'm a proud owner of that book already, so I'll look it up :)

ghidei avatar Sep 16 '22 13:09 ghidei

Refactorings done/in progress: https://github.com/zio/zio-http/pull/1513 https://github.com/zio/zio-http/pull/1536 https://github.com/zio/zio-http/pull/1544

Todo: Fix the flaky tests.

ghidei avatar Sep 21 '22 13:09 ghidei

Seems like this is done

vigoo avatar Jan 21 '23 13:01 vigoo