Skip to content

Commit 0eb5531

Browse files
committed
Add 'allow_uncertified_signer_registration' feature to 'mithril-common'
If activated, it auhorizes the now deprecated signer registration without certification. This feature will be removed soon when this deprecated registration is decommissioned.
1 parent 9d4b6f8 commit 0eb5531

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

mithril-common/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ mithril-stm = { path = "../mithril-stm", default-features = false, features = ["
5454
slog-scope = "4.4.0"
5555

5656
[features]
57+
default = ["allow_uncertified_signer_registration"]
5758
portable = ["mithril-stm/portable"]
5859
test_only = []
5960
allow_skip_signer_certification = []
61+
allow_uncertified_signer_registration = []
62+

mithril-common/src/crypto_helper/cardano/key_certification.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ pub enum ProtocolRegistrationErrorWrapper {
4343
#[error("party id does not exist in the stake distribution")]
4444
PartyIdNonExisting,
4545

46+
/// Error raised when the operational certificate is missing
47+
#[error("missing operational certificate")]
48+
OpCertMissing,
49+
4650
/// Error raised when an operational certificate is invalid
4751
#[error("invalid operational certificate")]
4852
OpCertInvalid,
@@ -243,7 +247,10 @@ impl KeyRegWrapper {
243247
}
244248
pool_id.ok_or(ProtocolRegistrationErrorWrapper::KesSignatureInvalid)?
245249
} else {
246-
println!("WARNING: Signer certification is skipped! {:?}", party_id);
250+
if cfg!(not(feature = "allow_uncertified_signer_registration")) {
251+
Err(ProtocolRegistrationErrorWrapper::OpCertMissing)?
252+
}
253+
println!("WARNING: Uncertified signer regsitration by providing a Pool Id is deprecated and will be removed soon! (Pool Id: {:?})", party_id);
247254
party_id.ok_or(ProtocolRegistrationErrorWrapper::PartyIdMissing)?
248255
};
249256

mithril-common/src/crypto_helper/tests_setup.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use std::{cmp::min, fs, sync::Arc};
1515

1616
use std::{collections::HashMap, path::PathBuf};
1717

18-
fn setup_temp_directory_for_signer(
18+
/// Create or retrieve a temporary directory for storing cryptographic material for a signer, use this for tests only.
19+
pub fn setup_temp_directory_for_signer(
1920
party_id: &ProtocolPartyId,
2021
auto_create: bool,
2122
) -> Option<PathBuf> {
@@ -62,8 +63,11 @@ pub fn setup_signers(
6263
let stake_distribution = (0..total)
6364
.into_iter()
6465
.map(|party_idx| {
65-
let party_id = if party_idx % 2 == 0 {
66-
// 50% of signers with key certification
66+
let party_id = if party_idx % 2 == 0
67+
|| cfg!(not(feature = "allow_uncertified_signer_registration"))
68+
{
69+
// 50% of signers with key certification if allow unverified signer registration
70+
// Or 100% of signers otherwise
6771
let keypair = ColdKeyGenerator::create_deterministic_keypair([party_idx as u8; 32]);
6872
let (kes_secret_key, kes_verification_key) = Sum6Kes::keygen(&mut kes_keys_seed);
6973
let operational_certificate = OpCert::new(kes_verification_key, 0, 0, keypair);
@@ -77,14 +81,15 @@ pub fn setup_signers(
7781
.to_file(temp_dir.join("kes.sk"))
7882
.expect("KES secret key file export should not fail");
7983
}
80-
if !temp_dir.join("pool.cert").exists() {
84+
if !temp_dir.join("opcert.cert").exists() {
8185
operational_certificate
82-
.to_file(temp_dir.join("pool.cert"))
86+
.to_file(temp_dir.join("opcert.cert"))
8387
.expect("operational certificate file export should not fail");
8488
}
8589
party_id
8690
} else {
87-
// 50% of signers without key certification (legacy)
91+
// 50% of signers without key certification (legacy) if allow unverified signer registration
92+
// Or 0% of signers otherwise
8893
// TODO: Should be removed once the signer certification is fully deployed
8994
format!("{:<032}", party_idx)
9095
};
@@ -132,7 +137,7 @@ pub fn setup_signers_from_stake_distribution(
132137
.for_each(|(party_id, _stake, protocol_initializer)| {
133138
let temp_dir = setup_temp_directory_for_signer(party_id, false);
134139
let operational_certificate = temp_dir.as_ref().map(|dir| {
135-
OpCert::from_file(dir.join("pool.cert"))
140+
OpCert::from_file(dir.join("opcert.cert"))
136141
.expect("operational certificate decoding should not fail")
137142
});
138143
let verification_key = protocol_initializer.verification_key();
@@ -154,7 +159,7 @@ pub fn setup_signers_from_stake_distribution(
154159
.map(|(party_id, stake, protocol_initializer)| {
155160
let temp_dir = setup_temp_directory_for_signer(&party_id, false);
156161
let operational_certificate: Option<OpCert> = temp_dir.as_ref().map(|dir| {
157-
OpCert::from_file(dir.join("pool.cert"))
162+
OpCert::from_file(dir.join("opcert.cert"))
158163
.expect("operational certificate decoding should not fail")
159164
});
160165
let kes_period = 0;

0 commit comments

Comments
 (0)