CORDA-1915 Update to Network Bootstrapper for signed JARs (#4008)

The cordapp and cordformation plugins (from v4.0.30) are going to have ability to sign JARs (in cordformation signing will be by default), to enable signature constraints to work out of box Network Bootstrapper will not whitelist contracts form signed JARs.
For unsigned JARs the Network Bootstrapper behaviour is unchanged.
This commit is contained in:
szymonsztuka
2018-10-02 20:45:50 +01:00
committed by GitHub
parent fa8761793f
commit 1e72298a46
2 changed files with 13 additions and 4 deletions

View File

@ -34,6 +34,7 @@ import java.time.Instant
import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.jar.JarInputStream
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.set
@ -208,7 +209,7 @@ internal constructor(private val initSerEnv: Boolean,
println("Gathering notary identities")
val notaryInfos = gatherNotaryInfos(nodeInfoFiles, configs)
println("Generating contract implementations whitelist")
val newWhitelist = generateWhitelist(existingNetParams, readExcludeWhitelist(directory), cordappJars.map(contractsJarConverter))
val newWhitelist = generateWhitelist(existingNetParams, readExcludeWhitelist(directory), cordappJars.filter { !isSigned(it) }.map(contractsJarConverter))
val newNetParams = installNetworkParameters(notaryInfos, newWhitelist, existingNetParams, nodeDirs)
if (newNetParams != existingNetParams) {
println("${if (existingNetParams == null) "New" else "Updated"} $newNetParams")
@ -398,4 +399,10 @@ internal constructor(private val initSerEnv: Boolean,
return magic == amqpMagic && target == SerializationContext.UseCase.P2P
}
}
private fun isSigned(file: Path): Boolean = file.read {
JarInputStream(it).use {
JarSignatureCollector.collectSigningParties(it).isNotEmpty()
}
}
}