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

[interop] ASN1 NULL parameter for AlgorithmIdentifier MUST be omit for Elliptic Curve #2924

Closed
Fassino opened this issue Nov 13, 2019 · 12 comments
Labels
bug component-x509 help-wanted This issue is not being actively worked on, but PRs welcome.

Comments

@Fassino
Copy link

Fassino commented Nov 13, 2019

Description

  • Type: Bug
  • Priority: Major

Bug

OS
Linux

mbed TLS build:
Version: Version: 2.16.3

Expected behavior

To be conform with RFC, mbedtls_asn1_write_algorithm_identifier MUSTN'T add a NULL parameter for Elliptic Curve Cryptography key pair.

RFC 5280 says NULL parameter is optional (see 4.1.1.2)

But, RFC 5754 (ECDSA for X509) says encoding MUST omit the parameters field (see 3.2).

Please note, that the RFC for RSA x509, specify that the NULL MUST be present… Cryptography is beautiful ;-)

Actual behavior

Implementation is not conform to RFC. So when using mbedtls to issue certificate based on ECC key pairs, the certificate is rejected by some cryptography implementations.

@gilles-peskine-arm gilles-peskine-arm added bug component-crypto Crypto primitives and low-level interfaces component-x509 labels Nov 19, 2019
@gilles-peskine-arm
Copy link
Contributor

Oh joy, a bug where the sensible fix is to change the API :( Thanks for the report!

Memo: when fixing this, add tests to make sure that Mbed TLS can read back both the correct encoding and the encoding it used to write.

@ciarmcom
Copy link

ARM Internal Ref: IOTSSL-2979

@mpg
Copy link
Contributor

mpg commented Dec 28, 2020

Note: this was reported again on the mailing list: https://lists.trustedfirmware.org/pipermail/mbed-tls/2020-December/000273.html

@mpg
Copy link
Contributor

mpg commented Dec 28, 2020

Note: OpenSSL and GnuTLS (certtool) both generate the correct encoding, so clearly we can read the proper encoding, and we have test certificates generated using Mbed TLS, so we can also read the current incorrect encoding, but I agree that when fixing we need to have an explicit test for that.

Also, I'm removing the label "component: crypto" as I believe this only affects X.509. The only place in the crypto library that calls mbedtls_asn1_write_algorithm_identifier() is from mbedtls_pk_write_pubkey_der(), where parameters are used (to identify the curve), so there's no extra NULL added. The only other places mbedtls_asn1_write_algorithm_identifier() is called are both in X.509, specifically in x509_create.c and x509write_crt.c.

@mpg mpg removed the component-crypto Crypto primitives and low-level interfaces label Dec 28, 2020
@mpg mpg changed the title ASN1 NULL parameter for AlgorithmIdentifier MUST be omit for Elliptic Curve [interop] ASN1 NULL parameter for AlgorithmIdentifier MUST be omit for Elliptic Curve Dec 29, 2020
@mpg
Copy link
Contributor

mpg commented Dec 29, 2020

The person who reported this by email confirmed that this bug is not just about compliance, but is causing interoperability issues in practice: for example, it causes Chrome to reject all ECDSA-signed certificates created with Mbed TLS.

@laumor01 laumor01 moved this from Incoming Items to February Sprint in OBSOLETE - SEE https://github.com/orgs/Mbed-TLS/projects/3 Jan 7, 2021
@laumor01 laumor01 moved this from February Sprint to Prioritised Backlog in OBSOLETE - SEE https://github.com/orgs/Mbed-TLS/projects/3 Feb 3, 2021
@daverodgman daverodgman added the help-wanted This issue is not being actively worked on, but PRs welcome. label Feb 3, 2021
@marekjansta
Copy link

I tried to fix this problem (ran into it when trying to connect to a device with a self-signed certificate using ECC using Chrome after it has switched to its own Certificate Verifier).

Could someone check if that looks ok? Thanks

https://github.com/marekjansta/mbedtls/tree/fix-asn1-algorithm-identifier

@gilles-peskine-arm
Copy link
Contributor

@marekjansta At first glance, the code looks correct.

However the patch would not be acceptable in Mbed TLS because it changes the API. We can't change the signature of an existing function that's declared and documented in a public header.

I think the best solution is to deprecate mbedtls_asn1_write_algorithm_identifier and create a new function that doesn't add the NULL automatically. Keep mbedtls_asn1_write_algorithm_identifier as a MBEDTLS_DEPRECATED function whose implementation is a call to the new function, plus what it takes to add NULL automatically. Both functions need to have unit tests.

@Fassino
Copy link
Author

Fassino commented Nov 22, 2022

Hi All, good to see that the fix of the issue is ongoing. It will solve many interoperability issue. Do you know when it will be released? And in which version? Thanks

@gilles-peskine-arm
Copy link
Contributor

@Fassino I'm afraid that so far we do not have a pending fix and I'm not aware of anybody working on it (unless @marekjansta plans to make a backward-compatible version of their fix?).

@marekjansta
Copy link

I updated my solution so that it does not break the rules.
Could someone verify if this changeset would be acceptable?
https://github.com/marekjansta/mbedtls/tree/fix-asn1-algorithm-identifier

@gilles-peskine-arm
Copy link
Contributor

gilles-peskine-arm commented Feb 3, 2023

@marekjansta Yes, that change looks fine in terms of not breaking the API. I haven't reviewed the implementation. And we would need unit tests, both for the new function and for the bug fix.

Please make a pull request. Preferably with the tests, but if you don't have time for those, maybe someone else can contribute the tests.

@daverodgman
Copy link
Contributor

Fixed by #7788

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug component-x509 help-wanted This issue is not being actively worked on, but PRs welcome.
Projects
None yet
Development

No branches or pull requests

8 participants