Created
August 24, 2017 11:27
-
-
Save s1monw1/6945c9613362cdf56adc24ede544db2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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