CORDA-2914: Allow certificate directory to be a symlink (#5102)

This commit is contained in:
Manoj
2019-07-03 17:39:40 +08:00
committed by Shams Asari
parent 88894bc592
commit 44835bd17c
3 changed files with 14 additions and 6 deletions

View File

@ -194,3 +194,12 @@ inline fun <reified T : Any> Path.readObject(): T = readAll().deserialize()
/** Calculate the hash of the contents of this file. */ /** Calculate the hash of the contents of this file. */
inline val Path.hash: SecureHash get() = read { it.hash() } inline val Path.hash: SecureHash get() = read { it.hash() }
/* Check if the Path is symbolic link */
fun Path.safeSymbolicRead(): Path {
if (Files.isSymbolicLink(this)) {
return (Files.readSymbolicLink(this))
} else {
return (this)
}
}

View File

@ -7,9 +7,11 @@ import net.corda.core.internal.createDirectories
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.write import net.corda.core.internal.write
import net.corda.core.internal.safeSymbolicRead
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Files
import java.security.* import java.security.*
import java.security.cert.Certificate import java.security.cert.Certificate
import java.security.cert.X509Certificate import java.security.cert.X509Certificate
@ -30,7 +32,7 @@ fun loadOrCreateKeyStore(keyStoreFilePath: Path, storePassword: String): KeyStor
keyStoreFilePath.read { keyStore.load(it, pass) } keyStoreFilePath.read { keyStore.load(it, pass) }
} else { } else {
keyStore.load(null, pass) keyStore.load(null, pass)
keyStoreFilePath.toAbsolutePath().parent?.createDirectories() keyStoreFilePath.toAbsolutePath().parent?.safeSymbolicRead()?.createDirectories()
keyStoreFilePath.write { keyStore.store(it, pass) } keyStoreFilePath.write { keyStore.store(it, pass) }
} }
return keyStore return keyStore

View File

@ -12,6 +12,7 @@ import net.corda.core.internal.*
import net.corda.core.internal.concurrent.thenMatch import net.corda.core.internal.concurrent.thenMatch
import net.corda.core.internal.cordapp.CordappImpl import net.corda.core.internal.cordapp.CordappImpl
import net.corda.core.internal.errors.AddressBindingException import net.corda.core.internal.errors.AddressBindingException
import net.corda.core.internal.safeSymbolicRead
import net.corda.core.utilities.Try import net.corda.core.utilities.Try
import net.corda.core.utilities.contextLogger import net.corda.core.utilities.contextLogger
import net.corda.core.utilities.loggerFor import net.corda.core.utilities.loggerFor
@ -487,11 +488,7 @@ fun CliWrapperBase.initLogging(baseDirectory: Path): Boolean {
//Test for access to the logging path and shutdown if we are unable to reach it. //Test for access to the logging path and shutdown if we are unable to reach it.
val logPath = baseDirectory / NodeCliCommand.LOGS_DIRECTORY_NAME val logPath = baseDirectory / NodeCliCommand.LOGS_DIRECTORY_NAME
try { try {
if (Files.isSymbolicLink(logPath)){ logPath.safeSymbolicRead()?.createDirectories()
Files.readSymbolicLink(logPath).createDirectories()
} else {
logPath.createDirectories()
}
} catch (e: IOException) { } catch (e: IOException) {
printError("Unable to create logging directory ${logPath.toString()}. Node will now shutdown.") printError("Unable to create logging directory ${logPath.toString()}. Node will now shutdown.")
return false return false