mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Improve bls::SecretKey privacy (#1164)
* Improve bls::SecretKey privacy * Add missed file * Remove more methods from bls::SecretKey * Add as_bytes() to SecretKey, remove as_raw * Remove as_raw * Add back as_raw * Address review comments
This commit is contained in:
@@ -17,8 +17,6 @@ eth2_keystore = { path = "../../crypto/eth2_keystore" }
|
||||
types = { path = "../../consensus/types" }
|
||||
rand = "0.7.2"
|
||||
deposit_contract = { path = "../deposit_contract" }
|
||||
eth2_ssz = { path = "../../consensus/ssz" }
|
||||
eth2_ssz_derive = { path = "../../consensus/ssz_derive" }
|
||||
rayon = "1.3.0"
|
||||
tree_hash = { path = "../../consensus/tree_hash" }
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
//! we're confident that no-one is using these keypairs anymore (hopefully mid-June 2020).
|
||||
#![cfg(feature = "unencrypted_keys")]
|
||||
|
||||
use bls::{BLS_PUBLIC_KEY_BYTE_SIZE as PK_LEN, BLS_SECRET_KEY_BYTE_SIZE as SK_LEN};
|
||||
use eth2_keystore::PlainText;
|
||||
use ssz::Decode;
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
@@ -32,35 +31,18 @@ pub fn load_unencrypted_keypair<P: AsRef<Path>>(path: P) -> Result<Keypair, Stri
|
||||
|
||||
let bytes: PlainText = bytes.into();
|
||||
|
||||
SszEncodableKeypair::from_ssz_bytes(bytes.as_bytes())
|
||||
.map(Into::into)
|
||||
.map_err(|e| format!("Unable to decode keypair: {:?}", e))
|
||||
}
|
||||
|
||||
/// A helper struct to allow SSZ enc/dec for a `Keypair`.
|
||||
///
|
||||
/// This only exists as compatibility with the old scheme and should not be implemented on any new
|
||||
/// features.
|
||||
#[derive(Encode, Decode)]
|
||||
pub struct SszEncodableKeypair {
|
||||
pk: PublicKey,
|
||||
sk: SecretKey,
|
||||
}
|
||||
|
||||
impl Into<Keypair> for SszEncodableKeypair {
|
||||
fn into(self) -> Keypair {
|
||||
Keypair {
|
||||
sk: self.sk,
|
||||
pk: self.pk,
|
||||
}
|
||||
if bytes.len() != PK_LEN + SK_LEN {
|
||||
return Err(format!("Invalid keypair byte length: {}", bytes.len()));
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keypair> for SszEncodableKeypair {
|
||||
fn from(kp: Keypair) -> Self {
|
||||
Self {
|
||||
sk: kp.sk,
|
||||
pk: kp.pk,
|
||||
}
|
||||
}
|
||||
let pk_bytes = &bytes.as_bytes()[..PK_LEN];
|
||||
let sk_bytes = &bytes.as_bytes()[PK_LEN..];
|
||||
|
||||
let pk = PublicKey::from_bytes(pk_bytes)
|
||||
.map_err(|e| format!("Unable to decode public key: {:?}", e))?;
|
||||
|
||||
let sk = SecretKey::from_bytes(sk_bytes)
|
||||
.map_err(|e| format!("Unable to decode secret key: {:?}", e))?;
|
||||
|
||||
Ok(Keypair { pk, sk })
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ impl Harness {
|
||||
check_keystore(&validator.dir().join(VOTING_KEYSTORE_FILE), &password_dir);
|
||||
|
||||
if !config.random_voting_keystore {
|
||||
assert_eq!(voting_keypair, generate_deterministic_keypair(0))
|
||||
assert_eq!(voting_keypair.pk, generate_deterministic_keypair(0).pk)
|
||||
}
|
||||
|
||||
// Use OR here instead of AND so we *always* check for the withdrawal keystores if random
|
||||
@@ -128,11 +128,11 @@ impl Harness {
|
||||
let withdrawal_keypair = check_keystore(&withdrawal_keystore_path, &password_dir);
|
||||
|
||||
if !config.random_withdrawal_keystore {
|
||||
assert_eq!(withdrawal_keypair, generate_deterministic_keypair(1))
|
||||
assert_eq!(withdrawal_keypair.pk, generate_deterministic_keypair(1).pk)
|
||||
}
|
||||
|
||||
// The withdrawal keys should be distinct from the voting keypairs.
|
||||
assert_ne!(withdrawal_keypair, voting_keypair);
|
||||
assert_ne!(withdrawal_keypair.pk, voting_keypair.pk);
|
||||
}
|
||||
|
||||
if !config.store_withdrawal_keystore && !config.random_withdrawal_keystore {
|
||||
|
||||
Reference in New Issue
Block a user