This file contains hidden or 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
| public class TLSConfiguration { ... } | |
| public class StoreType { ... } | |
| public void connectSSL(String host, int port, | |
| TLSConfiguration tlsConfiguration) throws IOException { | |
| String tlsVersion = tlsConfiguration.getProtocol(); | |
| StoreType keystore = tlsConfiguration.getKeystore(); | |
| StoreType trustStore = tlsConfiguration.getTruststore(); | |
| try { |
This file contains hidden or 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
| fun connectSSL(host: String, port: Int, protocols: List<String>, kmConfig: Store?, tmConfig: Store?){ | |
| val context = createSSLContext(protocols, kmConfig, tmConfig) | |
| val sslSocket = context.socketFactory.createSocket(host, port) as SSLSocket | |
| sslSocket.startHandshake() | |
| } | |
| fun createSSLContext(protocols: List<String>, kmConfig: Store?, tmConfig: Store?): SSLContext { | |
| if (protocols.isEmpty()) { | |
| throw IllegalArgumentException("At least one protocol must be provided.") | |
| } | |
| return SSLContext.getInstance(protocols[0]).apply { |
This file contains hidden or 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 ProviderConfiguration { | |
| var kmConfig: Store? = null | |
| var tmConfig: Store? = null | |
| var socketConfig: SocketConfiguration? = null | |
| fun open(name: String) = Store(name) | |
| fun sockets(configInit: SocketConfiguration.() -> Unit) { | |
| this.socketConfig = SocketConfiguration().apply(configInit) | |
| } | |
| fun keyManager(store: () -> Store) { | |
| this.kmConfig = store() |
This file contains hidden or 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
| data class SocketConfiguration( | |
| var cipherSuites: List<String>? = null, var timeout: Int? = null, | |
| var clientAuth: Boolean = false) | |
| class Store(val name: String) { | |
| var algorithm: String? = null | |
| var password: CharArray? = null | |
| var fileType: String = "JKS" | |
| infix fun withPass(pass: String) = apply { | |
| password = pass.toCharArray() | |
| } |
This file contains hidden or 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(), |
This file contains hidden or 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
| val fac = socketFactory { | |
| keyManager { | |
| open("certsandstores/clientkeystore") withPass "123456" beingA "jks" | |
| } | |
| trustManager { | |
| open("certsandstores/myTruststore") withPass "123456" beingA "jks" | |
| } | |
| sockets { | |
| cipherSuites = | |
| listOf("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", |
This file contains hidden or 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
| val fac = socketFactory { | |
| trustManager { | |
| if (System.currentTimeMillis() % 2 == 0L) { | |
| open("any") withPass "123456" beingA "jks" | |
| } else { | |
| open("other") withPass "123456" beingA "jks" | |
| } | |
| } | |
| } |
This file contains hidden or 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
| buildscript { | |
| ext { | |
| kotlinVersion = '1.1.4-3' | |
| springBootVersion = '2.0.0.M4' | |
| } | |
| repositories { | |
| mavenCentral() | |
| maven { url "https://repo.spring.io/snapshot" } | |
| maven { url "https://repo.spring.io/milestone" } | |
| } |
This file contains hidden or 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
| public class MultiReturn { | |
| public static void main(String[] args) { | |
| new MultiReturn().useMulti(); | |
| } | |
| public void useMulti() { | |
| Multi multi = helper(); | |
| System.out.println("Multi with " + multi.count + " and " + multi.name); | |
| } | |
| private Multi helper() { | |
| return new Multi(2, "test"); |
This file contains hidden or 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
| fun deployVerticles() { | |
| fun deploy(verticleClassName: String) { | |
| vertx.deployVerticle(verticleClassName, opt, { deploy -> | |
| LOG.info("$verticleClassName has been deployed? ${deploy.succeeded()}") | |
| }) | |
| } | |
| deploy("ServiceVerticle") | |
| deploy("WebVerticle") | |
| } |
OlderNewer