Commit cdd800d
committed
Refactor encrypted field decryption and add AuthenticatorCredStoreState to Fido2Session
This commit refactors the CTAP 2.2/2.3 encrypted field decryption logic
and exposes credential store state at the session level for easier access.
Refactoring (AuthenticatorInfo.cs):
- Extracted common decryption logic into DecryptEncryptedField() helper method
- Eliminated code duplication between GetIdentifier() and GetCredStoreState()
- Both methods now delegate to the shared helper with field-specific HKDF info
- Added comprehensive documentation to the helper method explaining the
CTAP 2.2/2.3 decryption scheme (HKDF-SHA-256 + AES-128-CBC)
- Reduced code from ~60 lines to ~25 lines while maintaining identical behavior
New Property (Fido2Session.cs):
- Added AuthenticatorCredStoreState property that mirrors AuthenticatorIdentifier
- Provides convenient session-level access to credential store state
- Automatically manages persistent PIN/UV auth token retrieval
- Enables easy detection of credential store changes across sessions/resets
- Follows the established pattern for encrypted field access
New Test (Fido2Tests.cs):
- Added Session_AuthenticatorCredStoreState_Returns_SameCredStoreState()
- Mirrors the existing AuthenticatorIdentifier test pattern
- Verifies credential store state consistency across sessions
- Requires YubiKey firmware 5.8.0+ for execution
Benefits:
- DRY principle: Single source of truth for encrypted field decryption
- Maintainability: Future encrypted fields can use the same helper
- Consistency: Both identifier and cred store state use identical patterns
- Simplicity: Session-level properties hide PPUAT management complexity
- API parity: .NET SDK now matches Java SDK feature set
The refactoring maintains 100% backward compatibility - all existing
code continues to work without changes.1 parent 3f4f29a commit cdd800d
File tree
3 files changed
+92
-31
lines changed- Yubico.YubiKey
- src/Yubico/YubiKey/Fido2
- tests/integration/Yubico/YubiKey/Fido2
3 files changed
+92
-31
lines changedLines changed: 38 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
597 | 597 | | |
598 | 598 | | |
599 | 599 | | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
| 600 | + | |
| 601 | + | |
624 | 602 | | |
625 | 603 | | |
626 | 604 | | |
| |||
631 | 609 | | |
632 | 610 | | |
633 | 611 | | |
634 | | - | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
635 | 642 | | |
636 | | - | |
| 643 | + | |
637 | 644 | | |
638 | 645 | | |
639 | 646 | | |
| |||
646 | 653 | | |
647 | 654 | | |
648 | 655 | | |
649 | | - | |
650 | | - | |
| 656 | + | |
| 657 | + | |
651 | 658 | | |
652 | | - | |
653 | | - | |
| 659 | + | |
| 660 | + | |
654 | 661 | | |
655 | 662 | | |
656 | | - | |
| 663 | + | |
657 | 664 | | |
658 | 665 | | |
659 | 666 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
156 | 189 | | |
157 | 190 | | |
158 | 191 | | |
| |||
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
40 | 61 | | |
41 | 62 | | |
42 | 63 | | |
| |||
0 commit comments