From 3a63f0c6063b3595f83cef2b26c4786de2a6c011 Mon Sep 17 00:00:00 2001 From: Patrick Kuo Date: Fri, 28 Jul 2017 16:18:49 +0100 Subject: [PATCH] * remove x500 name validation when loading config file (#1137) * added x500 name validation in Network registration. * fix for github issue #1130 --- .../main/kotlin/net/corda/core/utilities/LegalNameValidator.kt | 2 +- .../main/kotlin/net/corda/nodeapi/config/ConfigUtilities.kt | 2 +- .../node/utilities/registration/NetworkRegistrationHelper.kt | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/utilities/LegalNameValidator.kt b/core/src/main/kotlin/net/corda/core/utilities/LegalNameValidator.kt index 9ade89dfaf..bea9a6241d 100644 --- a/core/src/main/kotlin/net/corda/core/utilities/LegalNameValidator.kt +++ b/core/src/main/kotlin/net/corda/core/utilities/LegalNameValidator.kt @@ -113,7 +113,7 @@ private class X500NameRule : Rule { private class MustHaveAtLeastTwoLettersRule : Rule { override fun validate(legalName: String) { // Try to exclude names like "/", "£", "X" etc. - require(legalName.count { it.isLetter() } >= 3) { "Illegal input legal name '$legalName'. Legal name must have at least two letters" } + require(legalName.count { it.isLetter() } >= 2) { "Illegal input legal name '$legalName'. Legal name must have at least two letters" } } } diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/config/ConfigUtilities.kt b/node-api/src/main/kotlin/net/corda/nodeapi/config/ConfigUtilities.kt index e398b76c4b..34a7bbe87e 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/config/ConfigUtilities.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/config/ConfigUtilities.kt @@ -73,7 +73,7 @@ private fun Config.getSingleValue(path: String, type: KType): Any? { Path::class -> Paths.get(getString(path)) URL::class -> URL(getString(path)) Properties::class -> getConfig(path).toProperties() - X500Name::class -> X500Name(getString(path)).apply(::validateX500Name) + X500Name::class -> X500Name(getString(path)) else -> if (typeClass.java.isEnum) { parseEnum(typeClass.java, getString(path)) } else { diff --git a/node/src/main/kotlin/net/corda/node/utilities/registration/NetworkRegistrationHelper.kt b/node/src/main/kotlin/net/corda/node/utilities/registration/NetworkRegistrationHelper.kt index dde44de66e..863bee702c 100644 --- a/node/src/main/kotlin/net/corda/node/utilities/registration/NetworkRegistrationHelper.kt +++ b/node/src/main/kotlin/net/corda/node/utilities/registration/NetworkRegistrationHelper.kt @@ -9,9 +9,9 @@ import net.corda.core.crypto.X509Utilities.CORDA_ROOT_CA import net.corda.core.crypto.cert import net.corda.core.internal.* import net.corda.core.utilities.seconds +import net.corda.core.utilities.validateX500Name import net.corda.node.services.config.NodeConfiguration import net.corda.node.utilities.* -import org.bouncycastle.cert.path.CertPath import org.bouncycastle.openssl.jcajce.JcaPEMWriter import org.bouncycastle.util.io.pem.PemObject import java.io.StringWriter @@ -39,6 +39,7 @@ class NetworkRegistrationHelper(val config: NodeConfiguration, val certService: private val privateKeyPassword = config.keyStorePassword fun buildKeystore() { + validateX500Name(config.myLegalName) config.certificatesDirectory.createDirectories() val caKeyStore = loadOrCreateKeyStore(config.nodeKeystore, keystorePassword) if (!caKeyStore.containsAlias(CORDA_CLIENT_CA)) {