Skip to content

Factorize hardcoded keys #1109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.3.61"
version = "0.3.62"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion mithril-aggregator/src/database/provider/test_helper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use chrono::Utc;
use mithril_common::test_utils::fake_keys;
use mithril_common::{entities::Epoch, StdResult};
use sqlite::{Connection, Value};
use uuid::Uuid;
Expand All @@ -25,7 +26,7 @@ pub fn setup_single_signature_records(
signer_id: format!("signer-{signer_idx}"),
registration_epoch_setting_id: Epoch(epoch),
lottery_indexes: (1..=single_signature_id).collect(),
signature: "7b227369676d61223a5b3133302c32382c3134332c31372c38302c31302c3231352c3138382c3230352c3132322c31312c3233392c34362c3234352c32312c3139332c32382c3232312c3133302c34302c3131362c39322c3139362c33352c3235342c34332c3138382c362c38372c3136392c37312c3134352c3130342c3137382c392c3136362c39342c31332c3234372c3139302c3130322c37312c3232362c3230392c312c3230392c3235312c3137305d2c22696e6465786573223a5b302c312c382c31322c31332c31342c31382c31392c32332c32352c32362c32372c32382c33322c33332c33342c33352c33372c33382c33392c34312c34322c34332c34342c34352c34362c34372c34382c34392c35302c35312c35322c35332c35342c35352c35362c35372c35382c35392c36302c36312c36332c36342c36352c36372c36382c37302c37312c37352c37362c37372c37392c38302c38312c38322c38342c38352c38392c39302c39312c39332c39352c39372c39382c39395d2c227369676e65725f696e646578223a337d".to_string(),
signature: fake_keys::single_signature()[3].to_string(),
created_at: Utc::now(),
});
}
Expand Down
11 changes: 7 additions & 4 deletions mithril-aggregator/src/store/verification_key_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub(crate) use test_verification_key_storer;
#[cfg(test)]
pub mod test_suite {
use mithril_common::entities::{Epoch, PartyId, Signer, SignerWithStake};
use mithril_common::test_utils::fake_keys;
use std::collections::{BTreeMap, HashMap};
use std::sync::Arc;

Expand All @@ -156,7 +157,9 @@ pub mod test_suite {
party_id.clone(),
SignerWithStake {
party_id: party_id.clone(),
verification_key: "7b22766b223a5b3134352c32332c3135382c31322c3138332c3230392c33322c3134302c33372c3132342c3136362c3231352c3136302c3231352c3235302c3133342c3135342c3235302c3234312c3230362c3139342c3232322c382c35392c33332c392c35382c322c3235312c31302c33322c3135352c3232372c3134332c3232362c35372c3135312c37342c3139392c3131372c37352c3136382c3134302c34362c3233392c3134352c37322c31362c32312c3138312c3139332c3134362c38362c3231332c3230342c3139332c3232332c32352c3135372c33342c33332c3232372c35312c3132362c3132362c3135362c36342c3232302c3139392c3231332c31362c34352c3131302c3234332c33352c3134382c37312c3231382c3132342c3132332c31362c3132312c3135322c31382c32362c3231322c3231342c3230312c3139302c3137342c3131352c39372c3234392c3235342c3131362c3234335d2c22706f70223a5b3138332c3134352c3133392c3234322c3132302c3136302c35362c3131382c3234322c3230342c39312c38392c32312c3138342c382c34372c3231332c3130352c36332c3135302c32312c3231372c352c382c3231392c3138382c3131342c3230352c3136362c31362c3234302c3234302c3231342c31362c3230342c3231382c3139332c3138312c32342c35362c34352c39392c3234342c38312c32352c35322c3232342c36372c3136382c3136392c3130392c3132322c38372c34392c3137302c3138312c3135312c31352c3235322c3139352c3231312c3233342c3139352c34392c39312c31392c35312c3234312c33332c35382c3134302c3235322c3234322c362c342c34302c32312c3136372c3234392c3235312c33362c38372c36302c39362c36392c3135322c3231302c39382c3136352c352c362c34312c39362c3233352c37352c3138335d7d".try_into().unwrap(),
verification_key: fake_keys::signer_verification_key()[0]
.try_into()
.unwrap(),
verification_key_signature: None,
operational_certificate: None,
kes_period: None,
Expand All @@ -178,7 +181,7 @@ pub mod test_suite {
Epoch(0),
SignerWithStake {
party_id: "0".to_string(),
verification_key: "7b22766b223a5b3134352c32332c3135382c31322c3138332c3230392c33322c3134302c33372c3132342c3136362c3231352c3136302c3231352c3235302c3133342c3135342c3235302c3234312c3230362c3139342c3232322c382c35392c33332c392c35382c322c3235312c31302c33322c3135352c3232372c3134332c3232362c35372c3135312c37342c3139392c3131372c37352c3136382c3134302c34362c3233392c3134352c37322c31362c32312c3138312c3139332c3134362c38362c3231332c3230342c3139332c3232332c32352c3135372c33342c33332c3232372c35312c3132362c3132362c3135362c36342c3232302c3139392c3231332c31362c34352c3131302c3234332c33352c3134382c37312c3231382c3132342c3132332c31362c3132312c3135322c31382c32362c3231322c3231342c3230312c3139302c3137342c3131352c39372c3234392c3235342c3131362c3234335d2c22706f70223a5b3138332c3134352c3133392c3234322c3132302c3136302c35362c3131382c3234322c3230342c39312c38392c32312c3138342c382c34372c3231332c3130352c36332c3135302c32312c3231372c352c382c3231392c3138382c3131342c3230352c3136362c31362c3234302c3234302c3231342c31362c3230342c3231382c3139332c3138312c32342c35362c34352c39392c3234342c38312c32352c35322c3232342c36372c3136382c3136392c3130392c3132322c38372c34392c3137302c3138312c3135312c31352c3235322c3139352c3231312c3233342c3139352c34392c39312c31392c35312c3234312c33332c35382c3134302c3235322c3234322c362c342c34302c32312c3136372c3234392c3235312c33362c38372c36302c39362c36392c3135322c3231302c39382c3136352c352c362c34312c39362c3233352c37352c3138335d7d".try_into().unwrap(),
verification_key: fake_keys::signer_verification_key()[0].try_into().unwrap(),
verification_key_signature: None,
operational_certificate: None,
kes_period: None,
Expand All @@ -199,7 +202,7 @@ pub mod test_suite {
Epoch(1),
SignerWithStake {
party_id: "party_id:e1:1".to_string(),
verification_key: "7b22766b223a5b3134352c35362c3137352c33322c3132322c3138372c3231342c3232362c3235312c3134382c38382c392c312c3130332c3135392c3134362c38302c3136362c3130372c3234332c3235312c3233362c34312c32382c3131312c3132382c3230372c3136342c3133322c3134372c3232382c38332c3234362c3232382c3137302c36382c38392c37382c36302c32382c3132332c3133302c38382c3233342c33382c39372c34322c36352c312c3130302c35332c31382c37382c3133312c382c36312c3132322c3133312c3233382c38342c3233332c3232332c3135342c3131382c3131382c37332c32382c32372c3130312c37382c38302c3233332c3132332c3230362c3232302c3137342c3133342c3230352c37312c3131302c3131322c3138302c39372c39382c302c3131332c36392c3134352c3233312c3136382c34332c3137332c3137322c35362c3130342c3230385d2c22706f70223a5b3133372c3231342c37352c37352c3134342c3136312c3133372c37392c39342c3134302c3138312c34372c33312c38312c3231332c33312c3137312c3231362c32342c3137342c37382c3234382c3133302c37352c3235352c31312c3134352c3132342c36312c38302c3139302c32372c3231362c3130352c3130362c3234382c39312c3134332c3230342c3130322c3230332c3136322c37362c3130372c31352c35322c36312c38322c3134362c3133302c3132342c37342c382c33342c3136342c3138372c3230332c38322c36342c3130382c3139312c3138352c3138382c37372c3132322c352c3234362c3235352c3130322c3131392c3234372c3139392c3131372c36372c3234312c3134332c32392c3136382c36372c39342c3135312c37382c3132392c3133312c33302c3130312c3137332c31302c36392c36382c3137352c39382c33372c3233392c3139342c32395d7d".try_into().unwrap(),
verification_key: fake_keys::signer_verification_key()[2].try_into().unwrap(),
verification_key_signature: None,
operational_certificate: None,
kes_period: None,
Expand All @@ -212,7 +215,7 @@ pub mod test_suite {
assert_eq!(
Some(SignerWithStake {
party_id: "party_id:e1:1".to_string(),
verification_key: "7b22766b223a5b3134352c35362c3137352c33322c3132322c3138372c3231342c3232362c3235312c3134382c38382c392c312c3130332c3135392c3134362c38302c3136362c3130372c3234332c3235312c3233362c34312c32382c3131312c3132382c3230372c3136342c3133322c3134372c3232382c38332c3234362c3232382c3137302c36382c38392c37382c36302c32382c3132332c3133302c38382c3233342c33382c39372c34322c36352c312c3130302c35332c31382c37382c3133312c382c36312c3132322c3133312c3233382c38342c3233332c3232332c3135342c3131382c3131382c37332c32382c32372c3130312c37382c38302c3233332c3132332c3230362c3232302c3137342c3133342c3230352c37312c3131302c3131322c3138302c39372c39382c302c3131332c36392c3134352c3233312c3136382c34332c3137332c3137322c35362c3130342c3230385d2c22706f70223a5b3133372c3231342c37352c37352c3134342c3136312c3133372c37392c39342c3134302c3138312c34372c33312c38312c3231332c33312c3137312c3231362c32342c3137342c37382c3234382c3133302c37352c3235352c31312c3134352c3132342c36312c38302c3139302c32372c3231362c3130352c3130362c3234382c39312c3134332c3230342c3130322c3230332c3136322c37362c3130372c31352c35322c36312c38322c3134362c3133302c3132342c37342c382c33342c3136342c3138372c3230332c38322c36342c3130382c3139312c3138352c3138382c37372c3132322c352c3234362c3235352c3130322c3131392c3234372c3139392c3131372c36372c3234312c3134332c32392c3136382c36372c39342c3135312c37382c3132392c3133312c33302c3130312c3137332c31302c36392c36382c3137352c39382c33372c3233392c3139342c32395d7d".try_into().unwrap(),
verification_key: fake_keys::signer_verification_key()[2].try_into().unwrap(),
verification_key_signature: None,
operational_certificate: None,
kes_period: None,
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/tools/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl GenesisTools {
let mut genesis_secret_key_serialized = String::new();
genesis_secret_key_file.read_to_string(&mut genesis_secret_key_serialized)?;

let genesis_secret_key = key_decode_hex(&genesis_secret_key_serialized.trim().to_string())?;
let genesis_secret_key = key_decode_hex(genesis_secret_key_serialized.trim())?;
let genesis_signer = ProtocolGenesisSigner::from_secret_key(genesis_secret_key);

let mut to_sign_payload_file = File::open(to_sign_payload_path).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion mithril-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-client"
version = "0.3.24"
version = "0.3.25"
description = "A Mithril Client"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
15 changes: 6 additions & 9 deletions mithril-client/src/services/mithril_stake_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,12 @@ impl MithrilStakeDistributionService for AppMithrilStakeDistributionService {
)
})?;

let genesis_verification_key = key_decode_hex(&genesis_verification_key.to_string())
.map_err(
|e| MithrilStakeDistributionServiceError::InvalidParameters {
context: format!(
"Invalid genesis verification key '{genesis_verification_key}'"
),
error: e.into(),
},
)?;
let genesis_verification_key = key_decode_hex(genesis_verification_key).map_err(|e| {
MithrilStakeDistributionServiceError::InvalidParameters {
context: format!("Invalid genesis verification key '{genesis_verification_key}'"),
error: e.into(),
}
})?;
self.certificate_verifier
.verify_certificate_chain(
certificate.clone(),
Expand Down
7 changes: 4 additions & 3 deletions mithril-client/src/services/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ impl MithrilClientSnapshotService {
genesis_verification_key: &str,
certificate: &Certificate,
) -> StdResult<()> {
let genesis_verification_key = key_decode_hex(&genesis_verification_key.to_string())
.map_err(|e| SnapshotServiceError::InvalidParameters {
let genesis_verification_key = key_decode_hex(genesis_verification_key).map_err(|e| {
SnapshotServiceError::InvalidParameters {
context: format!("Invalid genesis verification key '{genesis_verification_key}'"),
error: e.into(),
})?;
}
})?;
let genesis_verifier =
ProtocolGenesisVerifier::from_verification_key(genesis_verification_key);

Expand Down
2 changes: 1 addition & 1 deletion mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-common"
version = "0.2.84"
version = "0.2.85"
authors = { workspace = true }
edition = { workspace = true }
documentation = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions mithril-common/src/certificate_chain/certificate_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ impl CertificateVerifier for MithrilCertificateVerifier {
"Verify multi signature for {:?}",
message.encode_hex::<String>()
);
let multi_signature: ProtocolMultiSignature = key_decode_hex(&multi_signature.to_string())
.map_err(CertificateVerifierError::Codec)?;
let aggregate_verification_key = key_decode_hex(&aggregate_verification_key.to_string())
.map_err(CertificateVerifierError::Codec)?;
let multi_signature: ProtocolMultiSignature =
key_decode_hex(multi_signature).map_err(CertificateVerifierError::Codec)?;
let aggregate_verification_key =
key_decode_hex(aggregate_verification_key).map_err(CertificateVerifierError::Codec)?;
multi_signature
.verify(
message,
Expand Down
4 changes: 2 additions & 2 deletions mithril-common/src/crypto_helper/codec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::entities::HexEncodedKey;
use crate::entities::{HexEncodedKey, HexEncodedKeySlice};

use hex::{FromHex, ToHex};
use serde::de::DeserializeOwned;
Expand All @@ -15,7 +15,7 @@ where
}

/// Decode key from hex helper
pub fn key_decode_hex<T>(from: &HexEncodedKey) -> Result<T, String>
pub fn key_decode_hex<T>(from: HexEncodedKeySlice) -> Result<T, String>
where
T: DeserializeOwned,
{
Expand Down
6 changes: 3 additions & 3 deletions mithril-common/src/crypto_helper/types/protocol_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ where

/// Create an instance from a JSON hex representation
pub fn from_json_hex(hex_string: &str) -> StdResult<Self> {
let key = key_decode_hex::<T>(&hex_string.to_owned())
let key = key_decode_hex::<T>(hex_string)
.map_err(|e| anyhow!(e))
.with_context(|| {
format!(
Expand Down Expand Up @@ -152,11 +152,11 @@ macro_rules! impl_from_to_stm_types_for_protocol_key {

#[cfg(test)]
mod test {
use crate::crypto_helper::ProtocolKey;
use crate::{crypto_helper::ProtocolKey, test_utils::fake_keys};
use mithril_stm::stm::StmVerificationKeyPoP;
use serde::{Deserialize, Serialize};

const VERIFICATION_KEY: &str = "7b22766b223a5b3134352c32332c3135382c31322c3138332c3230392c33322c3134302c33372c3132342c3136362c3231352c3136302c3231352c3235302c3133342c3135342c3235302c3234312c3230362c3139342c3232322c382c35392c33332c392c35382c322c3235312c31302c33322c3135352c3232372c3134332c3232362c35372c3135312c37342c3139392c3131372c37352c3136382c3134302c34362c3233392c3134352c37322c31362c32312c3138312c3139332c3134362c38362c3231332c3230342c3139332c3232332c32352c3135372c33342c33332c3232372c35312c3132362c3132362c3135362c36342c3232302c3139392c3231332c31362c34352c3131302c3234332c33352c3134382c37312c3231382c3132342c3132332c31362c3132312c3135322c31382c32362c3231322c3231342c3230312c3139302c3137342c3131352c39372c3234392c3235342c3131362c3234335d2c22706f70223a5b3138332c3134352c3133392c3234322c3132302c3136302c35362c3131382c3234322c3230342c39312c38392c32312c3138342c382c34372c3231332c3130352c36332c3135302c32312c3231372c352c382c3231392c3138382c3131342c3230352c3136362c31362c3234302c3234302c3231342c31362c3230342c3231382c3139332c3138312c32342c35362c34352c39392c3234342c38312c32352c35322c3232342c36372c3136382c3136392c3130392c3132322c38372c34392c3137302c3138312c3135312c31352c3235322c3139352c3231312c3233342c3139352c34392c39312c31392c35312c3234312c33332c35382c3134302c3235322c3234322c362c342c34302c32312c3136372c3234392c3235312c33362c38372c36302c39362c36392c3135322c3231302c39382c3136352c352c362c34312c39362c3233352c37352c3138335d7d";
static VERIFICATION_KEY: &str = fake_keys::signer_verification_key()[0];

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
struct Container {
Expand Down
9 changes: 6 additions & 3 deletions mithril-common/src/entities/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,25 @@ impl Certificate {
#[cfg(test)]
mod tests {
use super::*;
use crate::entities::{ProtocolMessagePartKey, ProtocolParameters, SignerWithStake};
use crate::{
entities::{ProtocolMessagePartKey, ProtocolParameters, SignerWithStake},
test_utils::fake_keys,
};
use chrono::{Duration, TimeZone, Timelike, Utc};

fn get_signers_with_stake() -> Vec<SignerWithStake> {
vec![
SignerWithStake::new(
"1".to_string(),
"7b22766b223a5b3134332c3136312c3235352c34382c37382c35372c3230342c3232302c32352c3232312c3136342c3235322c3234382c31342c35362c3132362c3138362c3133352c3232382c3138382c3134352c3138312c35322c3230302c39372c39392c3231332c34362c302c3139392c3139332c38392c3138372c38382c32392c3133352c3137332c3234342c38362c33362c38332c35342c36372c3136342c362c3133372c39342c37322c362c3130352c3132382c3132382c39332c34382c3137362c31312c342c3234362c3133382c34382c3138302c3133332c39302c3134322c3139322c32342c3139332c3131312c3134322c33312c37362c3131312c3131302c3233342c3135332c39302c3230382c3139322c33312c3132342c39352c3130322c34392c3135382c39392c35322c3232302c3136352c39342c3235312c36382c36392c3132312c31362c3232342c3139345d2c22706f70223a5b3136382c35302c3233332c3139332c31352c3133362c36352c37322c3132332c3134382c3132392c3137362c33382c3139382c3230392c34372c32382c3230342c3137362c3134342c35372c3235312c34322c32382c36362c37362c38392c39372c3135382c36332c35342c3139382c3139342c3137362c3133352c3232312c31342c3138352c3139372c3232352c3230322c39382c3234332c37342c3233332c3232352c3134332c3135312c3134372c3137372c3137302c3131372c36362c3136352c36362c36322c33332c3231362c3233322c37352c36382c3131342c3139352c32322c3130302c36352c34342c3139382c342c3136362c3130322c3233332c3235332c3234302c35392c3137352c36302c3131372c3134322c3131342c3134302c3132322c31372c38372c3131302c3138372c312c31372c31302c3139352c3135342c31332c3234392c38362c35342c3232365d7d".try_into().unwrap(),
fake_keys::signer_verification_key()[1].try_into().unwrap(),
None,
None,
None,
10,
),
SignerWithStake::new(
"2".to_string(),
"7b22766b223a5b3134352c35362c3137352c33322c3132322c3138372c3231342c3232362c3235312c3134382c38382c392c312c3130332c3135392c3134362c38302c3136362c3130372c3234332c3235312c3233362c34312c32382c3131312c3132382c3230372c3136342c3133322c3134372c3232382c38332c3234362c3232382c3137302c36382c38392c37382c36302c32382c3132332c3133302c38382c3233342c33382c39372c34322c36352c312c3130302c35332c31382c37382c3133312c382c36312c3132322c3133312c3233382c38342c3233332c3232332c3135342c3131382c3131382c37332c32382c32372c3130312c37382c38302c3233332c3132332c3230362c3232302c3137342c3133342c3230352c37312c3131302c3131322c3138302c39372c39382c302c3131332c36392c3134352c3233312c3136382c34332c3137332c3137322c35362c3130342c3230385d2c22706f70223a5b3133372c3231342c37352c37352c3134342c3136312c3133372c37392c39342c3134302c3138312c34372c33312c38312c3231332c33312c3137312c3231362c32342c3137342c37382c3234382c3133302c37352c3235352c31312c3134352c3132342c36312c38302c3139302c32372c3231362c3130352c3130362c3234382c39312c3134332c3230342c3130322c3230332c3136322c37362c3130372c31352c35322c36312c38322c3134362c3133302c3132342c37342c382c33342c3136342c3138372c3230332c38322c36342c3130382c3139312c3138352c3138382c37372c3132322c352c3234362c3235352c3130322c3131392c3234372c3139392c3131372c36372c3234312c3134332c32392c3136382c36372c39342c3135312c37382c3132392c3133312c33302c3130312c3137332c31302c36392c36382c3137352c39382c33372c3233392c3139342c32395d7d".try_into().unwrap(),
fake_keys::signer_verification_key()[2].try_into().unwrap(),
None,
None,
None,
Expand Down
Loading