mirror of
https://github.com/corda/corda.git
synced 2025-06-17 22:58:19 +00:00
Clarify exceptions thrown from loading a key store
Clarify exceptions thrown from loading a key store as a general cleanup. Also tightens the exceptions caught when loading key stores from AbstractNode, so in case of an unexpected error we don't silently drop the exception.
This commit is contained in:
@ -53,9 +53,11 @@ import net.corda.node.utilities.databaseTransaction
|
||||
import org.apache.activemq.artemis.utils.ReusableLatch
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.slf4j.Logger
|
||||
import java.io.IOException
|
||||
import java.nio.file.FileAlreadyExistsException
|
||||
import java.nio.file.Path
|
||||
import java.security.KeyPair
|
||||
import java.security.KeyStoreException
|
||||
import java.time.Clock
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@ -312,9 +314,12 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
||||
|
||||
private fun hasSSLCertificates(): Boolean {
|
||||
val keyStore = try {
|
||||
// This will throw exception if key file not found or keystore password is incorrect.
|
||||
// This will throw IOException if key file not found or KeyStoreException if keystore password is incorrect.
|
||||
X509Utilities.loadKeyStore(configuration.keyStoreFile, configuration.keyStorePassword)
|
||||
} catch (e: Exception) {
|
||||
} catch (e: IOException) {
|
||||
null
|
||||
} catch (e: KeyStoreException) {
|
||||
log.warn("Certificate key store found but key store password does not match configuration.")
|
||||
null
|
||||
}
|
||||
return keyStore?.containsAlias(X509Utilities.CORDA_CLIENT_CA) ?: false
|
||||
|
@ -50,6 +50,7 @@ import rx.Subscription
|
||||
import java.io.IOException
|
||||
import java.math.BigInteger
|
||||
import java.security.KeyStore
|
||||
import java.security.KeyStoreException
|
||||
import java.security.Principal
|
||||
import java.util.*
|
||||
import java.util.concurrent.Executor
|
||||
@ -113,6 +114,7 @@ class ArtemisMessagingServer(override val config: NodeConfiguration,
|
||||
* The server will make sure the bridge exists on network map changes, see method [updateBridgesOnNetworkChange]
|
||||
* We assume network map will be updated accordingly when the client node register with the network map server.
|
||||
*/
|
||||
@Throws(IOException::class, KeyStoreException::class)
|
||||
fun start() = mutex.locked {
|
||||
if (!running) {
|
||||
configureAndStartServer()
|
||||
@ -130,6 +132,9 @@ class ArtemisMessagingServer(override val config: NodeConfiguration,
|
||||
running = false
|
||||
}
|
||||
|
||||
// TODO: Maybe wrap [IOException] on a key store load error so that it's clearly splitting key store loading from
|
||||
// Artemis IO errors
|
||||
@Throws(IOException::class, KeyStoreException::class)
|
||||
private fun configureAndStartServer() {
|
||||
val config = createArtemisConfig()
|
||||
val securityManager = createArtemisSecurityManager()
|
||||
@ -225,6 +230,7 @@ class ArtemisMessagingServer(override val config: NodeConfiguration,
|
||||
deleteNonDurableQueue, manage, browse)
|
||||
}
|
||||
|
||||
@Throws(IOException::class, KeyStoreException::class)
|
||||
private fun createArtemisSecurityManager(): ActiveMQJAASSecurityManager {
|
||||
val ourCertificate = X509Utilities
|
||||
.loadCertificateFromKeyStore(config.keyStoreFile, config.keyStorePassword, CORDA_CLIENT_CA)
|
||||
|
@ -88,6 +88,8 @@ class ArtemisMessagingTests {
|
||||
fun cleanUp() {
|
||||
messagingClient?.stop()
|
||||
messagingServer?.stop()
|
||||
messagingClient = null
|
||||
messagingServer = null
|
||||
dataSource.close()
|
||||
LogHelper.reset(PersistentUniquenessProvider::class)
|
||||
}
|
||||
|
Reference in New Issue
Block a user