Skip to content

Dispose all resources used in CmsSignature #115666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

PranavSenthilnathan
Copy link
Member

Dispose keys in CmsSignature more consistently.

Contributes to #115578

@PranavSenthilnathan PranavSenthilnathan self-assigned this May 16, 2025
@Copilot Copilot AI review requested due to automatic review settings May 16, 2025 20:30
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

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 PR refactors the handling of signing keys in CmsSignature to ensure all disposable resources are consistently disposed. The changes include:

  • Introducing a new helper method GetSigningKey to centralize key retrieval and disposal.
  • Updating the implementations for RSA, DSA, ECDsa, and SlhDsa to use the new helper method.
  • Minor renaming adjustments for clarity in key-related parameters.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
CmsSignature.cs Added GetSigningKey helper to encapsulate key retrieval and disposal logic.
CmsSignature.SlhDsa.cs Updated signing logic to use GetSigningKey for consistent disposal.
CmsSignature.RSA.cs Refactored signing and verification for RSA to leverage GetSigningKey and ensure proper resource disposal.
CmsSignature.ECDsa.cs Replaced direct disposal of keys with GetSigningKey and adjusted parameter naming.
CmsSignature.DSA.cs Updated DSA signing to use GetSigningKey for improved resource management.

certificate.GetDSAPublicKey();

if (dsa == null)
using (GetSigningKey(key, certificate, silent, DSACertificateExtensions.GetDSAPublicKey, out DSA? dsa))
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: Using DSACertificateExtensions.GetDSAPublicKey is more succinct, but the main reason for changing to this is because I was getting errors due to dotnet/roslyn-analyzers#4282.

@PranavSenthilnathan PranavSenthilnathan enabled auto-merge (squash) June 5, 2025 23:20
@PranavSenthilnathan PranavSenthilnathan merged commit 211e8db into dotnet:main Jun 5, 2025
86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants