Skip to content

Conversation

DennisDyallo
Copy link
Collaborator

@DennisDyallo DennisDyallo commented May 5, 2025

Description

This PR fixes a bug where attestation cert could not be RSA3072 or RSA4096, as well as updates a number of tests that were made obsolete in recent refactors around ECPublicKey, ECPrivateKey, RSAPublicKey and RSAPrivateKey.

Additional changes:

  • logging: Added logging when changing pin or puk
  • refactor: refactor: Proper parsing of X509Certificate2 around Piv attestation and importing of attest certificate
  • refactor: Consolidated logic around key size and key definition lookup in Piv
  • refactor: Consolidated logic around GetMetadata in Piv
  • docs: Removed legacy documentation regarding valid key slots for creating attestations

Type of change

  • Refactor (non-breaking change which improves code quality or performance)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Test configuration:

  • OS version: Arch Linux
  • Firmware version: 5.7.4, 5.4.3
  • Yubikey model1: USB A, USB C

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have run dotnet format to format my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Footnotes

  1. See Yubikey models (Multi-protocol, Security Key, FIPS, Bio, YubiHSM, YubiHSM FIPS)

Copy link

github-actions bot commented May 5, 2025

Test Results: Windows

    2 files      2 suites   9s ⏱️
3 897 tests 3 897 ✅ 0 💤 0 ❌
3 899 runs  3 899 ✅ 0 💤 0 ❌

Results for commit dbb6718.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented May 5, 2025

Test Results: Ubuntu

    2 files      2 suites   13s ⏱️
3 889 tests 3 889 ✅ 0 💤 0 ❌
3 891 runs  3 891 ✅ 0 💤 0 ❌

Results for commit dbb6718.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented May 5, 2025

Test Results: MacOS

    2 files      2 suites   9s ⏱️
3 889 tests 3 889 ✅ 0 💤 0 ❌
3 891 runs  3 891 ✅ 0 💤 0 ❌

Results for commit dbb6718.

♻️ This comment has been updated with latest results.

remove unnecessary test on size of certs
reduced test logic
remove unused class
add default pin and puk to base class
remove overlapping test
add docs
fix tests with auth
add complex pin and puk
- added field DefaultManagementKey
- early exit when fail TryVerifyPin
- use range operator
…essful (PivSession)

- additional: added param docs for mutualAuthentication
AttestTests - added comment on CreateAttestationStatement
Added test for Ed25519 attest

Fix tests in PivSessionTests
- lookup of key definitions
- determine valid attestation cert
@DennisDyallo DennisDyallo changed the title tests: Updated obsolete tests fix,tests: Fixed bug where attest cert could not be RSA3072 or RSA4096, removed obsolete tests and consolidated Piv tests May 26, 2025
@DennisDyallo DennisDyallo requested a review from Copilot May 26, 2025 00:02
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request fixes a bug preventing RSA3072 and RSA4096 attestation certificates from being used, removes obsolete tests, and refactors several command and cryptographic methods to improve clarity and consistency. Key changes include:

  • Bug fix and consolidation of key size and definition lookup in PIV commands.
  • Refactoring of obsolete test invocations and adjustments in exception handling.
  • Code style improvements such as replacing explicit equality checks with negated Boolean expressions and updating inline comments.

Reviewed Changes

Copilot reviewed 148 out of 148 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Yubico.YubiKey/src/Yubico/YubiKey/Piv/Commands/GetMetadataCommand.cs Removed explicit initialization of _slotNumber in the parameterless constructor.
Yubico.YubiKey/src/Yubico/YubiKey/Piv/Commands/CreateAttestationStatementCommand.cs Replaced equality checks with negated conditions for slot number validation.
Yubico.YubiKey/src/Yubico/YubiKey/Piv/Commands/AuthenticateSignCommand.cs Refactored algorithm determination into a separate method using LINQ.
Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Commands/* Updated ReadOnlyMemory constructions to use full authParam data.
Yubico.YubiKey/src/Yubico/YubiKey/Cryptography/RSAPublicKey.cs Moved private key parameter validation into CreateFromParameters and updated key definition lookup.
Yubico.YubiKey/src/Yubico/YubiKey/Cryptography/KeyDefinitions.cs Introduced a convenience method for RSA modulus length and clarified ECDSA OID error handling.
Yubico/YubiKey/src/Yubico/YubiKey/Cryptography/ECPublicKey.cs Updated return types for public key creation methods for better type clarity.
Yubico.YubiKey/src/Yubico/YubiKey/Cryptography/AsnUtilities.cs Revised bit clamping checks for X25519 with updated (but inconsistent) inline comments.
Yubico.YubiKey/src/Yubico/YubiKey/Cryptography/AsnPublicKeyEncoder.cs Changed exception type and message for missing RSA parameters.
Various examples under /examples/PivSampleCode/ Added pragma warning disables around obsolete API usage.
Comments suppressed due to low confidence (1)

Yubico.YubiKey/src/Yubico/YubiKey/Cryptography/AsnPublicKeyEncoder.cs:105

  • [nitpick] The exception thrown for missing RSA parameter values now uses InvalidOperationException with a different message. Consider aligning the exception type and message with similar methods to ensure consistency in error reporting.
if (parameters.Exponent == null ||

tests: fixed comments and code restructure
# Conflicts:
#	Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Attestation.cs
#	Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Crypto.cs
#	Yubico.YubiKey/tests/integration/Yubico/YubiKey/Piv/ImportTests.cs
#	Yubico.YubiKey/tests/unit/Yubico/YubiKey/Cryptography/ECPrivateKeyTests.cs
#	Yubico.YubiKey/tests/unit/Yubico/YubiKey/Cryptography/ECPublicKeyTests.cs
#	Yubico.YubiKey/tests/unit/Yubico/YubiKey/Cryptography/RSAPublicKeyTests.cs
#	Yubico.YubiKey/tests/unit/Yubico/YubiKey/Piv/PivEncoderDecoderTests.cs
#	Yubico.YubiKey/tests/unit/Yubico/YubiKey/Piv/PivPrivateKeyTests.cs
#	Yubico.YubiKey/tests/unit/Yubico/YubiKey/Piv/PivPublicKeyTests.cs
#	Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/KeyConverter.cs
#	Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/PivKeyExtensions.cs
#	Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/SampleKeyPairs.cs
#	Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestKeyExtensions.cs
Copy link
Member

@AdamVe AdamVe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I ran the integration tests locally also. See my comments as ideas for future improvements.

Comment on lines +123 to +124
public void ChangeRetryCounts_Succeeds(
StandardTestDevice testDeviceType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, is this the way the formatter works on the c# code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know honestly, this is the way the formatter works with the current .editorconfig and Rider, so I dont question it too much. Im sure it could be optimized. I would only want it to split into rows if the params are larger than 2. Now I think it splits when it reaches a current viewport width

remove comments,
revert test change, simpler complexpin and complexpuk
@DennisDyallo DennisDyallo merged commit 76e5dd6 into develop May 27, 2025
4 checks passed
@DennisDyallo DennisDyallo deleted the dennisdyallo/tests branch May 27, 2025 22:32
Copy link

Code Coverage

Package Line Rate Branch Rate Complexity Health
Yubico.Core 40% 31% 4365
Yubico.YubiKey 51% 46% 20595
Summary 49% (35397 / 72330) 44% (8637 / 19755) 24960

Minimum allowed line rate is 40%

@DennisDyallo DennisDyallo mentioned this pull request Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants