Use parity-crypto updated to use upstream rust-secp256k1 (#11406)
* Use parity-crypto updated to use upstream rust-secp256k1 * Fetch dependency from git * Missed a session ID * Add free-standing inversion function that uses `libsecp256k1` * fixed tests * Update deps * Use parity-crypto 0.5.0 Use libsecp256k1 0.3.5 * Review grumble Co-authored-by: Svyatoslav Nikolsky <svyatonik@gmail.com>
This commit is contained in:
parent
2c4b51c3ea
commit
99271db9d3
247
Cargo.lock
generated
247
Cargo.lock
generated
@ -234,22 +234,21 @@ checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.9"
|
||||
version = "0.3.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
|
||||
checksum = "7f80256bc78f67e7df7e36d77366f636ed976895d91fe2ab9efa3973e8fe8c4f"
|
||||
dependencies = [
|
||||
"backtrace-sys",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"rustc-demangle",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backtrace-sys"
|
||||
version = "0.1.24"
|
||||
version = "0.1.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
|
||||
checksum = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
@ -543,12 +542,11 @@ checksum = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.46"
|
||||
version = "1.0.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0213d356d3c4ea2c18c40b037c3be23cd639825c18f25ee670ac7813beeef99c"
|
||||
checksum = "8dae9c4b8fedcae85592ba623c4fd08cfdab3e3b72d6df780c6ead964a69bfff"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
"num_cpus",
|
||||
"rayon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -778,7 +776,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"num-traits 0.2.6",
|
||||
"rand_core 0.5.1",
|
||||
"rand_os",
|
||||
"rand_os 0.2.2",
|
||||
"rand_xoshiro",
|
||||
"rayon",
|
||||
"serde",
|
||||
@ -1122,7 +1120,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1194,7 +1192,7 @@ dependencies = [
|
||||
"fixed-hash",
|
||||
"impl-rlp",
|
||||
"impl-serde",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1245,7 +1243,7 @@ dependencies = [
|
||||
"patricia-trie-ethereum",
|
||||
"pod",
|
||||
"rand 0.7.2",
|
||||
"rand_xorshift",
|
||||
"rand_xorshift 0.2.0",
|
||||
"rayon",
|
||||
"registrar",
|
||||
"rlp",
|
||||
@ -1530,7 +1528,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"slab 0.2.0",
|
||||
"tempdir",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1576,7 +1574,7 @@ dependencies = [
|
||||
"spec",
|
||||
"state-db",
|
||||
"time-utils",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
"trace",
|
||||
"transaction-pool",
|
||||
"trie-db",
|
||||
@ -1602,6 +1600,7 @@ dependencies = [
|
||||
"kvdb",
|
||||
"kvdb-rocksdb",
|
||||
"lazy_static",
|
||||
"libsecp256k1",
|
||||
"log",
|
||||
"parity-bytes",
|
||||
"parity-crypto",
|
||||
@ -1613,7 +1612,7 @@ dependencies = [
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"tempdir",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
"tokio",
|
||||
"tokio-io",
|
||||
"tokio-service",
|
||||
@ -1688,7 +1687,7 @@ dependencies = [
|
||||
"parity-util-mem",
|
||||
"parking_lot 0.10.0",
|
||||
"rand 0.7.2",
|
||||
"rand_xorshift",
|
||||
"rand_xorshift 0.2.0",
|
||||
"rlp",
|
||||
"rustc-hex 1.0.0",
|
||||
"snapshot",
|
||||
@ -1771,7 +1770,7 @@ dependencies = [
|
||||
"smallvec 1.2.0",
|
||||
"tempdir",
|
||||
"time",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2427,17 +2426,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f74e73053eaf95399bf926e48fc7a2a3ce50bd0eaaa2357d391e95b2dcdd4f10"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"rand 0.7.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "journaldb"
|
||||
version = "0.2.0"
|
||||
@ -2583,7 +2571,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e563fa6fe52b2686094846118bf2cb2e6f75e6b8cec6c3aba09be8e835c7f998"
|
||||
dependencies = [
|
||||
"primitive-types",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2593,7 +2581,7 @@ dependencies = [
|
||||
"ethereum-types",
|
||||
"hash-db",
|
||||
"plain_hasher",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2604,7 +2592,7 @@ checksum = "3bf18164fd7ce989041f8fc4a1ae72a8bd1bec3575f2aeaf1d4968fc053aabef"
|
||||
dependencies = [
|
||||
"hash-db",
|
||||
"hash256-std-hasher",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2705,6 +2693,19 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fc1e2c808481a63dc6da2074752fdd4336a3c8fcc68b83db6f1fd5224ae7962"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"crunchy 0.2.2",
|
||||
"digest 0.8.0",
|
||||
"rand 0.7.2",
|
||||
"subtle 2.2.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.1"
|
||||
@ -3017,7 +3018,7 @@ checksum = "c62469025f45dee2464ef9fc845f4683c543993792c1993e7d903c17a4546b74"
|
||||
dependencies = [
|
||||
"sha1",
|
||||
"sha2 0.7.1",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3239,9 +3240,9 @@ checksum = "fa5168b4cf41f3835e4bc6ffb32f51bc9365dc50cb351904595b3931d917fd0c"
|
||||
|
||||
[[package]]
|
||||
name = "parity-crypto"
|
||||
version = "0.4.2"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27a9c2b525c93d717a234eb220c26474f8d97b08ac50d79faeac4cb6c74bf0b9"
|
||||
checksum = "e4015edcfb0304c3b32f6c4ad68fb8b0a14f1d7d250bd0c6b9cd312d38038000"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"aes-ctr",
|
||||
@ -3250,15 +3251,15 @@ dependencies = [
|
||||
"ethereum-types",
|
||||
"hmac",
|
||||
"lazy_static",
|
||||
"parity-secp256k1",
|
||||
"pbkdf2",
|
||||
"rand 0.7.2",
|
||||
"ripemd160",
|
||||
"rustc-hex 2.1.0",
|
||||
"scrypt",
|
||||
"secp256k1",
|
||||
"sha2 0.8.0",
|
||||
"subtle 2.1.0",
|
||||
"tiny-keccak",
|
||||
"subtle 2.2.2",
|
||||
"tiny-keccak 2.0.1",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
@ -3472,7 +3473,7 @@ dependencies = [
|
||||
"parking_lot 0.10.0",
|
||||
"pretty_assertions",
|
||||
"rand 0.7.2",
|
||||
"rand_xorshift",
|
||||
"rand_xorshift 0.2.0",
|
||||
"rlp",
|
||||
"rustc-hex 1.0.0",
|
||||
"semver",
|
||||
@ -3483,7 +3484,7 @@ dependencies = [
|
||||
"spec",
|
||||
"stats",
|
||||
"tempdir",
|
||||
"tiny-keccak",
|
||||
"tiny-keccak 1.5.0",
|
||||
"tokio-timer 0.1.2",
|
||||
"trace",
|
||||
"transaction-pool",
|
||||
@ -3530,18 +3531,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parity-secp256k1"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fca4f82fccae37e8bbdaeb949a4a218a1bbc485d11598f193d2a908042e5fc1"
|
||||
dependencies = [
|
||||
"arrayvec 0.5.1",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"rand 0.7.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parity-snappy"
|
||||
version = "0.1.0"
|
||||
@ -4013,6 +4002,25 @@ dependencies = [
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"libc",
|
||||
"rand_chacha 0.1.1",
|
||||
"rand_core 0.4.2",
|
||||
"rand_hc 0.1.0",
|
||||
"rand_isaac",
|
||||
"rand_jitter",
|
||||
"rand_os 0.1.3",
|
||||
"rand_pcg",
|
||||
"rand_xorshift 0.1.1",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.7.2"
|
||||
@ -4021,9 +4029,19 @@ checksum = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_chacha 0.2.1",
|
||||
"rand_core 0.5.1",
|
||||
"rand_hc",
|
||||
"rand_hc 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4069,6 +4087,15 @@ dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.2.0"
|
||||
@ -4078,6 +4105,40 @@ dependencies = [
|
||||
"rand_core 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_isaac"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_jitter"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_core 0.4.2",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_os"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
|
||||
dependencies = [
|
||||
"cloudabi",
|
||||
"fuchsia-cprng",
|
||||
"libc",
|
||||
"rand_core 0.4.2",
|
||||
"rdrand",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_os"
|
||||
version = "0.2.2"
|
||||
@ -4088,6 +4149,25 @@ dependencies = [
|
||||
"rand_core 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_pcg"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"rand_core 0.4.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_xorshift"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_xorshift"
|
||||
version = "0.2.0"
|
||||
@ -4408,6 +4488,25 @@ dependencies = [
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "secp256k1"
|
||||
version = "0.17.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2932dc07acd2066ff2e3921a4419606b220ba6cd03a9935123856cc534877056"
|
||||
dependencies = [
|
||||
"rand 0.6.5",
|
||||
"secp256k1-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "secp256k1-sys"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ab2c26f0d3552a0f12e639ae8a64afc2e3db9c52fe32f5fc6c289d38519f220"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "security-framework"
|
||||
version = "0.3.4"
|
||||
@ -4608,7 +4707,7 @@ dependencies = [
|
||||
"parking_lot 0.10.0",
|
||||
"patricia-trie-ethereum",
|
||||
"rand 0.7.2",
|
||||
"rand_xorshift",
|
||||
"rand_xorshift 0.2.0",
|
||||
"rlp",
|
||||
"rlp_derive",
|
||||
"scopeguard 1.0.0",
|
||||
@ -4654,7 +4753,7 @@ dependencies = [
|
||||
"parking_lot 0.10.0",
|
||||
"patricia-trie-ethereum",
|
||||
"rand 0.7.2",
|
||||
"rand_xorshift",
|
||||
"rand_xorshift 0.2.0",
|
||||
"rlp",
|
||||
"snapshot",
|
||||
"spec",
|
||||
@ -4803,9 +4902,9 @@ checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.1.0"
|
||||
version = "2.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829"
|
||||
checksum = "7c65d530b10ccaeac294f349038a597e435b18fb456aadd0840a623f83b9e941"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
@ -4980,6 +5079,15 @@ dependencies = [
|
||||
"crunchy 0.2.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-keccak"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2953ca5148619bc99695c1274cb54c5275bbb913c6adad87e72eaf8db9787f69"
|
||||
dependencies = [
|
||||
"crunchy 0.2.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinytemplate"
|
||||
version = "1.0.2"
|
||||
@ -5343,9 +5451,9 @@ checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.10.0"
|
||||
version = "1.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
|
||||
checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9"
|
||||
|
||||
[[package]]
|
||||
name = "uint"
|
||||
@ -5861,21 +5969,6 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "0.9.3"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45af6a010d13e4cf5b54c94ba5a2b2eba5596b9e46bf5875612d332a1f2b3f86"
|
||||
dependencies = [
|
||||
"zeroize_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize_derive"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "080616bd0e31f36095288bb0acdf1f78ef02c2fa15527d7e993f2a6c7591643e"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.20",
|
||||
"quote 0.6.8",
|
||||
"syn 0.15.26",
|
||||
"synstructure 0.10.1",
|
||||
]
|
||||
checksum = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8"
|
||||
|
@ -50,7 +50,7 @@ num_cpus = "1.2"
|
||||
number_prefix = "0.2"
|
||||
panic_hook = { path = "util/panic-hook" }
|
||||
parity-bytes = "0.1"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
parity-daemonize = "0.3"
|
||||
parity-hash-fetch = { path = "updater/hash-fetch" }
|
||||
parity-ipfs-api = { path = "ipfs" }
|
||||
|
@ -11,7 +11,7 @@ edition = "2018"
|
||||
ethkey = { path = "ethkey" }
|
||||
ethstore = { path = "ethstore" }
|
||||
log = "0.4"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
parking_lot = "0.10.0"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
|
@ -9,5 +9,5 @@ edit-distance = "2.0"
|
||||
log = "0.4"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
parity-wordlist = "1.3.1"
|
||||
|
@ -9,7 +9,7 @@ docopt = "1.0"
|
||||
env_logger = "0.5"
|
||||
ethkey = { path = "../" }
|
||||
panic_hook = { path = "../../../util/panic-hook" }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
parity-wordlist= "1.3.1"
|
||||
rustc-hex = "1.0"
|
||||
serde = "1.0"
|
||||
|
@ -199,7 +199,7 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
|
||||
let result = if args.flag_brain {
|
||||
let phrase = args.arg_secret_or_phrase;
|
||||
let phrase_info = validate_phrase(&phrase);
|
||||
let keypair = Brain::new(phrase).generate().expect("Brain wallet generator is infallible; qed");
|
||||
let keypair = Brain::new(phrase).generate();
|
||||
(keypair, Some(phrase_info))
|
||||
} else {
|
||||
let secret = args.arg_secret_or_phrase.parse().map_err(|_| EthkeyError::InvalidSecretKey)?;
|
||||
@ -215,7 +215,7 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
|
||||
let phrase = format!("recovery phrase: {}", brain.phrase());
|
||||
(keypair, Some(phrase))
|
||||
} else {
|
||||
(Random.generate()?, None)
|
||||
(Random.generate(), None)
|
||||
}
|
||||
} else if args.cmd_prefix {
|
||||
let prefix = args.arg_prefix.from_hex()?;
|
||||
@ -271,7 +271,7 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
|
||||
while let Some(phrase) = it.next() {
|
||||
i += 1;
|
||||
|
||||
let keypair = Brain::new(phrase.clone()).generate().unwrap();
|
||||
let keypair = Brain::new(phrase.clone()).generate();
|
||||
if keypair.address() == address {
|
||||
return Ok(Some((phrase, keypair)))
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::convert::Infallible;
|
||||
use parity_crypto::publickey::{KeyPair, Generator, Secret};
|
||||
use parity_crypto::Keccak256;
|
||||
use parity_wordlist;
|
||||
@ -33,9 +32,7 @@ impl Brain {
|
||||
}
|
||||
|
||||
impl Generator for Brain {
|
||||
type Error = Infallible;
|
||||
|
||||
fn generate(&mut self) -> Result<KeyPair, Self::Error> {
|
||||
fn generate(&mut self) -> KeyPair {
|
||||
let seed = self.0.clone();
|
||||
let mut secret = seed.into_bytes().keccak256();
|
||||
|
||||
@ -51,7 +48,7 @@ impl Generator for Brain {
|
||||
{
|
||||
if pair.address()[0] == 0 {
|
||||
trace!("Testing: {}, got: {:?}", self.0, pair.address());
|
||||
return Ok(pair)
|
||||
return pair
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -68,8 +65,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_brain() {
|
||||
let words = "this is sparta!".to_owned();
|
||||
let first_keypair = Brain::new(words.clone()).generate().unwrap();
|
||||
let second_keypair = Brain::new(words.clone()).generate().unwrap();
|
||||
let first_keypair = Brain::new(words.clone()).generate();
|
||||
let second_keypair = Brain::new(words.clone()).generate();
|
||||
assert_eq!(first_keypair.secret(), second_keypair.secret());
|
||||
}
|
||||
}
|
||||
|
@ -39,15 +39,11 @@ impl BrainPrefix {
|
||||
pub fn phrase(&self) -> &str {
|
||||
&self.last_phrase
|
||||
}
|
||||
}
|
||||
|
||||
impl Generator for BrainPrefix {
|
||||
type Error = Error;
|
||||
|
||||
fn generate(&mut self) -> Result<KeyPair, Error> {
|
||||
pub fn generate(&mut self) -> Result<KeyPair, Error> {
|
||||
for _ in 0..self.iterations {
|
||||
let phrase = wordlist::random_phrase(self.no_of_words);
|
||||
let keypair = Brain::new(phrase.clone()).generate().unwrap();
|
||||
let keypair = Brain::new(phrase.clone()).generate();
|
||||
if keypair.address().as_ref().starts_with(&self.prefix) {
|
||||
self.last_phrase = phrase;
|
||||
return Ok(keypair)
|
||||
|
@ -33,7 +33,7 @@ pub fn brain_recover(
|
||||
) -> Option<String> {
|
||||
let it = PhrasesIterator::from_known_phrase(known_phrase, expected_words);
|
||||
for phrase in it {
|
||||
let keypair = Brain::new(phrase.clone()).generate().expect("Brain wallets are infallible; qed");
|
||||
let keypair = Brain::new(phrase.clone()).generate();
|
||||
trace!("Testing: {}, got: {:?}", phrase, keypair.address());
|
||||
if &keypair.address() == address {
|
||||
return Some(phrase);
|
||||
|
@ -24,19 +24,12 @@ pub struct Prefix {
|
||||
|
||||
impl Prefix {
|
||||
pub fn new(prefix: Vec<u8>, iterations: usize) -> Self {
|
||||
Prefix {
|
||||
prefix: prefix,
|
||||
iterations: iterations,
|
||||
}
|
||||
}
|
||||
Prefix { prefix, iterations }
|
||||
}
|
||||
|
||||
impl Generator for Prefix {
|
||||
type Error = Error;
|
||||
|
||||
fn generate(&mut self) -> Result<KeyPair, Error> {
|
||||
pub fn generate(&mut self) -> Result<KeyPair, Error> {
|
||||
for _ in 0..self.iterations {
|
||||
let keypair = Random.generate()?;
|
||||
let keypair = Random.generate();
|
||||
if keypair.address().as_ref().starts_with(&self.prefix) {
|
||||
return Ok(keypair)
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ rustc-hex = "1.0"
|
||||
tiny-keccak = "1.4"
|
||||
time = "0.1.34"
|
||||
parking_lot = "0.10.0"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
ethereum-types = "0.8.0"
|
||||
dir = { path = "../../util/dir" }
|
||||
smallvec = "1.2.0"
|
||||
|
@ -14,7 +14,7 @@ serde_derive = "1.0"
|
||||
parking_lot = "0.10.0"
|
||||
ethstore = { path = "../" }
|
||||
ethkey = { path = "../../ethkey" }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
dir = { path = '../../../util/dir' }
|
||||
panic_hook = { path = "../../../util/panic-hook" }
|
||||
|
||||
|
@ -164,7 +164,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn crypto_with_secret_create() {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let passwd = "this is sparta".into();
|
||||
let crypto = Crypto::with_secret(keypair.secret(), &passwd, 10240).unwrap();
|
||||
let secret = crypto.secret(&passwd).unwrap();
|
||||
@ -173,7 +173,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn crypto_with_secret_invalid_password() {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let crypto = Crypto::with_secret(keypair.secret(), &"this is sparta".into(), 10240).unwrap();
|
||||
assert_matches!(crypto.secret(&"this is sparta!".into()), Err(Error::InvalidPassword))
|
||||
}
|
||||
|
@ -205,9 +205,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sign_and_verify_public() {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let password = "hello world".into();
|
||||
let message = Message::default();
|
||||
let message = [1u8; 32].into();
|
||||
let account = SafeAccount::create(&keypair, [0u8; 16], &password, 10240, "Test".to_owned(), "{}".to_owned());
|
||||
let signature = account.unwrap().sign(&password, &message).unwrap();
|
||||
assert!(verify_public(keypair.public(), &signature, &message).unwrap());
|
||||
@ -215,11 +215,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn change_password() {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let first_password = "hello world".into();
|
||||
let sec_password = "this is sparta".into();
|
||||
let i = 10240;
|
||||
let message = Message::default();
|
||||
let message = [1u8; 32].into();
|
||||
let account = SafeAccount::create(&keypair, [0u8; 16], &first_password, i, "Test".to_owned(), "{}".to_owned()).unwrap();
|
||||
let new_account = account.change_password(&first_password, &sec_password, i).unwrap();
|
||||
assert!(account.sign(&first_password, &message).is_ok());
|
||||
|
@ -364,7 +364,7 @@ mod test {
|
||||
// given
|
||||
let mut dir = env::temp_dir();
|
||||
dir.push("ethstore_should_create_new_account");
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let password = "hello world".into();
|
||||
let directory = RootDiskDirectory::create(dir.clone()).unwrap();
|
||||
|
||||
@ -385,7 +385,7 @@ mod test {
|
||||
// given
|
||||
let mut dir = env::temp_dir();
|
||||
dir.push("ethstore_should_handle_duplicate_filenames");
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let password = "hello world".into();
|
||||
let directory = RootDiskDirectory::create(dir.clone()).unwrap();
|
||||
|
||||
@ -472,7 +472,7 @@ mod test {
|
||||
15130871412783076140
|
||||
);
|
||||
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let password = "test pass".into();
|
||||
let account = SafeAccount::create(&keypair, [0u8; 16], &password, 1024, "Test".to_owned(), "{}".to_owned());
|
||||
directory.insert(account.unwrap()).expect("Account should be inserted ok");
|
||||
|
@ -698,7 +698,7 @@ mod tests {
|
||||
use ethereum_types::H256;
|
||||
|
||||
fn keypair() -> KeyPair {
|
||||
Random.generate().unwrap()
|
||||
Random.generate()
|
||||
}
|
||||
|
||||
fn store() -> EthStore {
|
||||
@ -820,6 +820,7 @@ mod tests {
|
||||
let passwd2 = "xzy".into();
|
||||
let multi_store = multi_store();
|
||||
let keypair = keypair();
|
||||
let message = [1u8; 32].into();
|
||||
let address = store.insert_account(SecretVaultRef::Root, keypair.secret().clone(), &passwd1).unwrap();
|
||||
assert_eq!(multi_store.accounts().unwrap().len(), 0);
|
||||
|
||||
@ -828,7 +829,7 @@ mod tests {
|
||||
|
||||
// then
|
||||
assert!(store.test_password(&address, &passwd1).unwrap(), "First password should work for store.");
|
||||
assert!(multi_store.sign(&address, &passwd2, &Default::default()).is_ok(), "Second password should work for second store.");
|
||||
assert!(multi_store.sign(&address, &passwd2, &message).is_ok(), "Second password should work for second store.");
|
||||
assert_eq!(multi_store.accounts().unwrap().len(), 1);
|
||||
}
|
||||
|
||||
@ -1092,8 +1093,9 @@ mod tests {
|
||||
let accounts = store.accounts().unwrap();
|
||||
assert_eq!(accounts.len(), 2);
|
||||
|
||||
let message = [1u8; 32].into();
|
||||
// and we can sign with the derived contract
|
||||
assert!(store.sign(&derived, &"test".into(), &Default::default()).is_ok(), "Second password should work for second store.");
|
||||
assert!(store.sign(&derived, &"test".into(), &message).is_ok(), "Second password should work for second store.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -42,7 +42,7 @@ fn secret_store_open_not_existing() {
|
||||
}
|
||||
|
||||
fn random_secret() -> Secret {
|
||||
Random.generate().unwrap().secret().clone()
|
||||
Random.generate().secret().clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -62,9 +62,10 @@ fn secret_store_sign() {
|
||||
let store = EthStore::open(Box::new(dir)).unwrap();
|
||||
assert!(store.insert_account(SecretVaultRef::Root, random_secret(), &"".into()).is_ok());
|
||||
let accounts = store.accounts().unwrap();
|
||||
let message = [1u8; 32].into();
|
||||
assert_eq!(accounts.len(), 1);
|
||||
assert!(store.sign(&accounts[0], &"".into(), &Default::default()).is_ok());
|
||||
assert!(store.sign(&accounts[0], &"1".into(), &Default::default()).is_err());
|
||||
assert!(store.sign(&accounts[0], &"".into(), &message).is_ok());
|
||||
assert!(store.sign(&accounts[0], &"1".into(), &message).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -73,11 +74,12 @@ fn secret_store_change_password() {
|
||||
let store = EthStore::open(Box::new(dir)).unwrap();
|
||||
assert!(store.insert_account(SecretVaultRef::Root, random_secret(), &"".into()).is_ok());
|
||||
let accounts = store.accounts().unwrap();
|
||||
let message = [1u8; 32].into();
|
||||
assert_eq!(accounts.len(), 1);
|
||||
assert!(store.sign(&accounts[0], &"".into(), &Default::default()).is_ok());
|
||||
assert!(store.sign(&accounts[0], &"".into(), &message).is_ok());
|
||||
assert!(store.change_password(&accounts[0], &"".into(), &"1".into()).is_ok());
|
||||
assert!(store.sign(&accounts[0], &"".into(), &Default::default()).is_err());
|
||||
assert!(store.sign(&accounts[0], &"1".into(), &Default::default()).is_ok());
|
||||
assert!(store.sign(&accounts[0], &"".into(), &message).is_err());
|
||||
assert!(store.sign(&accounts[0], &"1".into(), &message).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -148,7 +150,7 @@ fn test_decrypting_files_with_short_ciphertext() {
|
||||
StoreAccountRef::root(Address::from_str("d1e64e5480bfaf733ba7d48712decb8227797a4e").unwrap()),
|
||||
]);
|
||||
|
||||
let message = Default::default();
|
||||
let message = [1u8; 32].into();
|
||||
|
||||
let s1 = store.sign(&accounts[0], &"foo".into(), &message).unwrap();
|
||||
let s2 = store.sign(&accounts[1], &"foo".into(), &message).unwrap();
|
||||
|
@ -125,7 +125,7 @@ impl AccountProvider {
|
||||
|
||||
/// Creates new random account and returns address and public key
|
||||
pub fn new_account_and_public(&self, password: &Password) -> Result<(Address, Public), Error> {
|
||||
let acc = Random.generate().expect("secp context has generation capabilities; qed");
|
||||
let acc = Random.generate();
|
||||
let public = acc.public().clone();
|
||||
let secret = acc.secret().clone();
|
||||
let account = self.sstore.insert_account(SecretVaultRef::Root, secret, password)?;
|
||||
@ -290,9 +290,10 @@ impl AccountProvider {
|
||||
let secret = self.sstore.raw_secret(&account, &password)?;
|
||||
self.unlocked_secrets.write().insert(account.clone(), secret);
|
||||
} else {
|
||||
// verify password by signing dump message
|
||||
// verify password by signing a dummy message
|
||||
// result may be discarded
|
||||
let _ = self.sstore.sign(&account, &password, &Default::default())?;
|
||||
let dummy_msg = [1u8;32].into();
|
||||
let _ = self.sstore.sign(&account, &password, &dummy_msg)?;
|
||||
}
|
||||
|
||||
let data = AccountData { unlock, password };
|
||||
@ -509,18 +510,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn unlock_account_temp() {
|
||||
let kp = Random.generate().unwrap();
|
||||
let kp = Random.generate();
|
||||
let ap = AccountProvider::transient_provider();
|
||||
let dummy_msg = [1u8; 32].into();
|
||||
assert!(ap.insert_account(kp.secret().clone(), &"test".into()).is_ok());
|
||||
assert!(ap.unlock_account_temporarily(kp.address(), "test1".into()).is_err());
|
||||
assert!(ap.unlock_account_temporarily(kp.address(), "test".into()).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, Default::default()).is_err());
|
||||
assert!(ap.sign(kp.address(), None, dummy_msg).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, dummy_msg).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derived_account_nosave() {
|
||||
let kp = Random.generate().unwrap();
|
||||
let kp = Random.generate();
|
||||
let ap = AccountProvider::transient_provider();
|
||||
assert!(ap.insert_account(kp.secret().clone(), &"base".into()).is_ok());
|
||||
assert!(ap.unlock_account_permanently(kp.address(), "base".into()).is_ok());
|
||||
@ -538,7 +540,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn derived_account_save() {
|
||||
let kp = Random.generate().unwrap();
|
||||
let kp = Random.generate();
|
||||
let ap = AccountProvider::transient_provider();
|
||||
assert!(ap.insert_account(kp.secret().clone(), &"base".into()).is_ok());
|
||||
assert!(ap.unlock_account_permanently(kp.address(), "base".into()).is_ok());
|
||||
@ -559,7 +561,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn derived_account_sign() {
|
||||
let kp = Random.generate().unwrap();
|
||||
let kp = Random.generate();
|
||||
let ap = AccountProvider::transient_provider();
|
||||
assert!(ap.insert_account(kp.secret().clone(), &"base".into()).is_ok());
|
||||
assert!(ap.unlock_account_permanently(kp.address(), "base".into()).is_ok());
|
||||
@ -573,7 +575,7 @@ mod tests {
|
||||
ap.unlock_account_permanently(derived_addr, "base".into())
|
||||
.expect("Should be ok because account is saved and password is valid");
|
||||
|
||||
let msg = Default::default();
|
||||
let msg = [2u8; 32].into();
|
||||
let signed_msg1 = ap.sign(derived_addr, None, msg)
|
||||
.expect("Signing with existing unlocked account should not fail");
|
||||
let signed_msg2 = ap.sign_derived(
|
||||
@ -589,44 +591,48 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn unlock_account_perm() {
|
||||
let kp = Random.generate().unwrap();
|
||||
let kp = Random.generate();
|
||||
let ap = AccountProvider::transient_provider();
|
||||
let dummy_msg = [1u8; 32].into();
|
||||
assert!(ap.insert_account(kp.secret().clone(), &"test".into()).is_ok());
|
||||
assert!(ap.unlock_account_permanently(kp.address(), "test1".into()).is_err());
|
||||
assert!(ap.unlock_account_permanently(kp.address(), "test".into()).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, dummy_msg).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, dummy_msg).is_ok());
|
||||
assert!(ap.unlock_account_temporarily(kp.address(), "test".into()).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, dummy_msg).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, dummy_msg).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unlock_account_timer() {
|
||||
let kp = Random.generate().unwrap();
|
||||
let kp = Random.generate();
|
||||
let ap = AccountProvider::transient_provider();
|
||||
let dummy_msg = [1u8; 32].into();
|
||||
|
||||
assert!(ap.insert_account(kp.secret().clone(), &"test".into()).is_ok());
|
||||
assert!(ap.unlock_account_timed(kp.address(), "test1".into(), Duration::from_secs(60)).is_err());
|
||||
assert!(ap.unlock_account_timed(kp.address(), "test".into(), Duration::from_secs(60)).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
|
||||
assert!(ap.sign(kp.address(), None, dummy_msg).is_ok());
|
||||
ap.unlocked.write().get_mut(&StoreAccountRef::root(kp.address())).unwrap().unlock = Unlock::Timed(Instant::now());
|
||||
assert!(ap.sign(kp.address(), None, Default::default()).is_err());
|
||||
assert!(ap.sign(kp.address(), None, dummy_msg).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_sign_and_return_token() {
|
||||
// given
|
||||
let kp = Random.generate().unwrap();
|
||||
let kp = Random.generate();
|
||||
let ap = AccountProvider::transient_provider();
|
||||
let dummy_msg = [1u8; 32].into();
|
||||
assert!(ap.insert_account(kp.secret().clone(), &"test".into()).is_ok());
|
||||
|
||||
// when
|
||||
let (_signature, token) = ap.sign_with_token(kp.address(), "test".into(), Default::default()).unwrap();
|
||||
let (_signature, token) = ap.sign_with_token(kp.address(), "test".into(), dummy_msg).unwrap();
|
||||
|
||||
// then
|
||||
ap.sign_with_token(kp.address(), token.clone(), Default::default())
|
||||
ap.sign_with_token(kp.address(), token.clone(), dummy_msg)
|
||||
.expect("First usage of token should be correct.");
|
||||
assert!(ap.sign_with_token(kp.address(), token, Default::default()).is_err(), "Second usage of the same token should fail.");
|
||||
assert!(ap.sign_with_token(kp.address(), token, dummy_msg).is_err(), "Second usage of the same token should fail.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -43,7 +43,7 @@ parity-bytes = "0.1"
|
||||
parking_lot = "0.10.0"
|
||||
pod = { path = "pod", optional = true }
|
||||
trie-db = "0.20.0"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"], optional = true }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"], optional = true }
|
||||
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
|
||||
rand = "0.7"
|
||||
rand_xorshift = "0.2"
|
||||
@ -76,7 +76,7 @@ env_logger = "0.5"
|
||||
ethcore-accounts = { path = "../accounts" }
|
||||
ethcore-builtin = { path = "./builtin" }
|
||||
ethjson = { path = "../json", features = ["test-helpers"] }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
fetch = { path = "../util/fetch" }
|
||||
kvdb-memorydb = "0.4.0"
|
||||
kvdb-rocksdb = "0.5.0"
|
||||
|
@ -29,7 +29,7 @@ triehash-ethereum = { version = "0.2", path = "../../util/triehash-ethereum" }
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.5"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
rustc-hex = "1.0"
|
||||
tempdir = "0.3"
|
||||
kvdb-memorydb = "0.4.0"
|
||||
|
@ -16,7 +16,7 @@ keccak-hash = "0.4.0"
|
||||
log = "0.4"
|
||||
num = { version = "0.1", default-features = false, features = ["bigint"] }
|
||||
parity-bytes = "0.1"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
|
||||
[dev-dependencies]
|
||||
hex-literal = "0.2.1"
|
||||
|
@ -13,7 +13,7 @@ bytes = { package = "parity-bytes", version = "0.1.0" }
|
||||
client-traits = { path = "../client-traits" }
|
||||
common-types = { path = "../types" }
|
||||
ethereum-types = "0.8.0"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
machine = { path = "../machine" }
|
||||
vm = { path = "../vm" }
|
||||
|
||||
|
@ -17,7 +17,7 @@ ethabi-contract = "9.0.0"
|
||||
ethabi-derive = "9.0.1"
|
||||
ethereum-types = "0.8.0"
|
||||
ethjson = { path = "../../../json" }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
engine = { path = "../../engine" }
|
||||
io = { package = "ethcore-io", path = "../../../util/io" }
|
||||
itertools = "0.8.2"
|
||||
|
@ -12,7 +12,7 @@ common-types = { path = "../../types" }
|
||||
engine = { path = "../../engine" }
|
||||
ethereum-types = "0.8.0"
|
||||
ethjson = { path = "../../../json" }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
log = "0.4.8"
|
||||
machine = { path = "../../machine" }
|
||||
parking_lot = "0.10.0"
|
||||
|
@ -11,7 +11,7 @@ client-traits = { path = "../../client-traits" }
|
||||
common-types = { path = "../../types" }
|
||||
ethereum-types = "0.8.0"
|
||||
ethjson = { path = "../../../json" }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
engine = { path = "../../engine" }
|
||||
keccak-hash = "0.4.0"
|
||||
lazy_static = "1.3.0"
|
||||
|
@ -36,7 +36,7 @@ call-contract = { package = "ethcore-call-contract", path = "../../call-contract
|
||||
engine = { path = "../../engine", features = ["test-helpers"] }
|
||||
env_logger = "0.6.2"
|
||||
ethcore = { path = "../..", features = ["test-helpers"] }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
keccak-hash = "0.4.0"
|
||||
rustc-hex = "1.0"
|
||||
spec = { path = "../../spec" }
|
||||
|
@ -24,7 +24,7 @@ vm = { path = "../vm" }
|
||||
[dev-dependencies]
|
||||
env_logger = "0.5"
|
||||
ethcore = { path = "..", features = ["test-helpers"] }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
evm = { path = "../evm" }
|
||||
keccak-hash = "0.4.0"
|
||||
pod = { path = "../pod" }
|
||||
|
@ -43,7 +43,7 @@ criterion = "0.3"
|
||||
ethcore = { path = "../", features = ["test-helpers"] }
|
||||
ethcore-io = { path = "../../util/io" }
|
||||
ethjson = { path = "../../json" }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
macros = { path = "../../util/macros" }
|
||||
rustc-hex = "1.0"
|
||||
spec = { path = "../spec" }
|
||||
|
@ -1963,7 +1963,7 @@ mod tests {
|
||||
// TODO: fix (preferred) or remove
|
||||
evm_test_ignore!{test_transact_simple: test_transact_simple_int}
|
||||
fn test_transact_simple(factory: Factory) {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let t = Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::from(17),
|
||||
@ -2002,7 +2002,7 @@ mod tests {
|
||||
|
||||
evm_test!{test_transact_invalid_nonce: test_transact_invalid_nonce_int}
|
||||
fn test_transact_invalid_nonce(factory: Factory) {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let t = Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::from(17),
|
||||
@ -2035,7 +2035,7 @@ mod tests {
|
||||
|
||||
evm_test!{test_transact_gas_limit_reached: test_transact_gas_limit_reached_int}
|
||||
fn test_transact_gas_limit_reached(factory: Factory) {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let t = Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::from(17),
|
||||
@ -2070,7 +2070,7 @@ mod tests {
|
||||
evm_test!{test_not_enough_cash: test_not_enough_cash_int}
|
||||
fn test_not_enough_cash(factory: Factory) {
|
||||
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let t = Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::from(18),
|
||||
|
@ -31,7 +31,7 @@ log = "0.4"
|
||||
machine = { path = "../machine" }
|
||||
journaldb = { path = "../../util/journaldb" }
|
||||
parity-bytes = "0.1"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
parking_lot = "0.10.0"
|
||||
trie-db = "0.20.0"
|
||||
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
|
||||
|
@ -27,7 +27,7 @@ kvdb = "0.4.0"
|
||||
kvdb-rocksdb = "0.5.0"
|
||||
log = "0.4.8"
|
||||
parking_lot = "0.10.0"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
rand = "0.7"
|
||||
rand_xorshift = "0.2"
|
||||
rlp = "0.4.2"
|
||||
|
@ -1569,7 +1569,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn transaction_with_chain_id(chain_id: u64) -> SignedTransaction {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::zero(),
|
||||
@ -1669,7 +1669,7 @@ mod tests {
|
||||
#[test]
|
||||
fn should_treat_unfamiliar_locals_selectively() {
|
||||
// given
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let client = TestBlockChainClient::default();
|
||||
let mut local_accounts = ::std::collections::HashSet::new();
|
||||
local_accounts.insert(keypair.address());
|
||||
@ -1813,7 +1813,7 @@ mod tests {
|
||||
let addr = tap.insert_account(keccak("1").into(), &"".into()).unwrap();
|
||||
let client = generate_dummy_client_with_spec(spec);
|
||||
let engine_signer = Box::new((tap.clone(), addr, "".into()));
|
||||
let msg = Default::default();
|
||||
let msg = [1u8; 32].into();
|
||||
assert!(client.engine().sign(msg).is_err());
|
||||
|
||||
// should set engine signer and miner author
|
||||
|
@ -295,7 +295,7 @@ impl TestBlockChainClient {
|
||||
_ => 1,
|
||||
};
|
||||
let mut txs = RlpStream::new_list(num_transactions);
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let mut nonce = U256::zero();
|
||||
|
||||
for _ in 0..num_transactions {
|
||||
@ -364,7 +364,7 @@ impl TestBlockChainClient {
|
||||
|
||||
/// Inserts a transaction with given gas price to miners transactions queue.
|
||||
pub fn insert_transaction_with_gas_price_to_queue(&self, gas_price: U256) -> H256 {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let tx = Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::from(100),
|
||||
|
@ -26,7 +26,7 @@ log = "0.4"
|
||||
macros = { path = "../../util/macros" }
|
||||
network = { package = "ethcore-network", path = "../../util/network" }
|
||||
parity-runtime = { path = "../../util/runtime" }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
parity-util-mem = "0.5.1"
|
||||
rand = "0.7"
|
||||
parking_lot = "0.10.0"
|
||||
|
@ -671,7 +671,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn dummy_signed_tx() -> SignedTransaction {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
Transaction::default().sign(keypair.secret(), None)
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ ethereum-types = "0.8.0"
|
||||
ethjson = { path = "../../json" }
|
||||
keccak-hash = "0.4.0"
|
||||
parity-bytes = "0.1"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
parity-util-mem = "0.5.1"
|
||||
parity-snappy = "0.1"
|
||||
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
|
||||
|
@ -589,7 +589,7 @@ mod tests {
|
||||
fn signing_eip155_zero_chainid() {
|
||||
use parity_crypto::publickey::{Random, Generator};
|
||||
|
||||
let key = Random.generate().unwrap();
|
||||
let key = Random.generate();
|
||||
let t = Transaction {
|
||||
action: Action::Create,
|
||||
nonce: U256::from(42),
|
||||
@ -610,7 +610,7 @@ mod tests {
|
||||
fn signing() {
|
||||
use parity_crypto::publickey::{Random, Generator};
|
||||
|
||||
let key = Random.generate().unwrap();
|
||||
let key = Random.generate();
|
||||
let t = Transaction {
|
||||
action: Action::Create,
|
||||
nonce: U256::from(42),
|
||||
@ -662,7 +662,7 @@ mod tests {
|
||||
#[test]
|
||||
fn should_recover_from_chain_specific_signing() {
|
||||
use parity_crypto::publickey::{Random, Generator};
|
||||
let key = Random.generate().unwrap();
|
||||
let key = Random.generate();
|
||||
let t = Transaction {
|
||||
action: Action::Create,
|
||||
nonce: U256::from(42),
|
||||
|
@ -34,7 +34,7 @@ unexpected = { path = "../../util/unexpected" }
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
ethcore = { path = "../", features = ["test-helpers"] }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
machine = { path = "../machine" }
|
||||
null-engine = { path = "../engines/null-engine" }
|
||||
spec = { path = "../spec" }
|
||||
|
@ -556,7 +556,7 @@ mod tests {
|
||||
good.set_timestamp(40);
|
||||
good.set_number(10);
|
||||
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
|
||||
let tr1 = Transaction {
|
||||
action: Action::Create,
|
||||
@ -763,7 +763,7 @@ mod tests {
|
||||
let mut header = Header::default();
|
||||
header.set_number(1);
|
||||
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let bad_transactions: Vec<_> = (0..3).map(|i| Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::zero(),
|
||||
|
@ -39,7 +39,7 @@ transaction-pool = "2.0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.5"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
rustc-hex = "1.0"
|
||||
|
||||
[features]
|
||||
|
@ -17,5 +17,5 @@ serde_json = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
ethkey = { path = "../../accounts/ethkey" }
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
kvdb-memorydb = "0.4.0"
|
||||
|
@ -229,7 +229,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn with_condition() {
|
||||
let keypair = Brain::new("abcd".into()).generate().unwrap();
|
||||
let keypair = Brain::new("abcd".into()).generate();
|
||||
let transactions: Vec<_> = (0..10u64).map(|nonce| {
|
||||
let mut tx = Transaction::default();
|
||||
tx.nonce = nonce.into();
|
||||
@ -264,7 +264,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn skips_bad_transactions() {
|
||||
let keypair = Brain::new("abcd".into()).generate().unwrap();
|
||||
let keypair = Brain::new("abcd".into()).generate();
|
||||
let mut transactions: Vec<_> = (0..10u64).map(|nonce| {
|
||||
let mut tx = Transaction::default();
|
||||
tx.nonce = nonce.into();
|
||||
|
@ -304,7 +304,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn new_tx<T: Into<U256>>(nonce: T) -> Arc<Transaction> {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let signed = transaction::Transaction {
|
||||
action: transaction::Action::Create,
|
||||
value: U256::from(100),
|
||||
|
@ -148,7 +148,7 @@ mod tests {
|
||||
let replace = ReplaceByScoreAndReadiness::new(scoring, client);
|
||||
|
||||
// same sender txs
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
|
||||
let same_sender_tx1 = local_tx_verified(Tx {
|
||||
nonce: 1,
|
||||
@ -169,14 +169,14 @@ mod tests {
|
||||
}, &keypair);
|
||||
|
||||
// different sender txs
|
||||
let sender1 = Random.generate().unwrap();
|
||||
let sender1 = Random.generate();
|
||||
let different_sender_tx1 = local_tx_verified(Tx {
|
||||
nonce: 2,
|
||||
gas_price: 1,
|
||||
..Default::default()
|
||||
}, &sender1);
|
||||
|
||||
let sender2 = Random.generate().unwrap();
|
||||
let sender2 = Random.generate();
|
||||
let different_sender_tx2 = local_tx_verified(Tx {
|
||||
nonce: 1,
|
||||
gas_price: 10,
|
||||
@ -221,7 +221,7 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let txs = vec![tx1, tx2, tx3, tx4].into_iter().map(|tx| {
|
||||
tx.unsigned().sign(keypair.secret(), None).verified()
|
||||
}).collect::<Vec<_>>();
|
||||
@ -322,7 +322,7 @@ mod tests {
|
||||
let client = TestClient::new().with_nonce(1);
|
||||
let replace = ReplaceByScoreAndReadiness::new(scoring, client);
|
||||
|
||||
let old_sender = Random.generate().unwrap();
|
||||
let old_sender = Random.generate();
|
||||
let tx_old_ready_1 = {
|
||||
let tx = Tx {
|
||||
nonce: 1,
|
||||
@ -387,7 +387,7 @@ mod tests {
|
||||
tx.signed().verified()
|
||||
};
|
||||
|
||||
let new_sender = Random.generate().unwrap();
|
||||
let new_sender = Random.generate();
|
||||
let tx_new_ready_1 = {
|
||||
let tx = Tx {
|
||||
nonce: 1,
|
||||
@ -443,7 +443,7 @@ mod tests {
|
||||
tx.signed().verified()
|
||||
};
|
||||
|
||||
let new_sender = Random.generate().unwrap();
|
||||
let new_sender = Random.generate();
|
||||
let tx_new_ready_1 = local_tx_verified(Tx {
|
||||
nonce: 1,
|
||||
gas_price: 1,
|
||||
@ -485,7 +485,7 @@ mod tests {
|
||||
tx.signed().verified()
|
||||
};
|
||||
|
||||
let new_sender = Random.generate().unwrap();
|
||||
let new_sender = Random.generate();
|
||||
let tx_new_ready_1 = local_tx_verified(Tx {
|
||||
nonce: 1,
|
||||
gas_price: 2,
|
||||
|
@ -47,7 +47,7 @@ impl Tx {
|
||||
}
|
||||
|
||||
pub fn signed(self) -> SignedTransaction {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
self.unsigned().sign(keypair.secret(), None)
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ impl Tx {
|
||||
}
|
||||
|
||||
pub fn signed_triple(mut self) -> (SignedTransaction, SignedTransaction, SignedTransaction) {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let tx1 = self.clone().unsigned().sign(keypair.secret(), None);
|
||||
self.nonce += 1;
|
||||
let tx2 = self.clone().unsigned().sign(keypair.secret(), None);
|
||||
@ -68,7 +68,7 @@ impl Tx {
|
||||
}
|
||||
|
||||
pub fn signed_replacement(mut self) -> (SignedTransaction, SignedTransaction) {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let tx1 = self.clone().unsigned().sign(keypair.secret(), None);
|
||||
self.gas_price += 1;
|
||||
let tx2 = self.unsigned().sign(keypair.secret(), None);
|
||||
@ -88,7 +88,7 @@ impl Tx {
|
||||
}
|
||||
|
||||
pub fn big_one(self) -> SignedTransaction {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let keypair = Random.generate();
|
||||
let tx = Transaction {
|
||||
action: transaction::Action::Create,
|
||||
value: U256::from(100),
|
||||
|
@ -51,7 +51,7 @@ ethereum-types = "0.8.0"
|
||||
fastmap = { path = "../util/fastmap" }
|
||||
machine = { path = "../ethcore/machine" }
|
||||
parity-bytes = "0.1"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
|
||||
eip-712 = { path = "../util/EIP-712" }
|
||||
ethjson = { path = "../json" }
|
||||
|
@ -31,7 +31,7 @@ const INIT_VEC_LEN: usize = 16;
|
||||
/// Generate document key to store in secret store.
|
||||
pub fn generate_document_key(account_public: Public, server_key_public: Public) -> Result<EncryptedDocumentKey, Error> {
|
||||
// generate random plain document key
|
||||
let document_key = Random.generate().map_err(errors::encryption)?;
|
||||
let document_key = Random.generate();
|
||||
|
||||
// encrypt document key using server key
|
||||
let (common_point, encrypted_point) = encrypt_secret(document_key.public(), &server_key_public)?;
|
||||
@ -141,8 +141,7 @@ fn encrypt_secret(secret: &Public, joint_public: &Public) -> Result<(Public, Pub
|
||||
// TODO: it is copypaste of `encrypt_secret` from secret_store/src/key_server_cluster/math.rs
|
||||
// use shared version from SS math library, when it'll be available
|
||||
|
||||
let key_pair = Random.generate()
|
||||
.map_err(errors::encryption)?;
|
||||
let key_pair = Random.generate();
|
||||
|
||||
// k * T
|
||||
let mut common_point = ec_math_utils::generation_point();
|
||||
|
@ -71,7 +71,7 @@ mod tests {
|
||||
/// mocked signer
|
||||
fn sign(should_prefix: bool, data: Vec<u8>, signing_chain_id: Option<u64>) -> (H160, [u8; 32], [u8; 32], U64) {
|
||||
let hash = if should_prefix { eth_data_hash(data) } else { keccak(data) };
|
||||
let account = Random.generate().unwrap();
|
||||
let account = Random.generate();
|
||||
let address = account.address();
|
||||
let sig = crypto::publickey::sign(account.secret(), &hash).unwrap();
|
||||
let (r, s, v) = (sig.r(), sig.s(), sig.v());
|
||||
|
@ -197,7 +197,7 @@ where
|
||||
}
|
||||
|
||||
fn phrase_to_address(&self, phrase: String) -> Result<H160> {
|
||||
Ok(Brain::new(phrase).generate().expect("Brain::generate always returns Ok; qed").address())
|
||||
Ok(Brain::new(phrase).generate().address())
|
||||
}
|
||||
|
||||
fn list_accounts(&self, _: u64, _: Option<H160>, _: Option<BlockNumber>) -> Result<Option<Vec<H160>>> {
|
||||
|
@ -205,7 +205,7 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
|
||||
}
|
||||
|
||||
fn phrase_to_address(&self, phrase: String) -> Result<H160> {
|
||||
Ok(Brain::new(phrase).generate().expect("Brain::generate always returns Ok; qed").address())
|
||||
Ok(Brain::new(phrase).generate().address())
|
||||
}
|
||||
|
||||
fn list_accounts(&self, count: u64, after: Option<H160>, block_number: Option<BlockNumber>) -> Result<Option<Vec<H160>>> {
|
||||
|
@ -118,7 +118,7 @@ impl ParityAccounts for ParityAccountsClient {
|
||||
|
||||
fn new_account_from_phrase(&self, phrase: String, pass: Password) -> Result<H160> {
|
||||
self.deprecation_notice("parity_newAccountFromPhrase");
|
||||
let brain = Brain::new(phrase).generate().unwrap();
|
||||
let brain = Brain::new(phrase).generate();
|
||||
self.accounts.insert_account(brain.secret().clone(), &pass)
|
||||
.map(Into::into)
|
||||
.map_err(|e| errors::account("Could not create account.", e))
|
||||
|
@ -363,7 +363,7 @@ fn rpc_parity_pending_transactions_with_limit_with_filter() {
|
||||
fn rpc_parity_encrypt() {
|
||||
let deps = Dependencies::new();
|
||||
let io = deps.default_client();
|
||||
let key = format!("{:x}", Random.generate().unwrap().public());
|
||||
let key = format!("{:x}", Random.generate().public());
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "parity_encryptMessage", "params":["0x"#.to_owned() + &key + r#"", "0x01"], "id": 1}"#;
|
||||
assert!(io.handle_request_sync(&request).unwrap().contains("result"), "Should return success.");
|
||||
|
@ -306,6 +306,7 @@ fn ec_recover_invalid_signature() {
|
||||
fn should_not_unlock_account_temporarily_if_allow_perm_is_disabled() {
|
||||
let tester = setup();
|
||||
let address = tester.accounts.new_account(&"password123".into()).unwrap();
|
||||
let message = [1u8; 32].into();
|
||||
|
||||
let request = r#"{
|
||||
"jsonrpc": "2.0",
|
||||
@ -320,13 +321,14 @@ fn should_not_unlock_account_temporarily_if_allow_perm_is_disabled() {
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32000,"message":"Time-unlocking is not supported when permanent unlock is disabled.","data":"Use personal_sendTransaction or enable permanent unlocking, instead."},"id":1}"#;
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.into()));
|
||||
|
||||
assert!(tester.accounts.sign(address, None, Default::default()).is_err(), "Should not unlock account.");
|
||||
assert!(tester.accounts.sign(address, None, message).is_err(), "Should not unlock account.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_unlock_account_permanently() {
|
||||
let tester = setup();
|
||||
let address = tester.accounts.new_account(&"password123".into()).unwrap();
|
||||
let message = [1u8; 32].into();
|
||||
|
||||
let request = r#"{
|
||||
"jsonrpc": "2.0",
|
||||
@ -340,7 +342,7 @@ fn should_unlock_account_permanently() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.into()));
|
||||
assert!(tester.accounts.sign(address, None, Default::default()).is_ok(), "Should unlock account.");
|
||||
assert!(tester.accounts.sign(address, None, message).is_ok(), "Should unlock account.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -496,7 +496,7 @@ fn should_decrypt_message_if_account_is_unlocked() {
|
||||
fn should_add_decryption_to_the_queue() {
|
||||
// given
|
||||
let tester = eth_signing(true);
|
||||
let acc = Random.generate().unwrap();
|
||||
let acc = Random.generate();
|
||||
assert_eq!(tester.signer.requests().len(), 0);
|
||||
|
||||
// when
|
||||
@ -533,7 +533,7 @@ fn should_add_decryption_to_the_queue() {
|
||||
fn should_compose_transaction() {
|
||||
// given
|
||||
let tester = eth_signing(true);
|
||||
let acc = Random.generate().unwrap();
|
||||
let acc = Random.generate();
|
||||
assert_eq!(tester.signer.requests().len(), 0);
|
||||
let from = format!("{:x}", acc.address());
|
||||
|
||||
|
@ -18,9 +18,10 @@ keccak-hash = "0.4.0"
|
||||
kvdb = "0.4.0"
|
||||
kvdb-rocksdb = "0.5.0"
|
||||
lazy_static = "1.0"
|
||||
libsecp256k1 = { version = "0.3.5", default-features = false }
|
||||
log = "0.4"
|
||||
parity-bytes = "0.1"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
parity-runtime = { path = "../util/runtime" }
|
||||
parking_lot = "0.10.0"
|
||||
percent-encoding = "2.1.0"
|
||||
|
@ -423,7 +423,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
fn make_key_servers(start_port: u16, num_nodes: usize) -> (Vec<KeyServerImpl>, Vec<Arc<DummyKeyStorage>>, Runtime) {
|
||||
let key_pairs: Vec<_> = (0..num_nodes).map(|_| Random.generate().unwrap()).collect();
|
||||
let key_pairs: Vec<_> = (0..num_nodes).map(|_| Random.generate()).collect();
|
||||
let configs: Vec<_> = (0..num_nodes).map(|i| ClusterConfiguration {
|
||||
listener_address: NodeAddress {
|
||||
address: "127.0.0.1".into(),
|
||||
@ -488,8 +488,8 @@ pub mod tests {
|
||||
|
||||
// generate document key
|
||||
let threshold = 0;
|
||||
let document = Random.generate().unwrap().secret().clone();
|
||||
let secret = Random.generate().unwrap().secret().clone();
|
||||
let document = Random.generate().secret().clone();
|
||||
let secret = Random.generate().secret().clone();
|
||||
let signature: Requester = crypto::publickey::sign(&secret, &document).unwrap().into();
|
||||
let generated_key = key_servers[0].generate_document_key(
|
||||
*document,
|
||||
@ -518,8 +518,8 @@ pub mod tests {
|
||||
let test_cases = [0, 1, 2];
|
||||
for threshold in &test_cases {
|
||||
// generate document key
|
||||
let document = Random.generate().unwrap().secret().clone();
|
||||
let secret = Random.generate().unwrap().secret().clone();
|
||||
let document = Random.generate().secret().clone();
|
||||
let secret = Random.generate().secret().clone();
|
||||
let signature: Requester = crypto::publickey::sign(&secret, &document).unwrap().into();
|
||||
let generated_key = key_servers[0].generate_document_key(
|
||||
*document,
|
||||
@ -553,8 +553,8 @@ pub mod tests {
|
||||
let test_cases = [0, 1, 2];
|
||||
for threshold in &test_cases {
|
||||
// generate server key
|
||||
let server_key_id = Random.generate().unwrap().secret().clone();
|
||||
let requestor_secret = Random.generate().unwrap().secret().clone();
|
||||
let server_key_id = Random.generate().secret().clone();
|
||||
let requestor_secret = Random.generate().secret().clone();
|
||||
let signature: Requester = crypto::publickey::sign(&requestor_secret, &server_key_id).unwrap().into();
|
||||
let server_public = key_servers[0].generate_key(
|
||||
*server_key_id,
|
||||
@ -563,7 +563,7 @@ pub mod tests {
|
||||
).wait().unwrap();
|
||||
|
||||
// generate document key (this is done by KS client so that document key is unknown to any KS)
|
||||
let generated_key = Random.generate().unwrap().public().clone();
|
||||
let generated_key = Random.generate().public().clone();
|
||||
let encrypted_document_key = math::encrypt_secret(&generated_key, &server_public).unwrap();
|
||||
|
||||
// store document key
|
||||
@ -589,8 +589,8 @@ pub mod tests {
|
||||
let test_cases = [0, 1, 2];
|
||||
for threshold in &test_cases {
|
||||
// generate server key
|
||||
let server_key_id = Random.generate().unwrap().secret().clone();
|
||||
let requestor_secret = Random.generate().unwrap().secret().clone();
|
||||
let server_key_id = Random.generate().secret().clone();
|
||||
let requestor_secret = Random.generate().secret().clone();
|
||||
let signature: Requester = crypto::publickey::sign(&requestor_secret, &server_key_id).unwrap().into();
|
||||
let server_public = key_servers[0].generate_key(
|
||||
*server_key_id,
|
||||
@ -622,8 +622,8 @@ pub mod tests {
|
||||
|
||||
// generate document key
|
||||
let threshold = 0;
|
||||
let document = Random.generate().unwrap().secret().clone();
|
||||
let secret = Random.generate().unwrap().secret().clone();
|
||||
let document = Random.generate().secret().clone();
|
||||
let secret = Random.generate().secret().clone();
|
||||
let signature: Requester = crypto::publickey::sign(&secret, &document).unwrap().into();
|
||||
let generated_key = key_servers[0].generate_document_key(
|
||||
*document,
|
||||
@ -649,8 +649,8 @@ pub mod tests {
|
||||
let threshold = 1;
|
||||
|
||||
// generate server key
|
||||
let server_key_id = Random.generate().unwrap().secret().clone();
|
||||
let requestor_secret = Random.generate().unwrap().secret().clone();
|
||||
let server_key_id = Random.generate().secret().clone();
|
||||
let requestor_secret = Random.generate().secret().clone();
|
||||
let signature: Requester = crypto::publickey::sign(&requestor_secret, &server_key_id).unwrap().into();
|
||||
let server_public = key_servers[0].generate_key(*server_key_id, signature.clone(), threshold).wait().unwrap();
|
||||
|
||||
@ -680,8 +680,8 @@ pub mod tests {
|
||||
let threshold = 1;
|
||||
|
||||
// generate server key
|
||||
let server_key_id = Random.generate().unwrap().secret().clone();
|
||||
let requestor_secret = Random.generate().unwrap().secret().clone();
|
||||
let server_key_id = Random.generate().secret().clone();
|
||||
let requestor_secret = Random.generate().secret().clone();
|
||||
let signature = crypto::publickey::sign(&requestor_secret, &server_key_id).unwrap();
|
||||
let server_public = key_servers[0].generate_key(
|
||||
*server_key_id,
|
||||
|
@ -1171,7 +1171,7 @@ pub mod tests {
|
||||
let isolated_nodes_ids = isolated_nodes_ids.unwrap_or_default();
|
||||
|
||||
// generate admin key pair
|
||||
let admin_key_pair = Random.generate().unwrap();
|
||||
let admin_key_pair = Random.generate();
|
||||
let admin_public = admin_key_pair.public().clone();
|
||||
|
||||
// all active nodes set
|
||||
@ -1195,7 +1195,7 @@ pub mod tests {
|
||||
let meta = ShareChangeSessionMeta {
|
||||
self_node_id: master,
|
||||
master_node_id: master,
|
||||
id: SessionId::default(),
|
||||
id: SessionId::from([1u8; 32]),
|
||||
configured_nodes_count: all_nodes_set.len(),
|
||||
connected_nodes_count: all_nodes_set.len(),
|
||||
};
|
||||
@ -1265,8 +1265,8 @@ pub mod tests {
|
||||
let document_secret_plain = math::generate_random_point().unwrap();
|
||||
for n1 in 0..n {
|
||||
for n2 in n1+1..n {
|
||||
let share1 = key_storages[n1].get(&SessionId::default()).unwrap();
|
||||
let share2 = key_storages[n2].get(&SessionId::default()).unwrap();
|
||||
let share1 = key_storages[n1].get(&SessionId::from([1u8; 32])).unwrap();
|
||||
let share2 = key_storages[n2].get(&SessionId::from([1u8; 32])).unwrap();
|
||||
|
||||
let id_number1 = share1.as_ref().unwrap().last_version().unwrap().id_numbers[nodes[n1]].clone();
|
||||
let id_number2 = share1.as_ref().unwrap().last_version().unwrap().id_numbers[nodes[n2]].clone();
|
||||
@ -1310,7 +1310,7 @@ pub mod tests {
|
||||
let gml = generate_key(3, 1);
|
||||
|
||||
// add 1 node so that it becames 2-of-4 session
|
||||
let add = vec![Random.generate().unwrap()];
|
||||
let add = vec![Random.generate()];
|
||||
let master = gml.0.node(0);
|
||||
let ml = MessageLoop::with_gml::<Adapter>(gml, master, Some(add), None, None).run_at(master);
|
||||
|
||||
@ -1328,7 +1328,7 @@ pub mod tests {
|
||||
// 1) add session is delegated to one of old nodes
|
||||
// 2) key share is pushed to new node
|
||||
// 3) delegated session is returned back to added node
|
||||
let add = vec![Random.generate().unwrap()];
|
||||
let add = vec![Random.generate()];
|
||||
let master = add[0].public().clone();
|
||||
let ml = MessageLoop::with_gml::<Adapter>(gml, master, Some(add), None, None).run_at(master);
|
||||
|
||||
@ -1344,7 +1344,7 @@ pub mod tests {
|
||||
// remove 1 node && insert 1 node so that one share is moved
|
||||
let master = gml.0.node(0);
|
||||
let remove: BTreeSet<_> = ::std::iter::once(gml.0.node(1)).collect();
|
||||
let add = vec![Random.generate().unwrap()];
|
||||
let add = vec![Random.generate()];
|
||||
let ml = MessageLoop::with_gml::<Adapter>(gml, master, Some(add), Some(remove.clone()), None).run_at(master);
|
||||
|
||||
// check that secret is still the same as before moving the share
|
||||
@ -1353,7 +1353,7 @@ pub mod tests {
|
||||
|
||||
// check that all removed nodes do not own key share
|
||||
assert!(ml.sessions.keys().filter(|k| remove.contains(k))
|
||||
.all(|k| ml.ml.key_storage_of(k).get(&SessionId::default()).unwrap().is_none()));
|
||||
.all(|k| ml.ml.key_storage_of(k).get(&SessionId::from([1u8; 32])).unwrap().is_none()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1372,7 +1372,7 @@ pub mod tests {
|
||||
|
||||
// check that all removed nodes do not own key share
|
||||
assert!(ml.sessions.keys().filter(|k| remove.contains(k))
|
||||
.all(|k| ml.ml.key_storage_of(k).get(&SessionId::default()).unwrap().is_none()));
|
||||
.all(|k| ml.ml.key_storage_of(k).get(&SessionId::from([1u8; 32])).unwrap().is_none()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1392,7 +1392,7 @@ pub mod tests {
|
||||
|
||||
// check that all isolated nodes still OWN key share
|
||||
assert!(ml.sessions.keys().filter(|k| isolate.contains(k))
|
||||
.all(|k| ml.ml.key_storage_of(k).get(&SessionId::default()).unwrap().is_some()));
|
||||
.all(|k| ml.ml.key_storage_of(k).get(&SessionId::from([1u8; 32])).unwrap().is_some()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1408,17 +1408,17 @@ pub mod tests {
|
||||
|
||||
// check that all removed nodes do not own key share
|
||||
assert!(ml.sessions.keys().filter(|k| remove.contains(k))
|
||||
.all(|k| ml.ml.key_storage_of(k).get(&SessionId::default()).unwrap().is_none()));
|
||||
.all(|k| ml.ml.key_storage_of(k).get(&SessionId::from([1u8; 32])).unwrap().is_none()));
|
||||
|
||||
// and now let's add new node (make sure the session is completed, even though key is still irrecoverable)
|
||||
// isolated here are not actually isolated, but removed on the previous step
|
||||
let add = vec![Random.generate().unwrap()];
|
||||
let add = vec![Random.generate()];
|
||||
let master = add[0].public().clone();
|
||||
let ml = ml.and_then::<Adapter>(master, Some(add.clone()), None, Some(remove)).run_at(master);
|
||||
|
||||
// check that all added nodes do not own key share (there's not enough nodes to run share add session)
|
||||
assert!(ml.sessions.keys().filter(|k| add.iter().any(|n| n.public() == *k))
|
||||
.all(|k| ml.ml.key_storage_of(k).get(&SessionId::default()).unwrap().is_none()));
|
||||
.all(|k| ml.ml.key_storage_of(k).get(&SessionId::from([1u8; 32])).unwrap().is_none()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1439,7 +1439,7 @@ pub mod tests {
|
||||
let gml = generate_key(2, 1);
|
||||
|
||||
// insert 1 node so that it becames 2-of-3 session
|
||||
let add = vec![Random.generate().unwrap()];
|
||||
let add = vec![Random.generate()];
|
||||
let master = gml.0.node(0);
|
||||
let ml = MessageLoop::with_gml::<Adapter>(gml, master, Some(add.clone()), None, None)
|
||||
.run_at(master);
|
||||
|
@ -945,7 +945,7 @@ pub mod tests {
|
||||
let gml = generate_key(3, 1);
|
||||
|
||||
// try to remove 1 node
|
||||
let add = vec![Random.generate().unwrap()];
|
||||
let add = vec![Random.generate()];
|
||||
let remove: BTreeSet<_> = ::std::iter::once(gml.0.node(1)).collect();
|
||||
let master = gml.0.node(0);
|
||||
assert_eq!(MessageLoop::with_gml::<Adapter>(gml, master, Some(add), Some(remove), None)
|
||||
@ -970,7 +970,7 @@ pub mod tests {
|
||||
let gml = generate_key(3, 1);
|
||||
|
||||
// try to add 1 node using this node as a master node
|
||||
let add = vec![Random.generate().unwrap()];
|
||||
let add = vec![Random.generate()];
|
||||
let master = *add[0].public();
|
||||
assert_eq!(MessageLoop::with_gml::<Adapter>(gml, master, Some(add), None, None)
|
||||
.run_at(master).unwrap_err(), Error::ServerKeyIsNotFound);
|
||||
@ -982,7 +982,7 @@ pub mod tests {
|
||||
let gml = generate_key(3, 1);
|
||||
|
||||
// try to add 1 node using this node as a master node
|
||||
let add = vec![Random.generate().unwrap()];
|
||||
let add = vec![Random.generate()];
|
||||
let master = gml.0.node(0);
|
||||
assert_eq!(MessageLoop::with_gml::<Adapter>(gml, master, Some(add), None, None)
|
||||
.init_at(master).unwrap()
|
||||
@ -995,7 +995,7 @@ pub mod tests {
|
||||
let gml = generate_key(3, 1);
|
||||
|
||||
// try to add 1 node using this node as a master node
|
||||
let add = vec![Random.generate().unwrap()];
|
||||
let add = vec![Random.generate()];
|
||||
let master = gml.0.node(0);
|
||||
assert_eq!(MessageLoop::with_gml::<Adapter>(gml, master, Some(add), None, None)
|
||||
.sessions[&master]
|
||||
@ -1010,7 +1010,7 @@ pub mod tests {
|
||||
let gml = generate_key(n, 1);
|
||||
|
||||
// run share add session
|
||||
let add = (0..add).map(|_| Random.generate().unwrap()).collect();
|
||||
let add = (0..add).map(|_| Random.generate()).collect();
|
||||
let master = gml.0.node(0);
|
||||
let ml = MessageLoop::with_gml::<Adapter>(gml, master, Some(add), None, None)
|
||||
.run_at(master).unwrap();
|
||||
@ -1030,7 +1030,7 @@ pub mod tests {
|
||||
// run share add session
|
||||
let master = gml.0.node(0);
|
||||
let node_to_isolate = gml.0.node(1);
|
||||
let add = (0..add).map(|_| Random.generate().unwrap()).collect();
|
||||
let add = (0..add).map(|_| Random.generate()).collect();
|
||||
let isolate = ::std::iter::once(node_to_isolate).collect();
|
||||
let ml = MessageLoop::with_gml::<Adapter>(gml, master, Some(add), None, Some(isolate))
|
||||
.run_at(master).unwrap();
|
||||
@ -1053,12 +1053,13 @@ pub mod tests {
|
||||
let isolated_key_storage = gml.0.key_storage(1).clone();
|
||||
let mut oldest_nodes_set = gml.0.nodes();
|
||||
oldest_nodes_set.remove(&node_to_isolate);
|
||||
let add = (0..add).map(|_| Random.generate().unwrap()).collect::<Vec<_>>();
|
||||
let add = (0..add).map(|_| Random.generate()).collect::<Vec<_>>();
|
||||
let newest_nodes_set = add.iter().map(|kp| *kp.public()).collect::<Vec<_>>();
|
||||
let isolate = ::std::iter::once(node_to_isolate).collect();
|
||||
let ml = MessageLoop::with_gml::<Adapter>(gml, master, Some(add), None, Some(isolate))
|
||||
.run_at(master).unwrap();
|
||||
let new_key_version = ml.ml.key_storage(0).get(&Default::default())
|
||||
let dummy_doc = [1u8; 32].into();
|
||||
let new_key_version = ml.ml.key_storage(0).get(&dummy_doc)
|
||||
.unwrap().unwrap().last_version().unwrap().hash;
|
||||
|
||||
// now let's add back old node so that key becames 2-of-6
|
||||
@ -1067,7 +1068,7 @@ pub mod tests {
|
||||
ml.original_key_version = new_key_version;
|
||||
ml.ml.replace_key_storage_of(&node_to_isolate, isolated_key_storage.clone());
|
||||
ml.sessions.get_mut(&node_to_isolate).unwrap().core.key_share =
|
||||
isolated_key_storage.get(&Default::default()).unwrap();
|
||||
isolated_key_storage.get(&dummy_doc).unwrap();
|
||||
ml.sessions.get_mut(&node_to_isolate).unwrap().core.key_storage = isolated_key_storage;
|
||||
let ml = ml.run_at(master).unwrap();
|
||||
|
||||
@ -1078,7 +1079,7 @@ pub mod tests {
|
||||
// isolated node has version A, C
|
||||
// new nodes have versions B, C
|
||||
let oldest_key_share = ml.ml.key_storage_of(oldest_nodes_set.iter().nth(0).unwrap())
|
||||
.get(&Default::default()).unwrap().unwrap();
|
||||
.get(&dummy_doc).unwrap().unwrap();
|
||||
debug_assert_eq!(oldest_key_share.versions.len(), 3);
|
||||
let version_a = oldest_key_share.versions[0].hash.clone();
|
||||
let version_b = oldest_key_share.versions[1].hash.clone();
|
||||
@ -1086,13 +1087,13 @@ pub mod tests {
|
||||
debug_assert!(version_a != version_b && version_b != version_c);
|
||||
|
||||
debug_assert!(oldest_nodes_set.iter().all(|n| vec![version_a.clone(), version_b.clone(), version_c.clone()] ==
|
||||
ml.ml.key_storage_of(n).get(&Default::default()).unwrap().unwrap()
|
||||
ml.ml.key_storage_of(n).get(&dummy_doc).unwrap().unwrap()
|
||||
.versions.iter().map(|v| v.hash).collect::<Vec<_>>()));
|
||||
debug_assert!(::std::iter::once(&node_to_isolate).all(|n| vec![version_a.clone(), version_c.clone()] ==
|
||||
ml.ml.key_storage_of(n).get(&Default::default()).unwrap().unwrap()
|
||||
ml.ml.key_storage_of(n).get(&dummy_doc).unwrap().unwrap()
|
||||
.versions.iter().map(|v| v.hash).collect::<Vec<_>>()));
|
||||
debug_assert!(newest_nodes_set.iter().all(|n| vec![version_b.clone(), version_c.clone()] ==
|
||||
ml.ml.key_storage_of(n).get(&Default::default()).unwrap().unwrap()
|
||||
ml.ml.key_storage_of(n).get(&dummy_doc).unwrap().unwrap()
|
||||
.versions.iter().map(|v| v.hash).collect::<Vec<_>>()));
|
||||
}
|
||||
|
||||
@ -1105,7 +1106,7 @@ pub mod tests {
|
||||
|
||||
// run share add session
|
||||
let master = gml.0.node(0);
|
||||
let add = (0..add).map(|_| Random.generate().unwrap()).collect::<Vec<_>>();
|
||||
let add = (0..add).map(|_| Random.generate()).collect::<Vec<_>>();
|
||||
let isolate = vec![gml.0.node(1), gml.0.node(2)].into_iter().collect();
|
||||
assert_eq!(MessageLoop::with_gml::<Adapter>(gml, master, Some(add), None, Some(isolate))
|
||||
.run_at(master).unwrap_err(), Error::ConsensusUnreachable);
|
||||
|
@ -859,11 +859,11 @@ mod tests {
|
||||
use std::str::FromStr;
|
||||
|
||||
const SECRET_PLAIN: &'static str = "d2b57ae7619e070af0af6bc8c703c0cd27814c54d5d6a999cacac0da34ede279ca0d9216e85991029e54e2f0c92ee0bd30237725fa765cbdbfc4529489864c5f";
|
||||
|
||||
const DUMMY_SESSION_ID: [u8; 32] = [1u8; 32];
|
||||
fn prepare_decryption_sessions() -> (KeyPair, Vec<Arc<DummyCluster>>, Vec<Arc<DummyAclStorage>>, Vec<SessionImpl>) {
|
||||
// prepare encrypted data + cluster configuration for scheme 4-of-5
|
||||
let session_id = SessionId::default();
|
||||
let access_key = Random.generate().unwrap().secret().clone();
|
||||
let session_id = SessionId::from(DUMMY_SESSION_ID);
|
||||
let access_key = Random.generate().secret().clone();
|
||||
let secret_shares: Vec<Secret> = vec![
|
||||
"834cb736f02d9c968dfaf0c37658a1d86ff140554fc8b59c9fdad5a8cf810eec".parse().unwrap(),
|
||||
"5a3c1d90fafafa66bb808bcc464354a98b05e6b2c95b5f609d4511cdd1b17a0b".parse().unwrap(),
|
||||
@ -905,11 +905,11 @@ mod tests {
|
||||
}
|
||||
cluster
|
||||
}).collect();
|
||||
let requester = Random.generate().unwrap();
|
||||
let signature = Some(crypto::publickey::sign(requester.secret(), &SessionId::default()).unwrap());
|
||||
let requester = Random.generate();
|
||||
let signature = Some(crypto::publickey::sign(requester.secret(), &session_id).unwrap());
|
||||
let sessions: Vec<_> = (0..5).map(|i| SessionImpl::new(SessionParams {
|
||||
meta: SessionMeta {
|
||||
id: session_id.clone(),
|
||||
id: session_id,
|
||||
self_node_id: id_numbers.iter().nth(i).clone().unwrap().0,
|
||||
master_node_id: id_numbers.iter().nth(0).clone().unwrap().0,
|
||||
threshold: encrypted_datas[i].threshold,
|
||||
@ -970,34 +970,37 @@ mod tests {
|
||||
#[test]
|
||||
fn constructs_in_cluster_of_single_node() {
|
||||
let mut nodes = BTreeMap::new();
|
||||
let self_node_id = Random.generate().unwrap().public().clone();
|
||||
nodes.insert(self_node_id, Random.generate().unwrap().secret().clone());
|
||||
match SessionImpl::new(SessionParams {
|
||||
let self_node_id = Random.generate().public().clone();
|
||||
nodes.insert(self_node_id, Random.generate().secret().clone());
|
||||
let msg = [1u8; 32].into();
|
||||
let requester = Some(Requester::Signature(crypto::publickey::sign(Random.generate().secret(), &msg).unwrap()));
|
||||
let params = SessionParams {
|
||||
meta: SessionMeta {
|
||||
id: SessionId::default(),
|
||||
id: SessionId::from([1u8; 32]),
|
||||
self_node_id: self_node_id.clone(),
|
||||
master_node_id: self_node_id.clone(),
|
||||
threshold: 0,
|
||||
configured_nodes_count: 1,
|
||||
connected_nodes_count: 1,
|
||||
},
|
||||
access_key: Random.generate().unwrap().secret().clone(),
|
||||
access_key: Random.generate().secret().clone(),
|
||||
key_share: Some(DocumentKeyShare {
|
||||
author: Default::default(),
|
||||
threshold: 0,
|
||||
public: Default::default(),
|
||||
common_point: Some(Random.generate().unwrap().public().clone()),
|
||||
encrypted_point: Some(Random.generate().unwrap().public().clone()),
|
||||
common_point: Some(Random.generate().public().clone()),
|
||||
encrypted_point: Some(Random.generate().public().clone()),
|
||||
versions: vec![DocumentKeyShareVersion {
|
||||
hash: Default::default(),
|
||||
id_numbers: nodes,
|
||||
secret_share: Random.generate().unwrap().secret().clone(),
|
||||
secret_share: Random.generate().secret().clone(),
|
||||
}],
|
||||
}),
|
||||
acl_storage: Arc::new(DummyAclStorage::default()),
|
||||
cluster: Arc::new(DummyCluster::new(self_node_id.clone())),
|
||||
nonce: 0,
|
||||
}, Some(Requester::Signature(crypto::publickey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()))) {
|
||||
};
|
||||
match SessionImpl::new(params, requester) {
|
||||
Ok(_) => (),
|
||||
_ => panic!("unexpected"),
|
||||
}
|
||||
@ -1005,23 +1008,23 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn fails_to_initialize_if_does_not_have_a_share() {
|
||||
let self_node_id = Random.generate().unwrap().public().clone();
|
||||
let self_node_id = Random.generate().public().clone();
|
||||
let session = SessionImpl::new(SessionParams {
|
||||
meta: SessionMeta {
|
||||
id: SessionId::default(),
|
||||
id: SessionId::from(DUMMY_SESSION_ID),
|
||||
self_node_id: self_node_id.clone(),
|
||||
master_node_id: self_node_id.clone(),
|
||||
threshold: 0,
|
||||
configured_nodes_count: 1,
|
||||
connected_nodes_count: 1,
|
||||
},
|
||||
access_key: Random.generate().unwrap().secret().clone(),
|
||||
access_key: Random.generate().secret().clone(),
|
||||
key_share: None,
|
||||
acl_storage: Arc::new(DummyAclStorage::default()),
|
||||
cluster: Arc::new(DummyCluster::new(self_node_id.clone())),
|
||||
nonce: 0,
|
||||
}, Some(Requester::Signature(
|
||||
crypto::publickey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()
|
||||
crypto::publickey::sign(Random.generate().secret(), &SessionId::from(DUMMY_SESSION_ID)).unwrap()
|
||||
))).unwrap().0;
|
||||
assert_eq!(session.initialize(Default::default(), Default::default(), false, false), Err(Error::InvalidMessage));
|
||||
}
|
||||
@ -1029,36 +1032,36 @@ mod tests {
|
||||
#[test]
|
||||
fn fails_to_initialize_if_threshold_is_wrong() {
|
||||
let mut nodes = BTreeMap::new();
|
||||
let self_node_id = Random.generate().unwrap().public().clone();
|
||||
nodes.insert(self_node_id.clone(), Random.generate().unwrap().secret().clone());
|
||||
nodes.insert(Random.generate().unwrap().public().clone(), Random.generate().unwrap().secret().clone());
|
||||
let self_node_id = Random.generate().public().clone();
|
||||
nodes.insert(self_node_id.clone(), Random.generate().secret().clone());
|
||||
nodes.insert(Random.generate().public().clone(), Random.generate().secret().clone());
|
||||
let session = SessionImpl::new(SessionParams {
|
||||
meta: SessionMeta {
|
||||
id: SessionId::default(),
|
||||
id: SessionId::from(DUMMY_SESSION_ID),
|
||||
self_node_id: self_node_id.clone(),
|
||||
master_node_id: self_node_id.clone(),
|
||||
threshold: 2,
|
||||
configured_nodes_count: 1,
|
||||
connected_nodes_count: 1,
|
||||
},
|
||||
access_key: Random.generate().unwrap().secret().clone(),
|
||||
access_key: Random.generate().secret().clone(),
|
||||
key_share: Some(DocumentKeyShare {
|
||||
author: Default::default(),
|
||||
threshold: 2,
|
||||
public: Default::default(),
|
||||
common_point: Some(Random.generate().unwrap().public().clone()),
|
||||
encrypted_point: Some(Random.generate().unwrap().public().clone()),
|
||||
common_point: Some(Random.generate().public().clone()),
|
||||
encrypted_point: Some(Random.generate().public().clone()),
|
||||
versions: vec![DocumentKeyShareVersion {
|
||||
hash: Default::default(),
|
||||
id_numbers: nodes,
|
||||
secret_share: Random.generate().unwrap().secret().clone(),
|
||||
secret_share: Random.generate().secret().clone(),
|
||||
}],
|
||||
}),
|
||||
acl_storage: Arc::new(DummyAclStorage::default()),
|
||||
cluster: Arc::new(DummyCluster::new(self_node_id.clone())),
|
||||
nonce: 0,
|
||||
}, Some(Requester::Signature(
|
||||
crypto::publickey::sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()
|
||||
crypto::publickey::sign(Random.generate().secret(), &SessionId::from(DUMMY_SESSION_ID)).unwrap()
|
||||
))).unwrap().0;
|
||||
assert_eq!(session.initialize(Default::default(), Default::default(), false, false), Err(Error::ConsensusUnreachable));
|
||||
}
|
||||
@ -1075,13 +1078,13 @@ mod tests {
|
||||
let (_, _, _, sessions) = prepare_decryption_sessions();
|
||||
assert_eq!(sessions[0].initialize(Default::default(), Default::default(), false, false).unwrap(), ());
|
||||
assert_eq!(sessions[0].on_consensus_message(sessions[1].node(), &message::DecryptionConsensusMessage {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from(DUMMY_SESSION_ID).into(),
|
||||
sub_session: sessions[0].access_key().clone().into(),
|
||||
session_nonce: 0,
|
||||
origin: None,
|
||||
message: message::ConsensusMessage::InitializeConsensusSession(message::InitializeConsensusSession {
|
||||
requester: Requester::Signature(crypto::publickey::sign(
|
||||
Random.generate().unwrap().secret(), &SessionId::default()).unwrap()).into(),
|
||||
Random.generate().secret(), &SessionId::from(DUMMY_SESSION_ID)).unwrap()).into(),
|
||||
version: Default::default(),
|
||||
}),
|
||||
}).unwrap_err(), Error::InvalidMessage);
|
||||
@ -1091,21 +1094,21 @@ mod tests {
|
||||
fn fails_to_partial_decrypt_if_requested_by_slave() {
|
||||
let (_, _, _, sessions) = prepare_decryption_sessions();
|
||||
assert_eq!(sessions[1].on_consensus_message(sessions[0].node(), &message::DecryptionConsensusMessage {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from(DUMMY_SESSION_ID).into(),
|
||||
sub_session: sessions[0].access_key().clone().into(),
|
||||
session_nonce: 0,
|
||||
origin: None,
|
||||
message: message::ConsensusMessage::InitializeConsensusSession(message::InitializeConsensusSession {
|
||||
requester: Requester::Signature(crypto::publickey::sign(Random.generate().unwrap().secret(),
|
||||
&SessionId::default()).unwrap()).into(),
|
||||
requester: Requester::Signature(crypto::publickey::sign(Random.generate().secret(),
|
||||
&SessionId::from(DUMMY_SESSION_ID)).unwrap()).into(),
|
||||
version: Default::default(),
|
||||
}),
|
||||
}).unwrap(), ());
|
||||
assert_eq!(sessions[1].on_partial_decryption_requested(sessions[2].node(), &message::RequestPartialDecryption {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from(DUMMY_SESSION_ID).into(),
|
||||
sub_session: sessions[0].access_key().clone().into(),
|
||||
session_nonce: 0,
|
||||
request_id: Random.generate().unwrap().secret().clone().into(),
|
||||
request_id: Random.generate().secret().clone().into(),
|
||||
is_shadow_decryption: false,
|
||||
is_broadcast_session: false,
|
||||
nodes: sessions.iter().map(|s| s.node().clone().into()).take(4).collect(),
|
||||
@ -1116,21 +1119,21 @@ mod tests {
|
||||
fn fails_to_partial_decrypt_if_wrong_number_of_nodes_participating() {
|
||||
let (_, _, _, sessions) = prepare_decryption_sessions();
|
||||
assert_eq!(sessions[1].on_consensus_message(sessions[0].node(), &message::DecryptionConsensusMessage {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from(DUMMY_SESSION_ID).into(),
|
||||
sub_session: sessions[0].access_key().clone().into(),
|
||||
session_nonce: 0,
|
||||
origin: None,
|
||||
message: message::ConsensusMessage::InitializeConsensusSession(message::InitializeConsensusSession {
|
||||
requester: Requester::Signature(crypto::publickey::sign(Random.generate().unwrap().secret(),
|
||||
&SessionId::default()).unwrap()).into(),
|
||||
requester: Requester::Signature(crypto::publickey::sign(Random.generate().secret(),
|
||||
&SessionId::from(DUMMY_SESSION_ID)).unwrap()).into(),
|
||||
version: Default::default(),
|
||||
}),
|
||||
}).unwrap(), ());
|
||||
assert_eq!(sessions[1].on_partial_decryption_requested(sessions[0].node(), &message::RequestPartialDecryption {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from(DUMMY_SESSION_ID).into(),
|
||||
sub_session: sessions[0].access_key().clone().into(),
|
||||
session_nonce: 0,
|
||||
request_id: Random.generate().unwrap().secret().clone().into(),
|
||||
request_id: Random.generate().secret().clone().into(),
|
||||
is_shadow_decryption: false,
|
||||
is_broadcast_session: false,
|
||||
nodes: sessions.iter().map(|s| s.node().clone().into()).take(2).collect(),
|
||||
@ -1141,11 +1144,11 @@ mod tests {
|
||||
fn fails_to_accept_partial_decrypt_if_not_waiting() {
|
||||
let (_, _, _, sessions) = prepare_decryption_sessions();
|
||||
assert_eq!(sessions[0].on_partial_decryption(sessions[1].node(), &message::PartialDecryption {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from(DUMMY_SESSION_ID).into(),
|
||||
sub_session: sessions[0].access_key().clone().into(),
|
||||
session_nonce: 0,
|
||||
request_id: Random.generate().unwrap().secret().clone().into(),
|
||||
shadow_point: Random.generate().unwrap().public().clone().into(),
|
||||
request_id: Random.generate().secret().clone().into(),
|
||||
shadow_point: Random.generate().public().clone().into(),
|
||||
decrypt_shadow: None,
|
||||
}).unwrap_err(), Error::InvalidStateForRequest);
|
||||
}
|
||||
@ -1196,9 +1199,9 @@ mod tests {
|
||||
#[test]
|
||||
fn session_does_not_fail_if_rejected_node_disconnects() {
|
||||
let (_, clusters, acl_storages, sessions) = prepare_decryption_sessions();
|
||||
let key_pair = Random.generate().unwrap();
|
||||
let key_pair = Random.generate();
|
||||
|
||||
acl_storages[1].prohibit(public_to_address(key_pair.public()), SessionId::default());
|
||||
acl_storages[1].prohibit(public_to_address(key_pair.public()), SessionId::from(DUMMY_SESSION_ID));
|
||||
sessions[0].initialize(Default::default(), Default::default(), false, false).unwrap();
|
||||
|
||||
do_messages_exchange_until(&clusters, &sessions, |_, _, _| sessions[0].state() == ConsensusSessionState::WaitingForPartialResults).unwrap();
|
||||
@ -1331,8 +1334,9 @@ mod tests {
|
||||
|
||||
// we need 4 out of 5 nodes to agree to do a decryption
|
||||
// let's say that 2 of these nodes are disagree
|
||||
acl_storages[1].prohibit(public_to_address(key_pair.public()), SessionId::default());
|
||||
acl_storages[2].prohibit(public_to_address(key_pair.public()), SessionId::default());
|
||||
let document = [1u8; 32].into();
|
||||
acl_storages[1].prohibit(public_to_address(key_pair.public()), document);
|
||||
acl_storages[2].prohibit(public_to_address(key_pair.public()), document);
|
||||
|
||||
assert_eq!(do_messages_exchange(&clusters, &sessions).unwrap_err(), Error::ConsensusUnreachable);
|
||||
|
||||
@ -1347,7 +1351,7 @@ mod tests {
|
||||
|
||||
// we need 4 out of 5 nodes to agree to do a decryption
|
||||
// let's say that 1 of these nodes (master) is disagree
|
||||
acl_storages[0].prohibit(public_to_address(key_pair.public()), SessionId::default());
|
||||
acl_storages[0].prohibit(public_to_address(key_pair.public()), SessionId::from(DUMMY_SESSION_ID));
|
||||
|
||||
// now let's try to do a decryption
|
||||
sessions[0].initialize(Default::default(), Default::default(), false, false).unwrap();
|
||||
@ -1371,7 +1375,7 @@ mod tests {
|
||||
let (_, _, _, sessions) = prepare_decryption_sessions();
|
||||
assert_eq!(sessions[1].process_message(sessions[0].node(), &message::DecryptionMessage::DecryptionSessionCompleted(
|
||||
message::DecryptionSessionCompleted {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from(DUMMY_SESSION_ID).into(),
|
||||
sub_session: sessions[0].access_key().clone().into(),
|
||||
session_nonce: 10,
|
||||
}
|
||||
|
@ -952,7 +952,7 @@ pub mod tests {
|
||||
use std::sync::Arc;
|
||||
use ethereum_types::H256;
|
||||
use crypto::publickey::{Random, Generator, KeyPair, Secret};
|
||||
use key_server_cluster::{NodeId, Error, KeyStorage};
|
||||
use key_server_cluster::{NodeId, Error, KeyStorage, SessionId};
|
||||
use key_server_cluster::message::{self, Message, GenerationMessage, KeysDissemination,
|
||||
PublicKeyShare, ConfirmInitialization};
|
||||
use key_server_cluster::cluster::tests::{MessageLoop as ClusterMessageLoop, make_clusters_and_preserve_sessions};
|
||||
@ -960,6 +960,7 @@ pub mod tests {
|
||||
use key_server_cluster::generation_session::{SessionImpl, SessionState};
|
||||
use key_server_cluster::math;
|
||||
use key_server_cluster::math::tests::do_encryption_and_decryption;
|
||||
use ServerKeyId;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MessageLoop(pub ClusterMessageLoop);
|
||||
@ -970,7 +971,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
pub fn init(self, threshold: usize) -> Result<Self, Error> {
|
||||
self.0.cluster(0).client().new_generation_session(Default::default(), None, Default::default(), threshold)
|
||||
self.0.cluster(0).client().new_generation_session(SessionId::from([1u8; 32]), None, Default::default(), threshold)
|
||||
.map(|_| self)
|
||||
}
|
||||
|
||||
@ -1021,7 +1022,8 @@ pub mod tests {
|
||||
}
|
||||
|
||||
pub fn compute_key_pair(&self) -> KeyPair {
|
||||
let t = self.0.key_storage(0).get(&Default::default()).unwrap().unwrap().threshold;
|
||||
let server_key_id = ServerKeyId::from([1u8; 32]);
|
||||
let t = self.0.key_storage(0).get(&server_key_id).unwrap().unwrap().threshold;
|
||||
let secret_shares = self.nodes_secret_shares();
|
||||
let id_numbers = self.nodes_id_numbers();
|
||||
let secret_shares = secret_shares.iter().take(t + 1).collect::<Vec<_>>();
|
||||
@ -1032,7 +1034,8 @@ pub mod tests {
|
||||
}
|
||||
|
||||
pub fn key_version(&self) -> H256 {
|
||||
self.0.key_storage(0).get(&Default::default())
|
||||
let server_key_id = ServerKeyId::from([1u8; 32]);
|
||||
self.0.key_storage(0).get(&server_key_id)
|
||||
.unwrap().unwrap().versions.iter().last().unwrap().hash
|
||||
}
|
||||
}
|
||||
@ -1103,7 +1106,7 @@ pub mod tests {
|
||||
ml.0.take_and_process_message();
|
||||
ml.0.take_and_process_message();
|
||||
assert_eq!(ml.session_at(0).on_confirm_initialization(ml.0.node(1), &message::ConfirmInitialization {
|
||||
session: Default::default(),
|
||||
session: [1u8; 32].into(),
|
||||
session_nonce: 0,
|
||||
derived_point: math::generate_random_point().unwrap().into(),
|
||||
}), Err(Error::InvalidStateForRequest));
|
||||
@ -1131,7 +1134,7 @@ pub mod tests {
|
||||
let ml = MessageLoop::new(2).init(0).unwrap();
|
||||
ml.0.take_and_process_message();
|
||||
assert_eq!(ml.session_at(0).on_complete_initialization(ml.0.node(1), &message::CompleteInitialization {
|
||||
session: Default::default(),
|
||||
session: [1u8; 32].into(),
|
||||
session_nonce: 0,
|
||||
derived_point: math::generate_random_point().unwrap().into(),
|
||||
}), Err(Error::InvalidStateForRequest));
|
||||
@ -1145,7 +1148,7 @@ pub mod tests {
|
||||
ml.0.take_and_process_message();
|
||||
ml.0.take_and_process_message();
|
||||
assert_eq!(ml.session_at(1).on_complete_initialization(ml.0.node(2), &message::CompleteInitialization {
|
||||
session: Default::default(),
|
||||
session: [1u8; 32].into(),
|
||||
session_nonce: 0,
|
||||
derived_point: math::generate_random_point().unwrap().into(),
|
||||
}), Err(Error::InvalidMessage));
|
||||
@ -1155,7 +1158,7 @@ pub mod tests {
|
||||
fn fails_to_accept_keys_dissemination_if_not_waiting_for_it() {
|
||||
let ml = MessageLoop::new(2).init(0).unwrap();
|
||||
assert_eq!(ml.session_at(0).on_keys_dissemination(ml.0.node(1), &message::KeysDissemination {
|
||||
session: Default::default(),
|
||||
session: [1u8; 32].into(),
|
||||
session_nonce: 0,
|
||||
secret1: math::generate_random_scalar().unwrap().into(),
|
||||
secret2: math::generate_random_scalar().unwrap().into(),
|
||||
@ -1197,7 +1200,7 @@ pub mod tests {
|
||||
fn should_not_accept_public_key_share_when_is_not_waiting_for_it() {
|
||||
let ml = MessageLoop::new(3).init(1).unwrap();
|
||||
assert_eq!(ml.session_at(0).on_public_key_share(ml.0.node(1), &message::PublicKeyShare {
|
||||
session: Default::default(),
|
||||
session: [1u8; 32].into(),
|
||||
session_nonce: 0,
|
||||
public_share: math::generate_random_point().unwrap().into(),
|
||||
}), Err(Error::InvalidStateForRequest));
|
||||
@ -1256,7 +1259,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
// now let's encrypt some secret (which is a point on EC)
|
||||
let document_secret_plain = Random.generate().unwrap().public().clone();
|
||||
let document_secret_plain = Random.generate().public().clone();
|
||||
let all_nodes_id_numbers = ml.nodes_id_numbers();
|
||||
let all_nodes_secret_shares = ml.nodes_secret_shares();
|
||||
let document_secret_decrypted = do_encryption_and_decryption(threshold, &joint_public_key,
|
||||
@ -1275,7 +1278,7 @@ pub mod tests {
|
||||
ml.0.take_and_process_message();
|
||||
|
||||
let msg = message::GenerationMessage::KeysDissemination(message::KeysDissemination {
|
||||
session: Default::default(),
|
||||
session: [1u8; 32].into(),
|
||||
session_nonce: 10,
|
||||
secret1: math::generate_random_scalar().unwrap().into(),
|
||||
secret2: math::generate_random_scalar().unwrap().into(),
|
||||
|
@ -1075,6 +1075,9 @@ mod tests {
|
||||
use key_server_cluster::cluster::tests::{MessageLoop as ClusterMessageLoop};
|
||||
use key_server_cluster::signing_session_ecdsa::SessionImpl;
|
||||
use key_server_cluster::generation_session::tests::MessageLoop as GenerationMessageLoop;
|
||||
use ServerKeyId;
|
||||
|
||||
const DUMMY_SESSION_ID: [u8; 32] = [1u8; 32];
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MessageLoop(pub ClusterMessageLoop);
|
||||
@ -1089,21 +1092,21 @@ mod tests {
|
||||
|
||||
pub fn init_with_version(self, key_version: Option<H256>) -> Result<(Self, Public, H256), Error> {
|
||||
let message_hash = H256::random();
|
||||
let requester = Random.generate().unwrap();
|
||||
let signature = crypto::publickey::sign(requester.secret(), &SessionId::default()).unwrap();
|
||||
let requester = Random.generate();
|
||||
let signature = crypto::publickey::sign(requester.secret(), &SessionId::from(DUMMY_SESSION_ID)).unwrap();
|
||||
self.0.cluster(0).client()
|
||||
.new_ecdsa_signing_session(Default::default(), signature.into(), key_version, message_hash)
|
||||
.new_ecdsa_signing_session(SessionId::from(DUMMY_SESSION_ID), signature.into(), key_version, message_hash)
|
||||
.map(|_| (self, *requester.public(), message_hash))
|
||||
}
|
||||
|
||||
pub fn init(self) -> Result<(Self, Public, H256), Error> {
|
||||
let key_version = self.0.key_storage(0).get(&Default::default())
|
||||
let key_version = self.0.key_storage(0).get(&ServerKeyId::from(DUMMY_SESSION_ID))
|
||||
.unwrap().unwrap().versions.iter().last().unwrap().hash;
|
||||
self.init_with_version(Some(key_version))
|
||||
}
|
||||
|
||||
pub fn init_delegated(self) -> Result<(Self, Public, H256), Error> {
|
||||
self.0.key_storage(0).remove(&Default::default()).unwrap();
|
||||
self.0.key_storage(0).remove(&ServerKeyId::from(DUMMY_SESSION_ID)).unwrap();
|
||||
self.init_with_version(None)
|
||||
}
|
||||
|
||||
@ -1138,7 +1141,7 @@ mod tests {
|
||||
let (ml, _, message) = MessageLoop::new(num_nodes, threshold).unwrap().init().unwrap();
|
||||
ml.0.loop_until(|| ml.0.is_empty());
|
||||
|
||||
let signer_public = ml.0.key_storage(0).get(&Default::default()).unwrap().unwrap().public;
|
||||
let signer_public = ml.0.key_storage(0).get(&ServerKeyId::from(DUMMY_SESSION_ID)).unwrap().unwrap().public;
|
||||
let signature = ml.session_at(0).wait().unwrap();
|
||||
assert!(verify_public(&signer_public, &signature, &message).unwrap());
|
||||
}
|
||||
@ -1150,7 +1153,7 @@ mod tests {
|
||||
|
||||
// we need at least 3-of-4 nodes to agree to reach consensus
|
||||
// let's say 1 of 4 nodes disagee
|
||||
ml.0.acl_storage(1).prohibit(public_to_address(&requester), Default::default());
|
||||
ml.0.acl_storage(1).prohibit(public_to_address(&requester), ServerKeyId::from(DUMMY_SESSION_ID));
|
||||
|
||||
// then consensus reachable, but single node will disagree
|
||||
ml.ensure_completed();
|
||||
@ -1162,7 +1165,7 @@ mod tests {
|
||||
|
||||
// we need at least 3-of-4 nodes to agree to reach consensus
|
||||
// let's say 1 of 4 nodes (here: master) disagee
|
||||
ml.0.acl_storage(0).prohibit(public_to_address(&requester), Default::default());
|
||||
ml.0.acl_storage(0).prohibit(public_to_address(&requester), ServerKeyId::from(DUMMY_SESSION_ID));
|
||||
|
||||
// then consensus reachable, but single node will disagree
|
||||
ml.ensure_completed();
|
||||
|
@ -842,19 +842,21 @@ mod tests {
|
||||
}
|
||||
|
||||
pub fn into_session(&self, at_node: usize) -> SessionImpl {
|
||||
let requester = Some(Requester::Signature(crypto::publickey::sign(Random.generate().unwrap().secret(),
|
||||
&SessionId::default()).unwrap()));
|
||||
let requester = Some(Requester::Signature(
|
||||
crypto::publickey::sign(Random.generate().secret(), &SessionId::from([1u8; 32])).unwrap())
|
||||
);
|
||||
let dummy_doc = [1u8; 32].into();
|
||||
SessionImpl::new(SessionParams {
|
||||
meta: SessionMeta {
|
||||
id: SessionId::default(),
|
||||
id: SessionId::from([1u8; 32]),
|
||||
self_node_id: self.0.node(at_node),
|
||||
master_node_id: self.0.node(0),
|
||||
threshold: self.0.key_storage(at_node).get(&Default::default()).unwrap().unwrap().threshold,
|
||||
threshold: self.0.key_storage(at_node).get(&dummy_doc).unwrap().unwrap().threshold,
|
||||
configured_nodes_count: self.0.nodes().len(),
|
||||
connected_nodes_count: self.0.nodes().len(),
|
||||
},
|
||||
access_key: Random.generate().unwrap().secret().clone(),
|
||||
key_share: self.0.key_storage(at_node).get(&Default::default()).unwrap(),
|
||||
access_key: Random.generate().secret().clone(),
|
||||
key_share: self.0.key_storage(at_node).get(&dummy_doc).unwrap(),
|
||||
acl_storage: Arc::new(DummyAclStorage::default()),
|
||||
cluster: self.0.cluster(0).view().unwrap(),
|
||||
nonce: 0,
|
||||
@ -863,13 +865,14 @@ mod tests {
|
||||
|
||||
pub fn init_with_version(self, key_version: Option<H256>) -> Result<(Self, Public, H256), Error> {
|
||||
let message_hash = H256::random();
|
||||
let requester = Random.generate().unwrap();
|
||||
let signature = crypto::publickey::sign(requester.secret(), &SessionId::default()).unwrap();
|
||||
let requester = Random.generate();
|
||||
let signature = crypto::publickey::sign(requester.secret(), &SessionId::from([1u8; 32])).unwrap();
|
||||
self.0.cluster(0).client().new_schnorr_signing_session(
|
||||
Default::default(),
|
||||
SessionId::from([1u8; 32]),
|
||||
signature.into(),
|
||||
key_version,
|
||||
message_hash).map(|_| (self, *requester.public(), message_hash))
|
||||
message_hash).map(|_| (self, *requester.public(), message_hash)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn init(self) -> Result<(Self, Public, H256), Error> {
|
||||
@ -878,7 +881,8 @@ mod tests {
|
||||
}
|
||||
|
||||
pub fn init_delegated(self) -> Result<(Self, Public, H256), Error> {
|
||||
self.0.key_storage(0).remove(&Default::default()).unwrap();
|
||||
let doc = [1u8; 32].into();
|
||||
self.0.key_storage(0).remove(&doc).unwrap();
|
||||
self.init_with_version(None)
|
||||
}
|
||||
|
||||
@ -889,7 +893,8 @@ mod tests {
|
||||
|
||||
pub fn init_without_share(self) -> Result<(Self, Public, H256), Error> {
|
||||
let key_version = self.key_version();
|
||||
self.0.key_storage(0).remove(&Default::default()).unwrap();
|
||||
let doc = [1u8; 32].into();
|
||||
self.0.key_storage(0).remove(&doc).unwrap();
|
||||
self.init_with_version(Some(key_version))
|
||||
}
|
||||
|
||||
@ -903,7 +908,8 @@ mod tests {
|
||||
}
|
||||
|
||||
pub fn key_version(&self) -> H256 {
|
||||
self.0.key_storage(0).get(&Default::default())
|
||||
let doc = [1u8; 32].into();
|
||||
self.0.key_storage(0).get(&doc)
|
||||
.unwrap().unwrap().versions.iter().last().unwrap().hash
|
||||
}
|
||||
}
|
||||
@ -915,7 +921,8 @@ mod tests {
|
||||
let (ml, _, message) = MessageLoop::new(num_nodes, threshold).unwrap().init().unwrap();
|
||||
ml.0.loop_until(|| ml.0.is_empty());
|
||||
|
||||
let signer_public = ml.0.key_storage(0).get(&Default::default()).unwrap().unwrap().public;
|
||||
let doc = [1u8; 32].into();
|
||||
let signer_public = ml.0.key_storage(0).get(&doc).unwrap().unwrap().public;
|
||||
let signature = ml.session_at(0).wait().unwrap();
|
||||
assert!(math::verify_schnorr_signature(&signer_public, &signature, &message).unwrap());
|
||||
}
|
||||
@ -971,7 +978,7 @@ mod tests {
|
||||
let ml = MessageLoop::new(3, 1).unwrap();
|
||||
let session = ml.into_session(0);
|
||||
assert_eq!(session.on_consensus_message(&ml.0.node(1), &SchnorrSigningConsensusMessage {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from([1u8; 32]).into(),
|
||||
sub_session: session.core.access_key.clone().into(),
|
||||
session_nonce: 0,
|
||||
message: ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization {
|
||||
@ -985,11 +992,11 @@ mod tests {
|
||||
let ml = MessageLoop::new(3, 1).unwrap();
|
||||
let session = ml.into_session(0);
|
||||
assert_eq!(session.on_generation_message(&ml.0.node(1), &SchnorrSigningGenerationMessage {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from([1u8; 32]).into(),
|
||||
sub_session: session.core.access_key.clone().into(),
|
||||
session_nonce: 0,
|
||||
message: GenerationMessage::ConfirmInitialization(ConfirmInitialization {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from([1u8; 32]).into(),
|
||||
session_nonce: 0,
|
||||
derived_point: Public::default().into(),
|
||||
}),
|
||||
@ -1006,11 +1013,11 @@ mod tests {
|
||||
let slave1_session = ml.session_at(1);
|
||||
|
||||
assert_eq!(slave1_session.on_generation_message(&slave2_id, &SchnorrSigningGenerationMessage {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from([1u8; 32]).into(),
|
||||
sub_session: session.core.access_key.clone().into(),
|
||||
session_nonce: 0,
|
||||
message: GenerationMessage::InitializeSession(InitializeSession {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from([1u8; 32]).into(),
|
||||
session_nonce: 0,
|
||||
origin: None,
|
||||
author: Address::zero().into(),
|
||||
@ -1027,7 +1034,7 @@ mod tests {
|
||||
let ml = MessageLoop::new(3, 1).unwrap();
|
||||
let session = ml.into_session(1);
|
||||
assert_eq!(session.on_partial_signature_requested(&ml.0.node(0), &SchnorrRequestPartialSignature {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from([1u8; 32]).into(),
|
||||
sub_session: session.core.access_key.clone().into(),
|
||||
session_nonce: 0,
|
||||
request_id: Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap().into(),
|
||||
@ -1041,7 +1048,7 @@ mod tests {
|
||||
let ml = MessageLoop::new(3, 1).unwrap();
|
||||
let session = ml.into_session(0);
|
||||
assert_eq!(session.on_partial_signature_requested(&ml.0.node(1), &SchnorrRequestPartialSignature {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from([1u8; 32]).into(),
|
||||
sub_session: session.core.access_key.clone().into(),
|
||||
session_nonce: 0,
|
||||
request_id: Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap().into(),
|
||||
@ -1056,8 +1063,8 @@ mod tests {
|
||||
|
||||
// we need at least 2-of-3 nodes to agree to reach consensus
|
||||
// let's say 2 of 3 nodes disagee
|
||||
ml.0.acl_storage(1).prohibit(public_to_address(&requester), SessionId::default());
|
||||
ml.0.acl_storage(2).prohibit(public_to_address(&requester), SessionId::default());
|
||||
ml.0.acl_storage(1).prohibit(public_to_address(&requester), SessionId::from([1u8; 32]));
|
||||
ml.0.acl_storage(2).prohibit(public_to_address(&requester), SessionId::from([1u8; 32]));
|
||||
|
||||
// then consensus is unreachable
|
||||
ml.0.loop_until(|| ml.0.is_empty());
|
||||
@ -1069,8 +1076,8 @@ mod tests {
|
||||
let (ml, requester, _) = MessageLoop::new(3, 1).unwrap().init().unwrap();
|
||||
|
||||
// we need at least 2-of-3 nodes to agree to reach consensus
|
||||
// let's say 1 of 3 nodes disagee
|
||||
ml.0.acl_storage(1).prohibit(public_to_address(&requester), SessionId::default());
|
||||
// let's say 1 of 3 nodes disagree
|
||||
ml.0.acl_storage(1).prohibit(public_to_address(&requester), SessionId::from([1u8; 32]));
|
||||
|
||||
// then consensus reachable, but single node will disagree
|
||||
ml.ensure_completed();
|
||||
@ -1081,8 +1088,8 @@ mod tests {
|
||||
let (ml, requester, _) = MessageLoop::new(3, 1).unwrap().init().unwrap();
|
||||
|
||||
// we need at least 2-of-3 nodes to agree to reach consensus
|
||||
// let's say 1 of 3 nodes disagee
|
||||
ml.0.acl_storage(0).prohibit(public_to_address(&requester), SessionId::default());
|
||||
// let's say 1 of 3 nodes disagree
|
||||
ml.0.acl_storage(0).prohibit(public_to_address(&requester), SessionId::from([1u8; 32]));
|
||||
|
||||
// then consensus reachable, but single node will disagree
|
||||
ml.ensure_completed();
|
||||
@ -1093,11 +1100,11 @@ mod tests {
|
||||
let ml = MessageLoop::new(3, 1).unwrap();
|
||||
let session = ml.into_session(1);
|
||||
let msg = SchnorrSigningMessage::SchnorrSigningGenerationMessage(SchnorrSigningGenerationMessage {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from([1u8; 32]).into(),
|
||||
sub_session: session.core.access_key.clone().into(),
|
||||
session_nonce: 10,
|
||||
message: GenerationMessage::ConfirmInitialization(ConfirmInitialization {
|
||||
session: SessionId::default().into(),
|
||||
session: SessionId::from([1u8; 32]).into(),
|
||||
session_nonce: 0,
|
||||
derived_point: Public::default().into(),
|
||||
}),
|
||||
|
@ -374,7 +374,7 @@ impl<C: ConnectionManager> ClusterClientImpl<C> {
|
||||
let mut connected_nodes = self.data.connections.provider().connected_nodes()?;
|
||||
connected_nodes.insert(self.data.self_key_pair.public().clone());
|
||||
|
||||
let access_key = Random.generate()?.secret().clone();
|
||||
let access_key = Random.generate().secret().clone();
|
||||
let session_id = SessionIdWithSubSession::new(session_id, access_key);
|
||||
let cluster = create_cluster_view(self.data.self_key_pair.clone(), self.data.connections.provider(), false)?;
|
||||
let session = self.data.sessions.negotiation_sessions.insert(cluster, self.data.self_key_pair.public().clone(), session_id.clone(), None, false, None)?;
|
||||
@ -435,7 +435,7 @@ impl<C: ConnectionManager> ClusterClient for ClusterClientImpl<C> {
|
||||
let mut connected_nodes = self.data.connections.provider().connected_nodes()?;
|
||||
connected_nodes.insert(self.data.self_key_pair.public().clone());
|
||||
|
||||
let access_key = Random.generate()?.secret().clone();
|
||||
let access_key = Random.generate().secret().clone();
|
||||
let session_id = SessionIdWithSubSession::new(session_id, access_key);
|
||||
let cluster = create_cluster_view(self.data.self_key_pair.clone(), self.data.connections.provider(), false)?;
|
||||
let session = self.data.sessions.decryption_sessions.insert(cluster, self.data.self_key_pair.public().clone(),
|
||||
@ -473,7 +473,7 @@ impl<C: ConnectionManager> ClusterClient for ClusterClientImpl<C> {
|
||||
let mut connected_nodes = self.data.connections.provider().connected_nodes()?;
|
||||
connected_nodes.insert(self.data.self_key_pair.public().clone());
|
||||
|
||||
let access_key = Random.generate()?.secret().clone();
|
||||
let access_key = Random.generate().secret().clone();
|
||||
let session_id = SessionIdWithSubSession::new(session_id, access_key);
|
||||
let cluster = create_cluster_view(self.data.self_key_pair.clone(), self.data.connections.provider(), false)?;
|
||||
let session = self.data.sessions.schnorr_signing_sessions.insert(cluster, self.data.self_key_pair.public().clone(), session_id.clone(), None, false, Some(requester))?;
|
||||
@ -505,7 +505,7 @@ impl<C: ConnectionManager> ClusterClient for ClusterClientImpl<C> {
|
||||
let mut connected_nodes = self.data.connections.provider().connected_nodes()?;
|
||||
connected_nodes.insert(self.data.self_key_pair.public().clone());
|
||||
|
||||
let access_key = Random.generate()?.secret().clone();
|
||||
let access_key = Random.generate().secret().clone();
|
||||
let session_id = SessionIdWithSubSession::new(session_id, access_key);
|
||||
let cluster = create_cluster_view(self.data.self_key_pair.clone(), self.data.connections.provider(), false)?;
|
||||
let session = self.data.sessions.ecdsa_signing_sessions.insert(cluster, self.data.self_key_pair.public().clone(), session_id.clone(), None, false, Some(requester))?;
|
||||
@ -1002,7 +1002,7 @@ pub mod tests {
|
||||
let ports_begin = 0;
|
||||
let messages = Arc::new(Mutex::new(VecDeque::new()));
|
||||
let key_pairs: Vec<_> = (0..num_nodes)
|
||||
.map(|_| Arc::new(PlainNodeKeyPair::new(Random.generate().unwrap()))).collect();
|
||||
.map(|_| Arc::new(PlainNodeKeyPair::new(Random.generate()))).collect();
|
||||
let key_storages: Vec<_> = (0..num_nodes).map(|_| Arc::new(DummyKeyStorage::default())).collect();
|
||||
let acl_storages: Vec<_> = (0..num_nodes).map(|_| Arc::new(DummyAclStorage::default())).collect();
|
||||
let cluster_params: Vec<_> = (0..num_nodes).map(|i| ClusterConfiguration {
|
||||
@ -1032,7 +1032,7 @@ pub mod tests {
|
||||
fn cluster_wont_start_generation_session_if_not_fully_connected() {
|
||||
let ml = make_clusters(3);
|
||||
ml.cluster(0).data.connections.disconnect(*ml.cluster(0).data.self_key_pair.public());
|
||||
match ml.cluster(0).client().new_generation_session(SessionId::default(), Default::default(), Default::default(), 1) {
|
||||
match ml.cluster(0).client().new_generation_session(SessionId::from([1u8; 32]), Default::default(), Default::default(), 1) {
|
||||
Err(Error::NodeDisconnected) => (),
|
||||
Err(e) => panic!("unexpected error {:?}", e),
|
||||
_ => panic!("unexpected success"),
|
||||
@ -1049,18 +1049,18 @@ pub mod tests {
|
||||
|
||||
// start && wait for generation session to fail
|
||||
let session = ml.cluster(0).client()
|
||||
.new_generation_session(SessionId::default(), Default::default(), Default::default(), 1).unwrap().session;
|
||||
.new_generation_session(SessionId::from([1u8; 32]), Default::default(), Default::default(), 1).unwrap().session;
|
||||
ml.loop_until(|| session.joint_public_and_secret().is_some()
|
||||
&& ml.cluster(0).client().generation_session(&SessionId::default()).is_none());
|
||||
&& ml.cluster(0).client().generation_session(&SessionId::from([1u8; 32])).is_none());
|
||||
assert!(session.joint_public_and_secret().unwrap().is_err());
|
||||
|
||||
// check that faulty session is either removed from all nodes, or nonexistent (already removed)
|
||||
for i in 1..3 {
|
||||
if let Some(session) = ml.cluster(i).client().generation_session(&SessionId::default()) {
|
||||
if let Some(session) = ml.cluster(i).client().generation_session(&SessionId::from([1u8; 32])) {
|
||||
// wait for both session completion && session removal (session completion event is fired
|
||||
// before session is removed from its own container by cluster)
|
||||
ml.loop_until(|| session.joint_public_and_secret().is_some()
|
||||
&& ml.cluster(i).client().generation_session(&SessionId::default()).is_none());
|
||||
&& ml.cluster(i).client().generation_session(&SessionId::from([1u8; 32])).is_none());
|
||||
assert!(session.joint_public_and_secret().unwrap().is_err());
|
||||
}
|
||||
}
|
||||
@ -1076,19 +1076,19 @@ pub mod tests {
|
||||
|
||||
// start && wait for generation session to fail
|
||||
let session = ml.cluster(0).client()
|
||||
.new_generation_session(SessionId::default(), Default::default(), Default::default(), 1).unwrap().session;
|
||||
.new_generation_session(SessionId::from([1u8; 32]), Default::default(), Default::default(), 1).unwrap().session;
|
||||
ml.loop_until(|| session.joint_public_and_secret().is_some()
|
||||
&& ml.cluster(0).client().generation_session(&SessionId::default()).is_none());
|
||||
&& ml.cluster(0).client().generation_session(&SessionId::from([1u8; 32])).is_none());
|
||||
assert!(session.joint_public_and_secret().unwrap().is_err());
|
||||
|
||||
// check that faulty session is either removed from all nodes, or nonexistent (already removed)
|
||||
for i in 1..3 {
|
||||
if let Some(session) = ml.cluster(i).client().generation_session(&SessionId::default()) {
|
||||
if let Some(session) = ml.cluster(i).client().generation_session(&SessionId::from([1u8; 32])) {
|
||||
let session = session.clone();
|
||||
// wait for both session completion && session removal (session completion event is fired
|
||||
// before session is removed from its own container by cluster)
|
||||
ml.loop_until(|| session.joint_public_and_secret().is_some()
|
||||
&& ml.cluster(i).client().generation_session(&SessionId::default()).is_none());
|
||||
&& ml.cluster(i).client().generation_session(&SessionId::from([1u8; 32])).is_none());
|
||||
assert!(session.joint_public_and_secret().unwrap().is_err());
|
||||
}
|
||||
}
|
||||
@ -1101,22 +1101,22 @@ pub mod tests {
|
||||
|
||||
// start && wait for generation session to complete
|
||||
let session = ml.cluster(0).client()
|
||||
.new_generation_session(SessionId::default(), Default::default(), Default::default(), 1).unwrap().session;
|
||||
.new_generation_session(SessionId::from([1u8; 32]), Default::default(), Default::default(), 1).unwrap().session;
|
||||
ml.loop_until(|| (session.state() == GenerationSessionState::Finished
|
||||
|| session.state() == GenerationSessionState::Failed)
|
||||
&& ml.cluster(0).client().generation_session(&SessionId::default()).is_none());
|
||||
&& ml.cluster(0).client().generation_session(&SessionId::from([1u8; 32])).is_none());
|
||||
assert!(session.joint_public_and_secret().unwrap().is_ok());
|
||||
|
||||
// check that on non-master nodes session is either:
|
||||
// already removed
|
||||
// or it is removed right after completion
|
||||
for i in 1..3 {
|
||||
if let Some(session) = ml.cluster(i).client().generation_session(&SessionId::default()) {
|
||||
if let Some(session) = ml.cluster(i).client().generation_session(&SessionId::from([1u8; 32])) {
|
||||
// run to completion if completion message is still on the way
|
||||
// AND check that it is actually removed from cluster sessions
|
||||
ml.loop_until(|| (session.state() == GenerationSessionState::Finished
|
||||
|| session.state() == GenerationSessionState::Failed)
|
||||
&& ml.cluster(i).client().generation_session(&SessionId::default()).is_none());
|
||||
&& ml.cluster(i).client().generation_session(&SessionId::from([1u8; 32])).is_none());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1130,12 +1130,12 @@ pub mod tests {
|
||||
{
|
||||
// try to start generation session => fail in initialization
|
||||
assert_eq!(
|
||||
client.new_generation_session(SessionId::default(), None, Default::default(), 100).map(|_| ()),
|
||||
client.new_generation_session(SessionId::from([1u8; 32]), None, Default::default(), 100).map(|_| ()),
|
||||
Err(Error::NotEnoughNodesForThreshold));
|
||||
|
||||
// try to start generation session => fails in initialization
|
||||
assert_eq!(
|
||||
client.new_generation_session(SessionId::default(), None, Default::default(), 100).map(|_| ()),
|
||||
client.new_generation_session(SessionId::from([1u8; 32]), None, Default::default(), 100).map(|_| ()),
|
||||
Err(Error::NotEnoughNodesForThreshold));
|
||||
|
||||
assert!(ml.cluster(0).data.sessions.generation_sessions.is_empty());
|
||||
@ -1166,23 +1166,25 @@ pub mod tests {
|
||||
fn schnorr_signing_session_completes_if_node_does_not_have_a_share() {
|
||||
let _ = ::env_logger::try_init();
|
||||
let ml = make_clusters(3);
|
||||
let dummy_session_id = SessionId::from([1u8; 32]);
|
||||
|
||||
// start && wait for generation session to complete
|
||||
let session = ml.cluster(0).client().
|
||||
new_generation_session(SessionId::default(), Default::default(), Default::default(), 1).unwrap().session;
|
||||
new_generation_session(dummy_session_id, Default::default(), Default::default(), 1).unwrap().session;
|
||||
ml.loop_until(|| (session.state() == GenerationSessionState::Finished
|
||||
|| session.state() == GenerationSessionState::Failed)
|
||||
&& ml.cluster(0).client().generation_session(&SessionId::default()).is_none());
|
||||
&& ml.cluster(0).client().generation_session(&dummy_session_id).is_none());
|
||||
assert!(session.joint_public_and_secret().unwrap().is_ok());
|
||||
|
||||
// now remove share from node2
|
||||
assert!((0..3).all(|i| ml.cluster(i).data.sessions.generation_sessions.is_empty()));
|
||||
ml.cluster(2).data.config.key_storage.remove(&Default::default()).unwrap();
|
||||
ml.cluster(2).data.config.key_storage.remove(&dummy_session_id).unwrap();
|
||||
|
||||
// and try to sign message with generated key
|
||||
let signature = sign(Random.generate().unwrap().secret(), &Default::default()).unwrap();
|
||||
let dummy_message = [1u8; 32].into();
|
||||
let signature = sign(Random.generate().secret(), &dummy_message).unwrap();
|
||||
let session0 = ml.cluster(0).client()
|
||||
.new_schnorr_signing_session(Default::default(), signature.into(), None, Default::default()).unwrap();
|
||||
.new_schnorr_signing_session(dummy_session_id, signature.into(), None, Default::default()).unwrap();
|
||||
let session = ml.cluster(0).data.sessions.schnorr_signing_sessions.first().unwrap();
|
||||
|
||||
ml.loop_until(|| session.is_finished() && (0..3).all(|i|
|
||||
@ -1190,9 +1192,9 @@ pub mod tests {
|
||||
session0.into_wait_future().wait().unwrap();
|
||||
|
||||
// and try to sign message with generated key using node that has no key share
|
||||
let signature = sign(Random.generate().unwrap().secret(), &Default::default()).unwrap();
|
||||
let signature = sign(Random.generate().secret(), &dummy_message).unwrap();
|
||||
let session2 = ml.cluster(2).client()
|
||||
.new_schnorr_signing_session(Default::default(), signature.into(), None, Default::default()).unwrap();
|
||||
.new_schnorr_signing_session(dummy_session_id, signature.into(), None, Default::default()).unwrap();
|
||||
let session = ml.cluster(2).data.sessions.schnorr_signing_sessions.first().unwrap();
|
||||
|
||||
ml.loop_until(|| session.is_finished() && (0..3).all(|i|
|
||||
@ -1200,12 +1202,12 @@ pub mod tests {
|
||||
session2.into_wait_future().wait().unwrap();
|
||||
|
||||
// now remove share from node1
|
||||
ml.cluster(1).data.config.key_storage.remove(&Default::default()).unwrap();
|
||||
ml.cluster(1).data.config.key_storage.remove(&dummy_session_id).unwrap();
|
||||
|
||||
// and try to sign message with generated key
|
||||
let signature = sign(Random.generate().unwrap().secret(), &Default::default()).unwrap();
|
||||
let signature = sign(Random.generate().secret(), &dummy_message).unwrap();
|
||||
let session1 = ml.cluster(0).client()
|
||||
.new_schnorr_signing_session(Default::default(), signature.into(), None, Default::default()).unwrap();
|
||||
.new_schnorr_signing_session(dummy_session_id, signature.into(), None, Default::default()).unwrap();
|
||||
let session = ml.cluster(0).data.sessions.schnorr_signing_sessions.first().unwrap();
|
||||
|
||||
ml.loop_until(|| session.is_finished());
|
||||
@ -1216,23 +1218,25 @@ pub mod tests {
|
||||
fn ecdsa_signing_session_completes_if_node_does_not_have_a_share() {
|
||||
let _ = ::env_logger::try_init();
|
||||
let ml = make_clusters(4);
|
||||
let dummy_session_id = SessionId::from([1u8; 32]);
|
||||
|
||||
// start && wait for generation session to complete
|
||||
let session = ml.cluster(0).client()
|
||||
.new_generation_session(SessionId::default(), Default::default(), Default::default(), 1).unwrap().session;
|
||||
.new_generation_session(dummy_session_id, Default::default(), Default::default(), 1).unwrap().session;
|
||||
ml.loop_until(|| (session.state() == GenerationSessionState::Finished
|
||||
|| session.state() == GenerationSessionState::Failed)
|
||||
&& ml.cluster(0).client().generation_session(&SessionId::default()).is_none());
|
||||
&& ml.cluster(0).client().generation_session(&dummy_session_id).is_none());
|
||||
assert!(session.joint_public_and_secret().unwrap().is_ok());
|
||||
|
||||
// now remove share from node2
|
||||
assert!((0..3).all(|i| ml.cluster(i).data.sessions.generation_sessions.is_empty()));
|
||||
ml.cluster(2).data.config.key_storage.remove(&Default::default()).unwrap();
|
||||
ml.cluster(2).data.config.key_storage.remove(&dummy_session_id).unwrap();
|
||||
|
||||
// and try to sign message with generated key
|
||||
let signature = sign(Random.generate().unwrap().secret(), &Default::default()).unwrap();
|
||||
let dummy_message = [1u8; 32].into();
|
||||
let signature = sign(Random.generate().secret(), &dummy_message).unwrap();
|
||||
let session0 = ml.cluster(0).client()
|
||||
.new_ecdsa_signing_session(Default::default(), signature.into(), None, H256::random()).unwrap();
|
||||
.new_ecdsa_signing_session(dummy_session_id, signature.into(), None, H256::random()).unwrap();
|
||||
let session = ml.cluster(0).data.sessions.ecdsa_signing_sessions.first().unwrap();
|
||||
|
||||
ml.loop_until(|| session.is_finished() && (0..3).all(|i|
|
||||
@ -1240,21 +1244,21 @@ pub mod tests {
|
||||
session0.into_wait_future().wait().unwrap();
|
||||
|
||||
// and try to sign message with generated key using node that has no key share
|
||||
let signature = sign(Random.generate().unwrap().secret(), &Default::default()).unwrap();
|
||||
let signature = sign(Random.generate().secret(), &dummy_message).unwrap();
|
||||
let session2 = ml.cluster(2).client()
|
||||
.new_ecdsa_signing_session(Default::default(), signature.into(), None, H256::random()).unwrap();
|
||||
.new_ecdsa_signing_session(dummy_session_id, signature.into(), None, H256::random()).unwrap();
|
||||
let session = ml.cluster(2).data.sessions.ecdsa_signing_sessions.first().unwrap();
|
||||
ml.loop_until(|| session.is_finished() && (0..3).all(|i|
|
||||
ml.cluster(i).data.sessions.ecdsa_signing_sessions.is_empty()));
|
||||
session2.into_wait_future().wait().unwrap();
|
||||
|
||||
// now remove share from node1
|
||||
ml.cluster(1).data.config.key_storage.remove(&Default::default()).unwrap();
|
||||
ml.cluster(1).data.config.key_storage.remove(&dummy_session_id).unwrap();
|
||||
|
||||
// and try to sign message with generated key
|
||||
let signature = sign(Random.generate().unwrap().secret(), &Default::default()).unwrap();
|
||||
let signature = sign(Random.generate().secret(), &dummy_message).unwrap();
|
||||
let session1 = ml.cluster(0).client()
|
||||
.new_ecdsa_signing_session(Default::default(), signature.into(), None, H256::random()).unwrap();
|
||||
.new_ecdsa_signing_session(dummy_session_id, signature.into(), None, H256::random()).unwrap();
|
||||
let session = ml.cluster(0).data.sessions.ecdsa_signing_sessions.first().unwrap();
|
||||
ml.loop_until(|| session.is_finished());
|
||||
session1.into_wait_future().wait().unwrap_err();
|
||||
|
@ -679,17 +679,17 @@ mod tests {
|
||||
ClusterSessionsContainerState, SESSION_TIMEOUT_INTERVAL};
|
||||
|
||||
pub fn make_cluster_sessions() -> ClusterSessions {
|
||||
let key_pair = Random.generate().unwrap();
|
||||
let key_pair = Random.generate();
|
||||
let config = ClusterConfiguration {
|
||||
self_key_pair: Arc::new(PlainNodeKeyPair::new(key_pair.clone())),
|
||||
key_server_set: Arc::new(MapKeyServerSet::new(false, vec![(key_pair.public().clone(), format!("127.0.0.1:{}", 100).parse().unwrap())].into_iter().collect())),
|
||||
key_storage: Arc::new(DummyKeyStorage::default()),
|
||||
acl_storage: Arc::new(DummyAclStorage::default()),
|
||||
admin_public: Some(Random.generate().unwrap().public().clone()),
|
||||
admin_public: Some(Random.generate().public().clone()),
|
||||
preserve_sessions: false,
|
||||
};
|
||||
ClusterSessions::new(&config, Arc::new(SimpleServersSetChangeSessionCreatorConnector {
|
||||
admin_public: Some(Random.generate().unwrap().public().clone()),
|
||||
admin_public: Some(Random.generate().public().clone()),
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -231,13 +231,13 @@ mod tests {
|
||||
|
||||
fn create_connections() -> TriggerConnections {
|
||||
TriggerConnections {
|
||||
self_key_pair: Arc::new(PlainNodeKeyPair::new(Random.generate().unwrap())),
|
||||
self_key_pair: Arc::new(PlainNodeKeyPair::new(Random.generate())),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn do_not_disconnect_if_set_is_not_changed() {
|
||||
let node_id = Random.generate().unwrap().public().clone();
|
||||
let node_id = Random.generate().public().clone();
|
||||
assert_eq!(select_nodes_to_disconnect(
|
||||
&vec![(node_id, "127.0.0.1:8081".parse().unwrap())].into_iter().collect(),
|
||||
&vec![(node_id, "127.0.0.1:8081".parse().unwrap())].into_iter().collect()),
|
||||
@ -246,7 +246,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn disconnect_if_address_has_changed() {
|
||||
let node_id = Random.generate().unwrap().public().clone();
|
||||
let node_id = Random.generate().public().clone();
|
||||
assert_eq!(select_nodes_to_disconnect(
|
||||
&vec![(node_id.clone(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(),
|
||||
&vec![(node_id.clone(), "127.0.0.1:8082".parse().unwrap())].into_iter().collect()),
|
||||
@ -255,7 +255,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn disconnect_if_node_has_removed() {
|
||||
let node_id = Random.generate().unwrap().public().clone();
|
||||
let node_id = Random.generate().public().clone();
|
||||
assert_eq!(select_nodes_to_disconnect(
|
||||
&vec![(node_id.clone(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(),
|
||||
&vec![].into_iter().collect()),
|
||||
@ -264,19 +264,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn does_not_disconnect_if_node_has_added() {
|
||||
let node_id = Random.generate().unwrap().public().clone();
|
||||
let node_id = Random.generate().public().clone();
|
||||
assert_eq!(select_nodes_to_disconnect(
|
||||
&vec![(node_id.clone(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(),
|
||||
&vec![(node_id.clone(), "127.0.0.1:8081".parse().unwrap()),
|
||||
(Random.generate().unwrap().public().clone(), "127.0.0.1:8082".parse().unwrap())]
|
||||
(Random.generate().public().clone(), "127.0.0.1:8082".parse().unwrap())]
|
||||
.into_iter().collect()),
|
||||
vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adjust_connections_disconnects_from_all_nodes_if_not_a_part_of_key_server() {
|
||||
let self_node_id = Random.generate().unwrap().public().clone();
|
||||
let other_node_id = Random.generate().unwrap().public().clone();
|
||||
let self_node_id = Random.generate().public().clone();
|
||||
let other_node_id = Random.generate().public().clone();
|
||||
let mut connection_data = default_connection_data();
|
||||
connection_data.nodes.insert(other_node_id.clone(), "127.0.0.1:8081".parse().unwrap());
|
||||
|
||||
@ -288,8 +288,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn adjust_connections_connects_to_new_nodes() {
|
||||
let self_node_id = Random.generate().unwrap().public().clone();
|
||||
let other_node_id = Random.generate().unwrap().public().clone();
|
||||
let self_node_id = Random.generate().public().clone();
|
||||
let other_node_id = Random.generate().public().clone();
|
||||
let mut connection_data = default_connection_data();
|
||||
|
||||
let required_set = vec![(self_node_id.clone(), "127.0.0.1:8081".parse().unwrap()),
|
||||
@ -301,8 +301,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn adjust_connections_reconnects_from_changed_nodes() {
|
||||
let self_node_id = Random.generate().unwrap().public().clone();
|
||||
let other_node_id = Random.generate().unwrap().public().clone();
|
||||
let self_node_id = Random.generate().public().clone();
|
||||
let other_node_id = Random.generate().public().clone();
|
||||
let mut connection_data = default_connection_data();
|
||||
connection_data.nodes.insert(other_node_id.clone(), "127.0.0.1:8082".parse().unwrap());
|
||||
|
||||
@ -315,8 +315,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn adjust_connections_disconnects_from_removed_nodes() {
|
||||
let self_node_id = Random.generate().unwrap().public().clone();
|
||||
let other_node_id = Random.generate().unwrap().public().clone();
|
||||
let self_node_id = Random.generate().public().clone();
|
||||
let other_node_id = Random.generate().public().clone();
|
||||
let mut connection_data = default_connection_data();
|
||||
connection_data.nodes.insert(other_node_id.clone(), "127.0.0.1:8082".parse().unwrap());
|
||||
|
||||
@ -328,7 +328,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn adjust_connections_does_not_connects_to_self() {
|
||||
let self_node_id = Random.generate().unwrap().public().clone();
|
||||
let self_node_id = Random.generate().public().clone();
|
||||
let mut connection_data = default_connection_data();
|
||||
|
||||
let required_set = vec![(self_node_id.clone(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect();
|
||||
@ -341,9 +341,9 @@ mod tests {
|
||||
fn maintain_connects_to_current_set_works() {
|
||||
let connections = create_connections();
|
||||
let self_node_id = connections.self_key_pair.public().clone();
|
||||
let current_node_id = Random.generate().unwrap().public().clone();
|
||||
let migration_node_id = Random.generate().unwrap().public().clone();
|
||||
let new_node_id = Random.generate().unwrap().public().clone();
|
||||
let current_node_id = Random.generate().public().clone();
|
||||
let migration_node_id = Random.generate().public().clone();
|
||||
let new_node_id = Random.generate().public().clone();
|
||||
|
||||
let mut connections_data = default_connection_data();
|
||||
connections.maintain(ConnectionsAction::ConnectToCurrentSet, &mut connections_data, &KeyServerSetSnapshot {
|
||||
@ -363,9 +363,9 @@ mod tests {
|
||||
fn maintain_connects_to_migration_set_works() {
|
||||
let connections = create_connections();
|
||||
let self_node_id = connections.self_key_pair.public().clone();
|
||||
let current_node_id = Random.generate().unwrap().public().clone();
|
||||
let migration_node_id = Random.generate().unwrap().public().clone();
|
||||
let new_node_id = Random.generate().unwrap().public().clone();
|
||||
let current_node_id = Random.generate().public().clone();
|
||||
let migration_node_id = Random.generate().public().clone();
|
||||
let new_node_id = Random.generate().public().clone();
|
||||
|
||||
let mut connections_data = default_connection_data();
|
||||
connections.maintain(ConnectionsAction::ConnectToMigrationSet, &mut connections_data, &KeyServerSetSnapshot {
|
||||
@ -385,7 +385,7 @@ mod tests {
|
||||
#[test]
|
||||
fn simple_connections_trigger_only_maintains_connections() {
|
||||
let key_server_set = Arc::new(MapKeyServerSet::new(false, Default::default()));
|
||||
let self_key_pair = Arc::new(PlainNodeKeyPair::new(Random.generate().unwrap()));
|
||||
let self_key_pair = Arc::new(PlainNodeKeyPair::new(Random.generate()));
|
||||
let mut trigger = SimpleConnectionTrigger::new(key_server_set, self_key_pair, None);
|
||||
assert_eq!(trigger.on_maintain(), Some(Maintain::Connections));
|
||||
}
|
||||
|
@ -48,9 +48,11 @@ use key_server_cluster::io::{write_message, write_encrypted_message, WriteMessag
|
||||
|
||||
/// Start handshake procedure with another node from the cluster.
|
||||
pub fn handshake<A>(a: A, self_key_pair: Arc<dyn SigningKeyPair>, trusted_nodes: BTreeSet<NodeId>) -> Handshake<A> where A: AsyncWrite + AsyncRead {
|
||||
let init_data = Random.generate().map(|kp| *kp.secret().clone()).map_err(Into::into)
|
||||
.and_then(|cp| Random.generate().map(|kp| (cp, kp)).map_err(Into::into));
|
||||
handshake_with_init_data(a, init_data, self_key_pair, trusted_nodes)
|
||||
let init_data = (
|
||||
*Random.generate().secret().clone(),
|
||||
Random.generate()
|
||||
);
|
||||
handshake_with_init_data(a, Ok(init_data), self_key_pair, trusted_nodes)
|
||||
}
|
||||
|
||||
/// Start handshake procedure with another node from the cluster and given plain confirmation + session key pair.
|
||||
@ -81,22 +83,16 @@ pub fn handshake_with_init_data<A>(a: A, init_data: Result<(H256, KeyPair), Erro
|
||||
|
||||
/// Wait for handshake procedure to be started by another node from the cluster.
|
||||
pub fn accept_handshake<A>(a: A, self_key_pair: Arc<dyn SigningKeyPair>) -> Handshake<A> where A: AsyncWrite + AsyncRead {
|
||||
let self_confirmation_plain = Random.generate().map(|kp| *kp.secret().clone()).map_err(Into::into);
|
||||
let handshake_input_data = self_confirmation_plain
|
||||
.and_then(|cp| Random.generate().map(|kp| (cp, kp)).map_err(Into::into));
|
||||
|
||||
let (error, cp, kp, state) = match handshake_input_data {
|
||||
Ok((cp, kp)) => (None, cp, Some(kp), HandshakeState::ReceivePublicKey(read_message(a))),
|
||||
Err(err) => (Some((a, Err(err))), Default::default(), None, HandshakeState::Finished),
|
||||
};
|
||||
let self_confirmation_plain = *Random.generate().secret().clone();
|
||||
let keypair = Random.generate();
|
||||
|
||||
Handshake {
|
||||
is_active: false,
|
||||
error: error,
|
||||
state: state,
|
||||
self_key_pair: self_key_pair,
|
||||
self_session_key_pair: kp,
|
||||
self_confirmation_plain: cp,
|
||||
error: None,
|
||||
state: HandshakeState::ReceivePublicKey(read_message(a)),
|
||||
self_key_pair,
|
||||
self_session_key_pair: Some(keypair),
|
||||
self_confirmation_plain,
|
||||
trusted_nodes: None,
|
||||
peer_node_id: None,
|
||||
peer_session_public: None,
|
||||
@ -328,8 +324,8 @@ mod tests {
|
||||
fn prepare_test_io() -> (H256, TestIo) {
|
||||
let mut io = TestIo::new();
|
||||
|
||||
let self_confirmation_plain = *Random.generate().unwrap().secret().clone();
|
||||
let peer_confirmation_plain = *Random.generate().unwrap().secret().clone();
|
||||
let self_confirmation_plain = *Random.generate().secret().clone();
|
||||
let peer_confirmation_plain = *Random.generate().secret().clone();
|
||||
|
||||
let self_confirmation_signed = sign(io.peer_key_pair().secret(), &self_confirmation_plain).unwrap();
|
||||
let peer_confirmation_signed = sign(io.peer_session_key_pair().secret(), &peer_confirmation_plain).unwrap();
|
||||
|
@ -323,10 +323,10 @@ pub mod tests {
|
||||
|
||||
impl TestIo {
|
||||
pub fn new() -> Self {
|
||||
let self_session_key_pair = Random.generate().unwrap();
|
||||
let peer_session_key_pair = Random.generate().unwrap();
|
||||
let self_key_pair = Random.generate().unwrap();
|
||||
let peer_key_pair = Random.generate().unwrap();
|
||||
let self_session_key_pair = Random.generate();
|
||||
let peer_session_key_pair = Random.generate();
|
||||
let self_key_pair = Random.generate();
|
||||
let peer_key_pair = Random.generate();
|
||||
let shared_key_pair = fix_shared_key(&agree(self_session_key_pair.secret(), peer_session_key_pair.public()).unwrap()).unwrap();
|
||||
TestIo {
|
||||
self_key_pair: self_key_pair,
|
||||
|
@ -377,11 +377,11 @@ mod tests {
|
||||
type SquaredSumConsensusSession = ConsensusSession<KeyAccessJob, DummyJobTransport<Requester, bool>, SquaredSumJobExecutor, DummyJobTransport<u32, u32>>;
|
||||
|
||||
fn make_master_consensus_session(threshold: usize, requester: Option<KeyPair>, acl_storage: Option<DummyAclStorage>) -> SquaredSumConsensusSession {
|
||||
let secret = requester.map(|kp| kp.secret().clone()).unwrap_or(Random.generate().unwrap().secret().clone());
|
||||
let secret = requester.map(|kp| kp.secret().clone()).unwrap_or(Random.generate().secret().clone());
|
||||
SquaredSumConsensusSession::new(ConsensusSessionParams {
|
||||
meta: make_master_session_meta(threshold),
|
||||
consensus_executor: KeyAccessJob::new_on_master(SessionId::default(), Arc::new(acl_storage.unwrap_or(DummyAclStorage::default())),
|
||||
sign(&secret, &SessionId::default()).unwrap().into()),
|
||||
consensus_executor: KeyAccessJob::new_on_master(SessionId::from([1u8; 32]), Arc::new(acl_storage.unwrap_or(DummyAclStorage::default())),
|
||||
sign(&secret, &SessionId::from([1u8; 32])).unwrap().into()),
|
||||
consensus_transport: DummyJobTransport::default(),
|
||||
}).unwrap()
|
||||
}
|
||||
@ -389,7 +389,7 @@ mod tests {
|
||||
fn make_slave_consensus_session(threshold: usize, acl_storage: Option<DummyAclStorage>) -> SquaredSumConsensusSession {
|
||||
SquaredSumConsensusSession::new(ConsensusSessionParams {
|
||||
meta: make_slave_session_meta(threshold),
|
||||
consensus_executor: KeyAccessJob::new_on_slave(SessionId::default(), Arc::new(acl_storage.unwrap_or(DummyAclStorage::default()))),
|
||||
consensus_executor: KeyAccessJob::new_on_slave(SessionId::from([1u8; 32]), Arc::new(acl_storage.unwrap_or(DummyAclStorage::default()))),
|
||||
consensus_transport: DummyJobTransport::default(),
|
||||
}).unwrap()
|
||||
}
|
||||
@ -418,9 +418,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn consensus_session_consensus_is_not_reached_when_initializes_with_zero_threshold_and_master_rejects() {
|
||||
let requester = Random.generate().unwrap();
|
||||
let requester = Random.generate();
|
||||
let acl_storage = DummyAclStorage::default();
|
||||
acl_storage.prohibit(public_to_address(requester.public()), SessionId::default());
|
||||
acl_storage.prohibit(public_to_address(requester.public()), SessionId::from([1u8; 32]));
|
||||
|
||||
let mut session = make_master_consensus_session(0, Some(requester), Some(acl_storage));
|
||||
session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap();
|
||||
@ -433,9 +433,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn consensus_session_consensus_is_failed_by_master_node() {
|
||||
let requester = Random.generate().unwrap();
|
||||
let requester = Random.generate();
|
||||
let acl_storage = DummyAclStorage::default();
|
||||
acl_storage.prohibit(public_to_address(requester.public()), SessionId::default());
|
||||
acl_storage.prohibit(public_to_address(requester.public()), SessionId::from([1u8; 32]));
|
||||
|
||||
let mut session = make_master_consensus_session(1, Some(requester), Some(acl_storage));
|
||||
assert_eq!(session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap_err(), Error::ConsensusUnreachable);
|
||||
@ -475,9 +475,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn consensus_session_job_dissemination_does_not_select_master_node_if_rejected() {
|
||||
let requester = Random.generate().unwrap();
|
||||
let requester = Random.generate();
|
||||
let acl_storage = DummyAclStorage::default();
|
||||
acl_storage.prohibit(public_to_address(requester.public()), SessionId::default());
|
||||
acl_storage.prohibit(public_to_address(requester.public()), SessionId::from([1u8; 32]));
|
||||
|
||||
let mut session = make_master_consensus_session(0, Some(requester), Some(acl_storage));
|
||||
session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap();
|
||||
@ -508,7 +508,7 @@ mod tests {
|
||||
let mut session = make_slave_consensus_session(0, None);
|
||||
assert_eq!(session.state(), ConsensusSessionState::WaitingForInitialization);
|
||||
session.on_consensus_message(&NodeId::from_low_u64_be(1), &ConsensusMessage::InitializeConsensusSession(InitializeConsensusSession {
|
||||
requester: Requester::Signature(sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()).into(),
|
||||
requester: Requester::Signature(sign(Random.generate().secret(), &SessionId::from([1u8; 32])).unwrap()).into(),
|
||||
version: Default::default(),
|
||||
})).unwrap();
|
||||
assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished);
|
||||
@ -521,7 +521,7 @@ mod tests {
|
||||
let mut session = make_slave_consensus_session(0, None);
|
||||
assert_eq!(session.state(), ConsensusSessionState::WaitingForInitialization);
|
||||
session.on_consensus_message(&NodeId::from_low_u64_be(1), &ConsensusMessage::InitializeConsensusSession(InitializeConsensusSession {
|
||||
requester: Requester::Signature(sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()).into(),
|
||||
requester: Requester::Signature(sign(Random.generate().secret(), &SessionId::from([1u8; 32])).unwrap()).into(),
|
||||
version: Default::default(),
|
||||
})).unwrap();
|
||||
assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished);
|
||||
@ -551,7 +551,7 @@ mod tests {
|
||||
fn consessus_session_completion_is_accepted() {
|
||||
let mut session = make_slave_consensus_session(0, None);
|
||||
session.on_consensus_message(&NodeId::from_low_u64_be(1), &ConsensusMessage::InitializeConsensusSession(InitializeConsensusSession {
|
||||
requester: Requester::Signature(sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()).into(),
|
||||
requester: Requester::Signature(sign(Random.generate().secret(), &SessionId::from([1u8; 32])).unwrap()).into(),
|
||||
version: Default::default(),
|
||||
})).unwrap();
|
||||
session.on_session_completed(&NodeId::from_low_u64_be(1)).unwrap();
|
||||
|
@ -434,12 +434,12 @@ pub mod tests {
|
||||
}
|
||||
|
||||
pub fn make_master_session_meta(threshold: usize) -> SessionMeta {
|
||||
SessionMeta { id: SessionId::default(), master_node_id: NodeId::from_low_u64_be(1), self_node_id: NodeId::from_low_u64_be(1), threshold: threshold,
|
||||
SessionMeta { id: SessionId::from([1u8; 32]), master_node_id: NodeId::from_low_u64_be(1), self_node_id: NodeId::from_low_u64_be(1), threshold: threshold,
|
||||
configured_nodes_count: 5, connected_nodes_count: 5 }
|
||||
}
|
||||
|
||||
pub fn make_slave_session_meta(threshold: usize) -> SessionMeta {
|
||||
SessionMeta { id: SessionId::default(), master_node_id: NodeId::from_low_u64_be(1), self_node_id: NodeId::from_low_u64_be(2), threshold: threshold,
|
||||
SessionMeta { id: SessionId::from([1u8; 32]), master_node_id: NodeId::from_low_u64_be(1), self_node_id: NodeId::from_low_u64_be(2), threshold: threshold,
|
||||
configured_nodes_count: 5, connected_nodes_count: 5 }
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,12 @@ pub struct EncryptedSecret {
|
||||
pub encrypted_point: Public,
|
||||
}
|
||||
|
||||
/// Calculate the inversion of a Secret key (in place) using the `libsecp256k1` crate.
|
||||
fn invert_secret(s: &mut Secret) -> Result<(), Error> {
|
||||
*s = secp256k1::SecretKey::parse(&s.0)?.inv().serialize().into();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create zero scalar.
|
||||
pub fn zero_scalar() -> Secret {
|
||||
Secret::zero()
|
||||
@ -44,12 +50,12 @@ pub fn to_scalar(hash: H256) -> Result<Secret, Error> {
|
||||
|
||||
/// Generate random scalar.
|
||||
pub fn generate_random_scalar() -> Result<Secret, Error> {
|
||||
Ok(Random.generate()?.secret().clone())
|
||||
Ok(Random.generate().secret().clone())
|
||||
}
|
||||
|
||||
/// Generate random point.
|
||||
pub fn generate_random_point() -> Result<Public, Error> {
|
||||
Ok(Random.generate()?.public().clone())
|
||||
Ok(Random.generate().public().clone())
|
||||
}
|
||||
|
||||
/// Get X coordinate of point.
|
||||
@ -97,12 +103,13 @@ pub fn compute_shadow_mul<'a, I>(coeff: &Secret, self_secret: &Secret, mut other
|
||||
|
||||
let mut shadow_mul = self_secret.clone();
|
||||
shadow_mul.sub(other_secret)?;
|
||||
shadow_mul.inv()?;
|
||||
invert_secret(&mut shadow_mul)?;
|
||||
|
||||
shadow_mul.mul(other_secret)?;
|
||||
while let Some(other_secret) = other_secrets.next() {
|
||||
let mut shadow_mul_element = self_secret.clone();
|
||||
shadow_mul_element.sub(other_secret)?;
|
||||
shadow_mul_element.inv()?;
|
||||
invert_secret(&mut shadow_mul_element)?;
|
||||
shadow_mul_element.mul(other_secret)?;
|
||||
shadow_mul.mul(&shadow_mul_element)?;
|
||||
}
|
||||
@ -253,7 +260,7 @@ pub fn compute_joint_secret_from_shares<'a>(t: usize, secret_shares: &[&'a Secre
|
||||
/// Encrypt secret with joint public key.
|
||||
pub fn encrypt_secret(secret: &Public, joint_public: &Public) -> Result<EncryptedSecret, Error> {
|
||||
// this is performed by KS-cluster client (or KS master)
|
||||
let key_pair = Random.generate()?;
|
||||
let key_pair = Random.generate();
|
||||
|
||||
// k * T
|
||||
let mut common_point = ec_math_utils::generation_point();
|
||||
@ -315,8 +322,7 @@ pub fn compute_joint_shadow_point_test<'a, I>(access_key: &Secret, common_point:
|
||||
/// Decrypt data using joint shadow point.
|
||||
pub fn decrypt_with_joint_shadow(threshold: usize, access_key: &Secret, encrypted_point: &Public, joint_shadow_point: &Public) -> Result<Public, Error> {
|
||||
let mut inv_access_key = access_key.clone();
|
||||
inv_access_key.inv()?;
|
||||
|
||||
invert_secret(&mut inv_access_key)?;
|
||||
let mut mul = joint_shadow_point.clone();
|
||||
ec_math_utils::public_mul_secret(&mut mul, &inv_access_key)?;
|
||||
|
||||
@ -526,14 +532,14 @@ pub fn compute_ecdsa_inversed_secret_coeff_from_shares(t: usize, id_numbers: &[S
|
||||
|
||||
// compute inv(u)
|
||||
let mut u_inv = u;
|
||||
u_inv.inv()?;
|
||||
invert_secret(&mut u_inv)?;
|
||||
Ok(u_inv)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use std::iter::once;
|
||||
use crypto::publickey::{KeyPair, recover, verify_public};
|
||||
use crypto::publickey::{KeyPair, Secret, recover, verify_public};
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -570,7 +576,7 @@ pub mod tests {
|
||||
// === PART1: DKG ===
|
||||
|
||||
// data, gathered during initialization
|
||||
let derived_point = Random.generate().unwrap().public().clone();
|
||||
let derived_point = Random.generate().public().clone();
|
||||
let id_numbers: Vec<_> = match id_numbers {
|
||||
Some(id_numbers) => id_numbers,
|
||||
None => (0..n).map(|_| generate_random_scalar().unwrap()).collect(),
|
||||
@ -801,7 +807,7 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
fn local_signature_works() {
|
||||
let key_pair = Random.generate().unwrap();
|
||||
let key_pair = Random.generate();
|
||||
let message_hash = "0000000000000000000000000000000000000000000000000000000000000042".parse().unwrap();
|
||||
let nonce = generate_random_scalar().unwrap();
|
||||
let signature = local_compute_schnorr_signature(&nonce, key_pair.secret(), &message_hash).unwrap();
|
||||
@ -887,8 +893,8 @@ pub mod tests {
|
||||
let test_cases = [(2, 5), (2, 6), (3, 11), (4, 11)];
|
||||
for &(t, n) in &test_cases {
|
||||
// values that can be hardcoded
|
||||
let joint_secret: Secret = Random.generate().unwrap().secret().clone();
|
||||
let joint_nonce: Secret = Random.generate().unwrap().secret().clone();
|
||||
let joint_secret: Secret = Random.generate().secret().clone();
|
||||
let joint_nonce: Secret = Random.generate().secret().clone();
|
||||
let message_hash: H256 = H256::random();
|
||||
|
||||
// convert message hash to EC scalar
|
||||
@ -1065,7 +1071,7 @@ pub mod tests {
|
||||
// calculate inversion of original shared secret
|
||||
let joint_secret = compute_joint_secret(artifacts.polynoms1.iter().map(|p| &p[0])).unwrap();
|
||||
let mut expected_joint_secret_inv = joint_secret.clone();
|
||||
expected_joint_secret_inv.inv().unwrap();
|
||||
invert_secret(&mut expected_joint_secret_inv).unwrap();
|
||||
|
||||
// run inversion protocol
|
||||
let reciprocal_shares = run_reciprocal_protocol(t, &artifacts);
|
||||
@ -1079,4 +1085,18 @@ pub mod tests {
|
||||
assert_eq!(actual_joint_secret_inv, expected_joint_secret_inv);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiplying_secret_inversion_with_secret_gives_one() {
|
||||
use std::str::FromStr;
|
||||
let secret = Random.generate().secret().clone();
|
||||
let mut inversion = secret.clone();
|
||||
invert_secret(&mut inversion).unwrap();
|
||||
inversion.mul(&secret).unwrap();
|
||||
assert_eq!(
|
||||
inversion,
|
||||
Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -323,14 +323,14 @@ pub mod tests {
|
||||
author: Default::default(),
|
||||
threshold: 100,
|
||||
public: Public::default(),
|
||||
common_point: Some(Random.generate().unwrap().public().clone()),
|
||||
encrypted_point: Some(Random.generate().unwrap().public().clone()),
|
||||
common_point: Some(Random.generate().public().clone()),
|
||||
encrypted_point: Some(Random.generate().public().clone()),
|
||||
versions: vec![DocumentKeyShareVersion {
|
||||
hash: Default::default(),
|
||||
id_numbers: vec![
|
||||
(Random.generate().unwrap().public().clone(), Random.generate().unwrap().secret().clone())
|
||||
(Random.generate().public().clone(), Random.generate().secret().clone())
|
||||
].into_iter().collect(),
|
||||
secret_share: Random.generate().unwrap().secret().clone(),
|
||||
secret_share: Random.generate().secret().clone(),
|
||||
}],
|
||||
};
|
||||
let key2 = ServerKeyId::from_low_u64_be(2);
|
||||
@ -338,14 +338,14 @@ pub mod tests {
|
||||
author: Default::default(),
|
||||
threshold: 200,
|
||||
public: Public::default(),
|
||||
common_point: Some(Random.generate().unwrap().public().clone()),
|
||||
encrypted_point: Some(Random.generate().unwrap().public().clone()),
|
||||
common_point: Some(Random.generate().public().clone()),
|
||||
encrypted_point: Some(Random.generate().public().clone()),
|
||||
versions: vec![DocumentKeyShareVersion {
|
||||
hash: Default::default(),
|
||||
id_numbers: vec![
|
||||
(Random.generate().unwrap().public().clone(), Random.generate().unwrap().secret().clone())
|
||||
(Random.generate().public().clone(), Random.generate().secret().clone())
|
||||
].into_iter().collect(),
|
||||
secret_share: Random.generate().unwrap().secret().clone(),
|
||||
secret_share: Random.generate().secret().clone(),
|
||||
}],
|
||||
};
|
||||
let key3 = ServerKeyId::from_low_u64_be(3);
|
||||
|
@ -18,6 +18,7 @@ extern crate byteorder;
|
||||
extern crate ethabi;
|
||||
extern crate ethereum_types;
|
||||
extern crate hyper;
|
||||
extern crate secp256k1;
|
||||
extern crate keccak_hash as hash;
|
||||
extern crate kvdb;
|
||||
extern crate kvdb_rocksdb;
|
||||
|
@ -639,13 +639,13 @@ mod tests {
|
||||
fn is_not_processed_by_this_key_server_with_zero_servers() {
|
||||
assert_eq!(is_processed_by_this_key_server(
|
||||
&MapKeyServerSet::default(),
|
||||
Random.generate().unwrap().public(),
|
||||
Random.generate().public(),
|
||||
&Default::default()), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_processed_by_this_key_server_with_single_server() {
|
||||
let self_key_pair = Random.generate().unwrap();
|
||||
let self_key_pair = Random.generate();
|
||||
assert_eq!(is_processed_by_this_key_server(
|
||||
&MapKeyServerSet::new(false, vec![
|
||||
(self_key_pair.public().clone(), "127.0.0.1:8080".parse().unwrap())
|
||||
@ -658,9 +658,9 @@ mod tests {
|
||||
fn is_not_processed_by_this_key_server_when_not_a_part_of_servers_set() {
|
||||
assert!(is_processed_by_this_key_server(
|
||||
&MapKeyServerSet::new(false, vec![
|
||||
(Random.generate().unwrap().public().clone(), "127.0.0.1:8080".parse().unwrap())
|
||||
(Random.generate().public().clone(), "127.0.0.1:8080".parse().unwrap())
|
||||
].into_iter().collect()),
|
||||
Random.generate().unwrap().public(),
|
||||
Random.generate().public(),
|
||||
&Default::default()));
|
||||
}
|
||||
|
||||
|
@ -191,3 +191,12 @@ impl From<net::AddrParseError> for Error {
|
||||
Error::Internal(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<secp256k1::Error> for Error {
|
||||
fn from(e: secp256k1::Error) -> Self {
|
||||
match e {
|
||||
secp256k1::Error::InvalidSecretKey => Error::EthKey("Invalid SecretKey".into()),
|
||||
_ => Error::EthKey(format!("Crypto error: {}", e).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ ansi_term = "0.11"
|
||||
rustc-hex = "1.0"
|
||||
ethcore-io = { path = "../io", features = ["mio"] }
|
||||
parity-bytes = "0.1"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
network = { package = "ethcore-network", path = "../network" }
|
||||
ethereum-types = "0.8.0"
|
||||
rlp = "0.4.0"
|
||||
|
@ -926,7 +926,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn ping_queue() {
|
||||
let key = Random.generate().unwrap();
|
||||
let key = Random.generate();
|
||||
let ep = NodeEndpoint { address: SocketAddr::from_str("127.0.0.1:40445").unwrap(), udp_port: 40445 };
|
||||
let mut discovery = Discovery::new(&key, ep.clone(), IpFilter::default());
|
||||
|
||||
@ -947,7 +947,7 @@ mod tests {
|
||||
#[test]
|
||||
fn discovery() {
|
||||
let mut discovery_handlers = (0..5).map(|i| {
|
||||
let key = Random.generate().unwrap();
|
||||
let key = Random.generate();
|
||||
let ep = NodeEndpoint {
|
||||
address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 41000 + i),
|
||||
udp_port: 41000 + i,
|
||||
@ -997,7 +997,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn removes_expired() {
|
||||
let key = Random.generate().unwrap();
|
||||
let key = Random.generate();
|
||||
let ep = NodeEndpoint { address: SocketAddr::from_str("127.0.0.1:40446").unwrap(), udp_port: 40447 };
|
||||
let discovery = Discovery::new(&key, ep.clone(), IpFilter::default());
|
||||
|
||||
@ -1042,7 +1042,7 @@ mod tests {
|
||||
let from = SocketAddr::from_str("99.99.99.99:40445").unwrap();
|
||||
|
||||
// FIND_NODE times out because it doesn't receive k results.
|
||||
let key = Random.generate().unwrap();
|
||||
let key = Random.generate();
|
||||
discovery.send_find_node(&node_entries[100], key.public()).unwrap();
|
||||
for payload in Discovery::prepare_neighbours_packets(&node_entries[101..116]) {
|
||||
let packet = assemble_packet(PACKET_NEIGHBOURS, &payload, &key.secret()).unwrap();
|
||||
@ -1089,7 +1089,7 @@ mod tests {
|
||||
fn find_nearest_saturated() {
|
||||
use super::*;
|
||||
|
||||
let key = Random.generate().unwrap();
|
||||
let key = Random.generate();
|
||||
let ep = NodeEndpoint { address: SocketAddr::from_str("127.0.0.1:40447").unwrap(), udp_port: 40447 };
|
||||
let mut discovery = Discovery::new(&key, ep.clone(), IpFilter::default());
|
||||
|
||||
@ -1191,7 +1191,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn packets() {
|
||||
let key = Random.generate().unwrap();
|
||||
let key = Random.generate();
|
||||
let ep = NodeEndpoint { address: SocketAddr::from_str("127.0.0.1:40449").unwrap(), udp_port: 40449 };
|
||||
let mut discovery = Discovery::new(&key, ep.clone(), IpFilter::default());
|
||||
discovery.check_timestamps = false;
|
||||
@ -1256,9 +1256,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_ping() {
|
||||
let key1 = Random.generate().unwrap();
|
||||
let key2 = Random.generate().unwrap();
|
||||
let key3 = Random.generate().unwrap();
|
||||
let key1 = Random.generate();
|
||||
let key2 = Random.generate();
|
||||
let key3 = Random.generate();
|
||||
let ep1 = NodeEndpoint { address: SocketAddr::from_str("127.0.0.1:40344").unwrap(), udp_port: 40344 };
|
||||
let ep2 = NodeEndpoint { address: SocketAddr::from_str("127.0.0.1:40345").unwrap(), udp_port: 40345 };
|
||||
let ep3 = NodeEndpoint { address: SocketAddr::from_str("127.0.0.1:40346").unwrap(), udp_port: 40345 };
|
||||
|
@ -83,20 +83,20 @@ const ECIES_OVERHEAD: usize = 113;
|
||||
|
||||
impl Handshake {
|
||||
/// Create a new handshake object
|
||||
pub fn new(token: StreamToken, id: Option<&NodeId>, socket: TcpStream, nonce: &H256) -> Result<Handshake, Error> {
|
||||
Ok(Handshake {
|
||||
pub fn new(token: StreamToken, id: Option<&NodeId>, socket: TcpStream, nonce: &H256) -> Handshake {
|
||||
Handshake {
|
||||
id: if let Some(id) = id { *id } else { NodeId::default() },
|
||||
connection: Connection::new(token, socket),
|
||||
originated: false,
|
||||
state: HandshakeState::New,
|
||||
ecdhe: Random.generate()?,
|
||||
ecdhe: Random.generate(),
|
||||
nonce: *nonce,
|
||||
remote_ephemeral: Public::default(),
|
||||
remote_nonce: H256::zero(),
|
||||
remote_version: PROTOCOL_VERSION,
|
||||
auth_cipher: Bytes::new(),
|
||||
ack_cipher: Bytes::new(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Start a handshake
|
||||
@ -358,7 +358,7 @@ mod test {
|
||||
let addr = "127.0.0.1:50556".parse().unwrap();
|
||||
let socket = TcpStream::connect(&addr).unwrap();
|
||||
let nonce = H256::zero();
|
||||
Handshake::new(0, to, socket, &nonce).unwrap()
|
||||
Handshake::new(0, to, socket, &nonce)
|
||||
}
|
||||
|
||||
fn test_io() -> IoContext<i32> {
|
||||
|
@ -290,7 +290,7 @@ impl Host {
|
||||
} else {
|
||||
config.config_path.clone().and_then(|ref p| load_key(Path::new(&p)))
|
||||
.map_or_else(|| {
|
||||
let key = Random.generate().expect("Error generating random key pair");
|
||||
let key = Random.generate();
|
||||
if let Some(path) = config.config_path.clone() {
|
||||
save_key(Path::new(&path), key.secret());
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ impl Session {
|
||||
nonce: &H256, host: &HostInfo) -> Result<Session, Error>
|
||||
where Message: Send + Clone + Sync + 'static {
|
||||
let originated = id.is_some();
|
||||
let mut handshake = Handshake::new(token, id, socket, nonce).expect("Can't create handshake");
|
||||
let mut handshake = Handshake::new(token, id, socket, nonce);
|
||||
let local_addr = handshake.connection.local_addr_str();
|
||||
handshake.start(io, host, originated)?;
|
||||
Ok(Session {
|
||||
|
@ -113,7 +113,7 @@ fn net_start_stop() {
|
||||
|
||||
#[test]
|
||||
fn net_disconnect() {
|
||||
let key1 = Random.generate().unwrap();
|
||||
let key1 = Random.generate();
|
||||
let mut config1 = NetworkConfiguration::new_local();
|
||||
config1.use_secret = Some(key1.secret().clone());
|
||||
config1.boot_nodes = vec![ ];
|
||||
|
@ -8,7 +8,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
derive_more = "0.99"
|
||||
parity-crypto = { version = "0.4.2", features = ["publickey"] }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
ethcore-io = { path = "../io" }
|
||||
ethereum-types = "0.8.0"
|
||||
ipnetwork = "0.12.6"
|
||||
|
@ -7,4 +7,4 @@ version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
backtrace = "0.3.2"
|
||||
backtrace = "0.3.43"
|
||||
|
Loading…
Reference in New Issue
Block a user