4 releases

0.1.3 Jul 5, 2024
0.1.2 Jul 5, 2024
0.1.1 Jul 5, 2024
0.1.0 Jul 3, 2024

#939 in Testing

MIT license

150KB
3.5K SLoC

asnfuzzgen - ASN.1 Structure-Aware Fuzzing Compiler

asnfuzzgen is an ASN.1 compiler capable of producing structure-aware fuzzing modules for arbitrary ASN.1 specifications. It currently supports Packed Encoding Rules (PER), and it generates a Rust module that can be exported into a linked C-ABI library for cross-compatibility with other languages.

This project is divided into three crates, described below.

  1. asnfuzzgen: This crate provides the actual ASN.1 Compiler. Typically a utility (asnfuzzgen) will generate Rust structures starting with ASN.1 Specifications. Basic working features required to work with the 3GPP specifications is provided by the compiler, this includes Parameterized Types, Information Object Classes and Type Constraints.

  2. asnfuzzgen-codecs: Support for different encodings supported by individual ASN.1 specifications is provided in this crate. As of the current release, APER/UPER Codecs are supported. Every Codec is supported as a trait implementing respective 'encode' and 'decode' functions. Support for different 'encoding rules' will be implemented in this crate and then the derive macros will utilize this code to actually generate the encoding support for Rust Structures generated by the compiler above.

  3. asnfuzzgen-codecs-derive: This crate provides the derive macros for the codecs in asn-codecs. The code generated using asnfuzzgen can be directed to derive appropriate codecs by passing the flags during compilation.

Acknowledgements

This project makes use of source code from the Hampi Rust ASN.1 Toolkit, which is likewise licensed under the MIT License. Special thanks goes to Abhijit Gadgil for authoring the Rust ASN.1 Toolkit that has contributed significantly to this project.

Supported Codecs

  • APER
  • UPER

Getting Started

build.rs Support

Typically the compiler can be invoked also using build.rs mechanism. An example build.rs is provided in the examples/ sub project. And the code generated through this build.rs can be integrated into your project. Examples of that is provided in examples/tests/ directory.

Using CLI tool

A tool asnfuzzgen can be installed using cargo install asnfuzzgen and then following the CLI usage.

cargo install asnfuzzgen
asnfuzzgen --help

Running Test Cases

  1. Test cases can be run through cargo test.

Generating ASN.1 spec files

Currently there are two ways of generating the 'ASN.1' spec files from the '.docx' specifications (This mainly applies to 3GPP specifications).

  1. Using the script inside examples/specs/parse_specs.py. This is recommended way. (note: this requires installation of docx or python-docx in the case of Python3).
  2. Using the rust binary extract-asn-spec. Note: this is not the recommended way and your mileage may vary. Eventual goal is to make this the default way - so as to also have a build.rs integration. But this is for now a work in progress. This is not available by default and is enabled only with a feature flag rs-specs-gen.

License & Attribution

The source code of this project is licensed under the MIT License.

Dependencies

~2.5MB
~62K SLoC