Coder Social home page Coder Social logo

Comments (4)

ovdink avatar ovdink commented on August 19, 2024

I checked this point using another lib (https://www.npmjs.com/package/asn1js)
using this method:

fromBER(buffer).result.valueBlock.value[1] (to pick up a only problem string)

where buffer is an hex code example above (30820c92020100031100890e6dada073475c839b216850c1...)

and saw this object:

{
  "blockName": "BIT STRING",
  "blockLength": 19,
  "error": "",
  "warnings": [],
  "valueBeforeDecode": "031100890e6dada073475c839b216850c19f48",
  "idBlock": {
    "blockName": "identificationBlock",
    "blockLength": 1,
    "error": "",
    "warnings": [],
    "valueBeforeDecode": "",
    "isHexOnly": false,
    "valueHex": "",
    "tagClass": 1,
    "tagNumber": 3,
    "isConstructed": false
  },
  "lenBlock": {
    "blockName": "lengthBlock",
    "blockLength": 1,
    "error": "",
    "warnings": [],
    "valueBeforeDecode": "",
    "isIndefiniteForm": false,
    "longFormUsed": false,
    "length": 17
  },
  "valueBlock": {
    "blockName": "BitStringValueBlock",
    "blockLength": 17,
    "error": "",
    "warnings": [],
    "valueBeforeDecode": "",
    "isIndefiniteForm": false,
    "value": [
      {
        "blockName": "PRIMITIVE",
        "blockLength": 16,
        "error": "",
        "warnings": [],
        "valueBeforeDecode": "890e6dada073475c839b216850c19f48",
        "idBlock": {
          "blockName": "identificationBlock",
          "blockLength": 1,
          "error": "",
          "warnings": [],
          "valueBeforeDecode": "",
          "isHexOnly": false,
          "valueHex": "",
          "tagClass": 3,
          "tagNumber": 9,
          "isConstructed": false
        },
        "lenBlock": {
          "blockName": "lengthBlock",
          "blockLength": 1,
          "error": "",
          "warnings": [],
          "valueBeforeDecode": "",
          "isIndefiniteForm": false,
          "longFormUsed": false,
          "length": 14
        },
        "valueBlock": {
          "blockName": "PrimitiveValueBlock",
          "blockLength": 14,
          "error": "",
          "warnings": [],
          "valueBeforeDecode": "",
          "isHexOnly": true,
          "valueHex": "6dada073475c839b216850c19f48"
        },
        "name": "",
        "optional": false
      }
    ],
    "isHexOnly": false,
    "valueHex": "890e6dada073475c839b216850c19f48",
    "unusedBits": 0,
    "isConstructed": false
  },
  "name": "",
  "optional": false
}

the most interesting thing is a field:

valueBlock.value.valueBlock.valueHex: "6dada073475c839b216850c19f48"

which is not valid for us

but, we also have another value from this object

"valueHex": "890e6dada073475c839b216850c19f48"

which is exactly what we need
so, I would like to understand why this happened. there is a feeling that the line "890e6dada073475c839b216850c19f48 "has undergone additional processing

and of course I wouldn't want to use this library, because I need process each value and also this library works twice as slow

from asn1js.

lapo-luchini avatar lapo-luchini commented on August 19, 2024

The problem is that unfortunately many "interesting" ASN.1 structures hide content inside either BIT STRINGs or OCTET STRINGs, and since asn1js has a "best effort" decoding approach it tries decoding the content of any of those and if it "just happens" to be valid ASN.1 it shows the content as "embedded" (instead of "constructed", which means it was done with proper ASN.1 structures).
image
As you can notice (while hovering the BIT STRING, not the content) is is made so:
03 11 00 89 0E 6D AD A0 73 47 5C 83 9B 21 68 50 C1 9F 48
Where 03 mean it's a BIT STRING, 11 means it is 17 bytes long, 00 is the number of unused bits (0 means the last byte is fully used), then the content which in this case is raw 89 0E 6D AD A0 73 47 5C 83 9B 21 68 50 C1 9F 48.
Problem is, 89 means custom tag [9] and 0E means 14 byte long, which actually match the rest of the content.
This is most probably a false positive, but it is unavoidable (while keeping the approach of decoding as much as possible for "hidden" internal structures, which are not rare).

You have the very same behavior that that other library you cite which I have no experience with, but they do basically the same I do in returnig you both the direct hex encoding of the current node, and a way to access inner structures with .value.valueBlock.

there is a feeling that the line "890e6dada073475c839b216850c19f48 "has undergone additional processing

Actualyl this is the raw content of the BIT STRING, it's the "6dada073475c839b216850c19f48" that actually has undergone additional processing, in trying to decode as inner value.

If you are using asn1js and never want to go inside "encapsulated" structures, you can do that by checking for that explicitly, there is currently no way to disable recursion altogether.

Would you like a checkbox in the GUI to avoid any recursion? (this is not a great approach when you have big ASN.1 structures with both BIT STRINGs that use recursion and ones that should not, though)

Or maybe, when using as a library, I could make it more easy to understand when a node is an actual "encapsulation" (which might be a false positive).

Actually your very example contains both an example you say is a "false" content, and a node that, from its complexity, I'd say it's DEFINITELY a real encapsulated content:

image

from asn1js.

lapo-luchini avatar lapo-luchini commented on August 19, 2024

I could make it more easy to understand when a node is an actual "encapsulation" (which might be a false positive).

Actually it's not very difficult (while not very documented), you could do it like this:

if (this.sub !== null) { // has inner structures
    if (this.tag.tagConstructed)
        // this is a constructed content (for sure)
    else
        // this is a (supposedly) encapsulated content
}

from asn1js.

lapo-luchini avatar lapo-luchini commented on August 19, 2024

There are cases when an application specifically considers that the client should parse a BitString, however the recurse variable defined in Line 332:

BTW I'm not sure I understood this correctly, as the rest of you message seems (to me) to be about a structure which was erroneously decoded, not a structure that hasn't been decoded but should have been.

Can you clarify?

from asn1js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.