Revert "Migrate from ring to ed25519-dalek" (#1798)

* Revert "Migrate from ring to ed25519-dalek"

This reverts commit 7c610b216b.

* Fix test failures with revert
This commit is contained in:
Sagar Dhawan
2018-11-12 22:34:43 -08:00
committed by GitHub
parent 1f6ece233f
commit a77b1ff767
14 changed files with 107 additions and 83 deletions

View File

@ -75,7 +75,6 @@ bytes = "0.4"
chrono = { version = "0.4.0", features = ["serde"] } chrono = { version = "0.4.0", features = ["serde"] }
clap = "2.31" clap = "2.31"
dirs = "1.0.2" dirs = "1.0.2"
ed25519-dalek = "1.0.0-pre.0"
elf = "0.0.10" elf = "0.0.10"
env_logger = "0.5.12" env_logger = "0.5.12"
generic-array = { version = "0.12.0", default-features = false, features = ["serde"] } generic-array = { version = "0.12.0", default-features = false, features = ["serde"] }
@ -98,6 +97,7 @@ pnet_datalink = "0.21.0"
rand = "0.5.1" rand = "0.5.1"
rayon = "1.0.0" rayon = "1.0.0"
reqwest = "0.9.0" reqwest = "0.9.0"
ring = "0.13.2"
sha2 = "0.8.0" sha2 = "0.8.0"
serde = "1.0.27" serde = "1.0.27"
serde_cbor = "0.9.0" serde_cbor = "0.9.0"
@ -108,6 +108,7 @@ solana-sdk = { path = "sdk", version = "0.11.0" }
sys-info = "0.5.6" sys-info = "0.5.6"
tokio = "0.1" tokio = "0.1"
tokio-codec = "0.1" tokio-codec = "0.1"
untrusted = "0.6.2"
solana-bpfloader = { path = "programs/native/bpf_loader", version = "0.11.0" } solana-bpfloader = { path = "programs/native/bpf_loader", version = "0.11.0" }
solana-erc20 = { path = "programs/native/erc20", version = "0.11.0" } solana-erc20 = { path = "programs/native/erc20", version = "0.11.0" }
solana-lualoader = { path = "programs/native/lua_loader", version = "0.11.0" } solana-lualoader = { path = "programs/native/lua_loader", version = "0.11.0" }

View File

@ -643,7 +643,7 @@ fn main() {
let mut barrier_client = mk_client(&leader); let mut barrier_client = mk_client(&leader);
let mut seed = [0u8; 32]; let mut seed = [0u8; 32];
seed.copy_from_slice(&id.to_bytes()[..32]); seed.copy_from_slice(&id.public_key_bytes()[..32]);
let mut rnd = GenKeys::new(seed); let mut rnd = GenKeys::new(seed);
println!("Creating {} keypairs...", tx_count * 2); println!("Creating {} keypairs...", tx_count * 2);

View File

@ -9,7 +9,7 @@ use solana::cluster_info::FULLNODE_PORT_RANGE;
use solana::fullnode::Config; use solana::fullnode::Config;
use solana::logger; use solana::logger;
use solana::netutil::{get_ip_addr, get_public_ip_addr, parse_port_or_addr}; use solana::netutil::{get_ip_addr, get_public_ip_addr, parse_port_or_addr};
use solana::signature::read_keypair; use solana::signature::read_pkcs8;
use std::io; use std::io;
use std::net::SocketAddr; use std::net::SocketAddr;
@ -65,11 +65,11 @@ fn main() {
path.extend(&[".config", "solana", "id.json"]); path.extend(&[".config", "solana", "id.json"]);
path.to_str().unwrap() path.to_str().unwrap()
}; };
let keypair = read_keypair(id_path).expect("client keypair"); let pkcs8 = read_pkcs8(id_path).expect("client keypair");
// we need all the receiving sockets to be bound within the expected // we need all the receiving sockets to be bound within the expected
// port range that we open on aws // port range that we open on aws
let config = Config::new(&bind_addr, keypair.to_bytes().to_vec()); let config = Config::new(&bind_addr, pkcs8);
let stdout = io::stdout(); let stdout = io::stdout();
serde_json::to_writer(stdout, &config).expect("serialize"); serde_json::to_writer(stdout, &config).expect("serialize");
} }

View File

@ -5,6 +5,7 @@ extern crate atty;
extern crate clap; extern crate clap;
extern crate serde_json; extern crate serde_json;
extern crate solana; extern crate solana;
extern crate untrusted;
use clap::{App, Arg}; use clap::{App, Arg};
use solana::fullnode::Config; use solana::fullnode::Config;
@ -60,8 +61,8 @@ fn main() -> Result<(), Box<error::Error>> {
// Parse the input mint configuration // Parse the input mint configuration
let num_tokens = value_t_or_exit!(matches, "num_tokens", u64); let num_tokens = value_t_or_exit!(matches, "num_tokens", u64);
let file = File::open(Path::new(&matches.value_of("mint").unwrap())).unwrap(); let file = File::open(Path::new(&matches.value_of("mint").unwrap())).unwrap();
let keypair_bytes: Vec<u8> = serde_json::from_reader(&file)?; let pkcs8: Vec<u8> = serde_json::from_reader(&file)?;
let mint = Mint::new_with_keypair_bytes(num_tokens, keypair_bytes, leader_keypair.pubkey(), 1); let mint = Mint::new_with_pkcs8(num_tokens, pkcs8, leader_keypair.pubkey(), 1);
// Write the ledger entries // Write the ledger entries
let ledger_path = matches.value_of("ledger").unwrap(); let ledger_path = matches.value_of("ledger").unwrap();

View File

@ -1,6 +1,7 @@
#[macro_use] #[macro_use]
extern crate clap; extern crate clap;
extern crate dirs; extern crate dirs;
extern crate ring;
extern crate serde_json; extern crate serde_json;
extern crate solana; extern crate solana;

View File

@ -610,14 +610,15 @@ mod test {
tx.userdata(0).to_vec(), tx.userdata(0).to_vec(),
vec![ vec![
0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 50, 48, 49, 54, 45, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 50, 48, 49, 54, 45,
48, 55, 45, 48, 56, 84, 48, 57, 58, 49, 48, 58, 49, 49, 90, 218, 65, 89, 124, 81, 48, 55, 45, 48, 56, 84, 48, 57, 58, 49, 48, 58, 49, 49, 90, 32, 253, 186, 201, 177,
87, 72, 141, 119, 36, 224, 63, 184, 216, 74, 55, 106, 67, 184, 244, 21, 24, 161, 11, 117, 135, 187, 167, 181, 188, 22, 59, 206, 105, 231, 150, 215, 30, 78, 212, 76,
28, 195, 135, 182, 105, 178, 238, 101, 134, 192, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 4, 16, 252, 180, 72, 134, 137, 247, 161, 68, 192, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 4, 5,
5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 6, 5, 4, 1, 1, 1, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 6, 5, 4, 1, 1, 1, 1,
1, 0, 0, 0, 218, 65, 89, 124, 81, 87, 72, 141, 119, 36, 224, 63, 184, 216, 74, 55, 0, 0, 0, 32, 253, 186, 201, 177, 11, 117, 135, 187, 167, 181, 188, 22, 59, 206,
106, 67, 184, 244, 21, 24, 161, 28, 195, 135, 182, 105, 178, 238, 101, 134, 192, 0, 105, 231, 150, 215, 30, 78, 212, 76, 16, 252, 180, 72, 134, 137, 247, 161, 68, 192,
0, 0, 0, 0, 0, 0, 218, 65, 89, 124, 81, 87, 72, 141, 119, 36, 224, 63, 184, 216, 0, 0, 0, 0, 0, 0, 0, 32, 253, 186, 201, 177, 11, 117, 135, 187, 167, 181, 188, 22,
74, 55, 106, 67, 184, 244, 21, 24, 161, 28, 195, 135, 182, 105, 178, 238, 101, 134 59, 206, 105, 231, 150, 215, 30, 78, 212, 76, 16, 252, 180, 72, 134, 137, 247, 161,
68
] ]
); );

View File

@ -18,6 +18,7 @@ use std::sync::{Arc, RwLock};
use std::thread::Result; use std::thread::Result;
use tpu::{Tpu, TpuReturnType}; use tpu::{Tpu, TpuReturnType};
use tvu::{Tvu, TvuReturnType}; use tvu::{Tvu, TvuReturnType};
use untrusted::Input;
use window::{new_window, SharedWindow}; use window::{new_window, SharedWindow};
pub enum NodeRole { pub enum NodeRole {
@ -107,22 +108,20 @@ pub struct Fullnode {
/// Fullnode configuration to be stored in file /// Fullnode configuration to be stored in file
pub struct Config { pub struct Config {
pub node_info: NodeInfo, pub node_info: NodeInfo,
keypair_bytes: Vec<u8>, pkcs8: Vec<u8>,
} }
impl Config { impl Config {
pub fn new(bind_addr: &SocketAddr, keypair_bytes: Vec<u8>) -> Self { pub fn new(bind_addr: &SocketAddr, pkcs8: Vec<u8>) -> Self {
let keypair = let keypair =
Keypair::from_bytes(&keypair_bytes).expect("from_bytes in fullnode::Config new"); Keypair::from_pkcs8(Input::from(&pkcs8)).expect("from_pkcs8 in fullnode::Config new");
let pubkey = keypair.pubkey(); let pubkey = keypair.pubkey();
let node_info = NodeInfo::new_with_pubkey_socketaddr(pubkey, bind_addr); let node_info = NodeInfo::new_with_pubkey_socketaddr(pubkey, bind_addr);
Config { Config { node_info, pkcs8 }
node_info,
keypair_bytes,
}
} }
pub fn keypair(&self) -> Keypair { pub fn keypair(&self) -> Keypair {
Keypair::from_bytes(&self.keypair_bytes).expect("from_bytes in fullnode::Config keypair") Keypair::from_pkcs8(Input::from(&self.pkcs8))
.expect("from_pkcs8 in fullnode::Config keypair")
} }
} }

View File

@ -87,7 +87,6 @@ extern crate bytes;
extern crate chrono; extern crate chrono;
extern crate clap; extern crate clap;
extern crate dirs; extern crate dirs;
extern crate ed25519_dalek;
extern crate elf; extern crate elf;
extern crate generic_array; extern crate generic_array;
#[cfg(test)] #[cfg(test)]
@ -104,6 +103,7 @@ extern crate nix;
extern crate pnet_datalink; extern crate pnet_datalink;
extern crate rayon; extern crate rayon;
extern crate reqwest; extern crate reqwest;
extern crate ring;
extern crate serde; extern crate serde;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
@ -122,6 +122,7 @@ extern crate solana_sdk;
extern crate sys_info; extern crate sys_info;
extern crate tokio; extern crate tokio;
extern crate tokio_codec; extern crate tokio_codec;
extern crate untrusted;
#[cfg(test)] #[cfg(test)]
#[macro_use] #[macro_use]

View File

@ -2,14 +2,16 @@
use entry::Entry; use entry::Entry;
use hash::{hash, Hash}; use hash::{hash, Hash};
use ring::rand::SystemRandom;
use signature::{Keypair, KeypairUtil}; use signature::{Keypair, KeypairUtil};
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
use system_transaction::SystemTransaction; use system_transaction::SystemTransaction;
use transaction::Transaction; use transaction::Transaction;
use untrusted::Input;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Mint { pub struct Mint {
pub keypair_bytes: Vec<u8>, pub pkcs8: Vec<u8>,
pubkey: Pubkey, pubkey: Pubkey,
pub tokens: u64, pub tokens: u64,
pub bootstrap_leader_id: Pubkey, pub bootstrap_leader_id: Pubkey,
@ -17,16 +19,17 @@ pub struct Mint {
} }
impl Mint { impl Mint {
pub fn new_with_keypair_bytes( pub fn new_with_pkcs8(
tokens: u64, tokens: u64,
keypair_bytes: Vec<u8>, pkcs8: Vec<u8>,
bootstrap_leader_id: Pubkey, bootstrap_leader_id: Pubkey,
bootstrap_leader_tokens: u64, bootstrap_leader_tokens: u64,
) -> Self { ) -> Self {
let keypair = Keypair::from_bytes(&keypair_bytes).expect("from_bytes in mint pub fn new"); let keypair =
Keypair::from_pkcs8(Input::from(&pkcs8)).expect("from_pkcs8 in mint pub fn new");
let pubkey = keypair.pubkey(); let pubkey = keypair.pubkey();
Mint { Mint {
keypair_bytes, pkcs8,
pubkey, pubkey,
tokens, tokens,
bootstrap_leader_id, bootstrap_leader_id,
@ -39,16 +42,23 @@ impl Mint {
bootstrap_leader: Pubkey, bootstrap_leader: Pubkey,
bootstrap_leader_tokens: u64, bootstrap_leader_tokens: u64,
) -> Self { ) -> Self {
let bytes = Keypair::new().to_bytes().to_vec(); let rnd = SystemRandom::new();
Self::new_with_keypair_bytes(tokens, bytes, bootstrap_leader, bootstrap_leader_tokens) let pkcs8 = Keypair::generate_pkcs8(&rnd)
.expect("generate_pkcs8 in mint pub fn new")
.to_vec();
Self::new_with_pkcs8(tokens, pkcs8, bootstrap_leader, bootstrap_leader_tokens)
} }
pub fn new(tokens: u64) -> Self { pub fn new(tokens: u64) -> Self {
Self::new_with_leader(tokens, Pubkey::default(), 0) let rnd = SystemRandom::new();
let pkcs8 = Keypair::generate_pkcs8(&rnd)
.expect("generate_pkcs8 in mint pub fn new")
.to_vec();
Self::new_with_pkcs8(tokens, pkcs8, Pubkey::default(), 0)
} }
pub fn seed(&self) -> Hash { pub fn seed(&self) -> Hash {
hash(&self.keypair_bytes) hash(&self.pkcs8)
} }
pub fn last_id(&self) -> Hash { pub fn last_id(&self) -> Hash {
@ -56,7 +66,7 @@ impl Mint {
} }
pub fn keypair(&self) -> Keypair { pub fn keypair(&self) -> Keypair {
Keypair::from_bytes(&self.keypair_bytes).expect("from_bytes in mint pub fn keypair") Keypair::from_pkcs8(Input::from(&self.pkcs8)).expect("from_pkcs8 in mint pub fn keypair")
} }
pub fn pubkey(&self) -> Pubkey { pub fn pubkey(&self) -> Pubkey {

View File

@ -1,19 +1,20 @@
//! The `signature` module provides functionality for public, and private keys. //! The `signature` module provides functionality for public, and private keys.
use bs58; use bs58;
use ed25519_dalek;
use generic_array::typenum::U64; use generic_array::typenum::U64;
use generic_array::GenericArray; use generic_array::GenericArray;
use rand::{ChaChaRng, OsRng, Rng, SeedableRng}; use rand::{ChaChaRng, Rng, SeedableRng};
use rayon::prelude::*; use rayon::prelude::*;
use ring::signature::Ed25519KeyPair;
use ring::{rand, signature};
use serde_json; use serde_json;
use sha2::Sha512;
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
use std::error; use std::error;
use std::fmt; use std::fmt;
use std::fs::File; use std::fs::File;
use untrusted::Input;
pub type Keypair = ed25519_dalek::Keypair; pub type Keypair = Ed25519KeyPair;
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Signature(GenericArray<u8, U64>); pub struct Signature(GenericArray<u8, U64>);
@ -23,9 +24,10 @@ impl Signature {
Signature(GenericArray::clone_from_slice(&signature_slice)) Signature(GenericArray::clone_from_slice(&signature_slice))
} }
pub fn verify(&self, pubkey_bytes: &[u8], message_bytes: &[u8]) -> bool { pub fn verify(&self, pubkey_bytes: &[u8], message_bytes: &[u8]) -> bool {
let pubkey = ed25519_dalek::PublicKey::from_bytes(pubkey_bytes).unwrap(); let pubkey = Input::from(pubkey_bytes);
let signature = ed25519_dalek::Signature::from_bytes(self.0.as_slice()).unwrap(); let message = Input::from(message_bytes);
pubkey.verify::<Sha512>(message_bytes, &signature).is_ok() let signature = Input::from(self.0.as_slice());
signature::verify(&signature::ED25519, pubkey, message, signature).is_ok()
} }
} }
@ -52,16 +54,17 @@ pub trait KeypairUtil {
fn pubkey(&self) -> Pubkey; fn pubkey(&self) -> Pubkey;
} }
impl KeypairUtil for Keypair { impl KeypairUtil for Ed25519KeyPair {
/// Return a new ED25519 keypair /// Return a new ED25519 keypair
fn new() -> Self { fn new() -> Self {
let mut rng: OsRng = OsRng::new().unwrap(); let rng = rand::SystemRandom::new();
Keypair::generate::<Sha512, _>(&mut rng) let pkcs8_bytes = Ed25519KeyPair::generate_pkcs8(&rng).expect("generate_pkcs8");
Ed25519KeyPair::from_pkcs8(Input::from(&pkcs8_bytes)).expect("from_pcks8")
} }
/// Return the public key for the given keypair /// Return the public key for the given keypair
fn pubkey(&self) -> Pubkey { fn pubkey(&self) -> Pubkey {
Pubkey::new(&self.public.to_bytes()) Pubkey::new(self.public_key_bytes())
} }
} }
@ -75,28 +78,33 @@ impl GenKeys {
GenKeys { generator } GenKeys { generator }
} }
fn gen_seed(&mut self) -> [u8; 64] { fn gen_seed(&mut self) -> [u8; 32] {
let mut seed = [0u8; 64]; let mut seed = [0u8; 32];
self.generator.fill(&mut seed); self.generator.fill(&mut seed);
seed seed
} }
fn gen_n_seeds(&mut self, n: u64) -> Vec<[u8; 64]> { fn gen_n_seeds(&mut self, n: u64) -> Vec<[u8; 32]> {
(0..n).map(|_| self.gen_seed()).collect() (0..n).map(|_| self.gen_seed()).collect()
} }
pub fn gen_n_keypairs(&mut self, n: u64) -> Vec<Keypair> { pub fn gen_n_keypairs(&mut self, n: u64) -> Vec<Keypair> {
self.gen_n_seeds(n) self.gen_n_seeds(n)
.into_par_iter() .into_par_iter()
.map(|seed| Keypair::from_bytes(&seed).unwrap()) .map(|seed| Keypair::from_seed_unchecked(Input::from(&seed)).unwrap())
.collect() .collect()
} }
} }
pub fn read_keypair(path: &str) -> Result<Keypair, Box<error::Error>> { pub fn read_pkcs8(path: &str) -> Result<Vec<u8>, Box<error::Error>> {
let file = File::open(path.to_string())?; let file = File::open(path.to_string())?;
let bytes: Vec<u8> = serde_json::from_reader(file)?; let pkcs8: Vec<u8> = serde_json::from_reader(file)?;
let keypair = Keypair::from_bytes(&bytes).unwrap(); 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))?;
Ok(keypair) Ok(keypair)
} }

View File

@ -59,8 +59,10 @@ pub fn init() {
} }
fn verify_packet(packet: &Packet) -> u8 { fn verify_packet(packet: &Packet) -> u8 {
use ring::signature;
use signature::Signature; use signature::Signature;
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
use untrusted;
let msg_start = TX_OFFSET + SIGNED_DATA_OFFSET; let msg_start = TX_OFFSET + SIGNED_DATA_OFFSET;
let sig_start = TX_OFFSET + SIG_OFFSET; let sig_start = TX_OFFSET + SIG_OFFSET;
@ -73,11 +75,12 @@ fn verify_packet(packet: &Packet) -> u8 {
} }
let msg_end = packet.meta.size; let msg_end = packet.meta.size;
let signature = Signature::new(&packet.data[sig_start..sig_end]); signature::verify(
signature.verify( &signature::ED25519,
&packet.data[pubkey_start..pubkey_end], untrusted::Input::from(&packet.data[pubkey_start..pubkey_end]),
&packet.data[msg_start..msg_end], untrusted::Input::from(&packet.data[msg_start..msg_end]),
) as u8 untrusted::Input::from(&packet.data[sig_start..sig_end]),
).is_ok() as u8
} }
fn verify_packet_disabled(_packet: &Packet) -> u8 { fn verify_packet_disabled(_packet: &Packet) -> u8 {

View File

@ -9,7 +9,6 @@ use hash::Hash;
use rand::{ChaChaRng, Rng, SeedableRng}; use rand::{ChaChaRng, Rng, SeedableRng};
use result::{Error, Result}; use result::{Error, Result};
use service::Service; use service::Service;
use sha2::Sha512;
use signature::Keypair; use signature::Keypair;
use signature::Signature; use signature::Signature;
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
@ -139,9 +138,9 @@ impl StorageStage {
entry_height: u64, entry_height: u64,
) -> Result<()> { ) -> Result<()> {
let mut seed = [0u8; 32]; let mut seed = [0u8; 32];
let signature = keypair.sign::<Sha512>(&entry_id.as_ref()); let signature = keypair.sign(&entry_id.as_ref());
seed.copy_from_slice(&signature.to_bytes()[..32]); seed.copy_from_slice(&signature.as_ref()[..32]);
let mut rng = ChaChaRng::from_seed(seed); let mut rng = ChaChaRng::from_seed(seed);
@ -152,7 +151,7 @@ impl StorageStage {
return Ok(()); return Ok(());
} }
// TODO: what if the validator does not have this slice // TODO: what if the validator does not have this slice
let slice = signature.to_bytes()[0] as usize % num_slices; let slice = signature.as_ref()[0] as usize % num_slices;
debug!( debug!(
"storage verifying: slice: {} identities: {}", "storage verifying: slice: {} identities: {}",

View File

@ -3,7 +3,6 @@
use bincode::serialize; use bincode::serialize;
use hash::{Hash, Hasher}; use hash::{Hash, Hasher};
use serde::Serialize; use serde::Serialize;
use sha2::Sha512;
use signature::{Keypair, KeypairUtil, Signature}; use signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
use std::mem::size_of; use std::mem::size_of;
@ -159,7 +158,7 @@ impl Transaction {
pub fn sign(&mut self, keypair: &Keypair, last_id: Hash) { pub fn sign(&mut self, keypair: &Keypair, last_id: Hash) {
self.last_id = last_id; self.last_id = last_id;
let sign_data = self.get_sign_data(); let sign_data = self.get_sign_data();
self.signature = Signature::new(&keypair.sign::<Sha512>(&sign_data).to_bytes()); self.signature = Signature::new(keypair.sign(&sign_data).as_ref());
} }
/// Verify only the transaction signature. /// Verify only the transaction signature.
@ -302,19 +301,19 @@ mod tests {
assert_eq!( assert_eq!(
serialize(&tx).unwrap(), serialize(&tx).unwrap(),
vec![ vec![
238, 228, 120, 18, 14, 44, 44, 74, 186, 124, 104, 174, 137, 227, 237, 157, 147, 37, 234, 139, 34, 5, 120, 28, 107, 203, 69, 25, 236, 200, 164, 1, 12, 47, 147, 53, 41,
230, 74, 20, 48, 234, 36, 170, 60, 68, 184, 171, 240, 203, 18, 255, 110, 164, 67, 143, 23, 116, 230, 203, 59, 228, 153, 14, 22, 241, 103, 226, 186, 169, 181, 65, 49,
212, 206, 115, 182, 13, 90, 38, 215, 191, 51, 79, 183, 57, 102, 248, 221, 114, 72, 215, 44, 2, 61, 214, 113, 216, 184, 206, 147, 104, 140, 225, 138, 21, 172, 135,
120, 66, 113, 146, 251, 102, 69, 187, 25, 8, 3, 0, 0, 0, 0, 0, 0, 0, 218, 65, 89, 211, 80, 103, 80, 216, 106, 249, 86, 194, 1, 3, 0, 0, 0, 0, 0, 0, 0, 32, 253, 186,
124, 81, 87, 72, 141, 119, 36, 224, 63, 184, 216, 74, 55, 106, 67, 184, 244, 21, 201, 177, 11, 117, 135, 187, 167, 181, 188, 22, 59, 206, 105, 231, 150, 215, 30,
24, 161, 28, 195, 135, 182, 105, 178, 238, 101, 134, 218, 65, 89, 124, 81, 87, 72, 78, 212, 76, 16, 252, 180, 72, 134, 137, 247, 161, 68, 32, 253, 186, 201, 177, 11,
141, 119, 36, 224, 63, 184, 216, 74, 55, 106, 67, 184, 244, 21, 24, 161, 28, 195, 117, 135, 187, 167, 181, 188, 22, 59, 206, 105, 231, 150, 215, 30, 78, 212, 76, 16,
135, 182, 105, 178, 238, 101, 134, 1, 1, 1, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 252, 180, 72, 134, 137, 247, 161, 68, 1, 1, 1, 4, 5, 6, 7, 8, 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, 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, 99, 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, 99, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 4, 5, 6, 7, 8, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 4, 5, 6, 7, 8, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 9, 8, 7, 6, 5, 4, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 9, 8, 7, 6, 5, 4, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0,
0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3
], ],
); );
} }

View File

@ -10,6 +10,8 @@ use elf;
use fullnode::Config; use fullnode::Config;
use hash::Hash; use hash::Hash;
use loader_transaction::LoaderTransaction; use loader_transaction::LoaderTransaction;
use ring::rand::SystemRandom;
use ring::signature::Ed25519KeyPair;
use rpc::RpcSignatureStatus; use rpc::RpcSignatureStatus;
use rpc_request::RpcRequest; use rpc_request::RpcRequest;
use serde_json; use serde_json;
@ -689,8 +691,9 @@ pub fn request_airdrop(
} }
pub fn gen_keypair_file(outfile: String) -> Result<String, Box<error::Error>> { pub fn gen_keypair_file(outfile: String) -> Result<String, Box<error::Error>> {
let keypair_bytes = Keypair::new().to_bytes(); let rnd = SystemRandom::new();
let serialized = serde_json::to_string(&keypair_bytes.to_vec())?; let pkcs8_bytes = Ed25519KeyPair::generate_pkcs8(&rnd)?;
let serialized = serde_json::to_string(&pkcs8_bytes.to_vec())?;
if outfile != "-" { if outfile != "-" {
if let Some(outdir) = Path::new(&outfile).parent() { if let Some(outdir) = Path::new(&outfile).parent() {
@ -792,7 +795,7 @@ mod tests {
use leader_scheduler::LeaderScheduler; use leader_scheduler::LeaderScheduler;
use ledger::create_tmp_genesis; use ledger::create_tmp_genesis;
use serde_json::Value; use serde_json::Value;
use signature::{read_keypair, Keypair, KeypairUtil}; use signature::{read_keypair, read_pkcs8, Keypair, KeypairUtil};
use std::fs::remove_dir_all; use std::fs::remove_dir_all;
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
@ -1250,10 +1253,8 @@ mod tests {
let serialized_keypair = gen_keypair_file(outfile.to_string()).unwrap(); let serialized_keypair = gen_keypair_file(outfile.to_string()).unwrap();
let keypair_vec: Vec<u8> = serde_json::from_str(&serialized_keypair).unwrap(); let keypair_vec: Vec<u8> = serde_json::from_str(&serialized_keypair).unwrap();
assert!(Path::new(&outfile).exists()); assert!(Path::new(&outfile).exists());
assert_eq!( assert_eq!(keypair_vec, read_pkcs8(&outfile).unwrap());
read_keypair(&outfile).unwrap().to_bytes().to_vec(), assert!(read_keypair(&outfile).is_ok());
keypair_vec
);
assert_eq!( assert_eq!(
read_keypair(&outfile).unwrap().pubkey().as_ref().len(), read_keypair(&outfile).unwrap().pubkey().as_ref().len(),
mem::size_of::<Pubkey>() mem::size_of::<Pubkey>()