feat: Always append APDU Le fields#503
Merged
DennisDyallo merged 2 commits intoJul 1, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR standardizes APDU wire formatting by always appending the Le field (short and extended APDUs), and updates SCP03 MAC computation so the MAC input excludes both the reserved MAC placeholder bytes and the newly appended trailing Le. It also adds focused regression tests to lock in the updated APDU and SCP behavior across Core, Oath, and SecurityDomain.
Changes:
- Always append Le in
ApduFormatterShortandApduFormatterExtended(including “zero Le” forms). - Update
ScpProcessorMAC input slicing to exclude the MAC placeholder and trailing Le bytes deterministically. - Add/adjust unit tests to validate formatter output and SCP MAC behavior, and update existing applet tests to expect the appended Le.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/SecurityDomain/tests/Yubico.YubiKit.SecurityDomain.UnitTests/SecurityDomainSessionTests.cs | Update expected transmitted APDUs to include the trailing Le byte. |
| src/Oath/tests/Yubico.YubiKit.Oath.UnitTests/OathSessionTests.cs | Adjust APDU assertions to ignore the appended Le in payload comparisons and assert Le is present. |
| src/Core/tests/Yubico.YubiKit.Core.UnitTests/Protocols/SmartCard/Scp/PcscProtocolScpTests.cs | Add regression vectors ensuring SCP MAC input excludes the appended Le (short + extended). |
| src/Core/tests/Yubico.YubiKit.Core.UnitTests/Protocols/SmartCard/Apdu/ApduFormatterTests.cs | New unit tests verifying always-appended Le behavior for short and extended APDU formatting. |
| src/Core/src/Protocols/SmartCard/Scp/ScpProcessor.cs | Fix MAC input length calculation to exclude MAC placeholder and trailing Le. |
| src/Core/src/Protocols/SmartCard/Apdu/ApduFormatterShort.cs | Always append Le for short APDUs (including Le=0). |
| src/Core/src/Protocols/SmartCard/Apdu/ApduFormatterExtended.cs | Always append extended Le (Case 2E/4E), improve Le validation, and use WriteUInt16BigEndian for Lc/Le encoding. |
Base automatically changed from
yubikit-performance
to
yubikit-composite-device-new
July 1, 2026 10:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Verification