mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
ENT-11722: Check at when load cordapp that the 4.12 cordapp is signed… (#7720)
* ENT-11722: Check at when load cordapp that the 4.12 cordapp is signed by same signers as legacy cordapp.
This commit is contained in:
parent
18e5f7d68f
commit
275ba7549a
@ -209,10 +209,20 @@ class JarScanningCordappLoader(private val cordappJars: Set<Path>,
|
||||
"(${newerCordapp.contractVersionId}) than corresponding legacy contract CorDapp " +
|
||||
"'${legacyCordapp.jarFile}' (${legacyCordapp.contractVersionId})"
|
||||
}
|
||||
checkSignersMatch(legacyCordapp, newerCordapp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkSignersMatch(legacyCordapp: CordappImpl, nonLegacyCordapp: CordappImpl) {
|
||||
val legacySigners = legacyCordapp.jarPath.openStream().let(::JarInputStream).use(JarSignatureCollector::collectSigners)
|
||||
val nonLegacySigners = nonLegacyCordapp.jarPath.openStream().let(::JarInputStream).use(JarSignatureCollector::collectSigners)
|
||||
check(legacySigners == nonLegacySigners) {
|
||||
"Newer contract CorDapp '${nonLegacyCordapp.jarFile}' signers do not match legacy contract CorDapp " +
|
||||
"'${legacyCordapp.jarFile}' signers."
|
||||
}
|
||||
}
|
||||
|
||||
private val CordappImpl.contractVersionId: Int
|
||||
get() = when (val info = info) {
|
||||
is Cordapp.Info.Contract -> info.versionId
|
||||
|
@ -264,6 +264,33 @@ class JarScanningCordappLoaderTest {
|
||||
assertThat(loader.legacyContractCordapps.single().jarFile).isEqualTo(legacyFinanceContractsJar)
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `exception raised if legacy and non legacy version of same contract signed by differet keys`() {
|
||||
val jar = currentFinanceContractsJar.duplicate {
|
||||
tempFolder.root.toPath().generateKey("testAlias", "testPassword", ALICE_NAME.toString())
|
||||
tempFolder.root.toPath().signJar(absolutePathString(), "testAlias", "testPassword")
|
||||
}
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy { JarScanningCordappLoader(setOf(jar), setOf(legacyFinanceContractsJar)).cordapps }
|
||||
.withMessageContaining("signers do not match legacy contract CorDapp")
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `loads legacy and non legacy version of same contract both signed by 2 keys`() {
|
||||
val jar = currentFinanceContractsJar.duplicate {
|
||||
tempFolder.root.toPath().generateKey("testAlias", "testPassword", ALICE_NAME.toString())
|
||||
tempFolder.root.toPath().signJar(absolutePathString(), "testAlias", "testPassword")
|
||||
}
|
||||
val legacyJar = legacyFinanceContractsJar.duplicate(name = "duplicate2.jar") {
|
||||
tempFolder.root.toPath().signJar(absolutePathString(), "testAlias", "testPassword")
|
||||
}
|
||||
val loader = JarScanningCordappLoader(setOf(jar), setOf(legacyJar))
|
||||
assertThat(jar.parent.getJarSigners(jar.name)).hasSize(2)
|
||||
assertThat(legacyJar.parent.getJarSigners(legacyJar.name)).hasSize(2)
|
||||
assertThat(loader.cordapps).hasSize(1)
|
||||
assertThat(loader.legacyContractCordapps).hasSize(1)
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `does not load legacy contracts CorDapp without the corresponding current version`() {
|
||||
val loader = JarScanningCordappLoader(setOf(currentFinanceWorkflowsJar), setOf(legacyFinanceContractsJar))
|
||||
|
Loading…
Reference in New Issue
Block a user