Skip to content
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

Change the default key generation type for DH and DSA #13228

Closed
wants to merge 5 commits into from

Conversation

mattcaswell
Copy link
Member

Previously both DH and DSA were using FIPS186-4 for all key generation for DH and DSA in both the default and FIPS providers.

This is a little too restrictive for general purpose use and is a significant breaking change (for example it introduces restrictions on the sizes keys can be). AFAIK there was no OTC/OMC decision to make this breaking change.

This PR changes things so that by default in the default provider, DH keys swap to DH_PARAMGEN_TYPE_GENERATOR (i.e. PKCS3) and DHX keys swap to DH_PARAMGEN_TYPE_FIPS_186_2.

For DSA we swap to DSA_PARAMGEN_TYPE_FIPS_186_2 in the default provider.

The defaults are unchanged for the FIPS provider.

This was discovered by the tests being introduced in #13138 and is required for those tests to pass.

… module

The documentation claimed this was already the default but it wasn't. This
was causing the dhparam application to change behaviour when compared to
1.1.1
Inside the FIPS module we continue to use FIPS186-4. We prefer FIPS186-2
in the default provider for backwards compatibility reasons.
@mattcaswell mattcaswell added the branch: master Merge to master branch label Oct 23, 2020
@mattcaswell mattcaswell added this to the 3.0.0 beta1 milestone Oct 23, 2020
$EC_GOAL=../../libimplementations.a
$ECX_GOAL=../../libimplementations.a
$KDF_GOAL=../../libimplementations.a

IF[{- !$disabled{dh} -}]
SOURCE[$DH_GOAL]=dh_kmgmt.c
SOURCE[../../libfips.a]=dh_kmgmt.c
SOURCE[../../libnonfips.a]=dh_kmgmt.c
Copy link
Member

Choose a reason for hiding this comment

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

The idea of libimplementations.a is going more and more to waste...

@mattcaswell
Copy link
Member Author

Fixup pushed. Please take another look.

@kroeckx
Copy link
Member

kroeckx commented Oct 23, 2020 via email

@mattcaswell
Copy link
Member Author

Why would we use the obsolete FIPS 186-2? Is there a reason not to
just use 186-4?

Because its a breaking change...its way more restrictive about key lengths etc that you are allowed, e.g. see:

static int ffc_validate_LN(size_t L, size_t N, int type, int verify)
{
if (type == FFC_PARAM_TYPE_DH) {
/* Allow legacy 1024/160 in non fips mode */
if (L == 1024 && N == 160)
return 80;
/* Valid DH L,N parameters from SP800-56Ar3 5.5.1 Table 1 */
if (L == 2048 && (N == 224 || N == 256))
return 112;
# ifndef OPENSSL_NO_DH
DHerr(0, DH_R_BAD_FFC_PARAMETERS);
# endif
} else if (type == FFC_PARAM_TYPE_DSA) {
if (L == 1024 && N == 160)
return 80;
if (L == 2048 && (N == 224 || N == 256))
return 112;
if (L == 3072 && N == 256)
return 128;
# ifndef OPENSSL_NO_DSA
DSAerr(0, DSA_R_BAD_FFC_PARAMETERS);
# endif
}
return 0;
}

We could choose to relax those restrictions in the default provider. Or we could choose to have the breaking change - but that requires an OMC vote.

Copy link
Member

@t8m t8m left a comment

Choose a reason for hiding this comment

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

LGTM

@t8m t8m added the approval: done This pull request has the required number of approvals label Oct 26, 2020
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Oct 27, 2020
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

Copy link
Member

@slontis slontis left a comment

Choose a reason for hiding this comment

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

Whilst I understand why you are doing this for backwards compatability- I think it is setting a really bad example if it generates params using a dead legacy algorithm (especially for key sizes larger than 2048).
Personally I think it should be using a named group (it if can) based on the size, and only use fips_1862 if that does not work..

@mattcaswell
Copy link
Member Author

Whilst I understand why you are doing this for backwards compatability- I think it is setting a really bad example if it generates params using a dead legacy algorithm (especially for key sizes larger than 2048).
Personally I think it should be using a named group (it if can) based on the size, and only use fips_1862 if that does not work..

I somehow suspected you might feel this way. I think this PR is worthy of an OTC discussion.

@mattcaswell mattcaswell added the hold: need otc decision The OTC needs to make a decision label Oct 30, 2020
@mattcaswell
Copy link
Member Author

For input into the OTC discussion, these are the things that I know of that break or change behaviour compared to 1.1.1 by having the default generation type be FIPS 186-4:

EVP impacts:

  • The only key size that can be generated is 2048 bits
  • In theory a key size of 1024 would also be ok, but the default q bits size is 224 which is not allowed in conjunction with a p bit size of 1024
  • The default generator changes from 2 to something random
  • EVP_PKEY_CTX_set_dh_paramgen_generator() no longer works (it returns success but doesn't do anything)
  • We no longer end up with a "safe" prime

dhparam app impacts:

  • The dhparam default generator will change (from 2 to something random)
  • The "-2" and "-5" options cannot be made to work, unless we change the generation type if they are supplied
  • Only 2048 and 1024 sizes can be generated, unless we decide to change the generation type if something else is selected
  • We no longer end up with a safe prime

@t8m
Copy link
Member

t8m commented Oct 30, 2020

IMO there is nothing wrong with DH_PARAMGEN_TYPE_GENERATOR (except of course that it is not FIPS compliant). However one useful thing would be to have a parameter generator that would simply select one of the known safe primes that has the nearest size to the requested one. That could IMO be even the default for the FIPS module for the DH key type.

@kroeckx
Copy link
Member

kroeckx commented Oct 30, 2020 via email

@slontis
Copy link
Member

slontis commented Oct 31, 2020

Another thing to keep in mind..
There is more than one issue with non named groups related to key validation.

  1. key validation - This is really easy to get wrong with generated parameters since they have parameters that are not stored as part of the ASN1 that need to be set before validation. Named groups don't have this problem.
  2. TLS doesnt transmit Q. So if you do need to validate you need to somehow know what Q is. Named Groups solve this problem also.

FIPS 186-2 was still present in FIPS 186-4 for backwards compatability for quite a long time(only the validation bit , not the generation part).
It is now completely removed. (I think it only used SHA1).

@mattcaswell
Copy link
Member Author

I added a couple of fixups to bring this into line with the proposal currently being voted on by OTC.

@mattcaswell mattcaswell added approval: review pending This pull request needs review by a committer and removed approval: ready to merge The 24 hour grace period has passed, ready to merge labels Nov 9, 2020
@mattcaswell
Copy link
Member Author

The travis failure does not seem relevant.

@t8m - can you reconfirm your approval of this?

I'm also still waiting on the conclusion of the OTC vote before I can merge this.

@t8m
Copy link
Member

t8m commented Nov 9, 2020

Yes, still approved.

@romen romen added the triaged: OTC evaluated This issue/pr was triaged by OTC label Nov 10, 2020
@mattcaswell
Copy link
Member Author

The vote for this passed, so I'm lifting the OTC hold.

@mattcaswell mattcaswell added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed hold: need otc decision The OTC needs to make a decision approval: review pending This pull request needs review by a committer labels Nov 18, 2020
@mattcaswell
Copy link
Member Author

The travis failure is not relevant.

@mattcaswell
Copy link
Member Author

Pushed. Thanks.

openssl-machine pushed a commit that referenced this pull request Nov 18, 2020
… module

The documentation claimed this was already the default but it wasn't. This
was causing the dhparam application to change behaviour when compared to
1.1.1

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from #13228)
openssl-machine pushed a commit that referenced this pull request Nov 18, 2020
Inside the FIPS module we continue to use FIPS186-4. We prefer FIPS186-2
in the default provider for backwards compatibility reasons.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from #13228)
@paulnelsontx paulnelsontx added this to Ready to merge in 3.0.0 estimator Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch triaged: OTC evaluated This issue/pr was triaged by OTC
Projects
No open projects
3.0.0 estimator
Ready to merge
Development

Successfully merging this pull request may close these issues.

None yet

7 participants