-
Notifications
You must be signed in to change notification settings - Fork 6.3k
fix(tls): validate RSA keys before marshaling #23295
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
fix(tls): validate RSA keys before marshaling #23295
Conversation
In Go 1.24, x509.MarshalPKCS1PrivateKey internally calls rsa.PrivateKey.Precompute() which panics on invalid RSA keys with nil pointer dereference. Add validation using rsa.PrivateKey.Validate() before marshaling to prevent panics. Update pemBlockForKey to return nil for invalid keys and modify callers to handle nil returns gracefully. Add comprehensive tests covering nil keys, validation failures, and unsupported key types to ensure robust error handling. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
❌ Preview Environment deleted from BunnyshellAvailable commands (reply to this comment):
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #23295 +/- ##
==========================================
+ Coverage 60.00% 60.07% +0.06%
==========================================
Files 341 341
Lines 57818 57831 +13
==========================================
+ Hits 34694 34742 +48
+ Misses 20344 20322 -22
+ Partials 2780 2767 -13 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/cherry-pick release-3.0 |
/cherry-pick release-2.14 |
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi> Signed-off-by: dsuhinin <suhinin.dmitriy@gmail.com>
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi> Signed-off-by: dsuhinin <suhinin.dmitriy@gmail.com>
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi> Signed-off-by: enneitex <etienne.divet@gmail.com>
In Go 1.24,
x509.MarshalPKCS1PrivateKey
(doc ref) internally callsrsa.PrivateKey.Precompute()
which panics on invalid RSA keys with nil pointer dereference.Add validation using
rsa.PrivateKey.Validate()
before marshaling to prevent panics. UpdatepemBlockForKey
to return nil for invalid keys and modify callers to handle nil returns gracefully.Add comprehensive tests covering nil keys, validation failures, and unsupported key types to ensure robust error handling. If you run the test against
master
now it'll panic.Noticed in #23294.
Checklist: