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

feat(fc-pallet-pass): more secure account derivation #29

Merged
merged 1 commit into from
Nov 22, 2024
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
10 changes: 7 additions & 3 deletions pallets/pass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use fc_traits_authn::{
util::AuthorityFromPalletId, Authenticator, DeviceChallengeResponse, DeviceId, HashedUserId,
UserAuthenticator, UserChallengeResponse,
UserAuthenticator, UserChallengeResponse, HASHED_USER_ID_LEN,
};
use frame_support::traits::schedule::DispatchTime;
use frame_support::traits::Bounded;
Expand Down Expand Up @@ -234,8 +234,12 @@ pub mod pallet {

impl<T: Config<I>, I: 'static> Pallet<T, I> {
pub fn account_id_for(user: HashedUserId) -> Result<T::AccountId, DispatchError> {
let account_id: T::AccountId = T::AccountId::decode(&mut TrailingZeroInput::new(&user))
.map_err(|_| Error::<T, I>::AccountNotFound)?;
// we know the length of HashedUserId
let mut input = [0u8; 2 * HASHED_USER_ID_LEN];
input[HASHED_USER_ID_LEN..].copy_from_slice(&user);
let account_id: T::AccountId =
T::AccountId::decode(&mut TrailingZeroInput::new(&blake2_256(&input)))
.map_err(|_| Error::<T, I>::AccountNotFound)?;
Ok(account_id)
}

Expand Down
3 changes: 2 additions & 1 deletion traits/authn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ type CxOf<C> = <C as Challenger>::Context;

pub type DeviceId = [u8; 32];
pub type AuthorityId = [u8; 32];
pub type HashedUserId = [u8; 32];
pub const HASHED_USER_ID_LEN: usize = 32;
pub type HashedUserId = [u8; HASHED_USER_ID_LEN];

/// Given some context it deterministically generates a "challenge" used by authenticators
pub trait Challenger {
Expand Down
Loading