ENT-2681: Ensure we can parse old style bridge configs. (#1529)

* ENT-2681: Ensure we can parse old style bridge configs.

* ENT-2681: Minor change

* ENT-2681: Minor change
This commit is contained in:
Viktor Kolomeyko 2018-11-02 10:45:52 +00:00 committed by GitHub
parent 8814a087ed
commit b1502c98f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 143 additions and 11 deletions

View File

@ -4,11 +4,33 @@ import net.corda.bridge.services.api.FirewallConfiguration
import net.corda.bridge.services.config.BridgeConfigHelper
import net.corda.bridge.services.config.parseAsFirewallConfiguration
import net.corda.core.internal.div
import net.corda.core.internal.exists
import net.corda.core.utilities.contextLogger
import picocli.CommandLine.Option
import java.nio.file.Path
import java.nio.file.Paths
class FirewallCmdLineOptions {
companion object {
val logger = contextLogger()
private fun Path.defaultConfigFile(): Path {
val newStyleConfig = (this / "firewall.conf")
return if (newStyleConfig.exists()) {
newStyleConfig
} else {
val oldStyleConfig = (this / "bridge.conf")
if (oldStyleConfig.exists()) {
logger.warn("Old style config 'bridge.conf' will be used. To prevent this warning in the future, please rename to 'firewall.conf'.")
oldStyleConfig
} else {
throw IllegalArgumentException("Neither new style config 'firewall.conf', nor old style 'bridge.conf' can be found")
}
}
}
}
@Option(
names = ["-b", "--base-directory"],
description = ["The firewall working directory where all the files are kept."]
@ -20,9 +42,9 @@ class FirewallCmdLineOptions {
description = ["The path to the config file. By default this is firewall.conf in the base directory."]
)
private var _configFile: Path? = null
val configFile: Path get() = _configFile ?: (baseDirectory / "firewall.conf")
fun loadConfig(): FirewallConfiguration {
val configFile = _configFile ?: baseDirectory.defaultConfigFile()
return BridgeConfigHelper.loadConfig(baseDirectory, configFile).parseAsFirewallConfiguration()
}
}

View File

@ -1,19 +1,83 @@
package net.corda.bridge.services.config
import com.typesafe.config.Config
import com.typesafe.config.ConfigRenderOptions
import net.corda.bridge.FirewallCmdLineOptions
import net.corda.bridge.services.api.*
import net.corda.core.identity.CordaX500Name
import net.corda.core.internal.div
import net.corda.core.utilities.NetworkHostAndPort
import net.corda.nodeapi.internal.ArtemisMessagingComponent
import net.corda.nodeapi.internal.config.FileBasedCertificateStoreSupplier
import net.corda.nodeapi.internal.config.MutualSslConfiguration
import net.corda.nodeapi.internal.config.SslConfiguration
import net.corda.nodeapi.internal.config.parseAs
import net.corda.nodeapi.internal.config.*
import net.corda.nodeapi.internal.protonwrapper.netty.SocksProxyConfig
import java.nio.file.Path
fun Config.parseAsFirewallConfiguration(): FirewallConfiguration = parseAs<FirewallConfigurationImpl>()
fun Config.parseAsFirewallConfiguration(): FirewallConfiguration {
return try {
parseAs<FirewallConfigurationImpl>()
} catch (ex: UnknownConfigurationKeysException) {
data class Version3BridgeConfigurationImpl(
val baseDirectory: Path,
val certificatesDirectory: Path = baseDirectory / "certificates",
val sslKeystore: Path = certificatesDirectory / "sslkeystore.jks",
val trustStoreFile: Path = certificatesDirectory / "truststore.jks",
val crlCheckSoftFail: Boolean,
val keyStorePassword: String,
val trustStorePassword: String,
val bridgeMode: FirewallMode,
val networkParametersPath: Path,
val outboundConfig: BridgeOutboundConfigurationImpl?,
val inboundConfig: BridgeInboundConfigurationImpl?,
val bridgeInnerConfig: BridgeInnerConfigurationImpl?,
val floatOuterConfig: FloatOuterConfigurationImpl?,
val haConfig: BridgeHAConfigImpl?,
val enableAMQPPacketTrace: Boolean,
val artemisReconnectionIntervalMin: Int = 5000,
val artemisReconnectionIntervalMax: Int = 60000,
val politeShutdownPeriod: Int = 1000,
val p2pConfirmationWindowSize: Int = 1048576,
val whitelistedHeaders: List<String> = ArtemisMessagingComponent.Companion.P2PMessagingHeaders.whitelistedHeaders.toList(),
val healthCheckPhrase: String? = null
) {
fun toConfig(): FirewallConfiguration {
return FirewallConfigurationImpl(
baseDirectory,
certificatesDirectory,
sslKeystore,
trustStoreFile,
crlCheckSoftFail,
keyStorePassword,
trustStorePassword,
bridgeMode,
networkParametersPath,
outboundConfig,
inboundConfig,
bridgeInnerConfig,
floatOuterConfig,
haConfig,
enableAMQPPacketTrace,
artemisReconnectionIntervalMin,
artemisReconnectionIntervalMax,
politeShutdownPeriod,
p2pConfirmationWindowSize,
whitelistedHeaders,
AuditServiceConfigurationImpl(60), // Same as `firewalldefault.conf`, new in v4
healthCheckPhrase
)
}
}
// Note: "Ignore" is needed to disregard any default properties from "firewalldefault.conf" that are not applicable to V3 configuration
val oldStyleConfig = parseAs<Version3BridgeConfigurationImpl>(UnknownConfigKeysPolicy.IGNORE::handle)
val newStyleConfig = oldStyleConfig.toConfig()
val configAsString = newStyleConfig.toConfig().root().render(ConfigRenderOptions.defaults())
FirewallCmdLineOptions.logger.warn("Old style config used. To avoid seeing this warning in the future, please upgrade to new style. " +
"New style config will look as follows:\n$configAsString")
newStyleConfig
}
}
data class BridgeSSLConfigurationImpl(private val sslKeystore: Path,
private val keyStorePassword: String,

View File

@ -4,6 +4,7 @@ import net.corda.bridge.services.api.FirewallConfiguration
import net.corda.core.crypto.Crypto.generateKeyPair
import net.corda.core.identity.CordaX500Name
import net.corda.core.internal.createDirectories
import net.corda.core.internal.div
import net.corda.core.internal.exists
import net.corda.core.node.NetworkParameters
import net.corda.core.node.NotaryInfo
@ -42,13 +43,13 @@ fun createNetworkParams(baseDirectory: Path): Int {
fun createAndLoadConfigFromResource(baseDirectory: Path, configResource: String): FirewallConfiguration {
val workspaceFolder = baseDirectory.normalize().toAbsolutePath()
workspaceFolder.createDirectories()
ConfigTest::class.java.getResourceAsStream(configResource).use {
Files.copy(it, baseDirectory / "firewall.conf")
}
val cmdLineOptions = FirewallCmdLineOptions()
cmdLineOptions.baseDirectory = workspaceFolder
val configFile = cmdLineOptions.configFile
configFile.normalize().parent?.createDirectories()
ConfigTest::class.java.getResourceAsStream(configResource).use {
Files.copy(it, configFile)
}
val config = cmdLineOptions.loadConfig()
return config
}

View File

@ -156,4 +156,12 @@ class ConfigTest {
val config = createAndLoadConfigFromResource(tempFolder.root.toPath(), configResource)
assertEquals("ISpeakAMQP!", config.healthCheckPhrase)
}
@Test
fun `Load old style config`() {
val configResource = "/net/corda/bridge/version3/bridge.conf"
val config = createAndLoadConfigFromResource(tempFolder.root.toPath(), configResource)
assertEquals("HelloCorda!", config.healthCheckPhrase)
assertEquals("proxyUser", config.outboundConfig?.socksProxyConfig?.userName)
}
}

View File

@ -0,0 +1,37 @@
//
// R3 Proprietary and Confidential
//
// Copyright (c) 2018 R3 Limited. All rights reserved.
//
// The intellectual and technical concepts contained herein are proprietary to R3 and its suppliers and are protected by trade secret law.
//
// Distribution of this file or any portion thereof via any medium without the express permission of R3 is strictly prohibited.
bridgeMode = BridgeInner
outboundConfig : {
artemisBrokerAddress = "fbantesting2-node-1:11005"
alternateArtemisBrokerAddresses = [ "10.155.0.4:11005" ]
socksProxyConfig : {
version = SOCKS5
proxyAddress = "proxy-ip.westeurope.cloudapp.azure.com:8080"
userName = "proxyUser"
password = "pwd"
}
}
bridgeInnerConfig : {
floatAddresses = ["10.155.0.12:12005", "10.155.0.10:12005"]
expectedCertificateSubject = "CN=Float Local,O=Local Only,L=London,C=GB"
customSSLConfiguration : {
keyStorePassword = "bridgepass"
trustStorePassword = "trustpass"
sslKeystore = "./bridgecerts/bridge.jks"
trustStoreFile = "./bridgecerts/trust.jks"
crlCheckSoftFail = true
}
}
haConfig {
haConnectionString = "zk://fbantesting2-zoo:2181,zk://fbantesting2-zoo:2182,zk://fbantesting2-zoo:2183"
}
networkParametersPath = network-parameters
healthCheckPhrase = "HelloCorda!"
enableAMQPPacketTrace = true