title: ktor sslConnector serve/read from jar p12 pkcs12 jks keystore and mtls mutual ssl connection
body: <p>I have figured out on how to start a ktor with embeddedServer Jetty and serving https/ssl/tls using my own signed Certificate (signed by my own self-signed rootCA certificate).</p>
  <p>Now ktor sslConnector needs to have the <code>keyStorePath</code> as <code>File</code>, but I'd prefer to serve the keystore from the/a file inside the final fat jar (mainly for being able to run it inside a kubernetes cluster)</p>
  <p>Is there a way to tell ktor to take/read a resource embedded in its jar file as keyStore?</p>
  <pre class="lang-kotlin prettyprint-override"><code>    // openssl pkcs12 -export -nodes -passout pass:${keystorePW} -in &quot;domain.cert&quot; -inkey &quot;domain.key&quot; -certfile &quot;intermediateAndRootCAchain.ca&quot; -name &quot;aliasName&quot; -out &quot;webserverKeystore.p12&quot;
      val keystore: KeyStore = KeyStore.getInstance(keystoreFile, keystorePW.toCharArray())
  
      @Suppress(&quot;UNUSED_PARAMETER&quot;)
      fun doIt(args: Array&lt;String&gt;) {
          val server = embeddedServer(Jetty, applicationEngineEnvironment {
              module {
                  configureRouting()
                  configureHTTP(sslPort)
                  configureSerialization()
              }
  
              connector {
                  this.host = host // redirected to https
                  this.port = port // redirected to sslPort
              }
  
              sslConnector(keystore,
                  keyAlias = certAlias, // alias name inside keystore: keytool -v -list -keystore certs/keystore.jks
                  keyStorePassword = { keystorePW.toCharArray() },
                  privateKeyPassword = { keystorePW.toCharArray() } // somehow this is the same as keystorePW if using openssl pkcs12 -export from above
              ) {
                  this.port = sslPort
                  keyStorePath = keystoreFile
              }
          })
  
          server.start(wait = true)
      }
  </code></pre>
  <p>Is there a way to tell ktor to take/read a resource embedded in its jar file as keyStore?</p>
  <p>(also wondering why <code>sslConnector</code> still needs the keystore as <code>File</code> if it already got the whole keystore as first parameter, but that's probably to be independant from the actual web container that's being used)</p>
  <p>a second question: is it possible to enable <em><strong>mutual</strong></em> tls, so that the ktor server refuses a connection if the client cannot present a valid certificate? if yes, how would I configure that?</p>