Revert-revert migrate to ed25519-dalek crate (#3877)
* Revert "Revert "Migrate from ring to ed25519-dalek, take 2 (#3844)" (#3868)"
This reverts commit 6a878602f2
.
* Fix Signature::verify method
This commit is contained in:
parent
8514d27c2f
commit
a9cfae486c
|
@ -347,6 +347,14 @@ dependencies = [
|
|||
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clear_on_drop"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clicolors-control"
|
||||
version = "1.0.0"
|
||||
|
@ -536,6 +544,18 @@ dependencies = [
|
|||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "curve25519-dalek"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "difference"
|
||||
version = "2.0.0"
|
||||
|
@ -572,6 +592,18 @@ name = "dtoa"
|
|||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ed25519-dalek"
|
||||
version = "1.0.0-pre.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.5.1"
|
||||
|
@ -2153,6 +2185,7 @@ dependencies = [
|
|||
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashbrown 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2171,7 +2204,6 @@ dependencies = [
|
|||
"rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"reqwest 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rocksdb 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2592,12 +2624,13 @@ dependencies = [
|
|||
"bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"generic-array 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2775,6 +2808,11 @@ name = "strsim"
|
|||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.11.11"
|
||||
|
@ -3388,6 +3426,7 @@ dependencies = [
|
|||
"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
|
||||
"checksum clang-sys 0.26.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ef0c1bcf2e99c649104bd7a7012d8f8802684400e03db0ec0af48583c6fa0e4"
|
||||
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
|
||||
"checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17"
|
||||
"checksum clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "73abfd4c73d003a674ce5d2933fca6ce6c42480ea84a5ffe0a2dc39ed56300f9"
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum colored 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e9a455e156a4271e12fd0246238c380b1e223e3736663c7a18ed8b6362028a9"
|
||||
|
@ -3407,11 +3446,13 @@ dependencies = [
|
|||
"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"
|
||||
"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
|
||||
"checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c"
|
||||
"checksum curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1f8a6fc0376eb52dc18af94915cc04dfdf8353746c0e8c550ae683a0815e5c1"
|
||||
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
||||
"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
|
||||
"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c"
|
||||
"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
|
||||
"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
|
||||
"checksum ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81956bcf7ef761fb4e1d88de3fa181358a0d26cbcb9755b587a08f9119824b86"
|
||||
"checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac"
|
||||
"checksum elf 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4841de15dbe0e49b9b62a417589299e3be0d557e0900d36acb87e6dae47197f5"
|
||||
"checksum elfkit 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "02f182eda16a7360c80a2f8638d0726e9d5478173058f1505c42536ca666ecd2"
|
||||
|
@ -3590,6 +3631,7 @@ dependencies = [
|
|||
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
|
||||
"checksum string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b639411d0b9c738748b5397d5ceba08e648f4f1992231aa859af1a017f31f60b"
|
||||
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
"checksum subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "702662512f3ddeb74a64ce2fbbf3707ee1b6bb663d28bb054e0779bbc720d926"
|
||||
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
|
||||
"checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2"
|
||||
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||
|
|
|
@ -2,9 +2,9 @@ use std::net::SocketAddr;
|
|||
use std::time::Duration;
|
||||
|
||||
use clap::{crate_description, crate_name, crate_version, value_t, App, Arg, ArgMatches};
|
||||
use solana::gen_keys::GenKeys;
|
||||
use solana_drone::drone::DRONE_PORT;
|
||||
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil};
|
||||
use untrusted::Input;
|
||||
|
||||
pub struct Config {
|
||||
pub network_addr: SocketAddr,
|
||||
|
@ -152,7 +152,8 @@ pub fn extract_args<'a>(matches: &ArgMatches<'a>) -> Config {
|
|||
} else {
|
||||
args.identity = {
|
||||
let seed = [42_u8; 32];
|
||||
Keypair::from_seed_unchecked(Input::from(&seed)).unwrap()
|
||||
let mut rnd = GenKeys::new(seed);
|
||||
rnd.gen_keypair()
|
||||
};
|
||||
}
|
||||
args.threads = value_t!(matches.value_of("threads"), usize).expect("Failed to parse threads");
|
||||
|
|
|
@ -68,7 +68,7 @@ pub fn do_bench_tps(config: Config) {
|
|||
let client = create_client(cluster_entrypoint.client_facing_addr(), FULLNODE_PORT_RANGE);
|
||||
|
||||
let mut seed = [0u8; 32];
|
||||
seed.copy_from_slice(&id.public_key_bytes()[..32]);
|
||||
seed.copy_from_slice(&id.to_bytes()[..32]);
|
||||
let mut rnd = GenKeys::new(seed);
|
||||
|
||||
println!("Creating {} keypairs...", tx_count * 2);
|
||||
|
|
|
@ -25,6 +25,7 @@ bs58 = "0.2.0"
|
|||
byteorder = "1.3.1"
|
||||
chrono = { version = "0.4.0", features = ["serde"] }
|
||||
crc = { version = "1.8.1", optional = true }
|
||||
ed25519-dalek = "1.0.0-pre.0"
|
||||
hashbrown = "0.2.0"
|
||||
indexmap = "1.0"
|
||||
itertools = "0.8.0"
|
||||
|
@ -41,7 +42,6 @@ rand = "0.6.5"
|
|||
rand_chacha = "0.1.1"
|
||||
rayon = "1.0.0"
|
||||
reqwest = "0.9.11"
|
||||
ring = "0.13.2"
|
||||
rocksdb = "0.11.0"
|
||||
serde = "1.0.89"
|
||||
serde_derive = "1.0.88"
|
||||
|
|
|
@ -94,7 +94,7 @@ mod tests {
|
|||
use crate::blocktree::Blocktree;
|
||||
use crate::chacha::chacha_cbc_encrypt_ledger;
|
||||
use crate::entry::Entry;
|
||||
use ring::signature::Ed25519KeyPair;
|
||||
use crate::gen_keys::GenKeys;
|
||||
use solana_sdk::hash::{hash, Hash, Hasher};
|
||||
use solana_sdk::signature::KeypairUtil;
|
||||
use solana_sdk::system_transaction;
|
||||
|
@ -103,19 +103,14 @@ mod tests {
|
|||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use untrusted::Input;
|
||||
|
||||
fn make_tiny_deterministic_test_entries(num: usize) -> Vec<Entry> {
|
||||
let zero = Hash::default();
|
||||
let one = hash(&zero.as_ref());
|
||||
let pkcs = [
|
||||
48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, 109, 148, 235, 20, 97, 127,
|
||||
43, 194, 109, 43, 121, 76, 54, 38, 234, 14, 108, 68, 209, 227, 137, 191, 167, 144, 177,
|
||||
174, 57, 182, 79, 198, 196, 93, 161, 35, 3, 33, 0, 116, 121, 255, 78, 31, 95, 179, 172,
|
||||
30, 125, 206, 87, 88, 78, 46, 145, 25, 154, 161, 252, 3, 58, 235, 116, 39, 148, 193,
|
||||
150, 111, 61, 20, 226,
|
||||
];
|
||||
let keypair = Ed25519KeyPair::from_pkcs8(Input::from(&pkcs)).unwrap();
|
||||
|
||||
let seed = [2u8; 32];
|
||||
let mut rnd = GenKeys::new(seed);
|
||||
let keypair = rnd.gen_keypair();
|
||||
|
||||
let mut id = one;
|
||||
let mut num_hashes = 0;
|
||||
|
@ -164,7 +159,7 @@ mod tests {
|
|||
use bs58;
|
||||
// golden needs to be updated if blob stuff changes....
|
||||
let golden = Hash::new(
|
||||
&bs58::decode("5NBn4cBZmNZRftkjxj3um8W1eyYPzn2RgUJSA3SVbHaJ")
|
||||
&bs58::decode("GD6xs6Loh9gci6b6P8FVVJ1c1whCqxDzaqBrQkpcxowA")
|
||||
.into_vec()
|
||||
.unwrap(),
|
||||
);
|
||||
|
|
|
@ -4,7 +4,6 @@ use rand::{Rng, SeedableRng};
|
|||
use rand_chacha::ChaChaRng;
|
||||
use rayon::prelude::*;
|
||||
use solana_sdk::signature::Keypair;
|
||||
use untrusted::Input;
|
||||
|
||||
pub struct GenKeys {
|
||||
generator: ChaChaRng,
|
||||
|
@ -26,10 +25,14 @@ impl GenKeys {
|
|||
(0..n).map(|_| self.gen_seed()).collect()
|
||||
}
|
||||
|
||||
pub fn gen_keypair(&mut self) -> Keypair {
|
||||
Keypair::generate(&mut self.generator)
|
||||
}
|
||||
|
||||
pub fn gen_n_keypairs(&mut self, n: u64) -> Vec<Keypair> {
|
||||
self.gen_n_seeds(n)
|
||||
.into_par_iter()
|
||||
.map(|seed| Keypair::from_seed_unchecked(Input::from(&seed)).unwrap())
|
||||
.map(|seed| Keypair::generate(&mut ChaChaRng::from_seed(seed)))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +55,17 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gen_keypair_is_deterministic() {
|
||||
let seed = [0u8; 32];
|
||||
let mut gen0 = GenKeys::new(seed);
|
||||
let mut gen1 = GenKeys::new(seed);
|
||||
assert_eq!(
|
||||
gen0.gen_keypair().to_bytes().to_vec(),
|
||||
gen1.gen_keypair().to_bytes().to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
fn gen_n_pubkeys(seed: [u8; 32], n: u64) -> HashSet<Pubkey> {
|
||||
GenKeys::new(seed)
|
||||
.gen_n_keypairs(n)
|
||||
|
|
|
@ -14,6 +14,7 @@ use crate::streamer::receiver;
|
|||
use crate::streamer::responder;
|
||||
use crate::window_service::WindowService;
|
||||
use bincode::deserialize;
|
||||
use ed25519_dalek;
|
||||
use rand::thread_rng;
|
||||
use rand::Rng;
|
||||
use solana_client::rpc_client::RpcClient;
|
||||
|
@ -60,7 +61,7 @@ pub struct Replicator {
|
|||
slot: u64,
|
||||
ledger_path: String,
|
||||
storage_keypair: Arc<Keypair>,
|
||||
signature: ring::signature::Signature,
|
||||
signature: ed25519_dalek::Signature,
|
||||
cluster_entrypoint: ContactInfo,
|
||||
ledger_data_file_encrypted: PathBuf,
|
||||
sampling_offsets: Vec<u64>,
|
||||
|
@ -107,10 +108,10 @@ pub fn sample_file(in_path: &Path, sample_offsets: &[u64]) -> io::Result<Hash> {
|
|||
}
|
||||
|
||||
fn get_entry_heights_from_blockhash(
|
||||
signature: &ring::signature::Signature,
|
||||
signature: &ed25519_dalek::Signature,
|
||||
storage_entry_height: u64,
|
||||
) -> u64 {
|
||||
let signature_vec = signature.as_ref();
|
||||
let signature_vec = signature.to_bytes();
|
||||
let mut segment_index = u64::from(signature_vec[0])
|
||||
| (u64::from(signature_vec[1]) << 8)
|
||||
| (u64::from(signature_vec[1]) << 16)
|
||||
|
@ -354,7 +355,7 @@ impl Replicator {
|
|||
#[cfg(feature = "chacha")]
|
||||
{
|
||||
let mut ivec = [0u8; 64];
|
||||
ivec.copy_from_slice(self.signature.as_ref());
|
||||
ivec.copy_from_slice(&self.signature.to_bytes());
|
||||
|
||||
let num_encrypted_bytes = chacha_cbc_encrypt_ledger(
|
||||
&self.blocktree,
|
||||
|
@ -383,7 +384,7 @@ impl Replicator {
|
|||
use rand_chacha::ChaChaRng;
|
||||
|
||||
let mut rng_seed = [0u8; 32];
|
||||
rng_seed.copy_from_slice(&self.signature.as_ref()[0..32]);
|
||||
rng_seed.copy_from_slice(&self.signature.to_bytes()[0..32]);
|
||||
let mut rng = ChaChaRng::from_seed(rng_seed);
|
||||
for _ in 0..NUM_STORAGE_SAMPLES {
|
||||
self.sampling_offsets
|
||||
|
@ -448,7 +449,7 @@ impl Replicator {
|
|||
&self.storage_keypair.pubkey(),
|
||||
self.hash,
|
||||
self.slot,
|
||||
Signature::new(self.signature.as_ref()),
|
||||
Signature::new(&self.signature.to_bytes()),
|
||||
);
|
||||
let mut tx = Transaction::new_unsigned_instructions(vec![ix]);
|
||||
client
|
||||
|
|
|
@ -67,10 +67,8 @@ pub fn init() {
|
|||
}
|
||||
|
||||
fn verify_packet(packet: &Packet) -> u8 {
|
||||
use ring::signature;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::Signature;
|
||||
use untrusted;
|
||||
|
||||
let (sig_len, sig_start, msg_start, pubkey_start) = get_packet_offsets(packet, 0);
|
||||
let mut sig_start = sig_start as usize;
|
||||
|
@ -90,14 +88,11 @@ fn verify_packet(packet: &Packet) -> u8 {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if signature::verify(
|
||||
&signature::ED25519,
|
||||
untrusted::Input::from(&packet.data[pubkey_start..pubkey_end]),
|
||||
untrusted::Input::from(&packet.data[msg_start..msg_end]),
|
||||
untrusted::Input::from(&packet.data[sig_start..sig_end]),
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
let signature = Signature::new(&packet.data[sig_start..sig_end]);
|
||||
if !signature.verify(
|
||||
&packet.data[pubkey_start..pubkey_end],
|
||||
&packet.data[msg_start..msg_end],
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
pubkey_start += size_of::<Pubkey>();
|
||||
|
|
|
@ -327,7 +327,7 @@ impl StorageStage {
|
|||
let tx = Transaction::new_unsigned_instructions(vec![ix]);
|
||||
tx_sender.send(tx)?;
|
||||
|
||||
seed.copy_from_slice(&signature.as_ref()[..32]);
|
||||
seed.copy_from_slice(&signature.to_bytes()[..32]);
|
||||
|
||||
let mut rng = ChaChaRng::from_seed(seed);
|
||||
|
||||
|
@ -340,7 +340,7 @@ impl StorageStage {
|
|||
return Ok(());
|
||||
}
|
||||
// TODO: what if the validator does not have this segment
|
||||
let segment = signature.as_ref()[0] as usize % num_segments;
|
||||
let segment = signature.to_bytes()[0] as usize % num_segments;
|
||||
|
||||
debug!(
|
||||
"storage verifying: segment: {} identities: {}",
|
||||
|
|
|
@ -171,7 +171,7 @@ fn test_replay() {
|
|||
// receive retransmitted messages
|
||||
let timer = Duration::new(1, 0);
|
||||
while let Ok(_msg) = r_reader.recv_timeout(timer) {
|
||||
trace!("got msg");
|
||||
info!("got msg");
|
||||
}
|
||||
|
||||
let working_bank = bank_forks.read().unwrap().working_bank();
|
||||
|
|
|
@ -11,6 +11,7 @@ edition = "2018"
|
|||
[dependencies]
|
||||
bincode = "1.1.3"
|
||||
bs58 = "0.2.0"
|
||||
ed25519-dalek = "1.0.0-pre.0"
|
||||
hex = "0.3.2"
|
||||
byteorder = "1.2.1"
|
||||
chrono = { version = "0.4.0", features = ["serde"] }
|
||||
|
@ -18,7 +19,7 @@ generic-array = { version = "0.13.0", default-features = false, features = ["ser
|
|||
itertools = "0.8.0"
|
||||
log = "0.4.2"
|
||||
rand = "0.6.5"
|
||||
ring = "0.13.2"
|
||||
rayon = "1.0.0"
|
||||
sha2 = "0.8.0"
|
||||
serde = "1.0.90"
|
||||
serde_derive = "1.0.90"
|
||||
|
|
|
@ -2,19 +2,18 @@
|
|||
|
||||
use crate::pubkey::Pubkey;
|
||||
use bs58;
|
||||
use ed25519_dalek;
|
||||
use generic_array::typenum::U64;
|
||||
use generic_array::GenericArray;
|
||||
use ring::signature::Ed25519KeyPair;
|
||||
use ring::{rand, signature};
|
||||
use rand::rngs::OsRng;
|
||||
use serde_json;
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use untrusted::Input;
|
||||
|
||||
pub type Keypair = Ed25519KeyPair;
|
||||
pub type Keypair = ed25519_dalek::Keypair;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct Signature(GenericArray<u8, U64>);
|
||||
|
@ -25,10 +24,15 @@ impl Signature {
|
|||
}
|
||||
|
||||
pub fn verify(&self, pubkey_bytes: &[u8], message_bytes: &[u8]) -> bool {
|
||||
let pubkey = Input::from(pubkey_bytes);
|
||||
let message = Input::from(message_bytes);
|
||||
let signature = Input::from(self.0.as_slice());
|
||||
signature::verify(&signature::ED25519, pubkey, message, signature).is_ok()
|
||||
let pubkey = ed25519_dalek::PublicKey::from_bytes(pubkey_bytes);
|
||||
let signature = ed25519_dalek::Signature::from_bytes(self.0.as_slice());
|
||||
if pubkey.is_err() || signature.is_err() {
|
||||
return false;
|
||||
}
|
||||
pubkey
|
||||
.unwrap()
|
||||
.verify(message_bytes, &signature.unwrap())
|
||||
.is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,45 +76,33 @@ pub trait KeypairUtil {
|
|||
fn sign_message(&self, message: &[u8]) -> Signature;
|
||||
}
|
||||
|
||||
impl KeypairUtil for Ed25519KeyPair {
|
||||
impl KeypairUtil for Keypair {
|
||||
/// Return a new ED25519 keypair
|
||||
fn new() -> Self {
|
||||
let rng = rand::SystemRandom::new();
|
||||
let pkcs8_bytes = Ed25519KeyPair::generate_pkcs8(&rng).expect("generate_pkcs8");
|
||||
Ed25519KeyPair::from_pkcs8(Input::from(&pkcs8_bytes)).expect("from_pcks8")
|
||||
let mut rng = OsRng::new().unwrap();
|
||||
Keypair::generate(&mut rng)
|
||||
}
|
||||
|
||||
/// Return the public key for the given keypair
|
||||
fn pubkey(&self) -> Pubkey {
|
||||
Pubkey::new(self.public_key_bytes())
|
||||
Pubkey::new(&self.public.as_ref())
|
||||
}
|
||||
|
||||
fn sign_message(&self, message: &[u8]) -> Signature {
|
||||
Signature::new(self.sign(message).as_ref())
|
||||
Signature::new(&self.sign(message).to_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_pkcs8(path: &str) -> Result<Vec<u8>, Box<error::Error>> {
|
||||
let file = File::open(path.to_string())?;
|
||||
let pkcs8: Vec<u8> = serde_json::from_reader(file)?;
|
||||
Ok(pkcs8)
|
||||
}
|
||||
|
||||
pub fn read_keypair(path: &str) -> Result<Keypair, Box<error::Error>> {
|
||||
let pkcs8 = read_pkcs8(path)?;
|
||||
let keypair = Ed25519KeyPair::from_pkcs8(Input::from(&pkcs8))?;
|
||||
let file = File::open(path.to_string())?;
|
||||
let bytes: Vec<u8> = serde_json::from_reader(file)?;
|
||||
let keypair = Keypair::from_bytes(&bytes).unwrap();
|
||||
Ok(keypair)
|
||||
}
|
||||
|
||||
pub fn gen_pkcs8() -> Result<Vec<u8>, Box<error::Error>> {
|
||||
let rnd = rand::SystemRandom::new();
|
||||
let pkcs8_bytes = Ed25519KeyPair::generate_pkcs8(&rnd)?;
|
||||
Ok(pkcs8_bytes.to_vec())
|
||||
}
|
||||
|
||||
//pub fn gen_keypair_file(outfile: String) -> Result<String, Box<dyn error::Error>> {
|
||||
pub fn gen_keypair_file(outfile: String) -> Result<String, Box<error::Error>> {
|
||||
let serialized = serde_json::to_string(&gen_pkcs8()?)?;
|
||||
let keypair_bytes = Keypair::new().to_bytes();
|
||||
let serialized = serde_json::to_string(&keypair_bytes.to_vec())?;
|
||||
|
||||
if outfile != "-" {
|
||||
if let Some(outdir) = Path::new(&outfile).parent() {
|
||||
|
@ -121,3 +113,35 @@ pub fn gen_keypair_file(outfile: String) -> Result<String, Box<error::Error>> {
|
|||
}
|
||||
Ok(serialized)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::mem;
|
||||
|
||||
fn tmp_file_path(name: &str) -> String {
|
||||
use std::env;
|
||||
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "target".to_string());
|
||||
let keypair = Keypair::new();
|
||||
|
||||
format!("{}/tmp/{}-{}", out_dir, name, keypair.pubkey()).to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gen_keypair_file() {
|
||||
let outfile = tmp_file_path("test_gen_keypair_file.json");
|
||||
let serialized_keypair = gen_keypair_file(outfile.to_string()).unwrap();
|
||||
let keypair_vec: Vec<u8> = serde_json::from_str(&serialized_keypair).unwrap();
|
||||
assert!(Path::new(&outfile).exists());
|
||||
assert_eq!(
|
||||
keypair_vec,
|
||||
read_keypair(&outfile).unwrap().to_bytes().to_vec()
|
||||
);
|
||||
assert_eq!(
|
||||
read_keypair(&outfile).unwrap().pubkey().as_ref().len(),
|
||||
mem::size_of::<Pubkey>()
|
||||
);
|
||||
fs::remove_file(&outfile).unwrap();
|
||||
assert!(!Path::new(&outfile).exists());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,14 +283,12 @@ mod tests {
|
|||
}
|
||||
|
||||
fn create_sample_transaction() -> Transaction {
|
||||
use untrusted::Input;
|
||||
let keypair = Keypair::from_pkcs8(Input::from(&[
|
||||
let keypair = Keypair::from_bytes(&[
|
||||
48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, 255, 101, 36, 24, 124, 23,
|
||||
167, 21, 132, 204, 155, 5, 185, 58, 121, 75, 156, 227, 116, 193, 215, 38, 142, 22, 8,
|
||||
14, 229, 239, 119, 93, 5, 218, 161, 35, 3, 33, 0, 36, 100, 158, 252, 33, 161, 97, 185,
|
||||
62, 89, 99, 195, 250, 249, 187, 189, 171, 118, 241, 90, 248, 14, 68, 219, 231, 62, 157,
|
||||
5, 142, 27, 210, 117,
|
||||
]))
|
||||
62, 89, 99,
|
||||
])
|
||||
.unwrap();
|
||||
let to = Pubkey::new(&[
|
||||
1, 1, 1, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 7, 6, 5, 4,
|
||||
|
@ -375,16 +373,16 @@ mod tests {
|
|||
assert_eq!(
|
||||
serialize(&create_sample_transaction()).unwrap(),
|
||||
vec![
|
||||
1, 0, 30, 236, 164, 222, 77, 89, 244, 36, 92, 35, 192, 25, 100, 18, 61, 155, 111,
|
||||
89, 189, 154, 90, 255, 217, 203, 105, 50, 243, 208, 179, 89, 146, 122, 222, 91, 34,
|
||||
106, 93, 82, 147, 213, 223, 184, 32, 204, 61, 227, 227, 41, 211, 67, 5, 156, 236,
|
||||
251, 178, 235, 234, 174, 123, 15, 26, 145, 3, 1, 2, 36, 100, 158, 252, 33, 161, 97,
|
||||
185, 62, 89, 99, 195, 250, 249, 187, 189, 171, 118, 241, 90, 248, 14, 68, 219, 231,
|
||||
62, 157, 5, 142, 27, 210, 117, 1, 1, 1, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 8, 7, 6, 5, 4, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 4, 5, 6, 7, 8,
|
||||
9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 8, 7, 6, 5, 4, 2, 2, 2, 1, 0, 2, 0,
|
||||
1, 3, 1, 2, 3
|
||||
1, 134, 84, 186, 62, 126, 175, 48, 6, 80, 185, 139, 108, 109, 157, 213, 17, 249, 3,
|
||||
79, 83, 21, 89, 242, 148, 51, 140, 115, 77, 161, 134, 116, 136, 206, 171, 239, 236,
|
||||
240, 19, 73, 217, 152, 60, 159, 170, 41, 104, 29, 217, 93, 65, 139, 191, 202, 181,
|
||||
77, 246, 26, 15, 156, 186, 66, 32, 139, 6, 1, 2, 156, 227, 116, 193, 215, 38, 142,
|
||||
22, 8, 14, 229, 239, 119, 93, 5, 218, 161, 35, 3, 33, 0, 36, 100, 158, 252, 33,
|
||||
161, 97, 185, 62, 89, 99, 1, 1, 1, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 8, 7, 6, 5, 4, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 4, 5, 6, 7, 8, 9, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 8, 7, 6, 5, 4, 2, 2, 2, 1, 0, 2, 0, 1, 3,
|
||||
1, 2, 3
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -776,11 +776,9 @@ mod tests {
|
|||
use clap::{App, Arg, SubCommand};
|
||||
use serde_json::Value;
|
||||
use solana_client::mock_rpc_client_request::SIGNATURE;
|
||||
use solana_sdk::signature::{gen_keypair_file, read_keypair, read_pkcs8, Keypair, KeypairUtil};
|
||||
use solana_sdk::transaction::TransactionError;
|
||||
use std::fs;
|
||||
use std::net::{Ipv4Addr, SocketAddr};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
fn test_wallet_config_drone_addr() {
|
||||
|
@ -1423,28 +1421,4 @@ mod tests {
|
|||
config.command = WalletCommand::Deploy("bad/file/location.so".to_string());
|
||||
assert!(process_command(&config).is_err());
|
||||
}
|
||||
|
||||
fn tmp_file_path(name: &str) -> String {
|
||||
use std::env;
|
||||
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "target".to_string());
|
||||
let keypair = Keypair::new();
|
||||
|
||||
format!("{}/tmp/{}-{}", out_dir, name, keypair.pubkey()).to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wallet_gen_keypair_file() {
|
||||
let outfile = tmp_file_path("test_gen_keypair_file.json");
|
||||
let serialized_keypair = gen_keypair_file(outfile.to_string()).unwrap();
|
||||
let keypair_vec: Vec<u8> = serde_json::from_str(&serialized_keypair).unwrap();
|
||||
assert!(Path::new(&outfile).exists());
|
||||
assert_eq!(keypair_vec, read_pkcs8(&outfile).unwrap());
|
||||
read_keypair(&outfile).unwrap();
|
||||
assert_eq!(
|
||||
read_keypair(&outfile).unwrap().pubkey().as_ref().len(),
|
||||
mem::size_of::<Pubkey>()
|
||||
);
|
||||
fs::remove_file(&outfile).unwrap();
|
||||
assert!(!Path::new(&outfile).exists());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue