mirror of
https://github.com/corda/corda.git
synced 2024-12-29 09:18:58 +00:00
Allow SLL configuration via command line parameters too.
This commit is contained in:
parent
6705c614a8
commit
51d02e1e45
@ -26,6 +26,7 @@ import net.corda.flows.IssuerFlow.IssuanceRequester
|
|||||||
import net.corda.node.driver.PortAllocation
|
import net.corda.node.driver.PortAllocation
|
||||||
import net.corda.node.driver.driver
|
import net.corda.node.driver.driver
|
||||||
import net.corda.node.services.User
|
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.messaging.ArtemisMessagingComponent
|
||||||
import net.corda.node.services.startFlowPermission
|
import net.corda.node.services.startFlowPermission
|
||||||
import net.corda.node.services.transactions.SimpleNotaryService
|
import net.corda.node.services.transactions.SimpleNotaryService
|
||||||
@ -34,6 +35,7 @@ import org.controlsfx.dialog.ExceptionDialog
|
|||||||
import tornadofx.App
|
import tornadofx.App
|
||||||
import tornadofx.addStageIcon
|
import tornadofx.addStageIcon
|
||||||
import tornadofx.find
|
import tornadofx.find
|
||||||
|
import java.nio.file.Paths
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,6 +66,12 @@ class Main : App(MainView::class) {
|
|||||||
|
|
||||||
if ((hostname != null) && (port != null) && (username != null) && (password != null)) {
|
if ((hostname != null) && (port != null) && (username != null) && (password != null)) {
|
||||||
try {
|
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)
|
loginView.login(hostname, port, username, password)
|
||||||
isLoggedIn = true
|
isLoggedIn = true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -80,16 +88,32 @@ class Main : App(MainView::class) {
|
|||||||
|
|
||||||
private fun asInteger(s: String?): Int? {
|
private fun asInteger(s: String?): Int? {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return s.toInt();
|
return s.toInt()
|
||||||
} catch (e: NumberFormatException) {
|
} catch (e: NumberFormatException) {
|
||||||
return null
|
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 {
|
init {
|
||||||
// Shows any uncaught exception in exception dialog.
|
// Shows any uncaught exception in exception dialog.
|
||||||
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
|
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
|
||||||
|
@ -38,6 +38,15 @@ class LoginView : View() {
|
|||||||
private val keyStorePasswordProperty by objectProperty(SettingsModel::keyStorePasswordProperty)
|
private val keyStorePasswordProperty by objectProperty(SettingsModel::keyStorePasswordProperty)
|
||||||
private val trustStorePasswordProperty by objectProperty(SettingsModel::trustStorePasswordProperty)
|
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) {
|
fun login(host: String?, port: Int, username: String, password: String) {
|
||||||
getModel<NodeMonitorModel>().register(HostAndPort.fromParts(host, port), configureSSL(), username, password)
|
getModel<NodeMonitorModel>().register(HostAndPort.fromParts(host, port), configureSSL(), username, password)
|
||||||
}
|
}
|
||||||
@ -84,11 +93,6 @@ class LoginView : View() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun configureSSL(): SSLConfiguration {
|
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.
|
// TODO : Don't use dev certificates.
|
||||||
return if (sslConfig.keyStoreFile.exists()) sslConfig else configureTestSSL().apply {
|
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.")
|
alert(Alert.AlertType.WARNING, "", "KeyStore not found in certificates directory.\nDEV certificates will be used by default.")
|
||||||
|
Loading…
Reference in New Issue
Block a user