FreeDSx / ASN1

An ASN.1 Library for PHP.
MIT License
10 stars 3 forks source link

OID Decoding/Encoding is wrong #8

Closed danielmarschall closed 3 years ago

danielmarschall commented 3 years ago

Hello,

I noticed that the BerEncoder::decodeOid() and BerEncoder::encodeOid() functions are not correctly implemented.

The formula "modulo 40" is only correct for the root OIDs 0 and 1. For 2, the procedure becomes more complex. More information at: https://misc.daniel-marschall.de/asn.1/oid_facts.html

Example: Your program is not able to handle th OID 2.999

Here is a tool that you can use to test if your implementation is correct: https://misc.daniel-marschall.de/asn.1/oid-converter/online.php

ChadSikorra commented 3 years ago

Hi @danielmarschall, thanks for reporting this issue. Indeed, looking at the x.690 spec, I am not handling that properly. They also include an example of how it should be encoded as well. I will work on it this week.

ChadSikorra commented 3 years ago

I think this should be resolved with https://github.com/FreeDSx/ASN1/commit/b854cf16d90e7b45a9d9ed9cd173881aca3229f4. I have tagged a new version with the fixes.

ChadSikorra commented 3 years ago

I thought of yet another case where I could potentially not be handling the encoding of the second OID component properly now when it reaches near the PHP_MAX_INT value. That has been resolved with https://github.com/FreeDSx/ASN1/commit/05206bfed39057070194f1bd422c9df7a17e1070.

ChadSikorra commented 3 years ago

Considering this resolved. If you still notice issues please feel free to re-open it or let me know. Thanks again for reporting this.