mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
Addressed PR issues
This commit is contained in:
parent
b651074523
commit
94bc130721
@ -1,6 +1,7 @@
|
|||||||
package com.r3.corda.doorman
|
package com.r3.corda.doorman
|
||||||
|
|
||||||
import com.google.common.net.HostAndPort
|
import com.google.common.net.HostAndPort
|
||||||
|
import com.r3.corda.doorman.DoormanServer.Companion.logger
|
||||||
import com.r3.corda.doorman.OptionParserHelper.toConfigWithOptions
|
import com.r3.corda.doorman.OptionParserHelper.toConfigWithOptions
|
||||||
import com.r3.corda.doorman.persistence.CertificationRequestStorage
|
import com.r3.corda.doorman.persistence.CertificationRequestStorage
|
||||||
import com.r3.corda.doorman.persistence.DBCertificateRequestStorage
|
import com.r3.corda.doorman.persistence.DBCertificateRequestStorage
|
||||||
@ -47,9 +48,12 @@ import kotlin.system.exitProcess
|
|||||||
* The server will require keystorePath, keystore password and key password via command line input.
|
* The server will require keystorePath, keystore password and key password via command line input.
|
||||||
* The Intermediate CA certificate,Intermediate CA private key and Root CA Certificate should use alias name specified in [X509Utilities]
|
* The Intermediate CA certificate,Intermediate CA private key and Root CA Certificate should use alias name specified in [X509Utilities]
|
||||||
*/
|
*/
|
||||||
val logger = loggerFor<DoormanServer>()
|
|
||||||
|
|
||||||
class DoormanServer(webServerAddr: HostAndPort, val caCertAndKey: CACertAndKey, val rootCACert: Certificate, val storage: CertificationRequestStorage) : Closeable {
|
class DoormanServer(webServerAddr: HostAndPort, val caCertAndKey: CACertAndKey, val rootCACert: Certificate, val storage: CertificationRequestStorage) : Closeable {
|
||||||
|
companion object {
|
||||||
|
val logger = loggerFor<DoormanServer>()
|
||||||
|
}
|
||||||
|
|
||||||
private val server: Server = Server(InetSocketAddress(webServerAddr.hostText, webServerAddr.port)).apply {
|
private val server: Server = Server(InetSocketAddress(webServerAddr.hostText, webServerAddr.port)).apply {
|
||||||
server.handler = HandlerCollection().apply {
|
server.handler = HandlerCollection().apply {
|
||||||
addHandler(buildServletContextHandler())
|
addHandler(buildServletContextHandler())
|
||||||
@ -89,7 +93,7 @@ class DoormanServer(webServerAddr: HostAndPort, val caCertAndKey: CACertAndKey,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DoormanParameters(args: Array<String>) {
|
class DoormanParameters(args: Array<String>) {
|
||||||
private val argConfig = args.toConfigWithOptions {
|
private val argConfig = args.toConfigWithOptions {
|
||||||
accepts("basedir", "Overriding configuration filepath, default to current directory.").withRequiredArg().describedAs("filepath")
|
accepts("basedir", "Overriding configuration filepath, default to current directory.").withRequiredArg().describedAs("filepath")
|
||||||
accepts("keygen", "Generate CA keypair and certificate using provide Root CA key.").withOptionalArg()
|
accepts("keygen", "Generate CA keypair and certificate using provide Root CA key.").withOptionalArg()
|
||||||
@ -136,10 +140,7 @@ private fun readPassword(fmt: String): String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
private fun DoormanParameters.generateRootKeyPair() {
|
||||||
DoormanParameters(args).run {
|
|
||||||
when (mode) {
|
|
||||||
DoormanParameters.Mode.ROOT_KEYGEN -> {
|
|
||||||
println("Generating Root CA keypair and certificate.")
|
println("Generating Root CA keypair and certificate.")
|
||||||
// Get password from console if not in config.
|
// Get password from console if not in config.
|
||||||
val rootKeystorePassword = rootKeystorePassword ?: readPassword("Root Keystore Password : ")
|
val rootKeystorePassword = rootKeystorePassword ?: readPassword("Root Keystore Password : ")
|
||||||
@ -161,8 +162,9 @@ fun main(args: Array<String>) {
|
|||||||
|
|
||||||
println("Root CA keypair and certificate stored in $rootStorePath.")
|
println("Root CA keypair and certificate stored in $rootStorePath.")
|
||||||
println(loadKeyStore(rootStorePath, rootKeystorePassword).getCertificate(CORDA_ROOT_CA_PRIVATE_KEY).publicKey)
|
println(loadKeyStore(rootStorePath, rootKeystorePassword).getCertificate(CORDA_ROOT_CA_PRIVATE_KEY).publicKey)
|
||||||
}
|
}
|
||||||
DoormanParameters.Mode.CA_KEYGEN -> {
|
|
||||||
|
private fun DoormanParameters.generateKeyPair() {
|
||||||
println("Generating Intermediate CA keypair and certificate using root keystore $rootStorePath.")
|
println("Generating Intermediate CA keypair and certificate using root keystore $rootStorePath.")
|
||||||
// Get password from console if not in config.
|
// Get password from console if not in config.
|
||||||
val rootKeystorePassword = rootKeystorePassword ?: readPassword("Root Keystore Password : ")
|
val rootKeystorePassword = rootKeystorePassword ?: readPassword("Root Keystore Password : ")
|
||||||
@ -190,8 +192,9 @@ fun main(args: Array<String>) {
|
|||||||
saveKeyStore(keyStore, keystorePath, keystorePassword)
|
saveKeyStore(keyStore, keystorePath, keystorePassword)
|
||||||
println("Intermediate CA keypair and certificate stored in $keystorePath.")
|
println("Intermediate CA keypair and certificate stored in $keystorePath.")
|
||||||
println(loadKeyStore(keystorePath, keystorePassword).getCertificate(CORDA_INTERMEDIATE_CA_PRIVATE_KEY).publicKey)
|
println(loadKeyStore(keystorePath, keystorePassword).getCertificate(CORDA_INTERMEDIATE_CA_PRIVATE_KEY).publicKey)
|
||||||
}
|
}
|
||||||
DoormanParameters.Mode.DOORMAN -> {
|
|
||||||
|
private fun DoormanParameters.startDoorman() {
|
||||||
logger.info("Starting Doorman server.")
|
logger.info("Starting Doorman server.")
|
||||||
// Get password from console if not in config.
|
// Get password from console if not in config.
|
||||||
val keystorePassword = keystorePassword ?: readPassword("Keystore Password : ")
|
val keystorePassword = keystorePassword ?: readPassword("Keystore Password : ")
|
||||||
@ -223,7 +226,14 @@ fun main(args: Array<String>) {
|
|||||||
val doorman = DoormanServer(HostAndPort.fromParts(host, port), caCertAndKey, rootCACert, storage)
|
val doorman = DoormanServer(HostAndPort.fromParts(host, port), caCertAndKey, rootCACert, storage)
|
||||||
doorman.start()
|
doorman.start()
|
||||||
Runtime.getRuntime().addShutdownHook(thread(start = false) { doorman.close() })
|
Runtime.getRuntime().addShutdownHook(thread(start = false) { doorman.close() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
DoormanParameters(args).run {
|
||||||
|
when (mode) {
|
||||||
|
DoormanParameters.Mode.ROOT_KEYGEN -> generateRootKeyPair()
|
||||||
|
DoormanParameters.Mode.CA_KEYGEN -> generateKeyPair()
|
||||||
|
DoormanParameters.Mode.DOORMAN -> startDoorman()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,5 +19,3 @@ class DoormanParametersTest {
|
|||||||
assertEquals(1000, params2.port)
|
assertEquals(1000, params2.port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user