Skip to content
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

fix(dpp): panic when generating more than 12 identity keys #2195

Open
wants to merge 4 commits into
base: v1.6-dev-ugly
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions packages/rs-dpp/src/identity/identity_public_key/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,15 +615,15 @@ impl IdentityPublicKey {
used_key_matrix[4] = true; //also a master key
used_key_matrix[8] = true; //also a master key
used_key_matrix[12] = true; //also a master key
main_keys.extend((3..key_count).map(|i| {
Self::random_authentication_key_with_private_key_with_rng(
for i in 3..key_count {
let privkey = Self::random_authentication_key_with_private_key_with_rng(
i,
rng,
Some((i, &mut used_key_matrix)),
platform_version,
)
.unwrap()
}));
)?;
main_keys.push(privkey);
}
Ok(main_keys)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ impl IdentityPublicKeyV0 {
used_key_matrix: Option<(KeyCount, &mut UsedKeyMatrix)>,
platform_version: &PlatformVersion,
) -> Result<(Self, Vec<u8>), ProtocolError> {
const MAX_KEYS: u8 = 16;
// we have 16 different permutations possible
let mut binding = [false; 16].to_vec();
let mut binding = [false; MAX_KEYS as usize].to_vec();
let (key_count, key_matrix) = used_key_matrix.unwrap_or((0, &mut binding));
if key_count > 16 {
if key_count > MAX_KEYS as u32 {
return Err(ProtocolError::PublicKeyGenerationError(
"too many keys already created".to_string(),
));
}
let key_number = rng.gen_range(0..(12 - key_count as u8));
let key_number = rng.gen_range(0..(MAX_KEYS - key_count as u8));
// now we need to find the first bool that isn't set to true
let mut needed_pos = None;
let mut counter = 0;
Expand Down
Loading