@@ -255,7 +255,7 @@ where
255
255
}
256
256
}
257
257
258
- impl < ' a , T : Client > LoadedAuthenticator < ' a , T > {
258
+ impl < T : Client > LoadedAuthenticator < ' _ , T > {
259
259
pub fn yubico_set_administration_key < const R : usize > (
260
260
& mut self ,
261
261
data : & [ u8 ] ,
@@ -482,7 +482,7 @@ impl<'a, T: Client> LoadedAuthenticator<'a, T> {
482
482
exponentiation : tlv:: get_do ( & [ 0x85 ] , input) ,
483
483
} ;
484
484
485
- error ! (
485
+ debug ! (
486
486
"witness: {}, challenge: {}, response: {}, exponentiation: {}" ,
487
487
& parsed. witness. is_some( ) ,
488
488
& parsed. challenge. is_some( ) ,
@@ -569,21 +569,22 @@ impl<'a, T: Client> LoadedAuthenticator<'a, T> {
569
569
) -> Result {
570
570
info ! ( "Single auth 1" ) ;
571
571
let key = self . validate_auth_management ( auth) ?;
572
- let pl = syscall ! ( self . trussed. random_bytes( key. alg. challenge_length( ) ) ) . bytes ;
573
- self . state . volatile . command_cache = Some ( CommandCache :: SingleAuthChallenge (
574
- Bytes :: from_slice ( & pl) . unwrap ( ) ,
572
+ let plaintext = syscall ! ( self . trussed. random_bytes( key. alg. challenge_length( ) ) ) . bytes ;
573
+ let ciphertext =
574
+ syscall ! ( self
575
+ . trussed
576
+ . encrypt( key. alg. mechanism( ) , key. id, & plaintext, & [ ] , None ) )
577
+ . ciphertext ;
578
+ self . state . volatile . command_cache = Some ( CommandCache :: SingleAuthChallengeReference (
579
+ Bytes :: from_slice ( & ciphertext) . unwrap ( ) ,
575
580
) ) ;
576
- let data = syscall ! ( self
577
- . trussed
578
- . encrypt( key. alg. mechanism( ) , key. id, & pl, & [ ] , None ) )
579
- . ciphertext ;
580
581
581
582
reply. expand ( & [ 0x7C ] ) ?;
582
583
let offset = reply. len ( ) ;
583
584
{
584
585
reply. expand ( & [ 0x81 ] ) ?;
585
- reply. append_len ( data . len ( ) ) ?;
586
- reply. expand ( & data ) ?;
586
+ reply. append_len ( plaintext . len ( ) ) ?;
587
+ reply. expand ( & plaintext ) ?;
587
588
}
588
589
reply. prepend_len ( offset) ?;
589
590
Ok ( ( ) )
@@ -599,14 +600,15 @@ impl<'a, T: Client> LoadedAuthenticator<'a, T> {
599
600
return Err ( Status :: IncorrectDataParameter ) ;
600
601
}
601
602
602
- let Some ( plaintext_challenge) = self . state . volatile . take_single_challenge ( ) else {
603
+ let Some ( challenge_reference) = self . state . volatile . take_single_challenge_reference ( )
604
+ else {
603
605
warn ! ( "Missing cached challenge for auth" ) ;
604
606
return Err ( Status :: ConditionsOfUseNotSatisfied ) ;
605
607
} ;
606
608
607
- let is_eq: bool = response. ct_eq ( & plaintext_challenge ) . into ( ) ;
608
- if is_eq {
609
- warn ! ( "Bad auth challenge " ) ;
609
+ let is_eq: bool = response. ct_eq ( & challenge_reference ) . into ( ) ;
610
+ if ! is_eq {
611
+ warn ! ( "Failed admin authentication. Challenge did not match " ) ;
610
612
return Err ( Status :: IncorrectDataParameter ) ;
611
613
}
612
614
@@ -616,31 +618,37 @@ impl<'a, T: Client> LoadedAuthenticator<'a, T> {
616
618
. administrator_verified = true ;
617
619
Ok ( ( ) )
618
620
}
621
+
619
622
fn mutual_auth_1 < const R : usize > (
620
623
& mut self ,
621
624
auth : GeneralAuthenticate ,
622
625
mut reply : Reply < ' _ , R > ,
623
626
) -> Result {
624
627
info ! ( "Mutual auth 1" ) ;
625
628
let key = self . validate_auth_management ( auth) ?;
626
- let pl = syscall ! ( self . trussed. random_bytes( key. alg. challenge_length( ) ) ) . bytes ;
627
- self . state . volatile . command_cache = Some ( CommandCache :: MutualAuthChallenge (
628
- Bytes :: from_slice ( & pl) . unwrap ( ) ,
629
+ let plaintext = syscall ! ( self . trussed. random_bytes( key. alg. challenge_length( ) ) ) . bytes ;
630
+
631
+ let ciphertext =
632
+ syscall ! ( self
633
+ . trussed
634
+ . encrypt( key. alg. mechanism( ) , key. id, & plaintext, & [ ] , None ) )
635
+ . ciphertext ;
636
+
637
+ self . state . volatile . command_cache = Some ( CommandCache :: MutualAuthWitnessReference (
638
+ Bytes :: from_slice ( & plaintext) . unwrap ( ) ,
629
639
) ) ;
630
- let data = syscall ! ( self
631
- . trussed
632
- . encrypt( key. alg. mechanism( ) , key. id, & pl, & [ ] , None ) )
633
- . ciphertext ;
640
+
634
641
reply. expand ( & [ 0x7C ] ) ?;
635
642
let offset = reply. len ( ) ;
636
643
{
637
644
reply. expand ( & [ 0x80 ] ) ?;
638
- reply. append_len ( data . len ( ) ) ?;
639
- reply. expand ( & data ) ?;
645
+ reply. append_len ( ciphertext . len ( ) ) ?;
646
+ reply. expand ( & ciphertext ) ?;
640
647
}
641
648
reply. prepend_len ( offset) ?;
642
649
Ok ( ( ) )
643
650
}
651
+
644
652
fn mutual_auth_2 < const R : usize > (
645
653
& mut self ,
646
654
auth : GeneralAuthenticate ,
@@ -661,13 +669,14 @@ impl<'a, T: Client> LoadedAuthenticator<'a, T> {
661
669
return Err ( Status :: IncorrectDataParameter ) ;
662
670
}
663
671
664
- let Some ( plaintext_challenge ) = self . state . volatile . take_mutual_challenge ( ) else {
672
+ let Some ( witness_reference ) = self . state . volatile . take_mutual_witness_reference ( ) else {
665
673
warn ! ( "Missing cached challenge for auth" ) ;
666
674
return Err ( Status :: ConditionsOfUseNotSatisfied ) ;
667
675
} ;
668
676
669
- if challenge. ct_eq ( & plaintext_challenge) . into ( ) {
670
- warn ! ( "Bad auth challenge" ) ;
677
+ let is_eq: bool = response. ct_eq ( & witness_reference) . into ( ) ;
678
+ if !is_eq {
679
+ warn ! ( "Failed admin authentication. Challenge did not match" ) ;
671
680
return Err ( Status :: IncorrectDataParameter ) ;
672
681
}
673
682
@@ -701,7 +710,7 @@ impl<'a, T: Client> LoadedAuthenticator<'a, T> {
701
710
just_verified : bool ,
702
711
mut reply : Reply < ' _ , R > ,
703
712
) -> Result {
704
- error ! ( "Request for sign, data length: {}, data:" , message. len( ) ) ;
713
+ debug ! ( "Request for sign, data length: {}, data:" , message. len( ) ) ;
705
714
// error!("{}", delog::hexstr!(message));
706
715
707
716
let Ok ( key_ref) = auth. key_reference . try_into ( ) else {
@@ -737,7 +746,7 @@ impl<'a, T: Client> LoadedAuthenticator<'a, T> {
737
746
reply. append_len ( response. len ( ) ) ?;
738
747
reply. expand ( & response) ?;
739
748
}
740
- error ! ( "Signed data len: {}, Data:" , response. len( ) ) ;
749
+ debug ! ( "Signed data len: {}, Data:" , response. len( ) ) ;
741
750
// error!("{}", delog::hexstr!(&response));
742
751
743
752
reply. prepend_len ( offset) ?;
0 commit comments