-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Remove DH generator size constraint #3364
Conversation
To my knowledge the only reason we have this constraint is that we don't have tests for anything other than generator values of 2 or 5. Are you aware of anywhere we can get tests to cover larger generator sizes, or, failing that, a reason why we shouldn't care? It seems clear it's desirable to remove it so I'd like to be confident that our test suite can handle the case properly in a future where we add a new backend that has a bug with larger generator sizes. |
Jenkins, ok to test. |
NIST provides test vectors with 512-bit generators here. Unfortunately the keys cannot be directly imported because of a call to However, when I bypassed this, I could check that the computed shared secret was the expected one. What do you think? Should the backend check be made unreceptive to those two codes (I did not come across any safe prime on 5 different groups)? Or should we rather not test this? |
@mtury you can pass DH_check by setting the appropriate |
Indeed Rather than weakening the backend check, I'd favor not testing long generators for now. The generator size distinction in New vectors could be added as soon as subgroup orders are supported. |
First I will start working on adding the subgroup order and hopefully will have a PR ready by next week. In any case I think that this is O.K to remove the |
@palaviv While it's possible to clear the |
I think that will be the best solution @markrwilliams. I now have problems with DH_check in #3369 and that change will make it easier. |
@palaviv Hm, looking at the code it appears that |
(We talked about this a bit in IRC and @markrwilliams is going to look at pulling in a local copy of DH_check as |
I looked at the logs of the IRC talk (hope I did not miss anything). I don't think that a local copy of the new
I think you misunderstood me @markrwilliams. My suggestion is to remove the It seems like there are a lot of problems with |
Hm, so then users would call If we did take that approach, we'd still have to backport a
I'm definitely not even a mathematics amateur :( OpenSSH seems to just check if the public key passes very basic sanity checks. The most nuanced thing there is the bit checking. Maybe that's good enough, and we can do this in our own replacement for @reaperhulk what do you think? |
Yes. I would suggest doing that in #3369 and not in the PR. Would you like me to do that or would you like to open a PR to my branch? Doing what OpenSSH does sounds good as a fallback. I looked in mbedtls and they do the same.
How about adding a |
I'll be happy to do a PR against your branch tonight :)
I like this. Since this is a |
Okay, so if I understand correctly, the order here is:
|
@reaperhulk Yes, with some additions:
The two together make me think we should have an private_numbers = DHPrivateNumbers(...)
private_key = private_numbers.parameters().private_key(DHCheck.CHECK_PARAMETERS)
# -or-
private_key = private_numbers.parameters().private_key(DHCheck.CHECK_PUBLIC_KEY) But if that happens, it would be happen after the PR to backport |
We're close here thanks to a bunch of DH subgroup order work landing, but this will be in 1.9 rather than 1.8. |
@mtury, @markrwilliams any of you planning on working on this or would you like me to do this? |
I was away for a few weeks, sorry. Unfortunately I won't have time to spend on the subject before the summer. Considering your involvement on the DH implementation, it would probably be better if you handled this. |
I am starting to work on this but I am having a little hard time understanding the use cases. As much as I can understand @mtury would like to remove the generator size constraint and @markrwilliams would like to remove (or replace) the |
#3755 might also be relevant since removing DH_check would make it so you could pass alternate generators without complaint. |
@palaviv Unfortunately the subgroup support is virtually of no use to TLS, as the protocol does not provide a way to send subgroup orders. I discussed this briefly in #3414. What prevents Scapy from using the library without any hack is basically a pre-DH_check test in DHParameterNumbers |
@@ -87,9 +87,6 @@ def __init__(self, p, g, q=None): | |||
if q is not None and not isinstance(q, six.integer_types): | |||
raise TypeError("q must be integer or None") | |||
|
|||
if q is None and g not in (2, 5): | |||
raise ValueError("DH generator must be 2 or 5") |
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.
Is this not redundant with DH_check?
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.
It is, in fact, worse than DH_check since DH_check allows 2, 3, and 5. Presumably scapy wants to convert Numbers into an instance of the object though, correct? So we need to potentially remove this check and also either remove or modify DH_check?
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.
Actually once these two lines are removed it works fine. Indeed Scapy uses instances of DHParameterNumbers, but this never calls DH_check.
As far as I can tell, for now DH_check is called only in asymmetric/dh.py for DHPrivateNumbers
through load_dh_private_numbers
(or in test_dh.py through dh_parameters_supported
). So apart from the library tests it is not called when dealing with DHParameterNumbers
or DHPublicNumbers
.
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.
Do you convert the DHParameterNumbers to a DHParameters via parameters
? I guess we don't validate anything on that path so you can make a parameters and then call generate_private_key
.
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.
Indeed we do not use DHParameterNumbers unless for immediate conversion to DHParameters. We'd be fine with the workaround you suggest. Do you see anything else to add to the PR?
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.
I'm mostly trying to reconcile the existence of DH_check
with the fact that we don't (and can't) validate here, but g=1 would still be a very bad thing to put here, so I think g > 1
is probably what the modified check should be if we're going to merge this.
LGTM, let's see what CI has to say :) (I hate FFDH) |
Now an error is raised when |
tests/hazmat/primitives/test_dh.py
Outdated
@@ -51,9 +51,9 @@ def test_dh_parameternumbers(): | |||
None, None | |||
) | |||
|
|||
with pytest.raises(ValueError): | |||
with pytest.raises(TypeError): |
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.
This still needs to be ValueError
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.
my bad
Thanks for sticking around for so long @mtury. Could I prevail on you to submit one more quick PR to update the docs to note the new restriction on DHParameterNumbers? |
Nevermind! I went ahead and put it in as #3786 |
Congrats for closing on the whole FFDH saga. :) |
I've been working on a
cryptography
based TLS module for Scapy (see PR secdev/scapy#476).During test handshakes with
openssl
, I came across this limitation on the generator size of DH groups. Default DH group parameters withopenssl
are currently 2048-bit order with a 2048-bit generator. While we could debate on the impact of choosing a long generator over a value of 2 or 5, it does not seem appropriate to keep this constraint in the library.