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 a1cf8f8933..dff6085f36 100644 --- a/core/src/main/kotlin/net/corda/core/utilities/X500NameUtils.kt +++ b/core/src/main/kotlin/net/corda/core/utilities/X500NameUtils.kt @@ -2,15 +2,10 @@ package net.corda.core.utilities -import net.corda.core.internal.toX509CertHolder import org.bouncycastle.asn1.ASN1ObjectIdentifier import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.asn1.x500.X500NameBuilder import org.bouncycastle.asn1.x500.style.BCStyle -import org.bouncycastle.cert.X509CertificateHolder -import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter -import java.security.KeyPair -import java.security.cert.X509Certificate val X500Name.commonName: String? get() = getRDNValueString(BCStyle.CN) val X500Name.organisationUnit: String? get() = getRDNValueString(BCStyle.OU) @@ -21,9 +16,6 @@ val X500Name.country: String get() = getRDNValueString(BCStyle.C) ?: throw Illeg private fun X500Name.getRDNValueString(identifier: ASN1ObjectIdentifier): String? = getRDNs(identifier).firstOrNull()?.first?.value?.toString() -val X509Certificate.subject: X500Name get() = toX509CertHolder().subject -val X509CertificateHolder.cert: X509Certificate get() = JcaX509CertificateConverter().getCertificate(this) - /** * Generate a distinguished name from the provided X500 . * @@ -54,5 +46,3 @@ fun X500Name.toWellFormattedName(): X500Name { validateX500Name(this) return getX500Name(organisation, locality, country, commonName, organisationUnit, state) } - -data class CertificateAndKeyPair(val certificate: X509CertificateHolder, val keyPair: KeyPair) diff --git a/core/src/main/kotlin/net/corda/core/utilities/X509Utils.kt b/core/src/main/kotlin/net/corda/core/utilities/X509Utils.kt new file mode 100644 index 0000000000..25b5001aa9 --- /dev/null +++ b/core/src/main/kotlin/net/corda/core/utilities/X509Utils.kt @@ -0,0 +1,12 @@ +@file:JvmName("X509Utils") + +package net.corda.core.utilities + +import net.corda.core.internal.toX509CertHolder +import org.bouncycastle.asn1.x500.X500Name +import org.bouncycastle.cert.X509CertificateHolder +import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter +import java.security.cert.X509Certificate + +val X509Certificate.subject: X500Name get() = toX509CertHolder().subject +val X509CertificateHolder.cert: X509Certificate get() = JcaX509CertificateConverter().getCertificate(this) \ No newline at end of file diff --git a/node/src/main/kotlin/net/corda/node/utilities/KeyStoreUtilities.kt b/node/src/main/kotlin/net/corda/node/utilities/KeyStoreUtilities.kt index 03427411e9..765bbae85a 100644 --- a/node/src/main/kotlin/net/corda/node/utilities/KeyStoreUtilities.kt +++ b/node/src/main/kotlin/net/corda/node/utilities/KeyStoreUtilities.kt @@ -1,12 +1,11 @@ package net.corda.node.utilities -import net.corda.core.utilities.CertificateAndKeyPair import net.corda.core.crypto.Crypto -import net.corda.core.utilities.cert import net.corda.core.internal.exists import net.corda.core.internal.read import net.corda.core.internal.toX509CertHolder import net.corda.core.internal.write +import net.corda.core.utilities.cert import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.cert.X509CertificateHolder import java.io.IOException diff --git a/node/src/main/kotlin/net/corda/node/utilities/X509Utilities.kt b/node/src/main/kotlin/net/corda/node/utilities/X509Utilities.kt index 7f67a4a8ac..af3b4bc1eb 100644 --- a/node/src/main/kotlin/net/corda/node/utilities/X509Utilities.kt +++ b/node/src/main/kotlin/net/corda/node/utilities/X509Utilities.kt @@ -255,3 +255,5 @@ enum class CertificateType(val keyUsage: KeyUsage, vararg val purposes: KeyPurpo // TODO: Identity certs should have only limited depth (i.e. 1) CA signing capability, with tight name constraints IDENTITY(KeyUsage(KeyUsage.digitalSignature or KeyUsage.keyCertSign), KeyPurposeId.id_kp_serverAuth, KeyPurposeId.id_kp_clientAuth, KeyPurposeId.anyExtendedKeyUsage, isCA = true) } + +data class CertificateAndKeyPair(val certificate: X509CertificateHolder, val keyPair: KeyPair) diff --git a/node/src/test/kotlin/net/corda/node/services/network/InMemoryIdentityServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/network/InMemoryIdentityServiceTests.kt index 43e917b73d..bbf0c8ca50 100644 --- a/node/src/test/kotlin/net/corda/node/services/network/InMemoryIdentityServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/network/InMemoryIdentityServiceTests.kt @@ -6,7 +6,7 @@ import net.corda.core.identity.AnonymousParty import net.corda.core.identity.Party import net.corda.core.identity.PartyAndCertificate import net.corda.core.node.services.UnknownAnonymousPartyException -import net.corda.core.utilities.CertificateAndKeyPair +import net.corda.node.utilities.CertificateAndKeyPair import net.corda.core.utilities.cert import net.corda.core.utilities.getX500Name import net.corda.node.services.identity.InMemoryIdentityService diff --git a/node/src/test/kotlin/net/corda/node/services/network/PersistentIdentityServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/network/PersistentIdentityServiceTests.kt index 1d936a0135..a87c0bf629 100644 --- a/node/src/test/kotlin/net/corda/node/services/network/PersistentIdentityServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/network/PersistentIdentityServiceTests.kt @@ -7,7 +7,7 @@ import net.corda.core.identity.Party import net.corda.core.identity.PartyAndCertificate import net.corda.core.node.services.IdentityService import net.corda.core.node.services.UnknownAnonymousPartyException -import net.corda.core.utilities.CertificateAndKeyPair +import net.corda.node.utilities.CertificateAndKeyPair import net.corda.core.utilities.cert import net.corda.core.utilities.getX500Name import net.corda.node.services.identity.PersistentIdentityService diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt index d747d090cb..d59836ecf6 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt @@ -27,6 +27,7 @@ import net.corda.node.services.network.NetworkMapService import net.corda.node.services.transactions.* import net.corda.node.utilities.AffinityExecutor import net.corda.node.utilities.AffinityExecutor.ServiceAffinityExecutor +import net.corda.node.utilities.CertificateAndKeyPair import net.corda.testing.* import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties import org.apache.activemq.artemis.utils.ReusableLatch diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt index 88987a562e..9262a697d7 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt @@ -13,6 +13,7 @@ import net.corda.core.utilities.* import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER import net.corda.node.services.config.configureDevKeyAndTrustStores import net.corda.node.services.identity.InMemoryIdentityService +import net.corda.node.utilities.CertificateAndKeyPair import net.corda.node.utilities.CertificateType import net.corda.node.utilities.X509Utilities import net.corda.nodeapi.config.SSLConfiguration 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 ba76178760..2618406cd9 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 @@ -8,7 +8,7 @@ import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.Party import net.corda.core.identity.PartyAndCertificate -import net.corda.core.utilities.CertificateAndKeyPair +import net.corda.node.utilities.CertificateAndKeyPair import net.corda.core.utilities.getX500Name import net.corda.node.utilities.X509Utilities import java.math.BigInteger