Some algorithm identifiers are not correctly encoded #361

Open
opened 2020-02-06 09:50:07 -06:00 by RonEld · 2 comments
RonEld commented 2020-02-06 09:50:07 -06:00 (Migrated from github.com)

Description

Raised in the forum by Michal Kochel:

I think there is an error in function mbedtls_asn1_write_algorithm_identifier (library\asn1write.c).
Depending on par_len it encodes par_len or NULL. But there is a third option.
If we look at https://tools.ietf.org/html/rfc7427#page-14 there are some algorithm identifiers which do not have parameter and NULL should not be placed.

We can see this problem when comparing what OpenSSL and Mbed TLS produces.

Mbed TLS produces following ASN.1

10:d=3 hl=2 l= 1 prim: INTEGER :00
13:d=2 hl=2 l= 3 prim: INTEGER :652040
18:d=2 hl=2 l= 12 cons: SEQUENCE
20:d=3 hl=2 l= 8 prim: OBJECT :ecdsa-with-SHA256
30:d=3 hl=2 l= 0 prim: NULL
32:d=2 hl=2 l= 53 cons: SEQUENCE

OpenSSL produces following ASN.1

4:d=1 hl=4 l= 279 cons: SEQUENCE
8:d=2 hl=2 l= 3 prim: INTEGER :652040
13:d=2 hl=2 l= 10 cons: SEQUENCE
15:d=3 hl=2 l= 8 prim: OBJECT :ecdsa-with-SHA256
25:d=2 hl=2 l= 53 cons: SEQUENCE
27:d=3 hl=2 l= 11 cons: SET

Problem was found when I wanted to create a CA certificate and an endpoint certificate (both with keys based on elliptic curves).
When CA certificate was created with RSA key, everything was correct.
There was no problem when endpoint certificate had key based on elliptic curves.
When I used keys based on elliptic curves with CA certificate Chrome reported NET::ERR_CERT_INVALID during SSL_do_handshake.

Issue request type

[ ] Question
[ ] Enhancement
[x ] Bug
<!-- ************************************** WARNING ************************************** The ciarcom bot parses this header automatically. Any deviation from the template may cause the bot to automatically correct this header or may result in a warning message, requesting updates. Please ensure that nothing follows the Issue request type section, all issue details are within the Description section and no changes are made to the template format (as detailed below). ************************************************************************************* --> ### Description <!-- Required Add detailed description of what you are reporting. Good example: https://os.mbed.com/docs/latest/reference/workflow.html Things to consider sharing: - What target does this relate to? - What toolchain (name + version) are you using? - What tools (name + version - is it mbed-cli, online compiler or IDE) are you using? - What is the SHA of Mbed OS (git log -n1 --oneline)? - Steps to reproduce. (Did you publish code or a test case that exhibits the problem?) --> Raised in the [forum](https://forums.mbed.com/t/some-algorithm-identifiers-are-not-correctly-encoded/7080) by Michal Kochel: >I think there is an error in function mbedtls_asn1_write_algorithm_identifier (library\asn1write.c). Depending on par_len it encodes par_len or NULL. But there is a third option. If we look at https://tools.ietf.org/html/rfc7427#page-14 there are some algorithm identifiers which do not have parameter and NULL should not be placed. >We can see this problem when comparing what OpenSSL and Mbed TLS produces. >Mbed TLS produces following ASN.1 ~~~ 10:d=3 hl=2 l= 1 prim: INTEGER :00 13:d=2 hl=2 l= 3 prim: INTEGER :652040 18:d=2 hl=2 l= 12 cons: SEQUENCE 20:d=3 hl=2 l= 8 prim: OBJECT :ecdsa-with-SHA256 30:d=3 hl=2 l= 0 prim: NULL 32:d=2 hl=2 l= 53 cons: SEQUENCE ~~~ >OpenSSL produces following ASN.1 ~~~ 4:d=1 hl=4 l= 279 cons: SEQUENCE 8:d=2 hl=2 l= 3 prim: INTEGER :652040 13:d=2 hl=2 l= 10 cons: SEQUENCE 15:d=3 hl=2 l= 8 prim: OBJECT :ecdsa-with-SHA256 25:d=2 hl=2 l= 53 cons: SEQUENCE 27:d=3 hl=2 l= 11 cons: SET ~~~ >Problem was found when I wanted to create a CA certificate and an endpoint certificate (both with keys based on elliptic curves). When CA certificate was created with RSA key, everything was correct. There was no problem when endpoint certificate had key based on elliptic curves. When I used keys based on elliptic curves with CA certificate Chrome reported NET::ERR_CERT_INVALID during SSL_do_handshake. ### Issue request type <!-- Required Please add only one X to one of the following types. Do not fill multiple types (split the issue otherwise.) Please note this is not a GitHub task list, indenting the boxes or changing the format to add a '.' or '*' in front of them would change the meaning incorrectly. The only changes to be made are to add a description text under the description heading and to add a 'x' to the correct box. --> [ ] Question [ ] Enhancement [x ] Bug
ciarmcom commented 2020-02-06 10:43:51 -06:00 (Migrated from github.com)
*Internal Jira reference: https://jira.arm.com/browse/IOTCRYPT-1046*
mkochel commented 2020-04-03 04:33:47 -05:00 (Migrated from github.com)

When can we expect correction of this bug?

When can we expect correction of this bug?
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-ARMmbed/mbed-crypto#361
No description provided.