mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
Clean up CordaX500Name (#1487)
* Remove unused imports * Move X500 name generation into test code as it's no longer used in the main code
This commit is contained in:
parent
de3468f8a7
commit
c18b0ecdc3
@ -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()
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -507,8 +507,9 @@ private class VerifyingNettyConnector(configuration: MutableMap<String, Any>,
|
||||
}
|
||||
// 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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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("""
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
}
|
@ -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
|
||||
|
@ -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<CordaX500Name> {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user