Allow SLL configuration via command line parameters too.

This commit is contained in:
Chris Rankin 2017-02-02 11:00:14 +00:00
parent 6705c614a8
commit 51d02e1e45
2 changed files with 35 additions and 7 deletions

View File

@ -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 ->

View File

@ -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<NodeMonitorModel>().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.")