diff --git a/core/src/main/kotlin/net/corda/core/utilities/X500NameUtils.kt b/core/src/main/kotlin/net/corda/core/utilities/X500NameUtils.kt index d141672122..6deb1d08f5 100644 --- a/core/src/main/kotlin/net/corda/core/utilities/X500NameUtils.kt +++ b/core/src/main/kotlin/net/corda/core/utilities/X500NameUtils.kt @@ -4,7 +4,6 @@ package net.corda.core.utilities import org.bouncycastle.asn1.ASN1ObjectIdentifier import org.bouncycastle.asn1.x500.X500Name -import org.bouncycastle.asn1.x500.X500NameBuilder import org.bouncycastle.asn1.x500.style.BCStyle val X500Name.commonName: String? get() = getRDNValueString(BCStyle.CN) @@ -14,25 +13,3 @@ val X500Name.locality: String get() = getRDNValueString(BCStyle.L) ?: throw Ille val X500Name.country: String get() = getRDNValueString(BCStyle.C) ?: throw IllegalArgumentException("Malformed X500 name, country attribute (C) cannot be empty.") private fun X500Name.getRDNValueString(identifier: ASN1ObjectIdentifier): String? = getRDNs(identifier).firstOrNull()?.first?.value?.toString() - -/** - * Generate a distinguished name from the provided X500 . - * - * @param O organisation name. - * @param L locality. - * @param C county. - * @param CN common name. - * @param OU organisation unit. - * @param ST state. - */ -@JvmOverloads -fun getX500Name(O: String, L: String, C: String, CN: String? = null, OU: String? = null, ST: String? = null): X500Name { - return X500NameBuilder(BCStyle.INSTANCE).apply { - addRDN(BCStyle.C, C) - ST?.let { addRDN(BCStyle.ST, it) } - addRDN(BCStyle.L, L) - addRDN(BCStyle.O, O) - OU?.let { addRDN(BCStyle.OU, it) } - CN?.let { addRDN(BCStyle.CN, it) } - }.build() -} \ No newline at end of file diff --git a/core/src/test/kotlin/net/corda/core/crypto/CompositeKeyTests.kt b/core/src/test/kotlin/net/corda/core/crypto/CompositeKeyTests.kt index 95a3c4ff18..6bbfcd49fc 100644 --- a/core/src/test/kotlin/net/corda/core/crypto/CompositeKeyTests.kt +++ b/core/src/test/kotlin/net/corda/core/crypto/CompositeKeyTests.kt @@ -7,10 +7,10 @@ import net.corda.core.internal.div import net.corda.core.serialization.serialize import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.cert -import net.corda.core.utilities.getX500Name import net.corda.core.utilities.toBase58String import net.corda.node.utilities.* import net.corda.testing.TestDependencyInjectionBase +import net.corda.testing.getX500Name import net.corda.testing.kryoSpecific import org.junit.Rule import org.junit.Test diff --git a/core/src/test/kotlin/net/corda/core/crypto/X509NameConstraintsTest.kt b/core/src/test/kotlin/net/corda/core/crypto/X509NameConstraintsTest.kt index 09b31737d1..cdfa974011 100644 --- a/core/src/test/kotlin/net/corda/core/crypto/X509NameConstraintsTest.kt +++ b/core/src/test/kotlin/net/corda/core/crypto/X509NameConstraintsTest.kt @@ -2,8 +2,8 @@ package net.corda.core.crypto import net.corda.core.internal.toTypedArray import net.corda.core.utilities.cert -import net.corda.core.utilities.getX500Name import net.corda.node.utilities.* +import net.corda.testing.getX500Name import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.asn1.x509.GeneralName import org.bouncycastle.asn1.x509.GeneralSubtree diff --git a/experimental/src/main/kotlin/net/corda/finance/contracts/universal/PrettyPrint.kt b/experimental/src/main/kotlin/net/corda/finance/contracts/universal/PrettyPrint.kt index 0db2bfc0ef..9ae517a824 100644 --- a/experimental/src/main/kotlin/net/corda/finance/contracts/universal/PrettyPrint.kt +++ b/experimental/src/main/kotlin/net/corda/finance/contracts/universal/PrettyPrint.kt @@ -1,6 +1,5 @@ package net.corda.finance.contracts.universal -import net.corda.core.utilities.organisation import net.corda.core.crypto.toStringShort import net.corda.core.identity.Party import java.math.BigDecimal diff --git a/node/src/integration-test/kotlin/net/corda/services/messaging/P2PSecurityTest.kt b/node/src/integration-test/kotlin/net/corda/services/messaging/P2PSecurityTest.kt index e743329824..4e5d08c746 100644 --- a/node/src/integration-test/kotlin/net/corda/services/messaging/P2PSecurityTest.kt +++ b/node/src/integration-test/kotlin/net/corda/services/messaging/P2PSecurityTest.kt @@ -5,7 +5,10 @@ import net.corda.core.concurrent.CordaFuture import net.corda.core.crypto.random63BitValue import net.corda.core.identity.CordaX500Name import net.corda.core.node.NodeInfo -import net.corda.core.utilities.* +import net.corda.core.utilities.NonEmptySet +import net.corda.core.utilities.cert +import net.corda.core.utilities.getOrThrow +import net.corda.core.utilities.seconds import net.corda.node.internal.NetworkMapInfo import net.corda.node.services.config.configureWithDevSSLCertificate import net.corda.node.services.messaging.sendRequest diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index 41ef04ce39..3e1e3e53c5 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -737,8 +737,8 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, } } - val subject = certificates[0].toX509CertHolder().subject - if (subject != name.x500Name) + val subject = CordaX500Name.build(certificates[0].toX509CertHolder().subject) + if (subject != name) throw ConfigurationException("The name for $id doesn't match what's in the key store: $name vs $subject") partyKeys += keys diff --git a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt index 8bb57a35b0..88f67b0b5a 100644 --- a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt +++ b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt @@ -7,7 +7,6 @@ import net.corda.core.internal.* import net.corda.core.internal.concurrent.thenMatch import net.corda.core.node.services.ServiceInfo import net.corda.core.utilities.loggerFor -import net.corda.core.utilities.organisation import net.corda.node.* import net.corda.node.services.config.FullNodeConfiguration import net.corda.node.services.transactions.bftSMaRtSerialFilter diff --git a/node/src/main/kotlin/net/corda/node/services/keys/KMSUtils.kt b/node/src/main/kotlin/net/corda/node/services/keys/KMSUtils.kt index fe21dac679..29dc0e6684 100644 --- a/node/src/main/kotlin/net/corda/node/services/keys/KMSUtils.kt +++ b/node/src/main/kotlin/net/corda/node/services/keys/KMSUtils.kt @@ -1,9 +1,9 @@ package net.corda.node.services.keys import net.corda.core.crypto.Crypto -import net.corda.core.utilities.cert import net.corda.core.identity.PartyAndCertificate import net.corda.core.node.services.IdentityService +import net.corda.core.utilities.cert import net.corda.core.utilities.days import net.corda.node.utilities.CertificateType import net.corda.node.utilities.ContentSignerBuilder diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt b/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt index c214e23d51..48dd2dc06a 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt @@ -507,8 +507,9 @@ private class VerifyingNettyConnector(configuration: MutableMap, } // Make sure certificate has the same name. val peerCertificate = session.peerCertificateChain[0].toX509CertHolder() - require(peerCertificate.subject == expectedLegalName.x500Name) { - "Peer has wrong subject name in the certificate - expected $expectedLegalName but got ${peerCertificate.subject}. This is either a fatal " + + val peerCertificateName = CordaX500Name.build(peerCertificate.subject) + require(peerCertificateName == expectedLegalName) { + "Peer has wrong subject name in the certificate - expected $expectedLegalName but got $peerCertificateName. This is either a fatal " + "misconfiguration by the remote peer or an SSL man-in-the-middle attack!" } X509Utilities.validateCertificateChain(session.localCertificates.last().toX509CertHolder(), *session.peerCertificates) diff --git a/node/src/main/kotlin/net/corda/node/shell/FlowWatchPrintingSubscriber.kt b/node/src/main/kotlin/net/corda/node/shell/FlowWatchPrintingSubscriber.kt index 72ae711a93..0c6db1a7b8 100644 --- a/node/src/main/kotlin/net/corda/node/shell/FlowWatchPrintingSubscriber.kt +++ b/node/src/main/kotlin/net/corda/node/shell/FlowWatchPrintingSubscriber.kt @@ -1,6 +1,5 @@ package net.corda.node.shell -import net.corda.core.utilities.organisation import net.corda.core.flows.FlowInitiator import net.corda.core.flows.StateMachineRunId import net.corda.core.internal.concurrent.openFuture diff --git a/node/src/test/kotlin/net/corda/node/services/config/FullNodeConfigurationTest.kt b/node/src/test/kotlin/net/corda/node/services/config/FullNodeConfigurationTest.kt index c37d17b897..b76393260e 100644 --- a/node/src/test/kotlin/net/corda/node/services/config/FullNodeConfigurationTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/config/FullNodeConfigurationTest.kt @@ -1,6 +1,5 @@ package net.corda.node.services.config -import net.corda.core.utilities.organisation import net.corda.core.utilities.NetworkHostAndPort import net.corda.nodeapi.User import net.corda.testing.ALICE diff --git a/node/src/test/kotlin/net/corda/node/utilities/X509UtilitiesTest.kt b/node/src/test/kotlin/net/corda/node/utilities/X509UtilitiesTest.kt index e79ead0fa9..2e08fd3ced 100644 --- a/node/src/test/kotlin/net/corda/node/utilities/X509UtilitiesTest.kt +++ b/node/src/test/kotlin/net/corda/node/utilities/X509UtilitiesTest.kt @@ -9,18 +9,13 @@ import net.corda.core.serialization.SerializationContext import net.corda.core.serialization.deserialize import net.corda.core.serialization.serialize import net.corda.core.utilities.cert -import net.corda.core.utilities.commonName -import net.corda.core.utilities.getX500Name import net.corda.node.serialization.KryoServerSerializationScheme import net.corda.node.services.config.createKeystoreForCordaNode import net.corda.nodeapi.internal.serialization.AllWhitelist import net.corda.nodeapi.internal.serialization.KryoHeaderV0_1 import net.corda.nodeapi.internal.serialization.SerializationContextImpl import net.corda.nodeapi.internal.serialization.SerializationFactoryImpl -import net.corda.testing.ALICE -import net.corda.testing.BOB -import net.corda.testing.BOB_PUBKEY -import net.corda.testing.MEGA_CORP +import net.corda.testing.* import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.asn1.x509.BasicConstraints import org.bouncycastle.asn1.x509.Extension @@ -58,7 +53,7 @@ class X509UtilitiesTest { fun `create valid self-signed CA certificate`() { val caKey = generateKeyPair(X509Utilities.DEFAULT_TLS_SIGNATURE_SCHEME) val caCert = X509Utilities.createSelfSignedCACertificate(getX500Name(CN = "Test Cert", O = "R3 Ltd", L = "London", C = "GB"), caKey) - assertTrue { caCert.subject.commonName == "Test Cert" } // using our subject common name + assertEquals(X500Name("CN=Test Cert,O=R3 Ltd,L=London,C=GB"), caCert.subject) assertEquals(caCert.issuer, caCert.subject) //self-signed caCert.isValidOn(Date()) // throws on verification problems caCert.isSignatureValid(JcaContentVerifierProviderBuilder().build(caKey.public)) // throws on verification problems diff --git a/node/src/test/kotlin/net/corda/node/utilities/registration/NetworkisRegistrationHelperTest.kt b/node/src/test/kotlin/net/corda/node/utilities/registration/NetworkisRegistrationHelperTest.kt index 542a4e610e..2e8ad9ce70 100644 --- a/node/src/test/kotlin/net/corda/node/utilities/registration/NetworkisRegistrationHelperTest.kt +++ b/node/src/test/kotlin/net/corda/node/utilities/registration/NetworkisRegistrationHelperTest.kt @@ -5,18 +5,16 @@ import com.nhaarman.mockito_kotlin.eq import com.nhaarman.mockito_kotlin.mock import net.corda.core.crypto.Crypto import net.corda.core.crypto.SecureHash -import net.corda.core.identity.CordaX500Name import net.corda.core.internal.exists import net.corda.core.internal.toTypedArray import net.corda.core.internal.toX509CertHolder import net.corda.core.utilities.cert import net.corda.core.utilities.commonName -import net.corda.core.utilities.getX500Name import net.corda.node.utilities.X509Utilities import net.corda.node.utilities.loadKeyStore import net.corda.testing.ALICE +import net.corda.testing.getX500Name import net.corda.testing.testNodeConfiguration -import org.bouncycastle.asn1.x500.X500Name import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder diff --git a/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt b/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt index 3e6aa896a4..309bfd5d67 100644 --- a/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt +++ b/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt @@ -11,7 +11,6 @@ import net.corda.core.node.services.ServiceInfo import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.getOrThrow -import net.corda.core.utilities.getX500Name import net.corda.finance.DOLLARS import net.corda.finance.contracts.Fix import net.corda.finance.contracts.FixOf @@ -20,7 +19,11 @@ import net.corda.irs.flows.RatesFixFlow import net.corda.node.utilities.CordaPersistence import net.corda.node.utilities.configureDatabase import net.corda.testing.* -import net.corda.testing.node.* +import net.corda.testing.node.MockNetwork +import net.corda.testing.node.MockServices +import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties +import net.corda.testing.node.MockServices.Companion.makeTestDatabaseProperties +import net.corda.testing.node.MockServices.Companion.makeTestIdentityService import org.junit.After import org.junit.Assert import org.junit.Before @@ -30,9 +33,6 @@ import java.util.function.Predicate import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertFalse -import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties -import net.corda.testing.node.MockServices.Companion.makeTestDatabaseProperties -import net.corda.testing.node.MockServices.Companion.makeTestIdentityService class NodeInterestRatesTest : TestDependencyInjectionBase() { val TEST_DATA = NodeInterestRates.parseFile(""" diff --git a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt index 16bf49e595..6ea3085e7b 100644 --- a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt +++ b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt @@ -11,7 +11,6 @@ import javafx.scene.input.KeyCodeCombination import javafx.scene.layout.VBox import javafx.stage.Stage import javafx.util.Duration -import net.corda.core.utilities.organisation import net.corda.core.serialization.deserialize import net.corda.core.utilities.ProgressTracker import net.corda.netmap.VisualiserViewModel.Style diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApiUtils.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApiUtils.kt index f4d4ad5bdc..f2a6b791f6 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApiUtils.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/api/PortfolioApiUtils.kt @@ -8,7 +8,6 @@ import net.corda.core.contracts.hash import net.corda.core.identity.AbstractParty import net.corda.core.identity.Party import net.corda.core.messaging.CordaRPCOps -import net.corda.core.utilities.organisation import net.corda.core.utilities.toBase58String import net.corda.vega.contracts.IRSState import net.corda.vega.contracts.PortfolioState diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt index eb39cfea62..e0fdcefced 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt @@ -8,7 +8,6 @@ import net.corda.core.internal.div import net.corda.core.node.services.ServiceInfo import net.corda.core.node.services.ServiceType import net.corda.core.utilities.getOrThrow -import net.corda.core.utilities.getX500Name import net.corda.core.utilities.organisation import net.corda.node.internal.Node import net.corda.node.services.config.ConfigHelper @@ -24,6 +23,7 @@ import net.corda.testing.DUMMY_MAP import net.corda.testing.TestDependencyInjectionBase import net.corda.testing.driver.addressMustNotBeBoundFuture import net.corda.testing.getFreeLocalPorts +import net.corda.testing.getX500Name import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO import org.apache.logging.log4j.Level import org.bouncycastle.asn1.x500.X500Name diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/SimpleNode.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/SimpleNode.kt index 34d0372409..726b0c5202 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/SimpleNode.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/SimpleNode.kt @@ -7,7 +7,6 @@ import net.corda.core.messaging.RPCOps import net.corda.core.node.services.IdentityService import net.corda.core.node.services.KeyManagementService import net.corda.core.utilities.NetworkHostAndPort -import net.corda.core.utilities.organisation import net.corda.node.services.RPCUserServiceImpl import net.corda.node.services.api.MonitoringService import net.corda.node.services.config.NodeConfiguration diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt index bb75d25961..d118cc66a1 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt @@ -10,7 +10,6 @@ import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.identity.PartyAndCertificate import net.corda.node.utilities.CertificateAndKeyPair -import net.corda.core.utilities.getX500Name import net.corda.node.utilities.X509Utilities import java.math.BigInteger import java.security.KeyPair diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/X500NameUtils.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/X500NameUtils.kt new file mode 100644 index 0000000000..1af6357b7e --- /dev/null +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/X500NameUtils.kt @@ -0,0 +1,29 @@ +@file:JvmName("X500NameUtils") + +package net.corda.testing + +import org.bouncycastle.asn1.x500.X500Name +import org.bouncycastle.asn1.x500.X500NameBuilder +import org.bouncycastle.asn1.x500.style.BCStyle + +/** + * Generate a distinguished name from the provided X500 . + * + * @param O organisation name. + * @param L locality. + * @param C county. + * @param CN common name. + * @param OU organisation unit. + * @param ST state. + */ +@JvmOverloads +fun getX500Name(O: String, L: String, C: String, CN: String? = null, OU: String? = null, ST: String? = null): X500Name { + return X500NameBuilder(BCStyle.INSTANCE).apply { + addRDN(BCStyle.C, C) + ST?.let { addRDN(BCStyle.ST, it) } + addRDN(BCStyle.L, L) + addRDN(BCStyle.O, O) + OU?.let { addRDN(BCStyle.OU, it) } + CN?.let { addRDN(BCStyle.CN, it) } + }.build() +} \ No newline at end of file diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt index b75ad5646a..141a9e1d68 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt @@ -2,9 +2,7 @@ package net.corda.demobench.model import com.typesafe.config.* import net.corda.core.identity.CordaX500Name -import net.corda.core.utilities.locality import net.corda.nodeapi.User -import org.bouncycastle.asn1.x500.X500Name import java.io.File import java.nio.file.Files import java.nio.file.Path diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/formatters/PartyNameFormatter.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/formatters/PartyNameFormatter.kt index 29ae6fe4c3..6622639f80 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/formatters/PartyNameFormatter.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/formatters/PartyNameFormatter.kt @@ -1,8 +1,6 @@ package net.corda.explorer.formatters import net.corda.core.identity.CordaX500Name -import net.corda.core.utilities.organisation -import org.bouncycastle.asn1.x500.X500Name object PartyNameFormatter { val short = object : Formatter { diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/cash/CashViewer.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/cash/CashViewer.kt index ab5bdfb82a..480ae1116e 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/cash/CashViewer.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/cash/CashViewer.kt @@ -23,7 +23,6 @@ import net.corda.core.contracts.Amount import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.withoutIssuer import net.corda.core.identity.AbstractParty -import net.corda.core.utilities.organisation import net.corda.explorer.formatters.AmountFormatter import net.corda.explorer.formatters.PartyNameFormatter import net.corda.explorer.identicon.identicon