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

Remove unnecessary uses of MD2 in X.509 parsing test suite #2430

Merged
merged 13 commits into from
Jun 14, 2019

Conversation

hanno-becker
Copy link

As has been reported in #821, many test cases in the X.509 parsing test suite use MD2 in places where an arbitrary hash algorithm would be supported. This is bad for two reasons: Firstly, it shows bad practice using a weak digest, and secondly, it significantly reduces negative test coverage in the default configuration which doesn't have MD2 enabled.

This PR changes the tests to use SHA-256 in place of MD2 in those instances where a general hash algorithm is allowed (and we're not specifically testing support for MD2).

Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

(Partial review so far.)

@@ -12,7 +12,7 @@ x509_cert_info:"data_files/test-ca.crt":"cert. version \: 3\nserial number

X509 Certificate information MD2 Digest
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_MD2_C
x509_cert_info:"data_files/cert_md2.crt":"cert. version \: 3\nserial number \: 09\nissuer name \: C=NL, O=PolarSSL, CN=PolarSSL Test CA\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Cert MD2\nissued on \: 2009-07-12 10\:56\:59\nexpires on \: 2011-07-12 10\:56\:59\nsigned using \: RSA with MD2\nRSA key size \: 2048 bits\nbasic constraints \: CA=false\n"
x509_cert_info:"data_files/cert_md2.crt":"cert. version \: 3\nserial number \: 09\nissuer name \: C=NL, O=PolarSSL, CN=PolarSSL Test CA\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Cert MD2\nissued on \: 2009-07-12 10\:56\:59\nexpires on \: 2011-07-12 10\:56\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 2048 bits\nbasic constraints \: CA=false\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you really mean SHA-256 here? The name of the test case seems pretty explicit about testing MD2. (A few other occurrences below.)

Copy link
Author

Choose a reason for hiding this comment

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

@mpg No, I'm sorry, that was careless.

@hanno-becker hanno-becker added needs-work and removed needs-review Every commit must be reviewed by at least two team members, labels Feb 12, 2019
@hanno-becker hanno-becker added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Feb 12, 2019
@hanno-becker
Copy link
Author

@mpg Could you take another look?

AndrzejKurek
AndrzejKurek previously approved these changes Feb 13, 2019
Patater
Patater previously approved these changes Feb 19, 2019
Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

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

LGTM

@hanno-becker
Copy link
Author

Nothing has changed since @AndrzejKurek's approval - I think it got lost when @mpg re-requested it. Was there a particular reason for that, @mpg?

@mpg
Copy link
Contributor

mpg commented Feb 19, 2019

I don't remember doing that, so probably no particular reason ^^

k-stachowiak
k-stachowiak previously approved these changes Feb 20, 2019
@hanno-becker hanno-becker removed the needs-review Every commit must be reviewed by at least two team members, label Feb 22, 2019
@hanno-becker
Copy link
Author

Ping @Patater for gatekeeping.

@Patater Patater added the approved Design and code approved - may be waiting for CI or backports label Feb 22, 2019
@mpg mpg removed request for mpg and AndrzejKurek February 28, 2019 09:58
@mpg
Copy link
Contributor

mpg commented Feb 28, 2019

This fixes #821 which is labeled as a bug, so relabeling this with "bug", and hence needing backports.

@mpg mpg added the bug label Feb 28, 2019
AndrzejKurek
AndrzejKurek previously approved these changes Jun 3, 2019
@gilles-peskine-arm gilles-peskine-arm self-requested a review June 3, 2019 11:42
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

The changes to the test data are fine, but we no longer have any test for a certificate that uses an MD2 digest. Please add a “Valid Cert MD2 Digest” test case that's similar to the “Valid Cert MD4 Digest“.

@gilles-peskine-arm gilles-peskine-arm removed the request for review from Patater June 3, 2019 12:29
@gilles-peskine-arm gilles-peskine-arm added needs-work and removed needs-ci Needs to pass CI tests labels Jun 3, 2019
Hanno Becker added 3 commits June 3, 2019 14:10
The example programs programs/x509/cert_req and programs/x509/cert_write
(demonstrating the use of X.509 CSR and CRT writing functionality)
previously didn't support MD2 signatures.

For testing purposes, this commit adds support for MD2 to cert_req,
and support for MD2 and MD4 to cert_write.
@hanno-becker
Copy link
Author

@gilles-peskine-arm Thanks for your review.

The PR doesn't make the situation worse, because it only replaces MD2 by SHA-256 in parsing tests, and a MD2-specific parsing test remains ("X509 Certification information MD2 digest").

Nonetheless, you have a point that there's a pre-existing gap in the tests in that we don't exercise verification of an MD2 signed certificate, and I've added an analogue of "Valid Cert MD4 Digest" for MD2.

Also, I noticed that these tests don't expect success because they use a profile which forbids MDx, and I've added three tests which use a test-only profile allowing all MDs, so that we now also cover successful verification of MDx-signed CRTs.

@gilles-peskine-arm @AndrzejKurek Can you please re-review?

@@ -2511,7 +2511,7 @@
* it, and considering stronger message digests instead.
*
*/
//#define MBEDTLS_MD2_C
#define MBEDTLS_MD2_C
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm Jun 3, 2019

Choose a reason for hiding this comment

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

You accidentally committed a modified config.h. Feel free to rebase the offending commit as far as I'm concerned.

Copy link
Author

Choose a reason for hiding this comment

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

Damn... sorry

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

Hanno Becker added 4 commits June 3, 2019 14:45
The X.509 parsing test suite test_suite_x509parse contains a test
exercising X.509 verification for a valid MD4/MD5 certificate in a
profile which doesn't allow MD4/MD5. This commit adds an analogous
test for MD2.
@hanno-becker hanno-becker force-pushed the x509_parse_test_fixes branch from 6335f7b to 024b53a Compare June 3, 2019 13:45
@hanno-becker hanno-becker removed the needs-review Every commit must be reviewed by at least two team members, label Jun 4, 2019
@Patater Patater added the approved Design and code approved - may be waiting for CI or backports label Jun 12, 2019
@Patater Patater merged commit 024b53a into Mbed-TLS:development Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports bug component-x509
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants