Skip to content

Instantly share code, notes, and snippets.

@s1monw1
Created August 24, 2017 11:27
Show Gist options
  • Save s1monw1/6945c9613362cdf56adc24ede544db2e to your computer and use it in GitHub Desktop.
Save s1monw1/6945c9613362cdf56adc24ede544db2e to your computer and use it in GitHub Desktop.
class TLSSocketFactoryProvider(init: ProviderConfiguration.() -> Unit) {
private val config: ProviderConfiguration = ProviderConfiguration().apply(init)
fun createSocketFactory(protocols: List<String>): SSLSocketFactory = with(createSSLContext(protocols)) {
return ExtendedSSLSocketFactory(
socketFactory, protocols.toTypedArray(),
getOptionalCipherSuites() ?: socketFactory.defaultCipherSuites)
}
fun createServerSocketFactory(protocols: List<String>): SSLServerSocketFactory = with(createSSLContext(protocols)) {
return ExtendedSSLServerSocketFactory(
serverSocketFactory, protocols.toTypedArray(),
getOptionalCipherSuites() ?: serverSocketFactory.defaultCipherSuites)
}
private fun getOptionalCipherSuites() =
config.socketConfig?.cipherSuites?.toTypedArray()
private fun createSSLContext(protocols: List<String>): SSLContext {
//... already known
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment