From 295a0df17de75442eaf9bd569bc506081dd286d5 Mon Sep 17 00:00:00 2001 From: SatoshiQaziMuhammed Date: Thu, 5 Nov 2026 02:29:13 +0400 Subject: [PATCH] Test root keys handed to new holders; sr25519 signing context vectors (#34) - Interceptor test: a root that gives the root keys to new holders is followed only with two signatures from the old root keys and two from the new ones; with the old ones alone it is refused and nothing is stored. - Device test with fixed vectors: the signed config check accepts an sr25519 signature over message made under the substrate signing context and refuses one made under bizinikiwi. The utils root check and signing page count only substrate signatures because of this; sr25519 is native code, so only a device can confirm it. --- .../nova/SignedConfigSignatureVectorTest.kt | 41 +++++++++++++++++++ .../signed/SignedConfigInterceptorTest.kt | 16 ++++++++ 2 files changed, 57 insertions(+) create mode 100644 app/src/androidTest/java/io/novafoundation/nova/SignedConfigSignatureVectorTest.kt diff --git a/app/src/androidTest/java/io/novafoundation/nova/SignedConfigSignatureVectorTest.kt b/app/src/androidTest/java/io/novafoundation/nova/SignedConfigSignatureVectorTest.kt new file mode 100644 index 00000000..62bc239a --- /dev/null +++ b/app/src/androidTest/java/io/novafoundation/nova/SignedConfigSignatureVectorTest.kt @@ -0,0 +1,41 @@ +package io.novafoundation.nova + +import io.novafoundation.nova.common.data.network.signed.KeyScheme +import io.novafoundation.nova.common.data.network.signed.SubstrateSignatureCheck +import io.novasama.substrate_sdk_android.extensions.fromHex +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +/** + * The root signing page and the utils root check count an sr25519 root signature only when it verifies under the + * "substrate" signing context, because that is what this check accepts. sr25519 runs in native code, so only a + * device can confirm it. Vectors: the public development phrase "bottom drive obey lake curtain smoke basket hold + * race lonely fit walk" (no derivation), signed with @polkadot/util-crypto (substrate) and @pezkuwi/util-crypto + * (bizinikiwi) over the message below. + */ +class SignedConfigSignatureVectorTest { + + private val publicKey = "0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a".fromHex() + private val message = "pezkuwi signed config test vector".toByteArray() + + private val substrateSignature = ("0x52bc9e50674838cf8dd06347715eed0047c1b6168fdbb9c19a272582a0bef41c" + + "f5eec26341b077331ca29bbb9cb3549af9e43b0ad6be722590c426502c068f83").fromHex() + private val bizinikiwiSignature = ("0x1a26e728fab052cf48c6bfd3762ba6221fb118f1efc2e659caefb015a0ee9734" + + "d1a50d92e1e61a09285a399627e94085d3c941b4dee055ddc60be16f97d40987").fromHex() + + @Test + fun aSubstrateContextSignatureIsAccepted() { + assertTrue(SubstrateSignatureCheck.verify(KeyScheme.SR25519, publicKey, message, substrateSignature)) + } + + @Test + fun aBizinikiwiContextSignatureIsNotAccepted() { + assertFalse(SubstrateSignatureCheck.verify(KeyScheme.SR25519, publicKey, message, bizinikiwiSignature)) + } + + @Test + fun aSignatureOverOtherBytesIsNotAccepted() { + assertFalse(SubstrateSignatureCheck.verify(KeyScheme.SR25519, publicKey, message + 0.toByte(), substrateSignature)) + } +} diff --git a/common/src/test/java/io/novafoundation/nova/common/data/network/signed/SignedConfigInterceptorTest.kt b/common/src/test/java/io/novafoundation/nova/common/data/network/signed/SignedConfigInterceptorTest.kt index c2e7e2bf..c5ba901d 100644 --- a/common/src/test/java/io/novafoundation/nova/common/data/network/signed/SignedConfigInterceptorTest.kt +++ b/common/src/test/java/io/novafoundation/nova/common/data/network/signed/SignedConfigInterceptorTest.kt @@ -174,6 +174,22 @@ class SignedConfigInterceptorTest { assertNull(fetch(CHAINS)) } + @Test + fun `root keys handed to new holders need two old and two new signatures`() { + val newHolders = List(3) { Key("sr25519") } + val root2 = rootPayload(2, newHolders, targetsKey) + publish(CHAINS to chains) + + served["signed/root.2.json"] = envelope(root2, rootKeys[0], rootKeys[1]) + assertNull(fetch(CHAINS)) + assertNull(store.trustedRoot) + + served["signed/root.2.json"] = envelope(root2, rootKeys[0], rootKeys[1], newHolders[0], newHolders[2]) + now += 600 + assertEquals("[\"pezkuwi\"]", fetch(CHAINS)) + assertNotNull(store.trustedRoot) + } + @Test fun `a root signed by one root key is not followed`() { val newTargetsKey = Key("ed25519")