Coder Social home page Coder Social logo

Feature idea: support ASN.1 (DER/BER) about fq HOT 5 CLOSED

wader avatar wader commented on May 18, 2024 1
Feature idea: support ASN.1 (DER/BER)

from fq.

Comments (5)

wader avatar wader commented on May 18, 2024 3

Hey, some update. I have a basic BER decoder working now, also working on adding support for arbitrary large integer to the decoder which will be useful for ASN.1. and make it more useful for certificates and crypto related things i think. Hope i can push something in the next few days.

from fq.

wader avatar wader commented on May 18, 2024

Hi, yes that is a good idea. It would also require figuring out a nice way of passing in a grammar file to the decoder.
If you want to work on this i would recommend having a look at the protobutf decoder https://github.com/wader/fq/blob/master/format/protobuf/protobuf.go. It does not support passing in schemas but other decoders can pass it something schema-like internally to improve the decode output.

from fq.

gjvnq avatar gjvnq commented on May 18, 2024

Thanks. I will take a look if I have time in January.

from fq.

wader avatar wader commented on May 18, 2024

πŸ‘ There are some other issues #25 #24 that will share som issues with this like how to provide an external description file and how to model the decoded value tree.

from fq.

wader avatar wader commented on May 18, 2024

Hey, now there is basic ASN1 BER support in master and also some kind of torepr support.

To make it a bit easer to work with PEM there is also frompem/topem now.

Any feedback what could be done differently or bugs are much appreciated.

Example reading PEM file, decode it and display it as decode tree, JSON and torepr JSON:

$ fq -o line_bytes=10 -d raw '(. | tobytes | tostring | println), (frompem | asn1_ber | d, tovalue, torepr)' format/asn1/testdata/test.pem
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMYfnvWtC8Id5bPKae5yXSxQTt
+Zpul6AnnZWfI2TtIarvjHBFUtXRo96y7hoL4VWOPKGCsRqMFDkrbeUjRrx8iL91
4/srnyf6sh9c8Zk04xEOpK1ypvBz+Ks4uZObtjnnitf0NBGdjMKxveTq+VE7BWUI
yQjtQ8mbDOsiLLvh7wIDAQAB
-----END PUBLIC KEY-----
    β”‚00 01 02 03 04 05 06 07 08 09β”‚0123456789β”‚.{}: (asn1_ber)
0x00β”‚30                           β”‚0         β”‚  class: "universal" (0)
0x00β”‚30                           β”‚0         β”‚  form: "constructed" (1)
0x00β”‚30                           β”‚0         β”‚  tag: "sequence" (0x10)
0x00β”‚   81 9f                     β”‚ ..       β”‚  length: 159
    β”‚                             β”‚          β”‚  constructed[0:2]:
    β”‚                             β”‚          β”‚    [0]{}:
0x00β”‚         30                  β”‚   0      β”‚      class: "universal" (0)
0x00β”‚         30                  β”‚   0      β”‚      form: "constructed" (1)
0x00β”‚         30                  β”‚   0      β”‚      tag: "sequence" (0x10)
0x00β”‚            0d               β”‚    .     β”‚      length: 13
    β”‚                             β”‚          β”‚      constructed[0:2]:
    β”‚                             β”‚          β”‚        [0]{}:
0x00β”‚               06            β”‚     .    β”‚          class: "universal" (0)
0x00β”‚               06            β”‚     .    β”‚          form: "primitive" (0)
0x00β”‚               06            β”‚     .    β”‚          tag: "object_identifier" (0x6)
0x00β”‚                  09         β”‚      .   β”‚          length: 9
    β”‚                             β”‚          β”‚          value[0:7]:
0x00β”‚                     2a      β”‚       *  β”‚            [0]: 1
0x00β”‚                     2a      β”‚       *  β”‚            [1]: 2
0x00β”‚                        86 48β”‚        .Hβ”‚            [2]: 840
0x0aβ”‚86 f7 0d                     β”‚...       β”‚            [3]: 113549
0x0aβ”‚         01                  β”‚   .      β”‚            [4]: 1
0x0aβ”‚            01               β”‚    .     β”‚            [5]: 1
0x0aβ”‚               01            β”‚     .    β”‚            [6]: 1
    β”‚                             β”‚          β”‚        [1]{}:
0x0aβ”‚                  05         β”‚      .   β”‚          class: "universal" (0)
0x0aβ”‚                  05         β”‚      .   β”‚          form: "primitive" (0)
0x0aβ”‚                  05         β”‚      .   β”‚          tag: "null" (0x5)
0x0aβ”‚                     00      β”‚       .  β”‚          length: "indefinite" (0)
    β”‚                             β”‚          β”‚          value: null
    β”‚                             β”‚          β”‚    [1]{}:
0x0aβ”‚                        03   β”‚        . β”‚      class: "universal" (0)
0x0aβ”‚                        03   β”‚        . β”‚      form: "primitive" (0)
0x0aβ”‚                        03   β”‚        . β”‚      tag: "bit_string" (0x3)
0x0aβ”‚                           81β”‚         .β”‚      length: 141
0x14β”‚8d                           β”‚.         β”‚
0x14β”‚   00                        β”‚ .        β”‚      unused_bits_count: 0
0x14β”‚      30 81 89 02 81 81 00 ccβ”‚  0.......β”‚      value: raw bits
0x1eβ”‚61 f9 ef 5a d0 bc 21 de 5b 3cβ”‚a..Z..!.[<β”‚
0x28β”‚a6 9e e7 25 d2 c5 04 ed f9 9aβ”‚...%......β”‚
*   β”‚until 0xa1.7 (end) (140)     β”‚          β”‚
{
  "class": "universal",
  "constructed": [
    {
      "class": "universal",
      "constructed": [
        {
          "class": "universal",
          "form": "primitive",
          "length": 9,
          "tag": "object_identifier",
          "value": [
            1,
            2,
            840,
            113549,
            1,
            1,
            1
          ]
        },
        {
          "class": "universal",
          "form": "primitive",
          "length": "indefinite",
          "tag": "null",
          "value": null
        }
      ],
      "form": "constructed",
      "length": 13,
      "tag": "sequence"
    },
    {
      "class": "universal",
      "form": "primitive",
      "length": 141,
      "tag": "bit_string",
      "unused_bits_count": 0,
      "value": "<140>MIGJAoGBAMxh+e9a0Lwh3ls8pp7nJdLFBO35mm6XoCedlZ8jZO0hqu+McEVS1dGj3rLuGgvhVY48oYKxGowUOStt5SNGvHyIv3Xj+yufJ/qyH1zxmTTjEQ6krXKm8HP4qzi5k5u2OeeK1/Q0EZ2MwrG95Or5UTsFZQjJCO1DyZsM6yIsu+HvAgMBAAE="
    }
  ],
  "form": "constructed",
  "length": 159,
  "tag": "sequence"
}
[
  [
    [
      1,
      2,
      840,
      113549,
      1,
      1,
      1
    ],
    null
  ],
  "<0b10001100>MIGJAoGBAMxh+e9a0Lwh3ls8pp7nJdLFBO35mm6XoCedlZ8jZO0hqu+McEVS1dGj3rLuGgvhVY48oYKxGowUOStt5SNGvHyIv3Xj+yufJ/qyH1zxmTTjEQ6krXKm8HP4qzi5k5u2OeeK1/Q0EZ2MwrG95Or5UTsFZQjJCO1DyZsM6yIsu+HvAgMBAAE="
]

from fq.

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.