Merge OS to Enterprise

This commit is contained in:
szymonsztuka
2018-11-27 12:53:31 +00:00
55 changed files with 1100 additions and 511 deletions

View File

@ -44,6 +44,7 @@ buildscript {
ext.fileupload_version = '1.3.3' ext.fileupload_version = '1.3.3'
ext.junit_version = '4.12' ext.junit_version = '4.12'
ext.mockito_version = '2.18.3' ext.mockito_version = '2.18.3'
ext.mockito_kotlin_version = '1.5.0'
ext.hamkrest_version = '1.4.2.2' ext.hamkrest_version = '1.4.2.2'
ext.jopt_simple_version = '5.0.2' ext.jopt_simple_version = '5.0.2'
ext.jansi_version = '1.14' ext.jansi_version = '1.14'
@ -93,9 +94,8 @@ buildscript {
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
jcenter() jcenter()
// This repository is needed for Dokka until 0.9.16 is released.
maven { maven {
url 'https://dl.bintray.com/kotlin/kotlin-eap/' url 'https://kotlin.bintray.com/kotlinx'
} }
maven { maven {
url "$artifactory_contextUrl/corda-releases" url "$artifactory_contextUrl/corda-releases"

View File

@ -448,7 +448,7 @@ object Configuration {
override fun toString(): String { override fun toString(): String {
return "(keyName='$keyName', typeName='$typeName', path=$path, message='$message')" return "$message: (keyName='$keyName', typeName='$typeName', path=$path)"
} }
/** /**

View File

@ -1,4 +1,4 @@
gradlePluginsVersion=4.0.34 gradlePluginsVersion=4.0.36
kotlinVersion=1.2.71 kotlinVersion=1.2.71
# ***************************************************************# # ***************************************************************#
# When incrementing platformVersion make sure to update # # When incrementing platformVersion make sure to update #

View File

@ -53,6 +53,7 @@ task patchCore(type: Zip, dependsOn: coreJarTask) {
exclude 'net/corda/core/internal/*ToggleField*.class' exclude 'net/corda/core/internal/*ToggleField*.class'
exclude 'net/corda/core/serialization/*SerializationFactory*.class' exclude 'net/corda/core/serialization/*SerializationFactory*.class'
exclude 'net/corda/core/serialization/internal/CheckpointSerializationFactory*.class' exclude 'net/corda/core/serialization/internal/CheckpointSerializationFactory*.class'
exclude 'net/corda/core/internal/rules/*.class'
exclude 'net/corda/core/utilities/SgxSupport*.class' exclude 'net/corda/core/utilities/SgxSupport*.class'
} }

View File

@ -0,0 +1,12 @@
package net.corda.core.internal.rules
import net.corda.core.contracts.ContractState
// This file provides rules that depend on the targetVersion of the current Contract or Flow.
// In core, this is determined by means which are unavailable in the DJVM,
// so we must provide deterministic alternatives here.
@Suppress("unused")
object StateContractValidationEnforcementRule {
fun shouldEnforce(state: ContractState): Boolean = true
}

View File

@ -149,7 +149,7 @@ abstract class TransactionVerificationException(val txId: SecureHash, message: S
"is not satisfied. Encumbered states should also be referenced as an encumbrance of another state to form " + "is not satisfied. Encumbered states should also be referenced as an encumbrance of another state to form " +
"a full cycle. Offending indices $nonMatching", null) "a full cycle. Offending indices $nonMatching", null)
/** /**HEAD
* All encumbered states should be assigned to the same notary. This is due to the fact that multi-notary * All encumbered states should be assigned to the same notary. This is due to the fact that multi-notary
* transactions are not supported and thus two encumbered states with different notaries cannot be consumed * transactions are not supported and thus two encumbered states with different notaries cannot be consumed
* in the same transaction. * in the same transaction.
@ -159,6 +159,36 @@ abstract class TransactionVerificationException(val txId: SecureHash, message: S
: TransactionVerificationException(txId, "Encumbered output states assigned to different notaries found. " + : TransactionVerificationException(txId, "Encumbered output states assigned to different notaries found. " +
"Output state with index $encumberedIndex is assigned to notary [$encumberedNotary], while its encumbrance with index $encumbranceIndex is assigned to notary [$encumbranceNotary]", null) "Output state with index $encumberedIndex is assigned to notary [$encumberedNotary], while its encumbrance with index $encumbranceIndex is assigned to notary [$encumbranceNotary]", null)
/**
* If a state is identified as belonging to a contract, either because the state class is defined as an inner class
* of the contract class or because the state class is annotated with [BelongsToContract], then it must not be
* bundled in a [TransactionState] with a different contract.
*
* @param state The [TransactionState] whose bundled state and contract are in conflict.
* @param requiredContractClassName The class name of the contract to which the state belongs.
*/
@KeepForDJVM
class TransactionContractConflictException(txId: SecureHash, state: TransactionState<ContractState>, requiredContractClassName: String)
: TransactionVerificationException(txId,
"""
State of class ${state.data::class.java.typeName} belongs to contract $requiredContractClassName, but
is bundled in TransactionState with ${state.contract}.
For details see: https://docs.corda.net/api-contract-constraints.html#contract-state-agreement
""".trimIndent().replace('\n', ' '), null)
// TODO: add reference to documentation
@KeepForDJVM
class TransactionRequiredContractUnspecifiedException(txId: SecureHash, state: TransactionState<ContractState>)
: TransactionVerificationException(txId,
"""
State of class ${state.data::class.java.typeName} does not have a specified owning contract.
Add the @BelongsToContract annotation to this class to ensure that it can only be bundled in a TransactionState
with the correct contract.
For details see: https://docs.corda.net/api-contract-constraints.html#contract-state-agreement
""".trimIndent(), null)
/** Whether the inputs or outputs list contains an encumbrance issue, see [TransactionMissingEncumbranceException]. */ /** Whether the inputs or outputs list contains an encumbrance issue, see [TransactionMissingEncumbranceException]. */
@CordaSerializable @CordaSerializable
@KeepForDJVM @KeepForDJVM

View File

@ -0,0 +1,55 @@
package net.corda.core.internal.rules
import net.corda.core.contracts.ContractState
import net.corda.core.utilities.contextLogger
import net.corda.core.utilities.warnOnce
import org.slf4j.LoggerFactory
import java.net.URL
import java.util.concurrent.ConcurrentHashMap
import java.util.jar.JarInputStream
import java.util.jar.Manifest
// This file provides rules that depend on the targetVersion of the current Contract or Flow.
// Rules defined in this package are automatically removed from the DJVM in core-deterministic,
// and must be replaced by a deterministic alternative defined within that module.
/**
* Rule which determines whether [ContractState]s must declare the [Contract] to which they belong (e.g. via the
* [BelongsToContract] annotation), and must be bundled together with that contract in any [TransactionState].
*
* This rule is consulted during validation by [LedgerTransaction].
*/
object StateContractValidationEnforcementRule {
private val logger = LoggerFactory.getLogger(StateContractValidationEnforcementRule::class.java)
private val targetVersionCache = ConcurrentHashMap<URL, Int>()
fun shouldEnforce(state: ContractState): Boolean {
val jarLocation = state::class.java.protectionDomain.codeSource.location
if (jarLocation == null) {
logger.warnOnce("""
Unable to determine JAR location for contract state class ${state::class.java.name},
and consequently unable to determine target platform version.
Enforcing state/contract agreement validation by default.
For details see: https://docs.corda.net/api-contract-constraints.html#contract-state-agreement
""".trimIndent().replace("\n", " "))
return true
}
val targetVersion = targetVersionCache.computeIfAbsent(jarLocation) {
jarLocation.openStream().use { inputStream ->
JarInputStream(inputStream).manifest?.targetPlatformVersion ?: 1
}
}
return targetVersion >= 4
}
}
private val Manifest.targetPlatformVersion: Int get() {
val minPlatformVersion = mainAttributes.getValue("Min-Platform-Version")?.toInt() ?: 1
return mainAttributes.getValue("Target-Platform-Version")?.toInt() ?: minPlatformVersion
}

View File

@ -107,8 +107,8 @@ data class NetworkParameters(
private fun owns(packageName: String, fullClassName: String) = fullClassName.startsWith("$packageName.", ignoreCase = true) private fun owns(packageName: String, fullClassName: String) = fullClassName.startsWith("$packageName.", ignoreCase = true)
// Make sure that packages don't overlap so that ownership is clear. // Make sure that packages don't overlap so that ownership is clear.
private fun noOverlap(packages: Collection<String>) = packages.all { currentPackage -> fun noOverlap(packages: Collection<String>) = packages.all { currentPackage ->
packages.none { otherPackage -> otherPackage != currentPackage && otherPackage.startsWith("${currentPackage}.") } packages.none { otherPackage -> otherPackage != currentPackage && otherPackage.startsWith("$currentPackage.") }
} }
private fun KProperty1<out NetworkParameters, Any?>.isAutoAcceptable(): Boolean { private fun KProperty1<out NetworkParameters, Any?>.isAutoAcceptable(): Boolean {
@ -117,14 +117,14 @@ data class NetworkParameters(
} }
init { init {
require(minimumPlatformVersion > 0) { "minimumPlatformVersion must be at least 1" } require(minimumPlatformVersion > 0) { "Minimum platform level must be at least 1" }
require(notaries.distinctBy { it.identity } == notaries) { "Duplicate notary identities" } require(notaries.distinctBy { it.identity } == notaries) { "Duplicate notary identities" }
require(epoch > 0) { "epoch must be at least 1" } require(epoch > 0) { "Epoch must be at least 1" }
require(maxMessageSize > 0) { "maxMessageSize must be at least 1" } require(maxMessageSize > 0) { "Maximum message size must be at least 1" }
require(maxTransactionSize > 0) { "maxTransactionSize must be at least 1" } require(maxTransactionSize > 0) { "Maximum transaction size must be at least 1" }
require(!eventHorizon.isNegative) { "eventHorizon must be positive value" } require(!eventHorizon.isNegative) { "Event Horizon must be a positive value" }
packageOwnership.keys.forEach(::requirePackageValid) packageOwnership.keys.forEach(::requirePackageValid)
require(noOverlap(packageOwnership.keys)) { "multiple packages added to the packageOwnership overlap." } require(noOverlap(packageOwnership.keys)) { "Multiple packages added to the packageOwnership overlap." }
} }
fun copy(minimumPlatformVersion: Int, fun copy(minimumPlatformVersion: Int,
@ -217,3 +217,7 @@ data class NotaryInfo(val identity: Party, val validating: Boolean)
* version. * version.
*/ */
class ZoneVersionTooLowException(message: String) : CordaRuntimeException(message) class ZoneVersionTooLowException(message: String) : CordaRuntimeException(message)
private fun KProperty1<out NetworkParameters, Any?>.isAutoAcceptable(): Boolean {
return this.findAnnotation<AutoAcceptable>() != null
}

View File

@ -3,10 +3,14 @@ package net.corda.core.transactions
import net.corda.core.CordaInternal import net.corda.core.CordaInternal
import net.corda.core.KeepForDJVM import net.corda.core.KeepForDJVM
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.TransactionVerificationException.TransactionContractConflictException
import net.corda.core.contracts.TransactionVerificationException.TransactionRequiredContractUnspecifiedException
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.isFulfilledBy import net.corda.core.crypto.isFulfilledBy
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.* import net.corda.core.internal.*
import net.corda.core.internal.rules.StateContractValidationEnforcementRule
import net.corda.core.internal.uncheckedCast
import net.corda.core.node.NetworkParameters import net.corda.core.node.NetworkParameters
import net.corda.core.serialization.ConstructorForDeserialization import net.corda.core.serialization.ConstructorForDeserialization
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
@ -133,7 +137,37 @@ private constructor(
} }
/** /**
* Verify that package ownership is respected. * For all input and output [TransactionState]s, validates that the wrapped [ContractState] matches up with the
* wrapped [Contract], as declared by the [BelongsToContract] annotation on the [ContractState]'s class.
*
* If the target platform version of the current CorDapp is lower than 4.0, a warning will be written to the log
* if any mismatch is detected. If it is 4.0 or later, then [TransactionContractConflictException] will be thrown.
*/
private fun validateStatesAgainstContract(internalTx: LedgerTransaction) =
internalTx.allStates.forEach(::validateStateAgainstContract)
private fun validateStateAgainstContract(state: TransactionState<ContractState>) {
val shouldEnforce = StateContractValidationEnforcementRule.shouldEnforce(state.data)
val requiredContractClassName = state.data.requiredContractClassName ?:
if (shouldEnforce) throw TransactionRequiredContractUnspecifiedException(id, state)
else return
if (state.contract != requiredContractClassName)
if (shouldEnforce) {
throw TransactionContractConflictException(id, state, requiredContractClassName)
} else {
logger.warnOnce("""
State of class ${state.data::class.java.typeName} belongs to contract $requiredContractClassName, but
is bundled in TransactionState with ${state.contract}.
For details see: https://docs.corda.net/api-contract-constraints.html#contract-state-agreement
""".trimIndent().replace('\n', ' '))
}
}
/**
* Verify that for each contract the network wide package owner is respected.
* *
* TODO - revisit once transaction contains network parameters. * TODO - revisit once transaction contains network parameters.
*/ */
@ -156,24 +190,6 @@ private constructor(
} }
} }
/**
* For all input and output [TransactionState]s, validates that the wrapped [ContractState] matches up with the
* wrapped [Contract], as declared by the [BelongsToContract] annotation on the [ContractState]'s class.
*
* A warning will be written to the log if any mismatch is detected.
*/
private fun validateStatesAgainstContract(internalTx: LedgerTransaction) = internalTx.allStates.forEach { validateStateAgainstContract(it) }
private fun validateStateAgainstContract(state: TransactionState<ContractState>) {
state.data.requiredContractClassName?.let { requiredContractClassName ->
if (state.contract != requiredContractClassName)
logger.warnOnce("""
State of class ${state.data::class.java.typeName} belongs to contract $requiredContractClassName, but
is bundled in TransactionState with ${state.contract}.
""".trimIndent().replace('\n', ' '))
}
}
/** /**
* Enforces the validity of the actual constraints. * Enforces the validity of the actual constraints.
* * Constraints should be one of the valid supported ones. * * Constraints should be one of the valid supported ones.

View File

@ -14,8 +14,6 @@ import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import net.corda.node.VersionInfo import net.corda.node.VersionInfo
import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.common.internal.testNetworkParameters
import net.corda.testing.contracts.DummyContract
import net.corda.testing.contracts.DummyState
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.InternalMockNodeParameters import net.corda.testing.node.internal.InternalMockNodeParameters
import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.cordappsForPackages
@ -106,16 +104,16 @@ internal class UseRefState(private val linearId: UniqueIdentifier) : FlowLogic<S
relevancyStatus = Vault.RelevancyStatus.ALL relevancyStatus = Vault.RelevancyStatus.ALL
) )
val referenceState = serviceHub.vaultService.queryBy<ContractState>(query).states.single() val referenceState = serviceHub.vaultService.queryBy<ContractState>(query).states.single()
val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply { val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply {
addReferenceState(referenceState.referenced()) addReferenceState(referenceState.referenced())
addOutputState(DummyState(), DummyContract.PROGRAM_ID) addOutputState(RefState.State(ourIdentity), RefState.CONTRACT_ID)
addCommand(DummyContract.Commands.Create(), listOf(ourIdentity.owningKey)) addCommand(RefState.Create(), listOf(ourIdentity.owningKey))
}) })
return subFlow(FinalityFlow(stx, emptyList())) return subFlow(FinalityFlow(stx, emptyList()))
} }
} }
class WithReferencedStatesFlowTests { class WithReferencedStatesFlowTests {
companion object { companion object {
@JvmStatic @JvmStatic

View File

@ -58,10 +58,21 @@ class ReferenceStateTests {
// check might not be present in other contracts, like Cash, for example. Cash might have a command // check might not be present in other contracts, like Cash, for example. Cash might have a command
// called "Share" that allows a party to prove to another that they own over a certain amount of cash. // called "Share" that allows a party to prove to another that they own over a certain amount of cash.
// As such, cash can be added to the references list with a "Share" command. // As such, cash can be added to the references list with a "Share" command.
@BelongsToContract(ExampleContract::class)
data class ExampleState(val creator: Party, val data: String) : ContractState { data class ExampleState(val creator: Party, val data: String) : ContractState {
override val participants: List<AbstractParty> get() = listOf(creator) override val participants: List<AbstractParty> get() = listOf(creator)
} }
// This state has only been created to serve reference data so it cannot ever be used as an input or
// output when it is being referred to. However, we might want all states to be referable, so this
// check might not be present in other contracts, like Cash, for example. Cash might have a command
// called "Share" that allows a party to prove to another that they own over a certain amount of cash.
// As such, cash can be added to the references list with a "Share" command.
@BelongsToContract(Cash::class)
data class ExampleCashState(val creator: Party, val data: String) : ContractState {
override val participants: List<AbstractParty> get() = listOf(creator)
}
class ExampleContract : Contract { class ExampleContract : Contract {
interface Commands : CommandData interface Commands : CommandData
class Create : Commands class Create : Commands
@ -169,7 +180,7 @@ class ReferenceStateTests {
transaction { transaction {
input("REF DATA") input("REF DATA")
command(ALICE_PUBKEY, ExampleContract.Update()) command(ALICE_PUBKEY, ExampleContract.Update())
output(Cash.PROGRAM_ID, "UPDATED REF DATA", "REF DATA".output<ExampleState>().copy(data = "NEW STUFF!")) output(ExampleContract::class.java.typeName, "UPDATED REF DATA", "REF DATA".output<ExampleState>().copy(data = "NEW STUFF!"))
verifies() verifies()
} }
// Try to use the old one. // Try to use the old one.

View File

@ -62,6 +62,58 @@ consumes notary and ledger resources, and is just in general more complex.
.. _implicit_constraint_types: .. _implicit_constraint_types:
Contract/State Agreement
------------------------
Starting with Corda 4, ``ContractState``s must explicitly indicate which ``Contract`` they belong to. When a transaction is
verified, the contract bundled with each state in the transaction must be its "owning" contract, otherwise we cannot guarantee that
the transition of the ``ContractState`` will be verified against the business rules that should apply to it.
There are two mechanisms for indicating ownership. One is to annotate the ``ContractState`` with the ``BelongsToContract`` annotation,
indicating the ``Contract`` class to which it is tied:
.. sourcecode:: java
@BelongToContract(MyContract.class)
public class MyState implements ContractState {
// implementation goes here
}
.. sourcecode:: kotlin
@BelongsToContract(MyContract::class)
data class MyState(val value: Int) : ContractState {
// implementation goes here
}
The other is to define the ``ContractState`` class as an inner class of the ``Contract`` class
.. sourcecode:: java
public class MyContract implements Contract {
public static class MyState implements ContractState {
// state implementation goes here
}
// contract implementation goes here
}
.. sourcecode:: kotlin
class MyContract : Contract {
data class MyState(val value: Int) : ContractState
}
If a ``ContractState``'s owning ``Contract`` cannot be identified by either of these mechanisms, and the ``targetVersion`` of the
CorDapp is 4 or greater, then transaction verification will fail with a ``TransactionRequiredContractUnspecifiedException``. If
the owning ``Contract`` _can_ be identified, but the ``ContractState`` has been bundled with a different contract, then
transaction verification will fail with a ``TransactionContractConflictException``.
How constraints work How constraints work
-------------------- --------------------

View File

@ -376,7 +376,7 @@ Configuring a node where the Corda Compatibility Zone's registration and Network
.. literalinclude:: example-code/src/main/resources/example-node-with-networkservices.conf .. literalinclude:: example-code/src/main/resources/example-node-with-networkservices.conf
Fields Override Fields override
--------------- ---------------
JVM options or environmental variables prefixed with ``corda.`` can override ``node.conf`` fields. JVM options or environmental variables prefixed with ``corda.`` can override ``node.conf`` fields.
Provided system properties can also set values for absent fields in ``node.conf``. Provided system properties can also set values for absent fields in ``node.conf``.
@ -387,7 +387,7 @@ This is an example of adding/overriding the keyStore password :
java -Dcorda.rpcSettings.ssl.keyStorePassword=mypassword -jar node.jar java -Dcorda.rpcSettings.ssl.keyStorePassword=mypassword -jar node.jar
CRL Configuration CRL configuration
----------------- -----------------
The Corda Network provides an endpoint serving an empty certificate revocation list for the TLS-level certificates. The Corda Network provides an endpoint serving an empty certificate revocation list for the TLS-level certificates.
This is intended for deployments that do not provide a CRL infrastructure but still require a strict CRL mode checking. This is intended for deployments that do not provide a CRL infrastructure but still require a strict CRL mode checking.
@ -406,7 +406,9 @@ Together with the above configuration `tlsCertCrlIssuer` option needs to be set
This set-up ensures that the TLS-level certificates are embedded with the CRL distribution point referencing the CRL issued by R3. This set-up ensures that the TLS-level certificates are embedded with the CRL distribution point referencing the CRL issued by R3.
In cases where a proprietary CRL infrastructure is provided those values need to be changed accordingly. In cases where a proprietary CRL infrastructure is provided those values need to be changed accordingly.
Hiding Sensitive Data .. _corda-configuration-hiding-sensitive-data:
Hiding sensitive data
--------------------- ---------------------
A frequent requirement is that configuration files must not expose passwords to unauthorised readers. By leveraging environment variables, it is possible to hide passwords and other similar fields. A frequent requirement is that configuration files must not expose passwords to unauthorised readers. By leveraging environment variables, it is possible to hide passwords and other similar fields.

View File

@ -15,7 +15,7 @@ In addition to the network map, all the nodes must also use the same set of netw
which guarantee interoperability between the nodes. The HTTP network map distributes the network parameters which are downloaded which guarantee interoperability between the nodes. The HTTP network map distributes the network parameters which are downloaded
automatically by the nodes. In the absence of this the network parameters must be generated locally. automatically by the nodes. In the absence of this the network parameters must be generated locally.
For these reasons, test deployments can avail themselves of the network bootstrapper. This is a tool that scans all the For these reasons, test deployments can avail themselves of the Network Bootstrapper. This is a tool that scans all the
node configurations from a common directory to generate the network parameters file, which is then copied to all the nodes' node configurations from a common directory to generate the network parameters file, which is then copied to all the nodes'
directories. It also copies each node's node-info file to every other node so that they can all be visible to each other. directories. It also copies each node's node-info file to every other node so that they can all be visible to each other.
@ -41,7 +41,7 @@ For example running the command on a directory containing these files:
└── partyb_node.conf // Party B's node.conf file └── partyb_node.conf // Party B's node.conf file
will generate directories containing three nodes: ``notary``, ``partya`` and ``partyb``. They will each use the ``corda.jar`` will generate directories containing three nodes: ``notary``, ``partya`` and ``partyb``. They will each use the ``corda.jar``
that comes with the bootstrapper. If a different version of Corda is required then simply place that ``corda.jar`` file that comes with the Network Bootstrapper. If a different version of Corda is required then simply place that ``corda.jar`` file
alongside the configuration files in the directory. alongside the configuration files in the directory.
You can also have the node directories containing their "node.conf" files already laid out. The previous example would be: You can also have the node directories containing their "node.conf" files already laid out. The previous example would be:
@ -56,7 +56,7 @@ You can also have the node directories containing their "node.conf" files alread
└── partyb └── partyb
└── node.conf └── node.conf
Similarly, each node directory may contain its own ``corda.jar``, which the bootstrapper will use instead. Similarly, each node directory may contain its own ``corda.jar``, which the Bootstrapper will use instead.
Providing CorDapps to the Network Bootstrapper Providing CorDapps to the Network Bootstrapper
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -87,7 +87,7 @@ Any CorDapps provided when bootstrapping a network will be scanned for contracts
The CorDapp JARs will be hashed and scanned for ``Contract`` classes. These contract class implementations will become part The CorDapp JARs will be hashed and scanned for ``Contract`` classes. These contract class implementations will become part
of the whitelisted contracts in the network parameters (see ``NetworkParameters.whitelistedContractImplementations`` :doc:`network-map`). of the whitelisted contracts in the network parameters (see ``NetworkParameters.whitelistedContractImplementations`` :doc:`network-map`).
By default the bootstrapper will whitelist all the contracts found in the unsigned CorDapp JARs (a JAR file not signed by jarSigner tool). By default the Bootstrapper will whitelist all the contracts found in the unsigned CorDapp JARs (a JAR file not signed by jarSigner tool).
Whitelisted contracts are checked by `Zone constraints`, while contract classes from signed JARs will be checked by `Signature constraints`. Whitelisted contracts are checked by `Zone constraints`, while contract classes from signed JARs will be checked by `Signature constraints`.
To prevent certain contracts from unsigned JARs from being whitelisted, add their fully qualified class name in the ``exclude_whitelist.txt``. To prevent certain contracts from unsigned JARs from being whitelisted, add their fully qualified class name in the ``exclude_whitelist.txt``.
These will instead use the more restrictive ``HashAttachmentConstraint``. These will instead use the more restrictive ``HashAttachmentConstraint``.
@ -103,7 +103,7 @@ For example:
Modifying a bootstrapped network Modifying a bootstrapped network
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The network bootstrapper is provided as a development tool for setting up Corda networks for development and testing. The Network Bootstrapper is provided as a development tool for setting up Corda networks for development and testing.
There is some limited functionality which can be used to make changes to a network, but for anything more complicated consider There is some limited functionality which can be used to make changes to a network, but for anything more complicated consider
using a :doc:`network-map` server. using a :doc:`network-map` server.
@ -115,7 +115,7 @@ the nodes are being run on different machines you need to do the following:
* Run the Network Bootstrapper from the root directory * Run the Network Bootstrapper from the root directory
* Copy each individual node's directory back to the original machine * Copy each individual node's directory back to the original machine
The network bootstrapper cannot dynamically update the network if an existing node has changed something in their node-info, The Network Bootstrapper cannot dynamically update the network if an existing node has changed something in their node-info,
e.g. their P2P address. For this the new node-info file will need to be placed in the other nodes' ``additional-node-infos`` directory. e.g. their P2P address. For this the new node-info file will need to be placed in the other nodes' ``additional-node-infos`` directory.
If the nodes are located on different machines, then a utility such as `rsync <https://en.wikipedia.org/wiki/Rsync>`_ can be used If the nodes are located on different machines, then a utility such as `rsync <https://en.wikipedia.org/wiki/Rsync>`_ can be used
so that the nodes can share node-infos. so that the nodes can share node-infos.
@ -123,11 +123,11 @@ so that the nodes can share node-infos.
Adding a new node to the network Adding a new node to the network
-------------------------------- --------------------------------
Running the bootstrapper again on the same network will allow a new node to be added and its Running the Bootstrapper again on the same network will allow a new node to be added and its
node-info distributed to the existing nodes. node-info distributed to the existing nodes.
As an example, if we have an existing bootstrapped network, with a Notary and PartyA and we want to add a PartyB, we As an example, if we have an existing bootstrapped network, with a Notary and PartyA and we want to add a PartyB, we
can use the network bootstrapper on the following network structure: can use the Network Bootstrapper on the following network structure:
.. sourcecode:: none .. sourcecode:: none
@ -148,7 +148,7 @@ can use the network bootstrapper on the following network structure:
│ └── node-info-partya │ └── node-info-partya
└── partyb_node.conf // the node.conf for the node to be added └── partyb_node.conf // the node.conf for the node to be added
Then run the network bootstrapper again from the root dir: Then run the Network Bootstrapper again from the root dir:
``java -jar network-bootstrapper-VERSION.jar --dir <nodes-root-dir>`` ``java -jar network-bootstrapper-VERSION.jar --dir <nodes-root-dir>``
@ -182,19 +182,19 @@ Which will give the following:
├── node-info-partya ├── node-info-partya
└── node-info-partyb └── node-info-partyb
The bootstrapper will generate a directory and the ``node-info`` file for PartyB, and will also make sure a copy of each The Bootstrapper will generate a directory and the ``node-info`` file for PartyB, and will also make sure a copy of each
nodes' ``node-info`` file is in the ``additional-node-info`` directory of every node. Any other files in the existing nodes, nodes' ``node-info`` file is in the ``additional-node-info`` directory of every node. Any other files in the existing nodes,
such a generated keys, will be unaffected. such a generated keys, will be unaffected.
.. note:: The bootstrapper is provided for test deployments and can only generate information for nodes collected on .. note:: The Network Bootstrapper is provided for test deployments and can only generate information for nodes collected on
the same machine. If a network needs to be updated using the bootstrapper once deployed, the nodes will need the same machine. If a network needs to be updated using the Bootstrapper once deployed, the nodes will need
collecting back together. collecting back together.
Updating the contract whitelist for bootstrapped networks Updating the contract whitelist for bootstrapped networks
--------------------------------------------------------- ---------------------------------------------------------
If the network already has a set of network parameters defined (i.e. the node directories all contain the same network-parameters If the network already has a set of network parameters defined (i.e. the node directories all contain the same network-parameters
file) then the bootstrapper can be used to append contracts from new CorDapps to the current whitelist. file) then the Network Bootstrapper can be used to append contracts from new CorDapps to the current whitelist.
For example, with the following pre-generated network: For example, with the following pre-generated network:
.. sourcecode:: none .. sourcecode:: none
@ -217,7 +217,7 @@ For example, with the following pre-generated network:
│ └── cordapp-a.jar │ └── cordapp-a.jar
└── cordapp-b.jar // The new cordapp to add to the existing nodes └── cordapp-b.jar // The new cordapp to add to the existing nodes
Then run the network bootstrapper again from the root dir: Then run the Network Bootstrapper again from the root dir:
``java -jar network-bootstrapper-VERSION.jar --dir <nodes-root-dir>`` ``java -jar network-bootstrapper-VERSION.jar --dir <nodes-root-dir>``
@ -247,81 +247,183 @@ To give the following:
.. note:: The whitelist can only ever be appended to. Once added a contract implementation can never be removed. .. note:: The whitelist can only ever be appended to. Once added a contract implementation can never be removed.
Package namespace ownership Modifying the network parameters
---------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Package namespace ownership is a Corda security feature that allows a compatibility zone to give ownership of parts of the Java package namespace to registered users (e.g. CorDapp development organisations). The Network Bootstrapper creates a network parameters file when bootstrapping a network, using a set of sensible defaults. However, if you would like
The exact mechanism used to claim a namespace is up to the zone operator. A typical approach would be to accept an SSL to override these defaults when testing, there are two ways of doing this. Options can be overridden via the command line or by supplying a configuration
certificate with the domain in it as proof of domain ownership, or to accept an email from that domain. file. If the same parameter is overridden both by a command line argument and in the configuration file, the command line value
will take precedence.
Overriding network parameters via command line
----------------------------------------------
The ``--minimum-platform-version``, ``--max-message-size``, ``--max-transaction-size`` and ``--event-horizon`` command line parameters can
be used to override the default network parameters. See `Command line options`_ for more information.
Overriding network parameters via a file
----------------------------------------
You can provide a network parameters overrides file using the following syntax:
``java -jar network-bootstrapper-VERSION.jar --network-parameters-overrides=<path_to_file>``
Or alternatively, by using the short form version:
``java -jar network-bootstrapper-VERSION.jar -n=<path_to_file>``
The network parameter overrides file is a HOCON file with the following fields, all of which are optional. Any field that is not provided will be
ignored. If a field is not provided and you are bootstrapping a new network, a sensible default value will be used. If a field is not provided and you
are updating an existing network, the value in the existing network parameters file will be used.
.. note:: All fields can be used with placeholders for environment variables. For example: ``${KEY_STORE_PASSWORD}`` would be replaced by the contents of environment
variable ``KEY_STORE_PASSWORD``. See: :ref:`corda-configuration-hiding-sensitive-data` .
The available configuration fields are listed below:
:minimumPlatformVersion: The minimum supported version of the Corda platform that is required for nodes in the network.
:maxMessageSize: The maximum permitted message size, in bytes. This is currently ignored but will be used in a future release.
:maxTransactionSize: The maximum permitted transaction size, in bytes.
:eventHorizon: The time after which nodes will be removed from the network map if they have not been seen during this period. This parameter uses
the ``parse`` function on the ``java.time.Duration`` class to interpret the data. See `here <https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#parse-java.lang.CharSequence->`_
for information on valid inputs.
:packageOwnership: A list of package owners. See `Package namespace ownership`_ for more information. For each package owner, the following fields
are required:
:packageName: Java package name (e.g `com.my_company` ).
:keystore: The path of the keystore file containing the signed certificate.
:keystorePassword: The password for the given keystore (not to be confused with the key password).
:keystoreAlias: The alias for the name associated with the certificate to be associated with the package namespace.
An example configuration file:
.. parsed-literal::
minimumPlatformVersion=4
maxMessageSize=10485760
maxTransactionSize=524288000
eventHorizon="30 days"
packageOwnership=[
{
packageName="com.example"
keystore="myteststore"
keystorePassword="MyStorePassword"
keystoreAlias="MyKeyAlias"
}
]
Package namespace ownership
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Package namespace ownership is a Corda security feature that allows a compatibility zone to give ownership of parts of the Java package
namespace to registered users (e.g. a CorDapp development organisation). The exact mechanism used to claim a namespace is up to the zone
operator. A typical approach would be to accept an SSL certificate with the domain in it as proof of domain ownership, or to accept an email from that domain.
.. note:: Read more about *Package ownership* :doc:`here<design/data-model-upgrades/package-namespace-ownership>`. .. note:: Read more about *Package ownership* :doc:`here<design/data-model-upgrades/package-namespace-ownership>`.
A Java package namespace is case insensitive and cannot be a sub-package of an existing registered namespace. A Java package namespace is case insensitive and cannot be a sub-package of an existing registered namespace.
See `Naming a Package <https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html>`_ and `Naming Conventions <https://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#28840 for guidelines and conventions>`_ for guidelines on naming conventions. See `Naming a Package <https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html>`_ and `Naming Conventions <https://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#28840 for guidelines and conventions>`_ for guidelines on naming conventions.
Registration of a java package namespace requires creation of a signed certificate as generated by the The registration of a Java package namespace requires the creation of a signed certificate as generated by the
`Java keytool <https://docs.oracle.com/javase/8/docs/technotes/tools/windows/keytool.html>`_. `Java keytool <https://docs.oracle.com/javase/8/docs/technotes/tools/windows/keytool.html>`_.
The following four items are passed as a semi-colon separated string to the ``--register-package-owner`` command: The packages can be registered by supplying a network parameters override config file via the command line, using the ``--network-parameters-overrides`` command.
1. Java package name (e.g `com.my_company` ). For each package to be registered, the following are required:
2. Keystore file refers to the full path of the file containing the signed certificate.
3. Password refers to the key store password (not to be confused with the key password).
4. Alias refers to the name associated with a certificate containing the public key to be associated with the package namespace.
Let's use the `Example CorDapp <https://github.com/corda/cordapp-example>`_ to initialise a simple network, and then register and unregister a package namespace. :packageName: Java package name (e.g `com.my_company` ).
:keystore: The path of the keystore file containing the signed certificate. If a relative path is provided, it is assumed to be relative to the
location of the configuration file.
:keystorePassword: The password for the given keystore (not to be confused with the key password).
:keystoreAlias: The alias for the name associated with the certificate to be associated with the package namespace.
Using the `Example CorDapp <https://github.com/corda/cordapp-example>`_ as an example, we will initialise a simple network and then register and unregister a package namespace.
Checkout the Example CorDapp and follow the instructions to build it `here <https://docs.corda.net/tutorial-cordapp.html#building-the-example-cordapp>`_. Checkout the Example CorDapp and follow the instructions to build it `here <https://docs.corda.net/tutorial-cordapp.html#building-the-example-cordapp>`_.
.. note:: You can point to any existing bootstrapped corda network (this will have the effect of updating the associated network parameters file). .. note:: You can point to any existing bootstrapped corda network (this will have the effect of updating the associated network parameters file).
1. Create a new public key to use for signing the java package namespace we wish to register: #. Create a new public key to use for signing the Java package namespace we wish to register:
.. code-block:: shell
$JAVA_HOME/bin/keytool -genkeypair -keystore _teststore -storepass MyStorePassword -keyalg RSA -alias MyKeyAlias -keypass MyKeyPassword -dname "O=Alice Corp, L=Madrid, C=ES"
This will generate a key store file called ``_teststore`` in the current directory.
#. Create a ``network-parameters.conf`` file in the same directory, with the following information:
.. parsed-literal::
packageOwnership=[
{
packageName="com.example"
keystore="_teststore"
keystorePassword="MyStorePassword"
keystoreAlias="MyKeyAlias"
}
]
#. Register the package namespace to be claimed by the public key generated above:
.. code-block:: shell
# Register the Java package namespace using the Network Bootstrapper
java -jar network-bootstrapper.jar --dir build/nodes --network-parameter-overrides=network-parameters.conf
#. To unregister the package namespace, edit the ``network-parameters.conf`` file to remove the package:
.. parsed-literal::
packageOwnership=[]
#. Unregister the package namespace:
.. code-block:: shell
# Unregister the Java package namespace using the Network Bootstrapper
java -jar network-bootstrapper.jar --dir build/nodes --network-parameter-overrides=network-parameters.conf
Command line options
~~~~~~~~~~~~~~~~~~~~
The Network Bootstrapper can be started with the following command line options:
.. code-block:: shell .. code-block:: shell
$JAVA_HOME/bin/keytool -genkeypair -keystore _teststore -storepass MyStorePassword -keyalg RSA -alias MyKeyAlias -keypass MyKeyPassword -dname "O=Alice Corp, L=Madrid, C=ES" bootstrapper [-hvV] [--no-copy] [--dir=<dir>] [--event-horizon=<eventHorizon>]
[--logging-level=<loggingLevel>]
This will generate a key store file called ``_teststore`` in the current directory. [--max-message-size=<maxMessageSize>]
[--max-transaction-size=<maxTransactionSize>]
2. Register the package namespace to be claimed by the public key generated above: [--minimum-platform-version=<minimumPlatformVersion>]
[-n=<networkParametersFile>] [COMMAND]
.. code-block:: shell
# Register the java package namespace using the bootstrapper tool
java -jar network-bootstrapper.jar --dir build/nodes --register-package-owner com.example;./_teststore;MyStorePassword;MyKeyAlias
3. Unregister the package namespace:
.. code-block:: shell
# Unregister the java package namespace using the bootstrapper tool
java -jar network-bootstrapper.jar --dir build/nodes --unregister-package-owner com.example
Command-line options
--------------------
The network bootstrapper can be started with the following command-line options:
.. code-block:: shell
bootstrapper [-hvV] [--no-copy] [--dir=<dir>] [--logging-level=<loggingLevel>]
[--minimum-platform-version=<minimumPlatformVersion>]
[--register-package-owner java-package-namespace=keystore-file:password:alias]
[--unregister-package-owner java-package-namespace]
[COMMAND]
* ``--dir=<dir>``: Root directory containing the node configuration files and CorDapp JARs that will form the test network. * ``--dir=<dir>``: Root directory containing the node configuration files and CorDapp JARs that will form the test network.
It may also contain existing node directories. Defaults to the current directory. It may also contain existing node directories. Defaults to the current directory.
* ``--no-copy``: Don't copy the CorDapp JARs into the nodes' "cordapps" directories. * ``--no-copy``: Don't copy the CorDapp JARs into the nodes' "cordapps" directories.
* ``--verbose``, ``--log-to-console``, ``-v``: If set, prints logging to the console as well as to a file. * ``--verbose``, ``--log-to-console``, ``-v``: If set, prints logging to the console as well as to a file.
* ``--logging-level=<loggingLevel>``: Enable logging at this level and higher. Possible values: ERROR, WARN, INFO, DEBUG, TRACE. Default: INFO. * ``--logging-level=<loggingLevel>``: Enable logging at this level and higher. Possible values: ERROR, WARN, INFO, DEBUG, TRACE. Default: INFO.
* ``--help``, ``-h``: Show this help message and exit. * ``--help``, ``-h``: Show this help message and exit.
* ``--version``, ``-V``: Print version information and exit. * ``--version``, ``-V``: Print version information and exit.
* ``--minimum-platform-version``: The minimum platform version to use in the generated network-parameters. * ``--minimum-platform-version``: The minimum platform version to use in the network-parameters.
* ``--register-package-owner``: Register a java package namespace with its owners public key. * ``--max-message-size``: The maximum message size to use in the network-parameters, in bytes.
* ``--unregister-package-owner``: Unregister a java package namespace. * ``--max-transaction-size``: The maximum transaction size to use in the network-parameters, in bytes.
* ``--event-horizon``: The event horizon to use in the network-parameters.
* ``--network-parameter-overrides=<networkParametersFile>``, ``-n=<networkParametersFile>`: Overrides the default network parameters with those
in the given file. See `Overriding network parameters via a file`_ for more information.
Sub-commands Sub-commands
^^^^^^^^^^^^ ------------
``install-shell-extensions``: Install ``bootstrapper`` alias and auto completion for bash and zsh. See :doc:`cli-application-shell-extensions` for more info. ``install-shell-extensions``: Install ``bootstrapper`` alias and auto completion for bash and zsh. See :doc:`cli-application-shell-extensions` for more info.

View File

@ -395,6 +395,10 @@ By default, the node database has the following tables:
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| NODE_TRANSACTIONS | TX_ID, TRANSACTION_VALUE, STATE_MACHINE_RUN_ID | | NODE_TRANSACTIONS | TX_ID, TRANSACTION_VALUE, STATE_MACHINE_RUN_ID |
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PK_HASH_TO_EXT_ID_MAP | ID, EXTERNAL_ID, PUBLIC_KEY_HASH |
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| STATE_PARTY | OUTPUT_INDEX, TRANSACTION_ID, ID, PUBLIC_KEY_HASH, X500_NAME |
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| VAULT_FUNGIBLE_STATES | OUTPUT_INDEX, TRANSACTION_ID, ISSUER_NAME, ISSUER_REF, OWNER_NAME, QUANTITY | | VAULT_FUNGIBLE_STATES | OUTPUT_INDEX, TRANSACTION_ID, ISSUER_NAME, ISSUER_REF, OWNER_NAME, QUANTITY |
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| VAULT_FUNGIBLE_STATES_PARTS | OUTPUT_INDEX, TRANSACTION_ID, PARTICIPANTS | | VAULT_FUNGIBLE_STATES_PARTS | OUTPUT_INDEX, TRANSACTION_ID, PARTICIPANTS |
@ -407,6 +411,8 @@ By default, the node database has the following tables:
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| VAULT_TRANSACTION_NOTES | SEQ_NO, NOTE, TRANSACTION_ID | | VAULT_TRANSACTION_NOTES | SEQ_NO, NOTE, TRANSACTION_ID |
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| V_PKEY_HASH_EX_ID_MAP | ID, PUBLIC_KEY_HASH, TRANSACTION_ID, OUTPUT_INDEX, EXTERNAL_ID |
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Guideline for adding support for other databases Guideline for adding support for other databases
```````````````````````````````````````````````` ````````````````````````````````````````````````

View File

@ -160,12 +160,17 @@ class CashTests {
} }
} }
@BelongsToContract(Cash::class)
object DummyState: ContractState {
override val participants: List<AbstractParty> = emptyList()
}
@Test @Test
fun `issue by move`() { fun `issue by move`() {
// Check we can't "move" money into existence. // Check we can't "move" money into existence.
transaction { transaction {
attachment(Cash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID, DummyState()) input(Cash.PROGRAM_ID, DummyState)
output(Cash.PROGRAM_ID, outState) output(Cash.PROGRAM_ID, outState)
command(miniCorp.publicKey, Cash.Commands.Move()) command(miniCorp.publicKey, Cash.Commands.Move())
this `fails with` "there is at least one cash input for this group" this `fails with` "there is at least one cash input for this group"

View File

@ -21,7 +21,6 @@ import net.corda.finance.contracts.NetType
import net.corda.finance.contracts.asset.Obligation.Lifecycle import net.corda.finance.contracts.asset.Obligation.Lifecycle
import net.corda.node.services.api.IdentityServiceInternal import net.corda.node.services.api.IdentityServiceInternal
import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.testing.contracts.DummyState
import net.corda.testing.core.* import net.corda.testing.core.*
import net.corda.testing.dsl.* import net.corda.testing.dsl.*
import net.corda.testing.internal.TEST_TX_TIME import net.corda.testing.internal.TEST_TX_TIME
@ -145,12 +144,17 @@ class ObligationTests {
} }
} }
@BelongsToContract(DummyContract::class)
object DummyState: ContractState {
override val participants: List<AbstractParty> = emptyList()
}
@Test @Test
fun `issue debt`() { fun `issue debt`() {
// Check we can't "move" debt into existence. // Check we can't "move" debt into existence.
transaction { transaction {
attachments(DummyContract.PROGRAM_ID, Obligation.PROGRAM_ID) attachments(DummyContract.PROGRAM_ID, Obligation.PROGRAM_ID)
input(DummyContract.PROGRAM_ID, DummyState()) input(DummyContract.PROGRAM_ID, DummyState)
output(Obligation.PROGRAM_ID, outState) output(Obligation.PROGRAM_ID, outState)
command(MINI_CORP_PUBKEY, Obligation.Commands.Move()) command(MINI_CORP_PUBKEY, Obligation.Commands.Move())
this `fails with` "at least one obligation input" this `fails with` "at least one obligation input"

View File

@ -3,7 +3,6 @@ package net.corda.nodeapi.internal.network
import com.typesafe.config.Config import com.typesafe.config.Config
import com.typesafe.config.ConfigException import com.typesafe.config.ConfigException
import com.typesafe.config.ConfigFactory import com.typesafe.config.ConfigFactory
import net.corda.core.crypto.toStringShort
import net.corda.core.identity.CordaX500Name import net.corda.core.identity.CordaX500Name
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.* import net.corda.core.internal.*
@ -19,7 +18,6 @@ import net.corda.core.serialization.deserialize
import net.corda.core.serialization.internal.SerializationEnvironment import net.corda.core.serialization.internal.SerializationEnvironment
import net.corda.core.serialization.internal._contextSerializationEnv import net.corda.core.serialization.internal._contextSerializationEnv
import net.corda.core.utilities.days import net.corda.core.utilities.days
import net.corda.core.utilities.filterNotNullValues
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import net.corda.core.utilities.seconds import net.corda.core.utilities.seconds
import net.corda.nodeapi.internal.* import net.corda.nodeapi.internal.*
@ -36,6 +34,7 @@ import java.nio.file.FileAlreadyExistsException
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.StandardCopyOption.REPLACE_EXISTING import java.nio.file.StandardCopyOption.REPLACE_EXISTING
import java.security.PublicKey import java.security.PublicKey
import java.time.Duration
import java.time.Instant import java.time.Instant
import java.util.* import java.util.*
import java.util.concurrent.Executors import java.util.concurrent.Executors
@ -56,7 +55,7 @@ class NetworkBootstrapper
internal constructor(private val initSerEnv: Boolean, internal constructor(private val initSerEnv: Boolean,
private val embeddedCordaJar: () -> InputStream, private val embeddedCordaJar: () -> InputStream,
private val nodeInfosGenerator: (List<Path>) -> List<Path>, private val nodeInfosGenerator: (List<Path>) -> List<Path>,
private val contractsJarConverter: (Path) -> ContractsJar) { private val contractsJarConverter: (Path) -> ContractsJar) : NetworkBootstrapperWithOverridableParameters {
constructor() : this( constructor() : this(
initSerEnv = true, initSerEnv = true,
@ -128,6 +127,9 @@ internal constructor(private val initSerEnv: Boolean,
throw IllegalStateException("Error while generating node info file. Please check the logs in $nodeDir.") throw IllegalStateException("Error while generating node info file. Please check the logs in $nodeDir.")
} }
} }
const val DEFAULT_MAX_MESSAGE_SIZE: Int = 10485760
const val DEFAULT_MAX_TRANSACTION_SIZE: Int = 524288000
} }
sealed class NotaryCluster { sealed class NotaryCluster {
@ -189,14 +191,15 @@ internal constructor(private val initSerEnv: Boolean,
} }
/** Entry point for the tool */ /** Entry point for the tool */
fun bootstrap(directory: Path, copyCordapps: Boolean, minimumPlatformVersion: Int, packageOwnership: Map<String, PublicKey?> = emptyMap()) { override fun bootstrap(directory: Path, copyCordapps: Boolean, networkParameterOverrides: NetworkParametersOverrides) {
require(minimumPlatformVersion <= PLATFORM_VERSION) { "Minimum platform version cannot be greater than $PLATFORM_VERSION" } require(networkParameterOverrides.minimumPlatformVersion == null || networkParameterOverrides.minimumPlatformVersion <= PLATFORM_VERSION) { "Minimum platform version cannot be greater than $PLATFORM_VERSION" }
// Don't accidently include the bootstrapper jar as a CorDapp! // Don't accidentally include the bootstrapper jar as a CorDapp!
val bootstrapperJar = javaClass.location.toPath() val bootstrapperJar = javaClass.location.toPath()
val cordappJars = directory.list { paths -> val cordappJars = directory.list { paths ->
paths.filter { it.toString().endsWith(".jar") && !it.isSameAs(bootstrapperJar) && it.fileName.toString() != "corda.jar" }.toList() paths.filter { it.toString().endsWith(".jar") && !it.isSameAs(bootstrapperJar) && it.fileName.toString() != "corda.jar" }
.toList()
} }
bootstrap(directory, cordappJars, copyCordapps, fromCordform = false, minimumPlatformVersion = minimumPlatformVersion, packageOwnership = packageOwnership) bootstrap(directory, cordappJars, copyCordapps, fromCordform = false, networkParametersOverrides = networkParameterOverrides)
} }
private fun bootstrap( private fun bootstrap(
@ -204,8 +207,7 @@ internal constructor(private val initSerEnv: Boolean,
cordappJars: List<Path>, cordappJars: List<Path>,
copyCordapps: Boolean, copyCordapps: Boolean,
fromCordform: Boolean, fromCordform: Boolean,
minimumPlatformVersion: Int = PLATFORM_VERSION, networkParametersOverrides: NetworkParametersOverrides = NetworkParametersOverrides()
packageOwnership: Map<String, PublicKey?> = emptyMap()
) { ) {
directory.createDirectories() directory.createDirectories()
println("Bootstrapping local test network in $directory") println("Bootstrapping local test network in $directory")
@ -250,8 +252,9 @@ internal constructor(private val initSerEnv: Boolean,
println("Gathering notary identities") println("Gathering notary identities")
val notaryInfos = gatherNotaryInfos(nodeInfoFiles, configs) val notaryInfos = gatherNotaryInfos(nodeInfoFiles, configs)
println("Generating contract implementations whitelist") println("Generating contract implementations whitelist")
// Only add contracts to the whitelist from unsigned jars
val newWhitelist = generateWhitelist(existingNetParams, readExcludeWhitelist(directory), cordappJars.filter { !isSigned(it) }.map(contractsJarConverter)) val newWhitelist = generateWhitelist(existingNetParams, readExcludeWhitelist(directory), cordappJars.filter { !isSigned(it) }.map(contractsJarConverter))
val newNetParams = installNetworkParameters(notaryInfos, newWhitelist, existingNetParams, nodeDirs, minimumPlatformVersion, packageOwnership) val newNetParams = installNetworkParameters(notaryInfos, newWhitelist, existingNetParams, nodeDirs, networkParametersOverrides)
if (newNetParams != existingNetParams) { if (newNetParams != existingNetParams) {
println("${if (existingNetParams == null) "New" else "Updated"} $newNetParams") println("${if (existingNetParams == null) "New" else "Updated"} $newNetParams")
} else { } else {
@ -283,7 +286,8 @@ internal constructor(private val initSerEnv: Boolean,
println("Generating node directory for $nodeName") println("Generating node directory for $nodeName")
val nodeDir = (directory / nodeName).createDirectories() val nodeDir = (directory / nodeName).createDirectories()
confFile.copyTo(nodeDir / "node.conf", REPLACE_EXISTING) confFile.copyTo(nodeDir / "node.conf", REPLACE_EXISTING)
webServerConfFiles.firstOrNull { directory.relativize(it).toString().removeSuffix("_web-server.conf") == nodeName }?.copyTo(nodeDir / "web-server.conf", REPLACE_EXISTING) webServerConfFiles.firstOrNull { directory.relativize(it).toString().removeSuffix("_web-server.conf") == nodeName }
?.copyTo(nodeDir / "web-server.conf", REPLACE_EXISTING)
cordaJar.copyToDirectory(nodeDir, REPLACE_EXISTING) cordaJar.copyToDirectory(nodeDir, REPLACE_EXISTING)
} }
@ -378,50 +382,42 @@ internal constructor(private val initSerEnv: Boolean,
throw IllegalStateException(msg.toString()) throw IllegalStateException(msg.toString())
} }
private fun defaultNetworkParametersWith(notaryInfos: List<NotaryInfo>,
whitelist: Map<String, List<AttachmentId>>): NetworkParameters {
return NetworkParameters(
minimumPlatformVersion = PLATFORM_VERSION,
notaries = notaryInfos,
modifiedTime = Instant.now(),
maxMessageSize = DEFAULT_MAX_MESSAGE_SIZE,
maxTransactionSize = DEFAULT_MAX_TRANSACTION_SIZE,
whitelistedContractImplementations = whitelist,
packageOwnership = emptyMap(),
epoch = 1,
eventHorizon = 30.days
)
}
private fun installNetworkParameters( private fun installNetworkParameters(
notaryInfos: List<NotaryInfo>, notaryInfos: List<NotaryInfo>,
whitelist: Map<String, List<AttachmentId>>, whitelist: Map<String, List<AttachmentId>>,
existingNetParams: NetworkParameters?, existingNetParams: NetworkParameters?,
nodeDirs: List<Path>, nodeDirs: List<Path>,
minimumPlatformVersion: Int, networkParametersOverrides: NetworkParametersOverrides
packageOwnership: Map<String, PublicKey?>
): NetworkParameters { ): NetworkParameters {
// TODO Add config for maxMessageSize and maxTransactionSize
val netParams = if (existingNetParams != null) { val netParams = if (existingNetParams != null) {
if (existingNetParams.whitelistedContractImplementations == whitelist && existingNetParams.notaries == notaryInfos && val newNetParams = existingNetParams
existingNetParams.packageOwnership.entries.containsAll(packageOwnership.entries)) { .copy(notaries = notaryInfos, whitelistedContractImplementations = whitelist)
existingNetParams .overrideWith(networkParametersOverrides)
} else { if (newNetParams != existingNetParams) {
var updatePackageOwnership = mutableMapOf(*existingNetParams.packageOwnership.map { Pair(it.key, it.value) }.toTypedArray()) newNetParams.copy(
packageOwnership.forEach { key, value ->
if (value == null) {
if (updatePackageOwnership.remove(key) != null)
println("Unregistering package $key")
} else {
if (updatePackageOwnership.put(key, value) == null)
println("Registering package $key for owner ${value.toStringShort()}")
}
}
existingNetParams.copy(
notaries = notaryInfos,
modifiedTime = Instant.now(), modifiedTime = Instant.now(),
whitelistedContractImplementations = whitelist,
packageOwnership = updatePackageOwnership,
epoch = existingNetParams.epoch + 1 epoch = existingNetParams.epoch + 1
) )
} else {
existingNetParams
} }
} else { } else {
NetworkParameters( defaultNetworkParametersWith(notaryInfos, whitelist).overrideWith(networkParametersOverrides)
minimumPlatformVersion = minimumPlatformVersion,
notaries = notaryInfos,
modifiedTime = Instant.now(),
maxMessageSize = 10485760,
maxTransactionSize = 524288000,
whitelistedContractImplementations = whitelist,
packageOwnership = packageOwnership.filterNotNullValues(),
epoch = 1,
eventHorizon = 30.days
)
} }
val copier = NetworkParametersCopier(netParams, overwriteFile = true) val copier = NetworkParametersCopier(netParams, overwriteFile = true)
nodeDirs.forEach(copier::install) nodeDirs.forEach(copier::install)
@ -435,7 +431,7 @@ internal constructor(private val initSerEnv: Boolean,
// Nodes which are part of a distributed notary have a second identity which is the composite identity of the // Nodes which are part of a distributed notary have a second identity which is the composite identity of the
// cluster and is shared by all the other members. This is the notary identity. // cluster and is shared by all the other members. This is the notary identity.
2 -> legalIdentities[1] 2 -> legalIdentities[1]
else -> throw IllegalArgumentException("Not sure how to get the notary identity in this scenerio: $this") else -> throw IllegalArgumentException("Not sure how to get the notary identity in this scenario: $this")
} }
} }
@ -464,3 +460,27 @@ internal constructor(private val initSerEnv: Boolean,
} }
} }
} }
fun NetworkParameters.overrideWith(override: NetworkParametersOverrides): NetworkParameters {
return this.copy(
minimumPlatformVersion = override.minimumPlatformVersion ?: this.minimumPlatformVersion,
maxMessageSize = override.maxMessageSize ?: this.maxMessageSize,
maxTransactionSize = override.maxTransactionSize ?: this.maxTransactionSize,
eventHorizon = override.eventHorizon ?: this.eventHorizon,
packageOwnership = override.packageOwnership?.map { it.javaPackageName to it.publicKey }?.toMap() ?: this.packageOwnership
)
}
data class PackageOwner(val javaPackageName: String, val publicKey: PublicKey)
data class NetworkParametersOverrides(
val minimumPlatformVersion: Int? = null,
val maxMessageSize: Int? = null,
val maxTransactionSize: Int? = null,
val packageOwnership: List<PackageOwner>? = null,
val eventHorizon: Duration? = null
)
interface NetworkBootstrapperWithOverridableParameters {
fun bootstrap(directory: Path, copyCordapps: Boolean, networkParameterOverrides: NetworkParametersOverrides = NetworkParametersOverrides())
}

View File

@ -11,9 +11,12 @@ import net.corda.core.serialization.serialize
import net.corda.node.services.config.NotaryConfig import net.corda.node.services.config.NotaryConfig
import net.corda.nodeapi.internal.DEV_ROOT_CA import net.corda.nodeapi.internal.DEV_ROOT_CA
import net.corda.core.internal.NODE_INFO_DIRECTORY import net.corda.core.internal.NODE_INFO_DIRECTORY
import net.corda.core.utilities.days
import net.corda.nodeapi.internal.SignedNodeInfo import net.corda.nodeapi.internal.SignedNodeInfo
import net.corda.nodeapi.internal.config.parseAs import net.corda.nodeapi.internal.config.parseAs
import net.corda.nodeapi.internal.config.toConfig import net.corda.nodeapi.internal.config.toConfig
import net.corda.nodeapi.internal.network.NetworkBootstrapper.Companion.DEFAULT_MAX_MESSAGE_SIZE
import net.corda.nodeapi.internal.network.NetworkBootstrapper.Companion.DEFAULT_MAX_TRANSACTION_SIZE
import net.corda.nodeapi.internal.network.NodeInfoFilesCopier.Companion.NODE_INFO_FILE_NAME_PREFIX import net.corda.nodeapi.internal.network.NodeInfoFilesCopier.Companion.NODE_INFO_FILE_NAME_PREFIX
import net.corda.testing.core.* import net.corda.testing.core.*
import net.corda.testing.internal.createNodeInfoAndSigned import net.corda.testing.internal.createNodeInfoAndSigned
@ -26,6 +29,7 @@ import org.junit.rules.ExpectedException
import org.junit.rules.TemporaryFolder import org.junit.rules.TemporaryFolder
import java.nio.file.Path import java.nio.file.Path
import java.security.PublicKey import java.security.PublicKey
import java.time.Duration
import kotlin.streams.toList import kotlin.streams.toList
class NetworkBootstrapperTest { class NetworkBootstrapperTest {
@ -210,6 +214,24 @@ class NetworkBootstrapperTest {
assertThat(networkParameters.epoch).isEqualTo(2) assertThat(networkParameters.epoch).isEqualTo(2)
} }
@Test
fun `network parameters overrides`() {
createNodeConfFile("alice", aliceConfig)
val minimumPlatformVersion = 2
val maxMessageSize = 10000
val maxTransactionSize = 20000
val eventHorizon = 7.days
bootstrap(minimumPlatformVerison = minimumPlatformVersion,
maxMessageSize = maxMessageSize,
maxTransactionSize = maxTransactionSize,
eventHorizon = eventHorizon)
val networkParameters = assertBootstrappedNetwork(fakeEmbeddedCordaJar, "alice" to aliceConfig)
assertThat(networkParameters.minimumPlatformVersion).isEqualTo(minimumPlatformVersion)
assertThat(networkParameters.maxMessageSize).isEqualTo(maxMessageSize)
assertThat(networkParameters.maxTransactionSize).isEqualTo(maxTransactionSize)
assertThat(networkParameters.eventHorizon).isEqualTo(eventHorizon)
}
private val ALICE = TestIdentity(ALICE_NAME, 70) private val ALICE = TestIdentity(ALICE_NAME, 70)
private val BOB = TestIdentity(BOB_NAME, 80) private val BOB = TestIdentity(BOB_NAME, 80)
@ -230,7 +252,7 @@ class NetworkBootstrapperTest {
assertContainsPackageOwner("alice", mapOf(Pair(alicePackageName, ALICE.publicKey))) assertContainsPackageOwner("alice", mapOf(Pair(alicePackageName, ALICE.publicKey)))
// register additional package name // register additional package name
createNodeConfFile("bob", bobConfig) createNodeConfFile("bob", bobConfig)
bootstrap(packageOwnership = mapOf(Pair(bobPackageName, BOB.publicKey))) bootstrap(packageOwnership = mapOf(Pair(alicePackageName, ALICE.publicKey), Pair(bobPackageName, BOB.publicKey)))
assertContainsPackageOwner("bob", mapOf(Pair(alicePackageName, ALICE.publicKey), Pair(bobPackageName, BOB.publicKey))) assertContainsPackageOwner("bob", mapOf(Pair(alicePackageName, ALICE.publicKey), Pair(bobPackageName, BOB.publicKey)))
} }
@ -243,8 +265,8 @@ class NetworkBootstrapperTest {
// register overlapping package name // register overlapping package name
createNodeConfFile("bob", bobConfig) createNodeConfFile("bob", bobConfig)
expectedEx.expect(IllegalArgumentException::class.java) expectedEx.expect(IllegalArgumentException::class.java)
expectedEx.expectMessage("multiple packages added to the packageOwnership overlap.") expectedEx.expectMessage("Multiple packages added to the packageOwnership overlap.")
bootstrap(packageOwnership = mapOf(Pair(bobPackageName, BOB.publicKey))) bootstrap(packageOwnership = mapOf(Pair(greedyNamespace, ALICE.publicKey), Pair(bobPackageName, BOB.publicKey)))
} }
@Test @Test
@ -253,7 +275,7 @@ class NetworkBootstrapperTest {
bootstrap(packageOwnership = mapOf(Pair(alicePackageName, ALICE.publicKey))) bootstrap(packageOwnership = mapOf(Pair(alicePackageName, ALICE.publicKey)))
assertContainsPackageOwner("alice", mapOf(Pair(alicePackageName, ALICE.publicKey))) assertContainsPackageOwner("alice", mapOf(Pair(alicePackageName, ALICE.publicKey)))
// unregister package name // unregister package name
bootstrap(packageOwnership = mapOf(Pair(alicePackageName, null))) bootstrap(packageOwnership = emptyMap())
assertContainsPackageOwner("alice", emptyMap()) assertContainsPackageOwner("alice", emptyMap())
} }
@ -262,8 +284,8 @@ class NetworkBootstrapperTest {
createNodeConfFile("alice", aliceConfig) createNodeConfFile("alice", aliceConfig)
bootstrap(packageOwnership = mapOf(Pair(alicePackageName, ALICE.publicKey), Pair(bobPackageName, BOB.publicKey))) bootstrap(packageOwnership = mapOf(Pair(alicePackageName, ALICE.publicKey), Pair(bobPackageName, BOB.publicKey)))
// unregister package name // unregister package name
bootstrap(packageOwnership = mapOf(Pair(alicePackageName, null))) bootstrap(packageOwnership = mapOf(Pair(alicePackageName, ALICE.publicKey)))
assertContainsPackageOwner("alice", mapOf(Pair(bobPackageName, BOB.publicKey))) assertContainsPackageOwner("alice", mapOf(Pair(alicePackageName, ALICE.publicKey)))
} }
@Test @Test
@ -271,19 +293,10 @@ class NetworkBootstrapperTest {
createNodeConfFile("alice", aliceConfig) createNodeConfFile("alice", aliceConfig)
bootstrap(packageOwnership = mapOf(Pair(alicePackageName, ALICE.publicKey), Pair(bobPackageName, BOB.publicKey))) bootstrap(packageOwnership = mapOf(Pair(alicePackageName, ALICE.publicKey), Pair(bobPackageName, BOB.publicKey)))
// unregister all package names // unregister all package names
bootstrap(packageOwnership = mapOf(Pair(alicePackageName, null), Pair(bobPackageName, null))) bootstrap(packageOwnership = emptyMap())
assertContainsPackageOwner("alice", emptyMap()) assertContainsPackageOwner("alice", emptyMap())
} }
@Test
fun `register and unregister sample package namespace in network`() {
createNodeConfFile("alice", aliceConfig)
bootstrap(packageOwnership = mapOf(Pair(alicePackageName, ALICE.publicKey), Pair(alicePackageName, null)))
assertContainsPackageOwner("alice", emptyMap())
bootstrap(packageOwnership = mapOf(Pair(alicePackageName, null), Pair(alicePackageName, ALICE.publicKey)))
assertContainsPackageOwner("alice", mapOf(Pair(alicePackageName, ALICE.publicKey)))
}
private val rootDir get() = tempFolder.root.toPath() private val rootDir get() = tempFolder.root.toPath()
private fun fakeFileBytes(writeToFile: Path? = null): ByteArray { private fun fakeFileBytes(writeToFile: Path? = null): ByteArray {
@ -292,9 +305,20 @@ class NetworkBootstrapperTest {
return bytes return bytes
} }
private fun bootstrap(copyCordapps: Boolean = true, packageOwnership : Map<String, PublicKey?> = emptyMap()) { private fun bootstrap(copyCordapps: Boolean = true,
packageOwnership: Map<String, PublicKey>? = emptyMap(),
minimumPlatformVerison: Int? = PLATFORM_VERSION,
maxMessageSize: Int? = DEFAULT_MAX_MESSAGE_SIZE,
maxTransactionSize: Int? = DEFAULT_MAX_TRANSACTION_SIZE,
eventHorizon: Duration? = 30.days) {
providedCordaJar = (rootDir / "corda.jar").let { if (it.exists()) it.readAll() else null } providedCordaJar = (rootDir / "corda.jar").let { if (it.exists()) it.readAll() else null }
bootstrapper.bootstrap(rootDir, copyCordapps, PLATFORM_VERSION, packageOwnership) bootstrapper.bootstrap(rootDir, copyCordapps, NetworkParametersOverrides(
minimumPlatformVersion = minimumPlatformVerison,
maxMessageSize = maxMessageSize,
maxTransactionSize = maxTransactionSize,
eventHorizon = eventHorizon,
packageOwnership = packageOwnership?.map { PackageOwner(it.key, it.value!!) }
))
} }
private fun createNodeConfFile(nodeDirName: String, config: FakeNodeConfig) { private fun createNodeConfFile(nodeDirName: String, config: FakeNodeConfig) {
@ -320,19 +344,23 @@ class NetworkBootstrapperTest {
return cordappBytes return cordappBytes
} }
private val Path.networkParameters: NetworkParameters get() { private val Path.networkParameters: NetworkParameters
return (this / NETWORK_PARAMS_FILE_NAME).readObject<SignedNetworkParameters>().verifiedNetworkParametersCert(DEV_ROOT_CA.certificate) get() {
} return (this / NETWORK_PARAMS_FILE_NAME).readObject<SignedNetworkParameters>()
.verifiedNetworkParametersCert(DEV_ROOT_CA.certificate)
}
private val Path.nodeInfoFile: Path get() { private val Path.nodeInfoFile: Path
return list { it.filter { it.fileName.toString().startsWith(NODE_INFO_FILE_NAME_PREFIX) }.toList() }.single() get() {
} return list { it.filter { it.fileName.toString().startsWith(NODE_INFO_FILE_NAME_PREFIX) }.toList() }.single()
}
private val Path.nodeInfo: NodeInfo get() = nodeInfoFile.readObject<SignedNodeInfo>().verified() private val Path.nodeInfo: NodeInfo get() = nodeInfoFile.readObject<SignedNodeInfo>().verified()
private val Path.fakeNodeConfig: FakeNodeConfig get() { private val Path.fakeNodeConfig: FakeNodeConfig
return ConfigFactory.parseFile((this / "node.conf").toFile()).parseAs(FakeNodeConfig::class) get() {
} return ConfigFactory.parseFile((this / "node.conf").toFile()).parseAs(FakeNodeConfig::class)
}
private fun assertBootstrappedNetwork(cordaJar: ByteArray, vararg nodes: Pair<String, FakeNodeConfig>): NetworkParameters { private fun assertBootstrappedNetwork(cordaJar: ByteArray, vararg nodes: Pair<String, FakeNodeConfig>): NetworkParameters {
val networkParameters = (rootDir / nodes[0].first).networkParameters val networkParameters = (rootDir / nodes[0].first).networkParameters

View File

@ -49,7 +49,6 @@ open class SharedNodeCmdLineOptions {
var devMode: Boolean? = null var devMode: Boolean? = null
open fun parseConfiguration(configuration: Config): Valid<NodeConfiguration> { open fun parseConfiguration(configuration: Config): Valid<NodeConfiguration> {
val option = Configuration.Validation.Options(strict = unknownConfigKeysPolicy == UnknownConfigKeysPolicy.FAIL) val option = Configuration.Validation.Options(strict = unknownConfigKeysPolicy == UnknownConfigKeysPolicy.FAIL)
return configuration.parseAsNodeConfiguration(option) return configuration.parseAsNodeConfiguration(option)
} }

View File

@ -144,21 +144,19 @@ open class NodeStartup : NodeStartupLogging {
val configuration = cmdLineOptions.parseConfiguration(rawConfig).doIfValid { logRawConfig(rawConfig) }.doOnErrors(::logConfigurationErrors).optional ?: return ExitCodes.FAILURE val configuration = cmdLineOptions.parseConfiguration(rawConfig).doIfValid { logRawConfig(rawConfig) }.doOnErrors(::logConfigurationErrors).optional ?: return ExitCodes.FAILURE
// Step 6. Configuring special serialisation requirements, i.e., bft-smart relies on Java serialization. // Step 6. Configuring special serialisation requirements, i.e., bft-smart relies on Java serialization.
attempt { banJavaSerialisation(configuration) }.doOnException { error -> error.logAsUnexpected("Exception while configuring serialisation") } as? Try.Success if (attempt { banJavaSerialisation(configuration) }.doOnException { error -> error.logAsUnexpected("Exception while configuring serialisation") } !is Try.Success) return ExitCodes.FAILURE
?: return ExitCodes.FAILURE
// Step 7. Any actions required before starting up the Corda network layer. // Step 7. Any actions required before starting up the Corda network layer.
attempt { preNetworkRegistration(configuration) }.doOnException(::handleRegistrationError) as? Try.Success if (attempt { preNetworkRegistration(configuration) }.doOnException(::handleRegistrationError) !is Try.Success) return ExitCodes.FAILURE
?: return ExitCodes.FAILURE
// Step 8. Log startup info. // Step 8. Log startup info.
logStartupInfo(versionInfo, configuration) logStartupInfo(versionInfo, configuration)
// Step 9. Start node: create the node, check for other command-line options, add extra logging etc. // Step 9. Start node: create the node, check for other command-line options, add extra logging etc.
attempt { if (attempt {
cmdLineOptions.baseDirectory.createDirectories() cmdLineOptions.baseDirectory.createDirectories()
afterNodeInitialisation.run(createNode(configuration, versionInfo)) afterNodeInitialisation.run(createNode(configuration, versionInfo))
}.doOnException(::handleStartError) as? Try.Success ?: return ExitCodes.FAILURE }.doOnException(::handleStartError) !is Try.Success) return ExitCodes.FAILURE
return ExitCodes.SUCCESS return ExitCodes.SUCCESS
} }

View File

@ -11,6 +11,7 @@ import net.corda.nodeapi.internal.persistence.CordaPersistence
import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX
import org.apache.commons.lang.ArrayUtils.EMPTY_BYTE_ARRAY import org.apache.commons.lang.ArrayUtils.EMPTY_BYTE_ARRAY
import org.bouncycastle.operator.ContentSigner import org.bouncycastle.operator.ContentSigner
import org.hibernate.annotations.Type
import java.security.KeyPair import java.security.KeyPair
import java.security.PrivateKey import java.security.PrivateKey
import java.security.PublicKey import java.security.PublicKey
@ -50,13 +51,14 @@ class PersistentKeyManagementService(cacheFactory: NamedCacheFactory, val identi
@Id @Id
@GeneratedValue @GeneratedValue
@Column(name = "id", unique = true, nullable = false) @Column(name = "id", unique = true, nullable = false)
var key: Long? = null, val key: Long?,
@Column(name = "external_id", nullable = false) @Column(name = "external_id", nullable = false)
var externalId: UUID, @Type(type = "uuid-char")
val externalId: UUID,
@Column(name = "public_key_hash", nullable = false) @Column(name = "public_key_hash", nullable = false)
var publicKeyHash: String val publicKeyHash: String
) { ) {
constructor(accountId: UUID, publicKey: PublicKey) constructor(accountId: UUID, publicKey: PublicKey)
: this(null, accountId, publicKey.toStringShort()) : this(null, accountId, publicKey.toStringShort())

View File

@ -114,7 +114,7 @@ class PersistentUniquenessProvider(val clock: Clock, val database: CordaPersiste
*/ */
private val throughputHistory = SlidingWindowReservoir(100) private val throughputHistory = SlidingWindowReservoir(100)
@Volatile @Volatile
var throughput: Double = 0.0 private var throughput: Double = 0.0
/** /**
* Estimated time of request processing. * Estimated time of request processing.

View File

@ -167,14 +167,14 @@ object VaultSchemaV1 : MappedSchema(
@Id @Id
@GeneratedValue @GeneratedValue
@Column(name = "id", unique = true, nullable = false) @Column(name = "id", unique = true, nullable = false)
var id: Long? = null, val id: Long?,
// Foreign key. // Foreign key.
@Column(name = "state_ref") @Column(name = "state_ref")
var stateRef: PersistentStateRef, val stateRef: PersistentStateRef,
@Column(name = "public_key_hash", nullable = false) @Column(name = "public_key_hash", nullable = false)
var publicKeyHash: String, val publicKeyHash: String,
@Column(name = "x500_name", nullable = true) @Column(name = "x500_name", nullable = true)
var x500Name: AbstractParty? = null var x500Name: AbstractParty? = null
@ -190,17 +190,18 @@ object VaultSchemaV1 : MappedSchema(
@Id @Id
@GeneratedValue @GeneratedValue
@Column(name = "id", unique = true, nullable = false) @Column(name = "id", unique = true, nullable = false)
var id: Long? = null, val id: Long,
// Foreign key. // Foreign key.
@Column(name = "state_ref") @Column(name = "state_ref")
var stateRef: PersistentStateRef, val stateRef: PersistentStateRef,
@Column(name = "public_key_hash") @Column(name = "public_key_hash")
var publicKeyHash: String, val publicKeyHash: String,
@Column(name = "external_id") @Column(name = "external_id")
var externalId: UUID @Type(type = "uuid-char")
val externalId: UUID
) : StatePersistable ) : StatePersistable
} }

View File

@ -6,17 +6,27 @@
<createTable tableName="state_party"> <createTable tableName="state_party">
<column name="output_index" type="INT"/> <column name="output_index" type="INT"/>
<column name="transaction_id" type="NVARCHAR(64)"/> <column name="transaction_id" type="NVARCHAR(64)"/>
<column name="id" type="INT"/> <column name="id" type="BIGINT">
<column name="public_key_hash" type="NVARCHAR(255)"/> <constraints nullable="false"/>
</column>
<column name="public_key_hash" type="NVARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="x500_name" type="NVARCHAR(255)"/> <column name="x500_name" type="NVARCHAR(255)"/>
</createTable> </createTable>
<createIndex indexName="state_pk_hash_idx" tableName="state_party"> <createIndex indexName="state_pk_hash_idx" tableName="state_party">
<column name="public_key_hash"/> <column name="public_key_hash"/>
</createIndex> </createIndex>
<createTable tableName="pk_hash_to_ext_id_map"> <createTable tableName="pk_hash_to_ext_id_map">
<column name="id" type="INT"/> <column name="id" type="BIGINT">
<column name="external_id" type="NVARCHAR(255)"/> <constraints nullable="false"/>
<column name="public_key_hash" type="NVARCHAR(255)"/> </column>
<column name="external_id" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="public_key_hash" type="NVARCHAR(255)">
<constraints nullable="false"/>
</column>
</createTable> </createTable>
<createIndex indexName="pk_hash_to_xid_idx" tableName="pk_hash_to_ext_id_map"> <createIndex indexName="pk_hash_to_xid_idx" tableName="pk_hash_to_ext_id_map">
<column name="public_key_hash"/> <column name="public_key_hash"/>

View File

@ -109,7 +109,7 @@ class NetworkParametersTest {
"com.example.stuff" to key2 "com.example.stuff" to key2
) )
) )
}.withMessage("multiple packages added to the packageOwnership overlap.") }.withMessage("Multiple packages added to the packageOwnership overlap.")
val params = NetworkParameters(1, val params = NetworkParameters(1,
emptyList(), emptyList(),

View File

@ -13,6 +13,10 @@ cordapp {
// but the jar signer doesn't support that yet. // but the jar signer doesn't support that yet.
enabled false enabled false
} }
sealing {
// Cannot seal JAR because other module also defines classes in the package net.corda.vega.analytics
enabled false
}
} }
configurations { configurations {

View File

@ -1,9 +1,6 @@
package net.corda.vega.contracts package net.corda.vega.contracts
import net.corda.core.contracts.Command import net.corda.core.contracts.*
import net.corda.core.contracts.ContractClassName
import net.corda.core.contracts.StateAndContract
import net.corda.core.contracts.UniqueIdentifier
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
@ -16,6 +13,7 @@ const val IRS_PROGRAM_ID: ContractClassName = "net.corda.vega.contracts.OGTrade"
* *
* TODO: Merge with the existing demo IRS code. * TODO: Merge with the existing demo IRS code.
*/ */
@BelongsToContract(OGTrade::class)
data class IRSState(val swap: SwapData, data class IRSState(val swap: SwapData,
val buyer: AbstractParty, val buyer: AbstractParty,
val seller: AbstractParty, val seller: AbstractParty,

View File

@ -17,6 +17,7 @@ const val PORTFOLIO_SWAP_PROGRAM_ID = "net.corda.vega.contracts.PortfolioSwap"
* Represents an aggregate set of trades agreed between two parties and a possible valuation of that portfolio at a * Represents an aggregate set of trades agreed between two parties and a possible valuation of that portfolio at a
* given point in time. This state can be consumed to create a new state with a mutated valuation or portfolio. * given point in time. This state can be consumed to create a new state with a mutated valuation or portfolio.
*/ */
@BelongsToContract(PortfolioSwap::class)
data class PortfolioState(val portfolio: List<StateRef>, data class PortfolioState(val portfolio: List<StateRef>,
val _parties: Pair<AbstractParty, AbstractParty>, val _parties: Pair<AbstractParty, AbstractParty>,
val valuationDate: LocalDate, val valuationDate: LocalDate,

View File

@ -9,6 +9,10 @@ cordapp {
signing { signing {
enabled false enabled false
} }
sealing {
// Cannot seal JAR because other module also defines classes in the package net.corda.vega.analytics
enabled false
}
} }
dependencies { dependencies {

View File

@ -7,7 +7,6 @@ import net.corda.core.serialization.SerializationFactory
import net.corda.core.utilities.contextLogger import net.corda.core.utilities.contextLogger
import net.corda.serialization.internal.amqp.* import net.corda.serialization.internal.amqp.*
import net.corda.serialization.internal.model.LocalConstructorInformation import net.corda.serialization.internal.model.LocalConstructorInformation
import net.corda.serialization.internal.model.LocalPropertyInformation
import net.corda.serialization.internal.model.LocalTypeInformation import net.corda.serialization.internal.model.LocalTypeInformation
import java.io.NotSerializableException import java.io.NotSerializableException
@ -26,7 +25,7 @@ class ThrowableSerializer(factory: LocalSerializerFactory) : CustomSerializer.Pr
is LocalTypeInformation.NonComposable -> constructor ?: is LocalTypeInformation.NonComposable -> constructor ?:
throw NotSerializableException("$this has no deserialization constructor") throw NotSerializableException("$this has no deserialization constructor")
is LocalTypeInformation.Composable -> constructor is LocalTypeInformation.Composable -> constructor
is LocalTypeInformation.Opaque -> expand.constructor is LocalTypeInformation.Opaque -> wrapped.constructor
else -> throw NotSerializableException("$this has no deserialization constructor") else -> throw NotSerializableException("$this has no deserialization constructor")
} }

View File

@ -91,7 +91,7 @@ sealed class LocalTypeInformation {
is LocalTypeInformation.Abstract -> properties is LocalTypeInformation.Abstract -> properties
is LocalTypeInformation.AnInterface -> properties is LocalTypeInformation.AnInterface -> properties
is LocalTypeInformation.NonComposable -> properties is LocalTypeInformation.NonComposable -> properties
is LocalTypeInformation.Opaque -> expand.propertiesOrEmptyMap is LocalTypeInformation.Opaque -> wrapped.propertiesOrEmptyMap
else -> emptyMap() else -> emptyMap()
} }
@ -154,22 +154,7 @@ sealed class LocalTypeInformation {
* May in fact be a more complex class, but is treated as if atomic, i.e. we don't further expand its properties. * May in fact be a more complex class, but is treated as if atomic, i.e. we don't further expand its properties.
*/ */
data class Opaque(override val observedType: Class<*>, override val typeIdentifier: TypeIdentifier, data class Opaque(override val observedType: Class<*>, override val typeIdentifier: TypeIdentifier,
private val _expand: () -> LocalTypeInformation) : LocalTypeInformation() { val wrapped: LocalTypeInformation) : LocalTypeInformation()
/**
* In some rare cases, e.g. during Exception serialisation, we may want to "look inside" an opaque type.
*/
val expand: LocalTypeInformation by lazy { _expand() }
// Custom equals / hashcode because otherwise the "expand" lambda makes equality harder to reason about.
override fun equals(other: Any?): Boolean =
other is Cycle &&
other.observedType == observedType &&
other.typeIdentifier == typeIdentifier
override fun hashCode(): Int = Objects.hash(observedType, typeIdentifier)
override fun toString(): String = "Opaque($observedType, $typeIdentifier)"
}
/** /**
* Represents a scalar type such as [Int]. * Represents a scalar type such as [Int].

View File

@ -94,12 +94,11 @@ internal data class LocalTypeInformationBuilder(val lookup: LocalTypeLookup,
buildInterfaceInformation(type)) buildInterfaceInformation(type))
type.isInterface -> buildInterface(type, typeIdentifier, emptyList()) type.isInterface -> buildInterface(type, typeIdentifier, emptyList())
type.isAbstractClass -> buildAbstract(type, typeIdentifier, emptyList()) type.isAbstractClass -> buildAbstract(type, typeIdentifier, emptyList())
else -> when { isOpaque -> LocalTypeInformation.Opaque(
isOpaque -> LocalTypeInformation.Opaque(type, typeIdentifier) { type,
buildNonAtomic(type, type, typeIdentifier, emptyList()) typeIdentifier,
} buildNonAtomic(type, type, typeIdentifier, emptyList(), true))
else -> buildNonAtomic(type, type, typeIdentifier, emptyList()) else -> buildNonAtomic(type, type, typeIdentifier, emptyList())
}
} }
} }
@ -118,12 +117,10 @@ internal data class LocalTypeInformationBuilder(val lookup: LocalTypeLookup,
} }
rawType.isInterface -> buildInterface(type, typeIdentifier, buildTypeParameterInformation(type)) rawType.isInterface -> buildInterface(type, typeIdentifier, buildTypeParameterInformation(type))
rawType.isAbstractClass -> buildAbstract(type, typeIdentifier, buildTypeParameterInformation(type)) rawType.isAbstractClass -> buildAbstract(type, typeIdentifier, buildTypeParameterInformation(type))
else -> when { isOpaque -> LocalTypeInformation.Opaque(rawType,
isOpaque -> LocalTypeInformation.Opaque(rawType, typeIdentifier) { typeIdentifier,
buildNonAtomic(rawType, type, typeIdentifier, buildTypeParameterInformation(type)) buildNonAtomic(rawType, type, typeIdentifier, buildTypeParameterInformation(type), true))
} else -> buildNonAtomic(rawType, type, typeIdentifier, buildTypeParameterInformation(type))
else -> buildNonAtomic(rawType, type, typeIdentifier, buildTypeParameterInformation(type))
}
} }
} }
@ -159,13 +156,15 @@ internal data class LocalTypeInformationBuilder(val lookup: LocalTypeLookup,
* Rather than throwing an exception if a type is [NonComposable], we capture its type information so that it can * Rather than throwing an exception if a type is [NonComposable], we capture its type information so that it can
* still be used to _serialize_ values, or as the basis for deciding on an evolution strategy. * still be used to _serialize_ values, or as the basis for deciding on an evolution strategy.
*/ */
private fun buildNonAtomic(rawType: Class<*>, type: Type, typeIdentifier: TypeIdentifier, typeParameterInformation: List<LocalTypeInformation>): LocalTypeInformation { private fun buildNonAtomic(rawType: Class<*>, type: Type, typeIdentifier: TypeIdentifier, typeParameterInformation: List<LocalTypeInformation>, suppressWarning: Boolean = false): LocalTypeInformation {
val superclassInformation = buildSuperclassInformation(type) val superclassInformation = buildSuperclassInformation(type)
val interfaceInformation = buildInterfaceInformation(type) val interfaceInformation = buildInterfaceInformation(type)
val observedConstructor = constructorForDeserialization(type) val observedConstructor = constructorForDeserialization(type)
if (observedConstructor == null) { if (observedConstructor == null) {
logger.warn("No unique deserialisation constructor found for class $rawType, type is marked as non-composable") if (!suppressWarning) {
logger.info("No unique deserialisation constructor found for class $rawType, type is marked as non-composable")
}
return LocalTypeInformation.NonComposable(type, typeIdentifier, null, buildReadOnlyProperties(rawType), return LocalTypeInformation.NonComposable(type, typeIdentifier, null, buildReadOnlyProperties(rawType),
superclassInformation, interfaceInformation, typeParameterInformation) superclassInformation, interfaceInformation, typeParameterInformation)
} }
@ -176,10 +175,12 @@ internal data class LocalTypeInformationBuilder(val lookup: LocalTypeLookup,
val hasNonComposableProperties = properties.values.any { it.type is LocalTypeInformation.NonComposable } val hasNonComposableProperties = properties.values.any { it.type is LocalTypeInformation.NonComposable }
if (!propertiesSatisfyConstructor(constructorInformation, properties) || hasNonComposableProperties) { if (!propertiesSatisfyConstructor(constructorInformation, properties) || hasNonComposableProperties) {
if (hasNonComposableProperties) { if (!suppressWarning) {
logger.warn("Type ${type.typeName} has non-composable properties and has been marked as non-composable") if (hasNonComposableProperties) {
} else { logger.info("Type ${type.typeName} has non-composable properties and has been marked as non-composable")
logger.warn("Properties of type ${type.typeName} do not satisfy its constructor, type has been marked as non-composable") } else {
logger.info("Properties of type ${type.typeName} do not satisfy its constructor, type has been marked as non-composable")
}
} }
return LocalTypeInformation.NonComposable(type, typeIdentifier, constructorInformation, properties, superclassInformation, return LocalTypeInformation.NonComposable(type, typeIdentifier, constructorInformation, properties, superclassInformation,
interfaceInformation, typeParameterInformation) interfaceInformation, typeParameterInformation)

View File

@ -90,7 +90,9 @@ sealed class TypeIdentifier {
(type.rawType as Class<*>).name, (type.rawType as Class<*>).name,
type.ownerType?.let { forGenericType(it) }, type.ownerType?.let { forGenericType(it) },
type.actualTypeArguments.map { type.actualTypeArguments.map {
forGenericType(it.resolveAgainst(resolutionContext)) val resolved = it.resolveAgainst(resolutionContext)
// Avoid cycles, e.g. Enum<E> where E resolves to Enum<E>
if (resolved == type) UnknownType else forGenericType(resolved)
}) })
is Class<*> -> forClass(type) is Class<*> -> forClass(type)
is GenericArrayType -> ArrayOf(forGenericType(type.genericComponentType.resolveAgainst(resolutionContext))) is GenericArrayType -> ArrayOf(forGenericType(type.genericComponentType.resolveAgainst(resolutionContext)))

View File

@ -4,9 +4,11 @@ import io.github.classgraph.ClassGraph
import net.corda.core.internal.outputStream import net.corda.core.internal.outputStream
import net.corda.node.internal.cordapp.createTestManifest import net.corda.node.internal.cordapp.createTestManifest
import net.corda.testing.node.TestCordapp import net.corda.testing.node.TestCordapp
import java.io.BufferedOutputStream
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.attribute.FileTime import java.nio.file.attribute.FileTime
import java.time.Instant import java.time.Instant
import java.util.jar.JarFile
import java.util.jar.JarOutputStream import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import kotlin.reflect.KClass import kotlin.reflect.KClass
@ -66,8 +68,13 @@ fun TestCordappImpl.packageAsJar(file: Path) {
scanResult.use { scanResult.use {
val manifest = createTestManifest(name, title, version, vendor, targetVersion) val manifest = createTestManifest(name, title, version, vendor, targetVersion)
JarOutputStream(file.outputStream(), manifest).use { jos -> JarOutputStream(file.outputStream()).use { jos ->
val time = FileTime.from(Instant.EPOCH) val time = FileTime.from(Instant.EPOCH)
val manifestEntry = ZipEntry(JarFile.MANIFEST_NAME).setCreationTime(time).setLastAccessTime(time).setLastModifiedTime(time)
jos.putNextEntry(manifestEntry)
manifest.write(BufferedOutputStream(jos))
jos.closeEntry()
// The same resource may be found in different locations (this will happen when running from gradle) so just // The same resource may be found in different locations (this will happen when running from gradle) so just
// pick the first one found. // pick the first one found.
scanResult.allResources.asMap().forEach { path, resourceList -> scanResult.allResources.asMap().forEach { path, resourceList ->

View File

@ -24,7 +24,7 @@ dependencies {
// Unit testing helpers. // Unit testing helpers.
compile "junit:junit:$junit_version" compile "junit:junit:$junit_version"
compile 'org.hamcrest:hamcrest-library:1.3' compile 'org.hamcrest:hamcrest-library:1.3'
compile 'com.nhaarman:mockito-kotlin:1.5.0' compile "com.nhaarman:mockito-kotlin:$mockito_kotlin_version"
compile "org.mockito:mockito-core:$mockito_version" compile "org.mockito:mockito-core:$mockito_version"
compile "org.assertj:assertj-core:$assertj_version" compile "org.assertj:assertj-core:$assertj_version"
compile "com.natpryce:hamkrest:$hamkrest_version" compile "com.natpryce:hamkrest:$hamkrest_version"

View File

@ -3,6 +3,7 @@ package net.corda.testing.core
import net.corda.core.internal.JarSignatureCollector import net.corda.core.internal.JarSignatureCollector
import net.corda.core.internal.div import net.corda.core.internal.div
import net.corda.nodeapi.internal.crypto.loadKeyStore import net.corda.nodeapi.internal.crypto.loadKeyStore
import net.corda.testing.core.JarSignatureTestUtils.signJar
import java.io.FileInputStream import java.io.FileInputStream
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
@ -44,6 +45,11 @@ object JarSignatureTestUtils {
return ks.getCertificate(alias).publicKey return ks.getCertificate(alias).publicKey
} }
fun Path.getPublicKey(alias: String, storePassword: String) : PublicKey {
val ks = loadKeyStore(this.resolve("_teststore"), storePassword)
return ks.getCertificate(alias).publicKey
}
fun Path.getJarSigners(fileName: String) = fun Path.getJarSigners(fileName: String) =
JarInputStream(FileInputStream((this / fileName).toFile())).use(JarSignatureCollector::collectSigners) JarInputStream(FileInputStream((this / fileName).toFile())).use(JarSignatureCollector::collectSigners)
} }

View File

@ -310,6 +310,7 @@ class VaultFiller @JvmOverloads constructor(
/** A state representing a commodity claim against some party */ /** A state representing a commodity claim against some party */
@BelongsToContract(Obligation::class)
data class CommodityState( data class CommodityState(
override val amount: Amount<Issued<Commodity>>, override val amount: Amount<Issued<Commodity>>,

View File

@ -7,6 +7,7 @@ description 'Network bootstrapper'
dependencies { dependencies {
compile project(':node-api') compile project(':node-api')
compile project(':tools:cliutils') compile project(':tools:cliutils')
compile project(':common-configuration-parsing')
compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version" compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"
testCompile(project(':test-utils')) { testCompile(project(':test-utils')) {
@ -14,6 +15,8 @@ dependencies {
} }
testCompile(project(':test-cli')) testCompile(project(':test-cli'))
testCompile "com.nhaarman:mockito-kotlin:$mockito_kotlin_version"
testCompile "org.mockito:mockito-core:$mockito_version"
} }
processResources { processResources {

View File

@ -1,109 +1,96 @@
package net.corda.bootstrapper package net.corda.bootstrapper
import com.typesafe.config.ConfigFactory
import com.typesafe.config.ConfigParseOptions
import net.corda.cliutils.CordaCliWrapper import net.corda.cliutils.CordaCliWrapper
import net.corda.cliutils.ExitCodes
import net.corda.cliutils.printError
import net.corda.cliutils.start import net.corda.cliutils.start
import net.corda.common.configuration.parsing.internal.Configuration
import net.corda.core.internal.PLATFORM_VERSION import net.corda.core.internal.PLATFORM_VERSION
import net.corda.core.internal.requirePackageValid import net.corda.core.internal.exists
import net.corda.nodeapi.internal.crypto.loadKeyStore
import net.corda.nodeapi.internal.network.NetworkBootstrapper import net.corda.nodeapi.internal.network.NetworkBootstrapper
import picocli.CommandLine import net.corda.nodeapi.internal.network.NetworkBootstrapper.Companion.DEFAULT_MAX_MESSAGE_SIZE
import net.corda.nodeapi.internal.network.NetworkBootstrapper.Companion.DEFAULT_MAX_TRANSACTION_SIZE
import net.corda.nodeapi.internal.network.NetworkBootstrapperWithOverridableParameters
import net.corda.nodeapi.internal.network.NetworkParametersOverrides
import picocli.CommandLine.Option import picocli.CommandLine.Option
import java.io.IOException import java.io.FileNotFoundException
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
import java.security.KeyStoreException import java.time.Duration
import java.security.PublicKey
fun main(args: Array<String>) { fun main(args: Array<String>) {
NetworkBootstrapperRunner().start(args) NetworkBootstrapperRunner().start(args)
} }
class NetworkBootstrapperRunner : CordaCliWrapper("bootstrapper", "Bootstrap a local test Corda network using a set of node configuration files and CorDapp JARs") { class NetworkBootstrapperRunner(private val bootstrapper: NetworkBootstrapperWithOverridableParameters = NetworkBootstrapper()) : CordaCliWrapper("bootstrapper", "Bootstrap a local test Corda network using a set of node configuration files and CorDapp JARs") {
@Option( @Option(names = ["--dir"],
names = ["--dir"], description = [ "Root directory containing the node configuration files and CorDapp JARs that will form the test network.",
description = [ "It may also contain existing node directories."])
"Root directory containing the node configuration files and CorDapp JARs that will form the test network.",
"It may also contain existing node directories."
]
)
var dir: Path = Paths.get(".") var dir: Path = Paths.get(".")
@Option(names = ["--no-copy"], description = ["""Don't copy the CorDapp JARs into the nodes' "cordapps" directories."""]) @Option(names = ["--no-copy"], description = ["""Don't copy the CorDapp JARs into the nodes' "cordapps" directories."""])
var noCopy: Boolean = false var noCopy: Boolean = false
@Option(names = ["--minimum-platform-version"], description = ["The minimumPlatformVersion to use in the network-parameters."]) @Option(names = ["--minimum-platform-version"], description = ["The minimum platform version to use in the network-parameters. Current default is $PLATFORM_VERSION."])
var minimumPlatformVersion = PLATFORM_VERSION var minimumPlatformVersion: Int? = null
@Option(names = ["--register-package-owner"], @Option(names = ["--max-message-size"], description = ["The maximum message size to use in the network-parameters, in bytes. Current default is $DEFAULT_MAX_MESSAGE_SIZE."])
converter = [PackageOwnerConverter::class], var maxMessageSize: Int? = null
description = [
"Register owner of Java package namespace in the network-parameters.",
"Format: [java-package-namespace;keystore-file;password;alias]",
" `java-package-namespace` is case insensitive and cannot be a sub-package of an existing registered namespace",
" `keystore-file` refers to the location of key store file containing the signed certificate as generated by the Java 'keytool' tool (see https://docs.oracle.com/javase/8/docs/technotes/tools/windows/keytool.html)",
" `password` to open the key store",
" `alias` refers to the name associated with a certificate containing the public key to be associated with the package namespace"
])
var registerPackageOwnership: List<PackageOwner> = mutableListOf()
@Option(names = ["--unregister-package-owner"], @Option(names = ["--max-transaction-size"], description = ["The maximum transaction size to use in the network-parameters, in bytes. Current default is $DEFAULT_MAX_TRANSACTION_SIZE."])
description = [ var maxTransactionSize: Int? = null
"Unregister owner of Java package namespace in the network-parameters.",
"Format: [java-package-namespace]", @Option(names = ["--event-horizon"], description = ["The event horizon to use in the network-parameters. Default is 30 days."])
" `java-package-namespace` is case insensitive and cannot be a sub-package of an existing registered namespace" var eventHorizon: Duration? = null
])
var unregisterPackageOwnership: List<String> = mutableListOf() @Option(names = ["--network-parameter-overrides", "-n"], description = ["Overrides the default network parameters with those in the given file."])
var networkParametersFile: Path? = null
private fun verifyInputs() {
require(minimumPlatformVersion == null || minimumPlatformVersion ?: 0 > 0) { "The --minimum-platform-version parameter must be at least 1" }
require(eventHorizon == null || eventHorizon?.isNegative == false) { "The --event-horizon parameter must be a positive value" }
require(maxTransactionSize == null || maxTransactionSize ?: 0 > 0) { "The --max-transaction-size parameter must be at least 1" }
require(maxMessageSize == null || maxMessageSize ?: 0 > 0) { "The --max-message-size parameter must be at least 1" }
}
private fun commandLineOverrides(): Map<String, Any> {
val overrides = mutableMapOf<String, Any>()
overrides += minimumPlatformVersion?.let { mapOf("minimumPlatformVersion" to minimumPlatformVersion!!) } ?: mutableMapOf()
overrides += maxMessageSize?.let { mapOf("maxMessageSize" to maxMessageSize!!) } ?: emptyMap()
overrides += maxTransactionSize?.let { mapOf("maxTransactionSize" to maxTransactionSize!!) } ?: emptyMap()
overrides += eventHorizon?.let { mapOf("eventHorizon" to eventHorizon!!) } ?: emptyMap()
return overrides
}
private fun getNetworkParametersOverrides(): Valid<NetworkParametersOverrides> {
val parseOptions = ConfigParseOptions.defaults()
val config = if (networkParametersFile == null) {
ConfigFactory.empty()
} else {
if (networkParametersFile?.exists() != true) throw FileNotFoundException("Unable to find specified network parameters config file at $networkParametersFile")
ConfigFactory.parseFile(networkParametersFile!!.toFile(), parseOptions)
}
val finalConfig = ConfigFactory.parseMap(commandLineOverrides()).withFallback(config).resolve()
return finalConfig.parseAsNetworkParametersConfiguration()
}
private fun <T> Collection<T>.pluralise() = if (this.count() > 1) "s" else ""
private fun reportErrors(errors: Set<Configuration.Validation.Error>) {
printError("Error${errors.pluralise()} found parsing the network parameter overrides file at $networkParametersFile:")
errors.forEach { printError("Error parsing ${it.pathAsString}: ${it.message}") }
}
override fun runProgram(): Int { override fun runProgram(): Int {
NetworkBootstrapper().bootstrap(dir.toAbsolutePath().normalize(), verifyInputs()
val networkParameterOverrides = getNetworkParametersOverrides().doOnErrors(::reportErrors).optional ?: return ExitCodes.FAILURE
bootstrapper.bootstrap(dir.toAbsolutePath().normalize(),
copyCordapps = !noCopy, copyCordapps = !noCopy,
minimumPlatformVersion = minimumPlatformVersion, networkParameterOverrides = networkParameterOverrides
packageOwnership = registerPackageOwnership.map { Pair(it.javaPackageName, it.publicKey) }.toMap()
.plus(unregisterPackageOwnership.map { Pair(it, null) })
) )
return 0 //exit code return ExitCodes.SUCCESS
}
}
data class PackageOwner(val javaPackageName: String, val publicKey: PublicKey)
/**
* Converter from String to PackageOwner (String and PublicKey)
*/
class PackageOwnerConverter : CommandLine.ITypeConverter<PackageOwner> {
override fun convert(packageOwner: String): PackageOwner {
if (!packageOwner.isBlank()) {
val packageOwnerSpec = packageOwner.split(";")
if (packageOwnerSpec.size < 4)
throw IllegalArgumentException("Package owner must specify 4 elements separated by semi-colon: 'java-package-namespace;keyStorePath;keyStorePassword;alias'")
// java package name validation
val javaPackageName = packageOwnerSpec[0]
requirePackageValid(javaPackageName)
// cater for passwords that include the argument delimiter field
val keyStorePassword =
if (packageOwnerSpec.size > 4)
packageOwnerSpec.subList(2, packageOwnerSpec.size-1).joinToString(";")
else packageOwnerSpec[2]
try {
val ks = loadKeyStore(Paths.get(packageOwnerSpec[1]), keyStorePassword)
try {
val publicKey = ks.getCertificate(packageOwnerSpec[packageOwnerSpec.size-1]).publicKey
return PackageOwner(javaPackageName,publicKey)
}
catch(kse: KeyStoreException) {
throw IllegalArgumentException("Keystore has not been initialized for alias ${packageOwnerSpec[3]}")
}
}
catch(kse: KeyStoreException) {
throw IllegalArgumentException("Password is incorrect or the key store is damaged for keyStoreFilePath: ${packageOwnerSpec[1]} and keyStorePassword: $keyStorePassword")
}
catch(e: IOException) {
throw IllegalArgumentException("Error reading the key store from the file for keyStoreFilePath: ${packageOwnerSpec[1]} and keyStorePassword: $keyStorePassword")
}
}
else throw IllegalArgumentException("Must specify package owner argument: 'java-package-namespace;keyStorePath;keyStorePassword;alias'")
} }
} }

View File

@ -0,0 +1,103 @@
package net.corda.bootstrapper
import com.typesafe.config.Config
import net.corda.common.configuration.parsing.internal.Configuration
import net.corda.common.configuration.parsing.internal.get
import net.corda.common.configuration.parsing.internal.mapValid
import net.corda.common.configuration.parsing.internal.nested
import net.corda.common.validation.internal.Validated
import net.corda.core.internal.div
import net.corda.core.internal.requirePackageValid
import net.corda.core.node.NetworkParameters
import net.corda.nodeapi.internal.crypto.loadKeyStore
import net.corda.nodeapi.internal.network.NetworkParametersOverrides
import net.corda.nodeapi.internal.network.PackageOwner
import java.io.IOException
import java.nio.file.InvalidPathException
import java.nio.file.Path
import java.nio.file.Paths
import java.security.KeyStoreException
internal typealias Valid<TARGET> = Validated<TARGET, Configuration.Validation.Error>
fun Config.parseAsNetworkParametersConfiguration(options: Configuration.Validation.Options = Configuration.Validation.Options(strict = false)):
Valid<NetworkParametersOverrides> = NetworkParameterOverridesSpec.parse(this, options)
internal fun <T> badValue(msg: String): Valid<T> = Validated.invalid(sequenceOf(Configuration.Validation.Error.BadValue.of(msg)).toSet())
internal fun <T> valid(value: T): Valid<T> = Validated.valid(value)
internal object NetworkParameterOverridesSpec : Configuration.Specification<NetworkParametersOverrides>("DefaultNetworkParameters") {
private val minimumPlatformVersion by int().mapValid(::parsePositiveInteger).optional()
private val maxMessageSize by int().mapValid(::parsePositiveInteger).optional()
private val maxTransactionSize by int().mapValid(::parsePositiveInteger).optional()
private val packageOwnership by nested(PackageOwnershipSpec).list().optional()
private val eventHorizon by duration().optional()
internal object PackageOwnershipSpec : Configuration.Specification<PackageOwner>("PackageOwners") {
private val packageName by string().mapValid(::toPackageName)
private val keystore by string().mapValid(::toPath)
private val keystorePassword by string()
private val keystoreAlias by string()
override fun parseValid(configuration: Config): Validated<PackageOwner, Configuration.Validation.Error> {
val suppliedKeystorePath = configuration[keystore]
val keystorePassword = configuration[keystorePassword]
return try {
val javaPackageName = configuration[packageName]
val absoluteKeystorePath = if (suppliedKeystorePath.isAbsolute) {
suppliedKeystorePath
} else {
//If a relative path is supplied, make it relative to the location of the config file
Paths.get(configuration.origin().filename()).resolveSibling(suppliedKeystorePath.toString())
}.toAbsolutePath()
val ks = loadKeyStore(absoluteKeystorePath, keystorePassword)
return try {
val publicKey = ks.getCertificate(configuration[keystoreAlias]).publicKey
valid(PackageOwner(javaPackageName, publicKey))
} catch (kse: KeyStoreException) {
badValue("Keystore has not been initialized for alias ${configuration[keystoreAlias]}")
}
} catch (kse: KeyStoreException) {
badValue("Password is incorrect or the key store is damaged for keyStoreFilePath: $suppliedKeystorePath and keyStorePassword: $keystorePassword")
} catch (e: IOException) {
badValue("Error reading the key store from the file for keyStoreFilePath: $suppliedKeystorePath and keyStorePassword: $keystorePassword ${e.message}")
}
}
private fun toPackageName(rawValue: String): Validated<String, Configuration.Validation.Error> {
return try {
requirePackageValid(rawValue)
valid(rawValue)
} catch (e: Exception) {
return badValue(e.message ?: e.toString())
}
}
private fun toPath(rawValue: String): Validated<Path, Configuration.Validation.Error> {
return try {
valid(Paths.get(rawValue))
} catch (e: InvalidPathException) {
return badValue("Path $rawValue not found")
}
}
}
override fun parseValid(configuration: Config): Valid<NetworkParametersOverrides> {
val packageOwnership = configuration[packageOwnership]
if (packageOwnership != null && !NetworkParameters.noOverlap(packageOwnership.map { it.javaPackageName })) {
return Validated.invalid(sequenceOf(Configuration.Validation.Error.BadValue.of("Package namespaces must not overlap", keyName = "packageOwnership", containingPath = listOf())).toSet())
}
return valid(NetworkParametersOverrides(
minimumPlatformVersion = configuration[minimumPlatformVersion],
maxMessageSize = configuration[maxMessageSize],
maxTransactionSize = configuration[maxTransactionSize],
packageOwnership = packageOwnership,
eventHorizon = configuration[eventHorizon]
))
}
private fun parsePositiveInteger(rawValue: Int): Valid<Int> {
if (rawValue > 0) return valid(rawValue)
return badValue("The value must be at least 1")
}
}

View File

@ -0,0 +1,5 @@
package net.corda.bootstrapper
import net.corda.testing.CliBackwardsCompatibleTest
class NetworkBootstrapperBackwardsCompatibilityTest : CliBackwardsCompatibleTest(NetworkBootstrapperRunner::class.java)

View File

@ -1,5 +0,0 @@
package net.corda.bootstrapper
import net.corda.testing.CliBackwardsCompatibleTest
class NetworkBootstrapperRunnerTest : CliBackwardsCompatibleTest(NetworkBootstrapperRunner::class.java)

View File

@ -0,0 +1,255 @@
package net.corda.bootstrapper
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.verify
import net.corda.core.internal.copyTo
import net.corda.core.internal.deleteRecursively
import net.corda.core.internal.div
import net.corda.core.utilities.days
import net.corda.nodeapi.internal.network.NetworkBootstrapperWithOverridableParameters
import net.corda.nodeapi.internal.network.NetworkParametersOverrides
import net.corda.nodeapi.internal.network.PackageOwner
import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.CHARLIE_NAME
import net.corda.testing.core.JarSignatureTestUtils.generateKey
import net.corda.testing.core.JarSignatureTestUtils.getPublicKey
import org.junit.*
import java.io.ByteArrayOutputStream
import java.io.FileNotFoundException
import java.io.PrintStream
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.security.PublicKey
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
class NetworkBootstrapperRunnerTests {
private val outContent = ByteArrayOutputStream()
private val errContent = ByteArrayOutputStream()
private val originalOut = System.out
private val originalErr = System.err
@Before
fun setUpStreams() {
System.setOut(PrintStream(outContent))
System.setErr(PrintStream(errContent))
}
@After
fun restoreStreams() {
System.setOut(originalOut)
System.setErr(originalErr)
}
companion object {
private const val ALICE = "alice"
private const val ALICE_PASS = "alicepass"
private const val aliceConfigFile = "alice-network.conf"
private const val correctNetworkFile = "correct-network.conf"
private const val packageOverlapConfigFile = "package-overlap.conf"
private val dirAlice = Files.createTempDirectory(ALICE)
private val dirAliceEC = Files.createTempDirectory("sdfsdfds")
private val dirAliceDSA = Files.createTempDirectory(ALICE)
private lateinit var alicePublicKey: PublicKey
private lateinit var alicePublicKeyEC: PublicKey
private lateinit var alicePublicKeyDSA: PublicKey
private val resourceDirectory = Paths.get(".") / "src" / "test" / "resources"
private fun String.copyToTestDir(dir: Path = dirAlice): Path {
return (resourceDirectory / this).copyTo(dir / this)
}
@BeforeClass
@JvmStatic
fun beforeClass() {
dirAlice.generateKey(ALICE, ALICE_PASS, ALICE_NAME.toString())
dirAliceEC.generateKey(ALICE, ALICE_PASS, ALICE_NAME.toString(), "EC")
dirAliceDSA.generateKey(ALICE, ALICE_PASS, ALICE_NAME.toString(), "DSA")
alicePublicKey = dirAlice.getPublicKey(ALICE, ALICE_PASS)
alicePublicKeyEC = dirAliceEC.getPublicKey(ALICE, ALICE_PASS)
alicePublicKeyDSA = dirAliceDSA.getPublicKey(ALICE, ALICE_PASS)
}
@AfterClass
@JvmStatic
fun afterClass() {
dirAlice.deleteRecursively()
}
}
private fun getRunner(): Pair<NetworkBootstrapperRunner, NetworkBootstrapperWithOverridableParameters> {
val mockBootstrapper = mock<NetworkBootstrapperWithOverridableParameters>()
return Pair(NetworkBootstrapperRunner(mockBootstrapper), mockBootstrapper)
}
@Test
fun `test when defaults are run bootstrapper is called correctly`() {
val (runner, mockBootstrapper) = getRunner()
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(Paths.get(".").toAbsolutePath().normalize(), true, NetworkParametersOverrides())
assertEquals(0, exitCode)
}
@Test
fun `test when base directory is specified it is passed through to the bootstrapper`() {
val (runner, mockBootstrapper) = getRunner()
val tempDir = createTempDir()
runner.dir = tempDir.toPath()
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(tempDir.toPath().toAbsolutePath().normalize(), true, NetworkParametersOverrides())
assertEquals(0, exitCode)
}
@Test
fun `test when copy cordapps is specified it is passed through to the bootstrapper`() {
val (runner, mockBootstrapper) = getRunner()
runner.noCopy = true
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(Paths.get(".").toAbsolutePath().normalize(), false, NetworkParametersOverrides())
assertEquals(0, exitCode)
}
@Test
fun `test when min platform version is specified it is passed through to the bootstrapper`() {
val (runner, mockBootstrapper) = getRunner()
runner.minimumPlatformVersion = 1
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(Paths.get(".").toAbsolutePath().normalize(), true, NetworkParametersOverrides(minimumPlatformVersion = 1))
assertEquals(0, exitCode)
}
@Test
fun `test when min platform version is invalid it fails to run with a sensible error message`() {
val runner = getRunner().first
runner.minimumPlatformVersion = 0
val exception = assertFailsWith<IllegalArgumentException> { runner.runProgram() }
assertEquals("The --minimum-platform-version parameter must be at least 1", exception.message)
}
@Test
fun `test when max message size is specified it is passed through to the bootstrapper`() {
val (runner, mockBootstrapper) = getRunner()
runner.maxMessageSize = 1
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(Paths.get(".").toAbsolutePath().normalize(), true, NetworkParametersOverrides(maxMessageSize = 1))
assertEquals(0, exitCode)
}
@Test
fun `test when max message size is invalid it fails to run with a sensible error message`() {
val runner = getRunner().first
runner.maxMessageSize = 0
val exception = assertFailsWith<IllegalArgumentException> { runner.runProgram() }
assertEquals("The --max-message-size parameter must be at least 1", exception.message)
}
@Test
fun `test when max transaction size is specified it is passed through to the bootstrapper`() {
val (runner, mockBootstrapper) = getRunner()
runner.maxTransactionSize = 1
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(Paths.get(".").toAbsolutePath().normalize(), true, NetworkParametersOverrides(maxTransactionSize = 1))
assertEquals(0, exitCode)
}
@Test
fun `test when max transaction size is invalid it fails to run with a sensible error message`() {
val runner = getRunner().first
runner.maxTransactionSize = 0
val exception = assertFailsWith<IllegalArgumentException> { runner.runProgram() }
assertEquals("The --max-transaction-size parameter must be at least 1", exception.message)
}
@Test
fun `test when event horizon is specified it is passed through to the bootstrapper`() {
val (runner, mockBootstrapper) = getRunner()
runner.eventHorizon = 7.days
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(Paths.get(".").toAbsolutePath().normalize(), true, NetworkParametersOverrides(eventHorizon = 7.days))
assertEquals(0, exitCode)
}
@Test
fun `test when event horizon is invalid it fails to run with a sensible error message`() {
val runner = getRunner().first
runner.eventHorizon = (-7).days
val exception = assertFailsWith<IllegalArgumentException> { runner.runProgram() }
assertEquals("The --event-horizon parameter must be a positive value", exception.message)
}
@Test
fun `test when a network parameters is specified the values are passed through to the bootstrapper`() {
val (runner, mockBootstrapper) = getRunner()
val conf = correctNetworkFile.copyToTestDir()
runner.networkParametersFile = conf
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(Paths.get(".").toAbsolutePath().normalize(), true, NetworkParametersOverrides(
maxMessageSize = 10000,
maxTransactionSize = 2000,
eventHorizon = 5.days,
minimumPlatformVersion = 2
))
assertEquals(0, exitCode)
}
@Test
fun `test when a package is specified in the network parameters file it is passed through to the bootstrapper`() {
val (runner, mockBootstrapper) = getRunner()
val conf = aliceConfigFile.copyToTestDir()
runner.networkParametersFile = conf
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(Paths.get(".").toAbsolutePath().normalize(), true, NetworkParametersOverrides(
packageOwnership = listOf(PackageOwner("com.example.stuff", publicKey = alicePublicKey))
))
assertEquals(0, exitCode)
}
@Test
fun `test when a package is specified in the network parameters file it is passed through to the bootstrapper EC`() {
val (runner, mockBootstrapper) = getRunner()
val conf = aliceConfigFile.copyToTestDir(dirAliceEC)
runner.networkParametersFile = conf
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(Paths.get(".").toAbsolutePath().normalize(), true, NetworkParametersOverrides(
packageOwnership = listOf(PackageOwner("com.example.stuff", publicKey = alicePublicKeyEC))
))
assertEquals(0, exitCode)
}
@Test
fun `test when a package is specified in the network parameters file it is passed through to the bootstrapper DSA`() {
val (runner, mockBootstrapper) = getRunner()
val conf = aliceConfigFile.copyToTestDir(dirAliceDSA)
runner.networkParametersFile = conf
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(Paths.get(".").toAbsolutePath().normalize(), true, NetworkParametersOverrides(
packageOwnership = listOf(PackageOwner("com.example.stuff", publicKey = alicePublicKeyDSA))
))
assertEquals(0, exitCode)
}
@Test
fun `test when packages overlap that the bootstrapper fails with a sensible message`() {
val (runner, mockBootstrapper) = getRunner()
val conf = packageOverlapConfigFile.copyToTestDir()
runner.networkParametersFile = conf
val exitCode = runner.runProgram()
val output = errContent.toString()
assert(output.contains("Error parsing packageOwnership: Package namespaces must not overlap"))
assertEquals(1, exitCode)
}
@Test
fun `test when keyfile does not exist then bootstrapper fails with a sensible message`() {
val (runner, mockBootstrapper) = getRunner()
runner.networkParametersFile = dirAlice / "filename-that-doesnt-exist"
val exception = assertFailsWith<FileNotFoundException> { runner.runProgram() }
assert(exception.message!!.startsWith("Unable to find specified network parameters config file at"))
}
}

View File

@ -1,164 +0,0 @@
package net.corda.bootstrapper
import net.corda.core.internal.deleteRecursively
import net.corda.core.internal.div
import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.CHARLIE_NAME
import net.corda.testing.core.JarSignatureTestUtils.generateKey
import org.assertj.core.api.Assertions.assertThat
import org.junit.*
import org.junit.rules.ExpectedException
import picocli.CommandLine
import java.nio.file.Files
class PackageOwnerParsingTest {
@Rule
@JvmField
val expectedEx: ExpectedException = ExpectedException.none()
companion object {
private const val ALICE = "alice"
private const val ALICE_PASS = "alicepass"
private const val BOB = "bob"
private const val BOB_PASS = "bobpass"
private const val CHARLIE = "charlie"
private const val CHARLIE_PASS = "charliepass"
private val dirAlice = Files.createTempDirectory(ALICE)
private val dirBob = Files.createTempDirectory(BOB)
private val dirCharlie = Files.createTempDirectory(CHARLIE)
val networkBootstrapper = NetworkBootstrapperRunner()
val commandLine = CommandLine(networkBootstrapper)
@BeforeClass
@JvmStatic
fun beforeClass() {
dirAlice.generateKey(ALICE, ALICE_PASS, ALICE_NAME.toString())
dirBob.generateKey(BOB, BOB_PASS, BOB_NAME.toString(), "EC")
dirCharlie.generateKey(CHARLIE, CHARLIE_PASS, CHARLIE_NAME.toString(), "DSA")
}
@AfterClass
@JvmStatic
fun afterClass() {
dirAlice.deleteRecursively()
}
}
@Test
fun `parse registration request with single mapping`() {
val aliceKeyStorePath = dirAlice / "_teststore"
val args = arrayOf("--register-package-owner", "com.example.stuff;$aliceKeyStorePath;$ALICE_PASS;$ALICE")
commandLine.parse(*args)
assertThat(networkBootstrapper.registerPackageOwnership[0].javaPackageName).isEqualTo("com.example.stuff")
}
@Test
fun `parse registration request with invalid arguments`() {
val args = arrayOf("--register-package-owner", "com.!example.stuff")
expectedEx.expect(CommandLine.ParameterException::class.java)
expectedEx.expectMessage("Package owner must specify 4 elements separated by semi-colon")
commandLine.parse(*args)
}
@Test
fun `parse registration request with incorrect keystore specification`() {
val aliceKeyStorePath = dirAlice / "_teststore"
val args = arrayOf("--register-package-owner", "com.example.stuff;$aliceKeyStorePath$ALICE_PASS")
expectedEx.expect(CommandLine.ParameterException::class.java)
expectedEx.expectMessage("Package owner must specify 4 elements separated by semi-colon")
commandLine.parse(*args)
}
@Test
fun `parse registration request with invalid java package name`() {
val args = arrayOf("--register-package-owner", "com.!example.stuff;A;B;C")
expectedEx.expect(CommandLine.ParameterException::class.java)
expectedEx.expectMessage("Invalid Java package name")
commandLine.parse(*args)
}
@Test
fun `parse registration request with invalid keystore file`() {
val args = arrayOf("--register-package-owner", "com.example.stuff;NONSENSE;B;C")
expectedEx.expect(CommandLine.ParameterException::class.java)
expectedEx.expectMessage("Error reading the key store from the file")
commandLine.parse(*args)
}
@Test
fun `parse registration request with invalid keystore password`() {
val aliceKeyStorePath = dirAlice / "_teststore"
val args = arrayOf("--register-package-owner", "com.example.stuff;$aliceKeyStorePath;BAD_PASSWORD;$ALICE")
expectedEx.expect(CommandLine.ParameterException::class.java)
expectedEx.expectMessage("Error reading the key store from the file")
commandLine.parse(*args)
}
@Test
fun `parse registration request with invalid keystore alias`() {
val aliceKeyStorePath = dirAlice / "_teststore"
val args = arrayOf("--register-package-owner", "com.example.stuff;$aliceKeyStorePath;$ALICE_PASS;BAD_ALIAS")
expectedEx.expect(CommandLine.ParameterException::class.java)
expectedEx.expectMessage("must not be null")
commandLine.parse(*args)
}
@Test
fun `parse registration request with multiple arguments`() {
val aliceKeyStorePath = dirAlice / "_teststore"
val bobKeyStorePath = dirBob / "_teststore"
val charlieKeyStorePath = dirCharlie / "_teststore"
val args = arrayOf("--register-package-owner", "com.example.stuff;$aliceKeyStorePath;$ALICE_PASS;$ALICE",
"--register-package-owner", "com.example.more.stuff;$bobKeyStorePath;$BOB_PASS;$BOB",
"--register-package-owner", "com.example.even.more.stuff;$charlieKeyStorePath;$CHARLIE_PASS;$CHARLIE")
commandLine.parse(*args)
assertThat(networkBootstrapper.registerPackageOwnership).hasSize(3)
}
@Ignore("Ignoring this test as the delimiters don't work correctly, see CORDA-2191")
@Test
fun `parse registration request with delimiter inclusive passwords`() {
val aliceKeyStorePath1 = dirAlice / "_alicestore1"
dirAlice.generateKey("${ALICE}1", "passw;rd", ALICE_NAME.toString(), storeName = "_alicestore1")
val aliceKeyStorePath2 = dirAlice / "_alicestore2"
dirAlice.generateKey("${ALICE}2", "\"passw;rd\"", ALICE_NAME.toString(), storeName = "_alicestore2")
val aliceKeyStorePath3 = dirAlice / "_alicestore3"
dirAlice.generateKey("${ALICE}3", "passw;rd", ALICE_NAME.toString(), storeName = "_alicestore3")
val aliceKeyStorePath4 = dirAlice / "_alicestore4"
dirAlice.generateKey("${ALICE}4", "\'passw;rd\'", ALICE_NAME.toString(), storeName = "_alicestore4")
val aliceKeyStorePath5 = dirAlice / "_alicestore5"
dirAlice.generateKey("${ALICE}5", "\"\"passw;rd\"\"", ALICE_NAME.toString(), storeName = "_alicestore5")
val packageOwnerSpecs = listOf("net.something0;$aliceKeyStorePath1;passw;rd;${ALICE}1",
"net.something1;$aliceKeyStorePath2;\"passw;rd\";${ALICE}2",
"\"net.something2;$aliceKeyStorePath3;passw;rd;${ALICE}3\"",
"net.something3;$aliceKeyStorePath4;\'passw;rd\';${ALICE}4",
"net.something4;$aliceKeyStorePath5;\"\"passw;rd\"\";${ALICE}5")
packageOwnerSpecs.forEachIndexed { i, packageOwnerSpec ->
commandLine.parse(*arrayOf("--register-package-owner", packageOwnerSpec))
assertThat(networkBootstrapper.registerPackageOwnership[0].javaPackageName).isEqualTo("net.something$i")
}
}
@Test
fun `parse unregister request with single mapping`() {
val args = arrayOf("--unregister-package-owner", "com.example.stuff")
commandLine.parse(*args)
assertThat(networkBootstrapper.unregisterPackageOwnership).contains("com.example.stuff")
}
@Test
fun `parse mixed register and unregister request`() {
val aliceKeyStorePath = dirAlice / "_teststore"
val args = arrayOf("--register-package-owner", "com.example.stuff;$aliceKeyStorePath;$ALICE_PASS;$ALICE",
"--unregister-package-owner", "com.example.stuff2")
commandLine.parse(*args)
assertThat(networkBootstrapper.registerPackageOwnership.map { it.javaPackageName }).contains("com.example.stuff")
assertThat(networkBootstrapper.unregisterPackageOwnership).contains("com.example.stuff2")
}
}

View File

@ -0,0 +1,8 @@
packageOwnership=[
{
packageName="com.example.stuff"
keystore="_teststore"
keystorePassword="alicepass"
keystoreAlias="alice"
}
]

View File

@ -0,0 +1,4 @@
minimumPlatformVersion=2
maxMessageSize=10000
maxTransactionSize=2000
eventHorizon="5 days"

View File

@ -0,0 +1,14 @@
packageOwnership=[
{
packageName="com.example"
keystore="_teststore"
keystorePassword="alicepass"
keystoreAlias="alice"
}
{
packageName="com.example.overlap"
keystore="_teststore"
keystorePassword="alicepass"
keystoreAlias="alice"
}
]

View File

@ -53,6 +53,7 @@ object CordaSystemUtils {
object ShellConstants { object ShellConstants {
const val RED = "\u001B[31m" const val RED = "\u001B[31m"
const val YELLOW = "\u001B[33m"
const val RESET = "\u001B[0m" const val RESET = "\u001B[0m"
} }
@ -86,8 +87,8 @@ fun CordaCliWrapper.start(args: Array<String>) {
if (this.verbose || this.subCommands().any { it.verbose }) { if (this.verbose || this.subCommands().any { it.verbose }) {
throwable.printStackTrace() throwable.printStackTrace()
} else { } else {
System.err.println("*ERROR*: ${throwable.rootMessage ?: "Use --verbose for more details"}")
} }
printError(throwable.rootMessage ?: "Use --verbose for more details")
exitProcess(ExitCodes.FAILURE) exitProcess(ExitCodes.FAILURE)
} }
} }
@ -185,11 +186,12 @@ abstract class CordaCliWrapper(alias: String, description: String) : CliWrapperB
fun printHelp() = cmd.usage(System.out) fun printHelp() = cmd.usage(System.out)
fun printlnErr(message: String) = System.err.println(message)
fun printlnWarn(message: String) = System.err.println(message)
} }
fun printWarning(message: String) = System.err.println("${ShellConstants.YELLOW}$message${ShellConstants.RESET}")
fun printError(message: String) = System.err.println("${ShellConstants.RED}$message${ShellConstants.RESET}")
/** /**
* Useful commonly used constants applicable to many CLI tools * Useful commonly used constants applicable to many CLI tools
*/ */

View File

@ -94,7 +94,7 @@ private class ShellExtensionsGenerator(val parent: CordaCliWrapper) {
val semanticParts = declaredBashVersion().split(".") val semanticParts = declaredBashVersion().split(".")
semanticParts.firstOrNull()?.toIntOrNull()?.let { major -> semanticParts.firstOrNull()?.toIntOrNull()?.let { major ->
if (major < minSupportedBashVersion) { if (major < minSupportedBashVersion) {
parent.printlnWarn("Cannot install shell extension for bash major version earlier than $minSupportedBashVersion. Please upgrade your bash version. Aliases should still work.") printWarning("Cannot install shell extension for bash major version earlier than $minSupportedBashVersion. Please upgrade your bash version. Aliases should still work.")
generateAutoCompleteFile = false generateAutoCompleteFile = false
} }
} }

View File

@ -37,7 +37,7 @@ public class FlowShellCommand extends InteractiveShellCommand {
@Usage("The data to pass as input") @Argument(unquote = false) List<String> input @Usage("The data to pass as input") @Argument(unquote = false) List<String> input
) { ) {
logger.info("Executing command \"flow start {} {}\",", name, (input != null) ? input.stream().collect(joining(" ")) : "<no arguments>"); logger.info("Executing command \"flow start {} {}\",", name, (input != null) ? input.stream().collect(joining(" ")) : "<no arguments>");
startFlow(name, input, out, ops(), ansiProgressRenderer(), objectMapper()); startFlow(name, input, out, ops(), ansiProgressRenderer(), objectMapper(null));
} }
// TODO Limit number of flows shown option? // TODO Limit number of flows shown option?

View File

@ -38,13 +38,13 @@ public class RunShellCommand extends InteractiveShellCommand {
@Usage("runs a method from the CordaRPCOps interface on the node.") @Usage("runs a method from the CordaRPCOps interface on the node.")
public Object main(InvocationContext<Map> context, @Usage("The command to run") @Argument(unquote = false) List<String> command) { public Object main(InvocationContext<Map> context, @Usage("The command to run") @Argument(unquote = false) List<String> command) {
logger.info("Executing command \"run {}\",", (command != null) ? command.stream().collect(joining(" ")) : "<no arguments>"); logger.info("Executing command \"run {}\",", (command != null) ? command.stream().collect(joining(" ")) : "<no arguments>");
StringToMethodCallParser<CordaRPCOps> parser = new StringToMethodCallParser<>(CordaRPCOps.class, objectMapper()); StringToMethodCallParser<CordaRPCOps> parser = new StringToMethodCallParser<>(CordaRPCOps.class, objectMapper(InteractiveShell.getCordappsClassloader()));
if (command == null) { if (command == null) {
emitHelp(context, parser); emitHelp(context, parser);
return null; return null;
} }
return InteractiveShell.runRPCFromString(command, out, context, ops(), objectMapper()); return InteractiveShell.runRPCFromString(command, out, context, ops(), objectMapper(InteractiveShell.getCordappsClassloader()));
} }
private void emitHelp(InvocationContext<Map> context, StringToMethodCallParser<CordaRPCOps> parser) { private void emitHelp(InvocationContext<Map> context, StringToMethodCallParser<CordaRPCOps> parser) {

View File

@ -23,6 +23,6 @@ public class StartShellCommand extends InteractiveShellCommand {
logger.info("Executing command \"start {} {}\",", name, (input != null) ? input.stream().collect(joining(" ")) : "<no arguments>"); logger.info("Executing command \"start {} {}\",", name, (input != null) ? input.stream().collect(joining(" ")) : "<no arguments>");
ANSIProgressRenderer ansiProgressRenderer = ansiProgressRenderer(); ANSIProgressRenderer ansiProgressRenderer = ansiProgressRenderer();
FlowShellCommand.startFlow(name, input, out, ops(), ansiProgressRenderer != null ? ansiProgressRenderer : new CRaSHANSIProgressRenderer(out), objectMapper()); FlowShellCommand.startFlow(name, input, out, ops(), ansiProgressRenderer != null ? ansiProgressRenderer : new CRaSHANSIProgressRenderer(out), objectMapper(null));
} }
} }

View File

@ -78,6 +78,10 @@ object InteractiveShell {
private var classLoader: ClassLoader? = null private var classLoader: ClassLoader? = null
private lateinit var shellConfiguration: ShellConfiguration private lateinit var shellConfiguration: ShellConfiguration
private var onExit: () -> Unit = {} private var onExit: () -> Unit = {}
@JvmStatic
fun getCordappsClassloader() = classLoader
/** /**
* Starts an interactive shell connected to the local terminal. This shell gives administrator access to the node * Starts an interactive shell connected to the local terminal. This shell gives administrator access to the node
* internals. * internals.

View File

@ -1,5 +1,7 @@
package net.corda.tools.shell package net.corda.tools.shell
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.type.TypeFactory
import org.crsh.command.BaseCommand import org.crsh.command.BaseCommand
import org.crsh.shell.impl.command.CRaSHSession import org.crsh.shell.impl.command.CRaSHSession
@ -9,6 +11,13 @@ import org.crsh.shell.impl.command.CRaSHSession
open class InteractiveShellCommand : BaseCommand() { open class InteractiveShellCommand : BaseCommand() {
fun ops() = ((context.session as CRaSHSession).authInfo as CordaSSHAuthInfo).rpcOps fun ops() = ((context.session as CRaSHSession).authInfo as CordaSSHAuthInfo).rpcOps
fun ansiProgressRenderer() = ((context.session as CRaSHSession).authInfo as CordaSSHAuthInfo).ansiProgressRenderer fun ansiProgressRenderer() = ((context.session as CRaSHSession).authInfo as CordaSSHAuthInfo).ansiProgressRenderer
fun objectMapper() = ((context.session as CRaSHSession).authInfo as CordaSSHAuthInfo).yamlInputMapper fun objectMapper(classLoader: ClassLoader?): ObjectMapper {
val om = ((context.session as CRaSHSession).authInfo as CordaSSHAuthInfo).yamlInputMapper
if (classLoader != null) {
om.typeFactory = TypeFactory.defaultInstance().withClassLoader(classLoader)
}
return om
}
fun isSsh() = ((context.session as CRaSHSession).authInfo as CordaSSHAuthInfo).isSsh fun isSsh() = ((context.session as CRaSHSession).authInfo as CordaSSHAuthInfo).isSsh
} }