From 7c415b7126439bd2369d7b1a771df422f9f1cc1b Mon Sep 17 00:00:00 2001 From: Michal Kit Date: Fri, 16 Feb 2018 11:23:40 +0000 Subject: [PATCH] Adding small fixes to the code. (#456) * Adding small fixes to the code. * Addressing review comments --- .../corda/nodeapi/internal/KeyStoreConfigHelpers.kt | 10 +++++----- .../net/corda/node/services/config/ConfigUtilities.kt | 10 ++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/KeyStoreConfigHelpers.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/KeyStoreConfigHelpers.kt index 96a78107a8..0d38e1daaf 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/KeyStoreConfigHelpers.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/KeyStoreConfigHelpers.kt @@ -96,11 +96,11 @@ fun createDevNodeCa(intermediateCa: CertificateAndKeyPair, val DEV_INTERMEDIATE_CA: CertificateAndKeyPair get() = DevCaHelper.loadDevCa(X509Utilities.CORDA_INTERMEDIATE_CA) val DEV_ROOT_CA: CertificateAndKeyPair get() = DevCaHelper.loadDevCa(X509Utilities.CORDA_ROOT_CA) -val DEV_CA_PRIVATE_KEY_PASS: String = "cordacadevkeypass" -val DEV_CA_KEY_STORE_FILE: String = "cordadevcakeys.jks" -val DEV_CA_KEY_STORE_PASS: String = "cordacadevpass" -val DEV_CA_TRUST_STORE_FILE: String = "cordatruststore.jks" -val DEV_CA_TRUST_STORE_PASS: String = "trustpass" +const val DEV_CA_PRIVATE_KEY_PASS: String = "cordacadevkeypass" +const val DEV_CA_KEY_STORE_FILE: String = "cordadevcakeys.jks" +const val DEV_CA_KEY_STORE_PASS: String = "cordacadevpass" +const val DEV_CA_TRUST_STORE_FILE: String = "cordatruststore.jks" +const val DEV_CA_TRUST_STORE_PASS: String = "trustpass" // We need a class so that we can get hold of the class loader internal object DevCaHelper { diff --git a/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt b/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt index 910e2832ff..b1d1e0e0ff 100644 --- a/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt +++ b/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt @@ -8,10 +8,8 @@ import net.corda.core.identity.CordaX500Name import net.corda.core.internal.createDirectories import net.corda.core.internal.div import net.corda.core.internal.exists -import net.corda.nodeapi.internal.DEV_CA_TRUST_STORE_FILE -import net.corda.nodeapi.internal.DEV_CA_TRUST_STORE_PASS +import net.corda.nodeapi.internal.* import net.corda.nodeapi.internal.config.SSLConfiguration -import net.corda.nodeapi.internal.createDevKeyStores import net.corda.nodeapi.internal.crypto.X509KeyStore import net.corda.nodeapi.internal.crypto.loadKeyStore import net.corda.nodeapi.internal.crypto.save @@ -57,7 +55,7 @@ fun NodeConfiguration.configureWithDevSSLCertificate() = configureDevKeyAndTrust fun SSLConfiguration.configureDevKeyAndTrustStores(myLegalName: CordaX500Name) { certificatesDirectory.createDirectories() if (!trustStoreFile.exists()) { - loadKeyStore(javaClass.classLoader.getResourceAsStream("certificates/$DEV_CA_TRUST_STORE_FILE"), "$DEV_CA_TRUST_STORE_PASS").save(trustStoreFile, trustStorePassword) + loadKeyStore(javaClass.classLoader.getResourceAsStream("certificates/$DEV_CA_TRUST_STORE_FILE"), DEV_CA_TRUST_STORE_PASS).save(trustStoreFile, trustStorePassword) } if (!sslKeystore.exists() || !nodeKeystore.exists()) { val (nodeKeyStore) = createDevKeyStores(myLegalName) @@ -65,11 +63,11 @@ fun SSLConfiguration.configureDevKeyAndTrustStores(myLegalName: CordaX500Name) { // Move distributed service composite key (generated by IdentityGenerator.generateToDisk) to keystore if exists. val distributedServiceKeystore = certificatesDirectory / "distributedService.jks" if (distributedServiceKeystore.exists()) { - val serviceKeystore = X509KeyStore.fromFile(distributedServiceKeystore, "cordacadevpass") + val serviceKeystore = X509KeyStore.fromFile(distributedServiceKeystore, DEV_CA_KEY_STORE_PASS) nodeKeyStore.update { serviceKeystore.aliases().forEach { if (serviceKeystore.internal.isKeyEntry(it)) { - setPrivateKey(it, serviceKeystore.getPrivateKey(it, "cordacadevkeypass"), serviceKeystore.getCertificateChain(it)) + setPrivateKey(it, serviceKeystore.getPrivateKey(it, DEV_CA_PRIVATE_KEY_PASS), serviceKeystore.getCertificateChain(it)) } else { setCertificate(it, serviceKeystore.getCertificate(it)) }