@@ -94,7 +94,6 @@ import net.corda.node.services.api.VaultServiceInternal
94
94
import net.corda.node.services.api.WritableTransactionStorage
95
95
import net.corda.node.services.attachments.NodeAttachmentTrustCalculator
96
96
import net.corda.node.services.config.NodeConfiguration
97
- import net.corda.node.services.config.configureWithDevSSLCertificate
98
97
import net.corda.node.services.config.rpc.NodeRpcOptions
99
98
import net.corda.node.services.config.shell.determineUnsafeUsers
100
99
import net.corda.node.services.config.shell.toShellConfig
@@ -149,8 +148,6 @@ import net.corda.nodeapi.internal.cordapp.CordappLoader
149
148
import net.corda.nodeapi.internal.crypto.CertificateType
150
149
import net.corda.nodeapi.internal.crypto.X509Utilities
151
150
import net.corda.nodeapi.internal.crypto.X509Utilities.CORDA_CLIENT_CA
152
- import net.corda.nodeapi.internal.crypto.X509Utilities.CORDA_CLIENT_TLS
153
- import net.corda.nodeapi.internal.crypto.X509Utilities.CORDA_ROOT_CA
154
151
import net.corda.nodeapi.internal.crypto.X509Utilities.DEFAULT_VALIDITY_WINDOW
155
152
import net.corda.nodeapi.internal.crypto.X509Utilities.DISTRIBUTED_NOTARY_COMPOSITE_KEY_ALIAS
156
153
import net.corda.nodeapi.internal.crypto.X509Utilities.DISTRIBUTED_NOTARY_KEY_ALIAS
@@ -176,10 +173,8 @@ import org.jolokia.jvmagent.JolokiaServer
176
173
import org.jolokia.jvmagent.JolokiaServerConfig
177
174
import org.slf4j.Logger
178
175
import rx.Scheduler
179
- import java.io.IOException
180
176
import java.lang.reflect.InvocationTargetException
181
177
import java.security.KeyPair
182
- import java.security.KeyStoreException
183
178
import java.security.cert.X509Certificate
184
179
import java.sql.Connection
185
180
import java.sql.Savepoint
@@ -434,18 +429,6 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
434
429
return proxies.fold(ops) { delegate, decorate -> decorate(delegate) }
435
430
}
436
431
437
- private fun initKeyStores (): X509Certificate {
438
- if (configuration.devMode) {
439
- configuration.configureWithDevSSLCertificate(cryptoService)
440
- // configureWithDevSSLCertificate is a devMode process that writes directly to keystore files, so
441
- // we should re-synchronise BCCryptoService with the updated keystore file.
442
- if (cryptoService is BCCryptoService ) {
443
- cryptoService.resyncKeystore()
444
- }
445
- }
446
- return validateKeyStores()
447
- }
448
-
449
432
private fun quasarExcludePackages (nodeConfiguration : NodeConfiguration ) {
450
433
val quasarInstrumentor = Retransform .getInstrumentor()
451
434
@@ -457,7 +440,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
457
440
open fun generateAndSaveNodeInfo (): NodeInfo {
458
441
check(started == null ) { " Node has already been started" }
459
442
log.info(" Generating nodeInfo ..." )
460
- val trustRoot = initKeyStores()
443
+ val trustRoot = configuration. initKeyStores(cryptoService )
461
444
startDatabase()
462
445
val (identity, identityKeyPair) = obtainIdentity()
463
446
val nodeCa = configuration.signingCertificateStore.get()[CORDA_CLIENT_CA ]
@@ -497,7 +480,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
497
480
logVendorString(database, log)
498
481
if (allowHibernateToManageAppSchema) {
499
482
Node .printBasicNodeInfo(" Initialising CorDapps to get schemas created by hibernate" )
500
- val trustRoot = initKeyStores()
483
+ val trustRoot = configuration. initKeyStores(cryptoService )
501
484
networkMapClient?.start(trustRoot)
502
485
val (netParams, signedNetParams) = NetworkParametersReader (trustRoot, networkMapClient, configuration.baseDirectory).read()
503
486
log.info(" Loaded network parameters: $netParams " )
@@ -536,7 +519,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
536
519
nodeLifecycleEventsDistributor.distributeEvent(NodeLifecycleEvent .BeforeNodeStart (nodeServicesContext))
537
520
log.info(" Node starting up ..." )
538
521
539
- val trustRoot = initKeyStores()
522
+ val trustRoot = configuration. initKeyStores(cryptoService )
540
523
initialiseJolokia()
541
524
542
525
schemaService.mappedSchemasWarnings().forEach {
@@ -980,57 +963,6 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
980
963
@VisibleForTesting
981
964
protected open fun acceptableLiveFiberCountOnStop (): Int = 0
982
965
983
- private fun getCertificateStores (): AllCertificateStores ? {
984
- return try {
985
- // The following will throw IOException if key file not found or KeyStoreException if keystore password is incorrect.
986
- val sslKeyStore = configuration.p2pSslOptions.keyStore.get()
987
- val signingCertificateStore = configuration.signingCertificateStore.get()
988
- val trustStore = configuration.p2pSslOptions.trustStore.get()
989
- AllCertificateStores (trustStore, sslKeyStore, signingCertificateStore)
990
- } catch (e: IOException ) {
991
- log.error(" IO exception while trying to validate keystores and truststore" , e)
992
- null
993
- }
994
- }
995
-
996
- private data class AllCertificateStores (val trustStore : CertificateStore , val sslKeyStore : CertificateStore , val identitiesKeyStore : CertificateStore )
997
-
998
- private fun validateKeyStores (): X509Certificate {
999
- // Step 1. Check trustStore, sslKeyStore and identitiesKeyStore exist.
1000
- val certStores = try {
1001
- requireNotNull(getCertificateStores()) {
1002
- " One or more keyStores (identity or TLS) or trustStore not found. " +
1003
- " Please either copy your existing keys and certificates from another node, " +
1004
- " or if you don't have one yet, fill out the config file and run corda.jar initial-registration."
1005
- }
1006
- } catch (e: KeyStoreException ) {
1007
- throw IllegalArgumentException (" At least one of the keystores or truststore passwords does not match configuration." )
1008
- }
1009
- // Step 2. Check that trustStore contains the correct key-alias entry.
1010
- require(CORDA_ROOT_CA in certStores.trustStore) {
1011
- " Alias for trustRoot key not found. Please ensure you have an updated trustStore file."
1012
- }
1013
- // Step 3. Check that tls keyStore contains the correct key-alias entry.
1014
- require(CORDA_CLIENT_TLS in certStores.sslKeyStore) {
1015
- " Alias for TLS key not found. Please ensure you have an updated TLS keyStore file."
1016
- }
1017
-
1018
- // Step 4. Check that identity keyStores contain the correct key-alias entry for Node CA.
1019
- require(CORDA_CLIENT_CA in certStores.identitiesKeyStore) {
1020
- " Alias for Node CA key not found. Please ensure you have an updated identity keyStore file."
1021
- }
1022
-
1023
- // Step 5. Check all cert paths chain to the trusted root.
1024
- val trustRoot = certStores.trustStore[CORDA_ROOT_CA ]
1025
- val sslCertChainRoot = certStores.sslKeyStore.query { getCertificateChain(CORDA_CLIENT_TLS ) }.last()
1026
- val nodeCaCertChainRoot = certStores.identitiesKeyStore.query { getCertificateChain(CORDA_CLIENT_CA ) }.last()
1027
-
1028
- require(sslCertChainRoot == trustRoot) { " TLS certificate must chain to the trusted root." }
1029
- require(nodeCaCertChainRoot == trustRoot) { " Client CA certificate must chain to the trusted root." }
1030
-
1031
- return trustRoot
1032
- }
1033
-
1034
966
// Specific class so that MockNode can catch it.
1035
967
class DatabaseConfigurationException (message : String ) : CordaException(message)
1036
968
0 commit comments