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

Use size of server key when selecting signature algorithm. #4389

Closed
wants to merge 2 commits into from

Conversation

nrobbin
Copy link

@nrobbin nrobbin commented Sep 19, 2017

The server should not pick a signature algorithm that is incompatible with its configured key if the client offers a compatible algorithm of lower preference.

Fixes #4042

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label Sep 19, 2017
Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

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

i assume this is the right thing to do, but @snhenson should comment. There are some changes needed.

ssl/t1_lib.c Outdated
/* validate that key is large enough for the signature algorithm */
const RSA *rsa = EVP_PKEY_get0_RSA(s->cert->pkeys[SSL_PKEY_RSA_PSS_SIGN].privatekey);
const EVP_MD *hash = EVP_get_digestbynid(lu->hash);
if ((NULL == rsa)
Copy link
Contributor

Choose a reason for hiding this comment

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

Our coding style says to leave a blank line after declarations. And we'd write the if test like this:

if (rsa == NULL
     || hash == NULL
     || RSA_size(rsa) < (2 * EVP_MD_size(hash) + 2))

Consider a new define RSA_PSS_KEY_BIG_ENOUGH or something, that captures that last less-than test.

Copy link
Author

Choose a reason for hiding this comment

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

I'd be happy to add a define or function for the check. Where is the best location for such a function?

ssl/t1_lib.c Outdated
@@ -2379,6 +2387,15 @@ int tls_choose_sigalg(SSL *s, int *al)
} else if (lu->sig_idx != s->cert->key - s->cert->pkeys) {
continue;
}
if (lu->sig == EVP_PKEY_RSA_PSS) {
/* validate that key is large enough for the signature algorithm */
const RSA *rsa = EVP_PKEY_get0_RSA(s->cert->pkeys[SSL_PKEY_RSA_PSS_SIGN].privatekey);
Copy link
Contributor

Choose a reason for hiding this comment

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

and, of course, same comment as above. Maybe even make a function that takes rsa and hash as parameters.

@richsalz
Copy link
Contributor

Also, you will have to sign our CLA; this is not a trivial change. Please see https://www.openssl.org/policies/cla.html for details.

@richsalz
Copy link
Contributor

you can put it up near the top of the same file

@snhenson
Copy link
Contributor

As indicated in the original issue we shouldn't hit this unless the key size is quite small anyway. If we care about that then do not use EVP_get_digestbynid(): that's quite an expensive operation to perform multiple times. Use the hash_idx field instead like this ssl_md(lu->hash_idx). I agree that bypassing the whole check if the key is big enough is a good idea too.

@nrobbin
Copy link
Author

nrobbin commented Sep 21, 2017

Now I see the ssl_md() function (and tls1_lookup_md()). I'll use that instead of EVP_get_digestbynid().

I agree 1024 bit keys are small and should not be used. However, I think this is worthwhile to fix because I can get two different behaviors depending on how the client orders the same set of signature algorithms. Using s_client with the -sigalgs option to connect to s_server running with a 1024 bit key I see the following

Works: -sigalgs "RSA-PSS+SHA256:RSA+SHA256:RSA-PSS+SHA384:RSA+SHA384:RSA-PSS+SHA512:RSA+SHA512"
Fails: -sigalgs "RSA-PSS+SHA512:RSA+SHA512:RSA-PSS+SHA384:RSA+SHA384:RSA-PSS+SHA256:RSA+SHA256"

Since it works in one case, I would expect it to work in both.

@richsalz
Copy link
Contributor

Close/open to kick the CLA bot.

@richsalz richsalz closed this Nov 28, 2017
@richsalz richsalz reopened this Nov 28, 2017
@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label Nov 28, 2017
@richsalz
Copy link
Contributor

@nrobbin you need to edit the commit to set the Author properly. Perhaps best to squash and fix the author in the new single commit?

@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Nov 28, 2017
@nrobbin
Copy link
Author

nrobbin commented Nov 28, 2017

The code in the pull request is no longer working. It looks like the definition of SSL_PKEY_RSA_PSS_SIGN changed. I'll re-work against the latest code.

… or SSL_PKEY_RSA).

Extract the RSA key using EVP_PKEY_get0.  Type is checked externally to be either EVP_PKEY_RSA_PSS or EVP_PKEY_RSA.
Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

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

Ping another reviewer. This is a useful safety to have

@levitte levitte added branch: master Merge to master branch approval: done This pull request has the required number of approvals labels Jan 8, 2018
levitte pushed a commit that referenced this pull request Jan 8, 2018
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from #4389)
levitte pushed a commit that referenced this pull request Jan 8, 2018
… or SSL_PKEY_RSA).

Extract the RSA key using EVP_PKEY_get0.  Type is checked externally to be either EVP_PKEY_RSA_PSS or EVP_PKEY_RSA.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from #4389)
@richsalz
Copy link
Contributor

richsalz commented Jan 8, 2018

Merged. Thanks for all your efforts to get this code usable by OpenSSL. Nice security/usability feature!

@richsalz richsalz closed this Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: done This pull request has the required number of approvals branch: master Merge to master branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RSA key size not used when selecting shared signature algorithms
5 participants