Skip to content

ASN1 layer can't parse nested constructive octet strings #2138

@HoneyryderChuck

Description

@HoneyryderChuck

BouncyCastle ASN1 API parsers don't seem to be able to parse some complex constructed DERs. Here are two examples (in hexa notation):

  • 24 80 04 01 01 04 01 02 00 00
  • 24 80 24 80 04 01 01 00 00 24 80 04 01 02 00 00 04 01 03 00 00

Assuming that an ASN1InputStream is initialized with each, readObject() will return, an OctetString, in the first case with the 01 02 value, and in the second case with 01 02 03.

This parsing is wrong. In the first case, the encoded stream represents a "raw constructed" indefinite length (with UNIVERSAL tag 4) containing two octet strings (04 01 01 and 04 01 02). In the second case, it represents a "raw constructed" indefinite length (with UNIVERSAL tag 4) containing 2 "raw constructed" indefinite length (with UNIVERSAL tag 4) objects (each containing an octet string, 04 01 01 and 04 01 02) and an octetstring (04 01 03).

This seems to be an unsupported case, because BouncyCastle does not define the concept of a "raw constructed" object. While this seems to work well for Sequences and Sets, when it comes to OctetStrings (and maybe BitStrings?), internal data seems to be concatenated into a single OctetString object, ignoring relevant bits, I believe, due to the usage of this parser. But even assuming that a correct parser would exist, there is no defined class that could represent that, as the only constructed classes are around must map to ASN1Sequence or ASN1Set, i.e. a tagnumber of 4, which maps to a universal primitive, does not have a corresponding class around.

So this is essentially a feature request to create the concept of such a class, and support it in parsers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions