From 51d02e1e458bd4a757fdf74c03db18e4c9bd78a9 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Thu, 2 Feb 2017 11:00:14 +0000 Subject: [PATCH] Allow SLL configuration via command line parameters too. --- .../main/kotlin/net/corda/explorer/Main.kt | 28 +++++++++++++++++-- .../net/corda/explorer/views/LoginView.kt | 14 ++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/Main.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/Main.kt index 93daf83e88..29badd9f0f 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/Main.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/Main.kt @@ -26,6 +26,7 @@ import net.corda.flows.IssuerFlow.IssuanceRequester import net.corda.node.driver.PortAllocation import net.corda.node.driver.driver import net.corda.node.services.User +import net.corda.node.services.config.SSLConfiguration import net.corda.node.services.messaging.ArtemisMessagingComponent import net.corda.node.services.startFlowPermission import net.corda.node.services.transactions.SimpleNotaryService @@ -34,6 +35,7 @@ import org.controlsfx.dialog.ExceptionDialog import tornadofx.App import tornadofx.addStageIcon import tornadofx.find +import java.nio.file.Paths import java.util.* /** @@ -64,6 +66,12 @@ class Main : App(MainView::class) { if ((hostname != null) && (port != null) && (username != null) && (password != null)) { try { + // Allow us optionally to override the SSL configuration too. + val sslConfig = getSSLConfig() + if (sslConfig != null) { + loginView.sslConfig = sslConfig + } + loginView.login(hostname, port, username, password) isLoggedIn = true } catch (e: Exception) { @@ -80,16 +88,32 @@ class Main : App(MainView::class) { private fun asInteger(s: String?): Int? { if (s == null) { - return null; + return null } try { - return s.toInt(); + return s.toInt() } catch (e: NumberFormatException) { return null } } + private fun getSSLConfig(): SSLConfiguration? { + val certificatesDir = parameters.named["certificatesDir"] + val keyStorePassword = parameters.named["keyStorePassword"] + val trustStorePassword = parameters.named["trustStorePassword"] + + return if ((certificatesDir != null) && (keyStorePassword != null) && (trustStorePassword != null)) { + object: SSLConfiguration { + override val certificatesDirectory = Paths.get(certificatesDir) + override val keyStorePassword: String = keyStorePassword + override val trustStorePassword: String = trustStorePassword + } + } else { + null + } + } + init { // Shows any uncaught exception in exception dialog. Thread.setDefaultUncaughtExceptionHandler { thread, throwable -> diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/views/LoginView.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/views/LoginView.kt index ec74a96e1b..d0fb0bbe32 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/views/LoginView.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/views/LoginView.kt @@ -38,6 +38,15 @@ class LoginView : View() { private val keyStorePasswordProperty by objectProperty(SettingsModel::keyStorePasswordProperty) private val trustStorePasswordProperty by objectProperty(SettingsModel::trustStorePasswordProperty) + private var sslConfigValue: SSLConfiguration = object : SSLConfiguration { + override val certificatesDirectory: Path get() = certificatesDir.get() + override val keyStorePassword: String get() = keyStorePasswordProperty.get() + override val trustStorePassword: String get() = trustStorePasswordProperty.get() + } + var sslConfig : SSLConfiguration + get() = sslConfigValue + set(value) { sslConfigValue = value } + fun login(host: String?, port: Int, username: String, password: String) { getModel().register(HostAndPort.fromParts(host, port), configureSSL(), username, password) } @@ -84,11 +93,6 @@ class LoginView : View() { } private fun configureSSL(): SSLConfiguration { - val sslConfig = object : SSLConfiguration { - override val certificatesDirectory: Path get() = certificatesDir.get() - override val keyStorePassword: String get() = keyStorePasswordProperty.get() - override val trustStorePassword: String get() = trustStorePasswordProperty.get() - } // TODO : Don't use dev certificates. return if (sslConfig.keyStoreFile.exists()) sslConfig else configureTestSSL().apply { alert(Alert.AlertType.WARNING, "", "KeyStore not found in certificates directory.\nDEV certificates will be used by default.")