Moved stuff out of X500NameUtils.kt not related to X500Name

This commit is contained in:
Shams Asari 2017-09-10 14:23:14 +01:00
parent 40f791a5d0
commit 763539b5f0
9 changed files with 20 additions and 15 deletions

View File

@ -2,15 +2,10 @@
package net.corda.core.utilities package net.corda.core.utilities
import net.corda.core.internal.toX509CertHolder
import org.bouncycastle.asn1.ASN1ObjectIdentifier import org.bouncycastle.asn1.ASN1ObjectIdentifier
import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.asn1.x500.X500Name
import org.bouncycastle.asn1.x500.X500NameBuilder import org.bouncycastle.asn1.x500.X500NameBuilder
import org.bouncycastle.asn1.x500.style.BCStyle 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.commonName: String? get() = getRDNValueString(BCStyle.CN)
val X500Name.organisationUnit: String? get() = getRDNValueString(BCStyle.OU) 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() 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 . * Generate a distinguished name from the provided X500 .
* *
@ -54,5 +46,3 @@ fun X500Name.toWellFormattedName(): X500Name {
validateX500Name(this) validateX500Name(this)
return getX500Name(organisation, locality, country, commonName, organisationUnit, state) return getX500Name(organisation, locality, country, commonName, organisationUnit, state)
} }
data class CertificateAndKeyPair(val certificate: X509CertificateHolder, val keyPair: KeyPair)

View File

@ -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)

View File

@ -1,12 +1,11 @@
package net.corda.node.utilities package net.corda.node.utilities
import net.corda.core.utilities.CertificateAndKeyPair
import net.corda.core.crypto.Crypto import net.corda.core.crypto.Crypto
import net.corda.core.utilities.cert
import net.corda.core.internal.exists import net.corda.core.internal.exists
import net.corda.core.internal.read import net.corda.core.internal.read
import net.corda.core.internal.toX509CertHolder import net.corda.core.internal.toX509CertHolder
import net.corda.core.internal.write import net.corda.core.internal.write
import net.corda.core.utilities.cert
import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.asn1.x500.X500Name
import org.bouncycastle.cert.X509CertificateHolder import org.bouncycastle.cert.X509CertificateHolder
import java.io.IOException import java.io.IOException

View File

@ -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 // 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) 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)

View File

@ -6,7 +6,7 @@ import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.identity.PartyAndCertificate import net.corda.core.identity.PartyAndCertificate
import net.corda.core.node.services.UnknownAnonymousPartyException 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.cert
import net.corda.core.utilities.getX500Name import net.corda.core.utilities.getX500Name
import net.corda.node.services.identity.InMemoryIdentityService import net.corda.node.services.identity.InMemoryIdentityService

View File

@ -7,7 +7,7 @@ import net.corda.core.identity.Party
import net.corda.core.identity.PartyAndCertificate import net.corda.core.identity.PartyAndCertificate
import net.corda.core.node.services.IdentityService import net.corda.core.node.services.IdentityService
import net.corda.core.node.services.UnknownAnonymousPartyException 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.cert
import net.corda.core.utilities.getX500Name import net.corda.core.utilities.getX500Name
import net.corda.node.services.identity.PersistentIdentityService import net.corda.node.services.identity.PersistentIdentityService

View File

@ -27,6 +27,7 @@ import net.corda.node.services.network.NetworkMapService
import net.corda.node.services.transactions.* import net.corda.node.services.transactions.*
import net.corda.node.utilities.AffinityExecutor import net.corda.node.utilities.AffinityExecutor
import net.corda.node.utilities.AffinityExecutor.ServiceAffinityExecutor import net.corda.node.utilities.AffinityExecutor.ServiceAffinityExecutor
import net.corda.node.utilities.CertificateAndKeyPair
import net.corda.testing.* import net.corda.testing.*
import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties
import org.apache.activemq.artemis.utils.ReusableLatch import org.apache.activemq.artemis.utils.ReusableLatch

View File

@ -13,6 +13,7 @@ import net.corda.core.utilities.*
import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER
import net.corda.node.services.config.configureDevKeyAndTrustStores import net.corda.node.services.config.configureDevKeyAndTrustStores
import net.corda.node.services.identity.InMemoryIdentityService import net.corda.node.services.identity.InMemoryIdentityService
import net.corda.node.utilities.CertificateAndKeyPair
import net.corda.node.utilities.CertificateType import net.corda.node.utilities.CertificateType
import net.corda.node.utilities.X509Utilities import net.corda.node.utilities.X509Utilities
import net.corda.nodeapi.config.SSLConfiguration import net.corda.nodeapi.config.SSLConfiguration

View File

@ -8,7 +8,7 @@ import net.corda.core.crypto.entropyToKeyPair
import net.corda.core.crypto.generateKeyPair import net.corda.core.crypto.generateKeyPair
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.identity.PartyAndCertificate 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.core.utilities.getX500Name
import net.corda.node.utilities.X509Utilities import net.corda.node.utilities.X509Utilities
import java.math.BigInteger import java.math.BigInteger