From b1180b467ba77b50a5bb06008e0d9d74af03be8b Mon Sep 17 00:00:00 2001 From: Denis Rekalov Date: Wed, 25 Mar 2020 12:56:33 +0000 Subject: [PATCH] ENT-4659: Remove CryptoServiceFactory from OS --- .../net/corda/node/internal/AbstractNode.kt | 14 ++++++------ .../cryptoservice/CryptoServiceFactory.kt | 22 ------------------- .../cryptoservice/SupportedCryptoServices.kt | 6 ----- .../registration/NetworkRegistrationHelper.kt | 4 +--- 4 files changed, 8 insertions(+), 38 deletions(-) delete mode 100644 node/src/main/kotlin/net/corda/node/utilities/cryptoservice/CryptoServiceFactory.kt delete mode 100644 node/src/main/kotlin/net/corda/node/utilities/cryptoservice/SupportedCryptoServices.kt 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 045136c9b3..ec24382622 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -150,8 +150,7 @@ import net.corda.nodeapi.internal.crypto.X509Utilities.DEFAULT_VALIDITY_WINDOW import net.corda.nodeapi.internal.crypto.X509Utilities.DISTRIBUTED_NOTARY_COMPOSITE_KEY_ALIAS import net.corda.nodeapi.internal.crypto.X509Utilities.DISTRIBUTED_NOTARY_KEY_ALIAS import net.corda.nodeapi.internal.crypto.X509Utilities.NODE_IDENTITY_KEY_ALIAS -import net.corda.node.utilities.cryptoservice.CryptoServiceFactory -import net.corda.node.utilities.cryptoservice.SupportedCryptoServices +import net.corda.nodeapi.internal.cryptoservice.CryptoService import net.corda.nodeapi.internal.cryptoservice.bouncycastle.BCCryptoService import net.corda.nodeapi.internal.lifecycle.NodeLifecycleEvent import net.corda.nodeapi.internal.lifecycle.NodeLifecycleEventsDistributor @@ -266,11 +265,8 @@ abstract class AbstractNode(val configuration: NodeConfiguration, configuration.devMode ).tokenize() val attachmentTrustCalculator = makeAttachmentTrustCalculator(configuration, database) - val cryptoService = CryptoServiceFactory.makeCryptoService( - SupportedCryptoServices.BC_SIMPLE, - configuration.myLegalName, - configuration.signingCertificateStore - ) + @Suppress("LeakingThis") + val cryptoService = makeCryptoService() @Suppress("LeakingThis") val networkParametersStorage = makeNetworkParametersStorage() val cordappProvider = CordappProviderImpl(cordappLoader, CordappConfigFileProvider(configuration.cordappDirectories), attachments).tokenize() @@ -880,6 +876,10 @@ abstract class AbstractNode(val configuration: NodeConfiguration, return DBNetworkParametersStorage(cacheFactory, database, networkMapClient).tokenize() } + protected open fun makeCryptoService(): CryptoService { + return BCCryptoService(configuration.myLegalName.x500Principal, configuration.signingCertificateStore) + } + @VisibleForTesting protected open fun acceptableLiveFiberCountOnStop(): Int = 0 diff --git a/node/src/main/kotlin/net/corda/node/utilities/cryptoservice/CryptoServiceFactory.kt b/node/src/main/kotlin/net/corda/node/utilities/cryptoservice/CryptoServiceFactory.kt deleted file mode 100644 index 2a633bf61a..0000000000 --- a/node/src/main/kotlin/net/corda/node/utilities/cryptoservice/CryptoServiceFactory.kt +++ /dev/null @@ -1,22 +0,0 @@ -package net.corda.node.utilities.cryptoservice - -import net.corda.core.identity.CordaX500Name -import net.corda.nodeapi.internal.config.FileBasedCertificateStoreSupplier -import net.corda.nodeapi.internal.cryptoservice.CryptoService -import net.corda.nodeapi.internal.cryptoservice.bouncycastle.BCCryptoService - -class CryptoServiceFactory { - companion object { - fun makeCryptoService( - cryptoServiceName: SupportedCryptoServices, - legalName: CordaX500Name, - signingCertificateStore: FileBasedCertificateStoreSupplier? = null - ): CryptoService { - // The signing certificate store can be null for other services as only BCC requires is at the moment. - if (cryptoServiceName != SupportedCryptoServices.BC_SIMPLE || signingCertificateStore == null) { - throw IllegalArgumentException("Currently only BouncyCastle is used as a crypto service. A valid signing certificate store is required.") - } - return BCCryptoService(legalName.x500Principal, signingCertificateStore) - } - } -} \ No newline at end of file diff --git a/node/src/main/kotlin/net/corda/node/utilities/cryptoservice/SupportedCryptoServices.kt b/node/src/main/kotlin/net/corda/node/utilities/cryptoservice/SupportedCryptoServices.kt deleted file mode 100644 index 9c5b6fe4b2..0000000000 --- a/node/src/main/kotlin/net/corda/node/utilities/cryptoservice/SupportedCryptoServices.kt +++ /dev/null @@ -1,6 +0,0 @@ -package net.corda.node.utilities.cryptoservice - -enum class SupportedCryptoServices(val userFriendlyName: String) { - /** Identifier for [BCCryptoService]. */ - BC_SIMPLE("file-based keystore") -} 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 08678c16c8..45aa089f9e 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 @@ -18,8 +18,6 @@ import net.corda.nodeapi.internal.crypto.X509Utilities.CORDA_CLIENT_TLS import net.corda.nodeapi.internal.crypto.X509Utilities.CORDA_ROOT_CA import net.corda.nodeapi.internal.crypto.X509Utilities.DEFAULT_VALIDITY_WINDOW import net.corda.nodeapi.internal.cryptoservice.CryptoService -import net.corda.node.utilities.cryptoservice.CryptoServiceFactory -import net.corda.node.utilities.cryptoservice.SupportedCryptoServices import net.corda.nodeapi.internal.cryptoservice.bouncycastle.BCCryptoService import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.openssl.jcajce.JcaPEMWriter @@ -288,7 +286,7 @@ class NodeRegistrationConfiguration( tlsCertCrlDistPoint = config.tlsCertCrlDistPoint, certificatesDirectory = config.certificatesDirectory, emailAddress = config.emailAddress, - cryptoService = CryptoServiceFactory.makeCryptoService(SupportedCryptoServices.BC_SIMPLE, config.myLegalName, config.signingCertificateStore), + cryptoService = BCCryptoService(config.myLegalName.x500Principal, config.signingCertificateStore), certificateStore = config.signingCertificateStore.get(true) ) }