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

mbedTLS NewCertificateSigningRequest fills wrong CSR length #2910

Closed
nileshvora-sls opened this issue Sep 29, 2020 · 3 comments · Fixed by #2913
Closed

mbedTLS NewCertificateSigningRequest fills wrong CSR length #2910

nileshvora-sls opened this issue Sep 29, 2020 · 3 comments · Fixed by #2913
Assignees
Labels
bug Something isn't working

Comments

@nileshvora-sls
Copy link

Problem
I was looking into creating csr for OpCSR for my ESP32 platform. However I was getting CSR length 0 when I call P256Keypair::NewCertificateSigningRequest. Then I looked into definition of it, it has written something like below.

    result = mbedtls_x509write_csr_pem(&csr, out_csr, length, CryptoRNG, nullptr);
    VerifyOrExit(result >= 0, error = CHIP_ERROR_INTERNAL);
    csr_length = static_cast<unsigned int>(result);

Proposed Solution
According to mbedtls API description mbedtls_x509write_csr_pem API return error code, not length. For length, we need to write something like below.

    result = mbedtls_x509write_csr_pem(&csr, out_csr, length, CryptoRNG, nullptr);
    VerifyOrExit(result >= 0, error = CHIP_ERROR_INTERNAL);
    csr_length = strlen((char *)out_csr);
@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.87. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@issue-label-bot issue-label-bot bot added the bug Something isn't working label Sep 29, 2020
@nileshvora-sls
Copy link
Author

CC @pan-apple @bzbarsky-apple

@pan-apple pan-apple self-assigned this Sep 29, 2020
@pan-apple
Copy link
Contributor

Thanks @nileshvora-sls , you are right about the return code. I'll push a fix for it.
The code was originally written to use mbedtls_x509write_csr() API, which returns the length. But in some iteration of the PR it got changed to PEM format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants