-
Notifications
You must be signed in to change notification settings - Fork 18k
crypto/rsa: mismatched keys no longer error #61077
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
Comments
cc @golang/security |
This comment was marked as spam.
This comment was marked as spam.
This one is easy to root-cause (5aa6313). The code has had bit of a refactor since the change that introduced the issue, I will refer to what is currently in tree. Line 689 in 18e17e2
This used to call Line 663 in 18e17e2
The fix to restore previous behavior is to unconditionally de-serialize
Edit: One could conceivably also splatter checks all over the place where the precomputed values are used to try to detect "user did something unwise and there is now a mismatch", but I'm not sure how much that is worth it. |
The check is there to ensure that if we do the CRT wrong due to a bug or a fault, we don't leak the private key. It's actually safer and more correct to do it against what we used to produce the signature. The consistency check was a side effect, and I'm not sure it was an intentional one. (For sure there was no test or dedicated error message.) NewModulusFromBig is a slow operation, adding it to every signature would be significant. We can probably find a quicker way to check the PublicKey is not mismatched but 1) how can that happen? and 2) how bad is it? PrivateKeys can be corrupted in a number of ways we don't catch, the assumption is always that the private key is trusted (for better or worse). |
Makes sense.
This sort of thing is why I tend to be a proponent of "make key types as opaque as I can get away with", but due to backward compatibility concerns that ship has long sailed here. FWIW, I personally also would not be overly concerned with this case, because this feels like something that lands firmly in "So don't do that then" territory.
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
rsa.SignPKCS1v15
does not return an error ingo1.20.5
when public key and private key are mismatched.The test below passes in
go.1.19.7
because the error is returned as expected.In
go1.20.5
no error is returned and hence the test fails.What did you expect to see?
I expect this test to pass in
go.1.20.5
.What did you see instead?
The test fails in
go1.20.5
.The text was updated successfully, but these errors were encountered: