Skip to content

Commit

Permalink
feat(traits/authn): add log information
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed Nov 18, 2024
1 parent 4f34f38 commit 463ed5c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ target/
*.pdb
.vscode
.DS_Store
.idea
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions traits/authn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ version = "0.1.0"
codec.workspace = true
frame-support.workspace = true
fc-traits-authn-proc.workspace = true
log.workspace = true
scale-info.workspace = true

[features]
Expand Down
26 changes: 25 additions & 1 deletion traits/authn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub mod util;

pub use fc_traits_authn_proc::composite_authenticator;

const LOG_TARGET: &'static str = "authn";

Check warning on line 11 in traits/authn/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

constants have by default a `'static` lifetime

warning: constants have by default a `'static` lifetime --> traits/authn/src/lib.rs:11:20 | 11 | const LOG_TARGET: &'static str = "authn"; | -^^^^^^^---- help: consider removing `'static`: `&str` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes = note: `#[warn(clippy::redundant_static_lifetimes)]` on by default

pub mod composite_prelude {
pub use crate::{
Authenticator, AuthorityId, Challenge, Challenger, DeviceChallengeResponse, DeviceId,
Expand Down Expand Up @@ -36,7 +38,7 @@ macro_rules! composite_authenticators {
}
}

// A reasonabily sized secure challenge
// A reasonably sized secure challenge
const CHALLENGE_SIZE: usize = 32;
pub type Challenge = [u8; CHALLENGE_SIZE];
type CxOf<C> = <C as Challenger>::Context;
Expand Down Expand Up @@ -65,13 +67,24 @@ pub trait Authenticator {
type Device: UserAuthenticator<Challenger = Self::Challenger>;

fn verify_device(attestation: Self::DeviceAttestation) -> Option<Self::Device> {
log::trace!(target: LOG_TARGET, "Verifying device with attestation: {:?}", attestation);

log::trace!(target: LOG_TARGET, "Assert authority {:?}", attestation.authority());
attestation
.authority()
.eq(&Self::Authority::get())
.then_some(())?;
log::trace!(target: LOG_TARGET, "Authority verified");

let (cx, challenge) = attestation.used_challenge();
log::trace!(target: LOG_TARGET, "Check challenge for context ({:?}): {:?}", &cx, &challenge);

Check failure on line 80 in traits/authn/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

`<<Self as Authenticator>::Challenger as Challenger>::Context` doesn't implement `std::fmt::Debug`

error[E0277]: `<<Self as Authenticator>::Challenger as Challenger>::Context` doesn't implement `std::fmt::Debug` --> traits/authn/src/lib.rs:80:85 | 80 | log::trace!(target: LOG_TARGET, "Check challenge for context ({:?}): {:?}", &cx, &challenge); | ^^^ `<<Self as Authenticator>::Challenger as Challenger>::Context` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` | = help: the trait `std::fmt::Debug` is not implemented for `<<Self as Authenticator>::Challenger as Challenger>::Context`, which is required by `&<<Self as Authenticator>::Challenger as Challenger>::Context: std::fmt::Debug` = note: this error originates in the macro `$crate::__private_api::format_args` which comes from the expansion of the macro `log::trace` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting the associated type | 69 | fn verify_device(attestation: Self::DeviceAttestation) -> Option<Self::Device> where <<Self as Authenticator>::Challenger as Challenger>::Context: std::fmt::Debug { | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Self::Challenger::check_challenge(&cx, &challenge)?;
log::trace!(target: LOG_TARGET, "Challenge checked");

log::trace!(target: LOG_TARGET, "Validate attestation");
attestation.is_valid().then_some(())?;

log::trace!(target: LOG_TARGET, "Retrieve device");
Some(Self::unpack_device(attestation))
}

Expand All @@ -86,13 +99,24 @@ pub trait UserAuthenticator: FullCodec + MaxEncodedLen + TypeInfo {
type Credential: UserChallengeResponse<CxOf<Self::Challenger>>;

fn verify_user(&self, credential: &Self::Credential) -> Option<()> {
log::trace!(target: LOG_TARGET, "Verifying user for credential: {:?}", credential);

log::trace!(target: LOG_TARGET, "Assert authority {:?}", credential.authority());
credential
.authority()
.eq(&Self::Authority::get())
.then_some(())?;
log::trace!(target: LOG_TARGET, "Authority verified");

let (cx, challenge) = credential.used_challenge();
log::trace!(target: LOG_TARGET, "Check challenge for context ({:?}): {:?}", &cx, &challenge);

Check failure on line 112 in traits/authn/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

`<<Self as UserAuthenticator>::Challenger as Challenger>::Context` doesn't implement `std::fmt::Debug`

error[E0277]: `<<Self as UserAuthenticator>::Challenger as Challenger>::Context` doesn't implement `std::fmt::Debug` --> traits/authn/src/lib.rs:112:85 | 112 | log::trace!(target: LOG_TARGET, "Check challenge for context ({:?}): {:?}", &cx, &challenge); | ^^^ `<<Self as UserAuthenticator>::Challenger as Challenger>::Context` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` | = help: the trait `std::fmt::Debug` is not implemented for `<<Self as UserAuthenticator>::Challenger as Challenger>::Context`, which is required by `&<<Self as UserAuthenticator>::Challenger as Challenger>::Context: std::fmt::Debug` = note: this error originates in the macro `$crate::__private_api::format_args` which comes from the expansion of the macro `log::trace` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting the associated type | 101 | fn verify_user(&self, credential: &Self::Credential) -> Option<()> where <<Self as UserAuthenticator>::Challenger as Challenger>::Context: std::fmt::Debug { | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Self::Challenger::check_challenge(&cx, &challenge)?;
log::trace!(target: LOG_TARGET, "Challenge checked");

log::trace!(target: LOG_TARGET, "Credential verified");
credential.is_valid().then_some(())?;

log::trace!(target: LOG_TARGET, "Verify credential");
self.verify_credential(credential)
}

Expand Down
2 changes: 1 addition & 1 deletion traits/authn/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<Id: Get<PalletId>> Get<AuthorityId> for AuthorityFromPalletId<Id> {
}
}

/// Convenient auto-implemtator of the Authenticator trait
/// Convenient auto-implementor of the Authenticator trait
pub struct Auth<Dev, Att>(PhantomData<(Dev, Att)>);

impl<Dev, Att> Authenticator for Auth<Dev, Att>
Expand Down

0 comments on commit 463ed5c

Please sign in to comment.