Code Monkey home page Code Monkey logo

recordflux-specifications's Introduction

RecordFlux Specifications

This repository contains specifications of real-world binary formats using RecordFlux.

Development

For developing new specifications a recent version of RecordFlux and some testing tools need to be installed. The use of a virtual environment is recommended. Apart from GNAT, the installation of all Python dependencies can be done in three simple steps:

$ virtualenv -p python3 venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt

The tests can be executed using make test. New specifications in the top-level directory are automatically detected. Each message specification is validated by valid and invalid binary samples, which are expected in tests/data/<package_name>/<message_name>/valid and tests/data/<package_name>/<message_name>/invalid, respectively.

recordflux-specifications's People

Contributors

jklmnn avatar rssen avatar treiher avatar urbasus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

urbasus

recordflux-specifications's Issues

Enable additional mypy checks

I reviewed the optional checks which are enabled by mypy --strict. The following checks seem to be useful:

warn_unused_configs = True
disallow_any_generics = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_incomplete_defs = True
check_untyped_defs = True

The following options seem not that useful to me at the moment:

disallow_untyped_decorators = True
no_implicit_optional = True
warn_return_any = True
no_implicit_reexport = True

Validation tool for message specifications

Correctly verified message specifications are not sufficient, as such specification can still turn out to be invalid in practice (e.g., by misinterpreted descriptions in English prose). A test tool should be created which validates that specified messages are correctly parsed (and serialized). The tool should take a specification and a set of known valid and invalid messages as input and should check, if all messages are correctly classified as valid or invalid. The basis for the tool should be PyRFLX. There is already a very small number of test files available for Ethernet and IPv4 in tests.data.captured which could be used for the beginning. For a larger test HTTP/2 should be used (#3).

Tasks

  • Create validation tool tools/validate_spec.py
    • Input: specification file, message identifier, directory for valid messages (optional), directory for invalid messages (optional))
    • Output: return value, list of failed validations (message identifier, test file, error message) on stdout, detailed output in JSON file (optional)
  • Add existing test data from RecordFlux to test/data
  • Extend test in tests/test_spec.py by call of validation tool (in a generic way, i.e. it should not be necessary to add invocations for new specifications or test data of the validation tool manually)

Parsing failure for tls_record.rflx

I tried parsing the tls_record.rflx example and get this result:

$ rflx generate ../tls_record.rflx
Parsing ../tls_record.rflx
../tls_record.rflx:13:21: parser: error: Expected {{"First" - "=>" - MathematicalExpression} | {"Length" - "=>" - MathematicalExpression}}

Using rflx v0.4.1, Python 3.7.3.

Add README

  • Dependency RecordFlux develop/0.5
  • Python dependencies?

Tool for generating specification from IANA document

IANA provides XML documents listing assigned numbers. Currently, we have a tool which generates a specification from the IANA Assigned Internet Protocol Numbers document. The tool could be made more generic and also used for other documents, e.g., TLS Parameters.

Naming of specification files

<registry xmlns="http://www.iana.org/assignments" id="bootp-dhcp-parameters"> -> Bootp_Dhcp_Parameters.rflx

Test coverage of Python code

The test coverage of all Python code should be checked. Full test coverage should be enforced as in RecordFlux.

Support checksums in validation tool

Specifications which have a checksum attached, currently raise an exception (even on correct input data):

$ ./tools/validate_spec.py -s igmp.rflx -m IGMP::Message -v tests/data/igmp/valid/
Traceback (most recent call last):
  File "./tools/validate_spec.py", line 334, in <module>
    sys.exit(cli(sys.argv))
  File "./tools/validate_spec.py", line 82, in cli
    validation_main(args)
  File "./tools/validate_spec.py", line 135, in validation_main
    validation_result = validator.validate_message(msg)
  File "./tools/validate_spec.py", line 206, in validate_message
    parsed_message.bytestring == original_message.bytes
  File "/home/senier/.local/lib/python3.7/site-packages/rflx/pyrflx/typevalue.py", line 1046, in bytestring
    if not self._skip_verification and not self.valid_message:
  File "/home/senier/.local/lib/python3.7/site-packages/rflx/pyrflx/typevalue.py", line 1103, in valid_message
    for checksum in self._checksums.values()
  File "/home/senier/.local/lib/python3.7/site-packages/rflx/pyrflx/typevalue.py", line 1103, in <genexpr>
    for checksum in self._checksums.values()
  File "/home/senier/.local/lib/python3.7/site-packages/rflx/pyrflx/typevalue.py", line 981, in _calculate_checksum
    f"cannot calculate checksum for {checksum.field_name}: "
rflx.pyrflx.error.PyRFLXError: pyrflx: error: cannot calculate checksum for Checksum: no callable checksum function provided

We currently have no way to provide a checksum function to the validation tool.

The following needs to be done additionally as part of this ticket:

  • Fix checksum in TCP specification (cf. #63).

TLS Server Hello: Extensions_Length constraint failure

When parsing a Server Hello message, the following error occurs:

E       AssertionError: unresolved field conditions in Server_Hello.Extensions_Length: Random /= [16#CF#, 16#21#, 16#AD#, 16#74#, 16#E5#, 16#9A#, 16#61#, 16#11#, 16#BE#, 16#1D#, 16#8C#, 16#2#, 16#1E#, 16#65#, 16#B8#, 16#91#, 16#C2#, 16#A2#, 16#11#, 16#16#, 16#7A#, 16#BB#, 16#8C#, 16#5E#, 16#7#, 16#9E#, 16#9#, 16#E2#, 16#C8#, 16#A8#, 16#33#, 16#9C#], Random = [16#CF#, 16#21#, 16#AD#, 16#74#, 16#E5#, 16#9A#, 16#61#, 16#11#, 16#BE#, 16#1D#, 16#8C#, 16#2#, 16#1E#, 16#65#, 16#B8#, 16#91#, 16#C2#, 16#A2#, 16#11#, 16#16#, 16#7A#, 16#BB#, 16#8C#, 16#5E#, 16#7#, 16#9E#, 16#9#, 16#E2#, 16#C8#, 16#A8#, 16#33#, 16#9C#]

VLAN tags in Ethernet frames

#18 seems to have introduced an error into the Ethernet frame specification. Since this change only Ethernet II frames can have VLAN tags, but not IEEE 802.3 frames (i.e. the current specification only allows a EtherType field after a VLAN tag, but not a Length field). I'm not aware that IEEE 802.1Q is restricted to Ethernet II.

type Frame is
message
Destination : Address;
Source : Address;
Type_Length_TPID : Type_Length
then TPID
with First => Type_Length_TPID'First
if Type_Length_TPID = 16#8100#
then Payload
with Size => Type_Length_TPID * 8
if Type_Length_TPID <= 1500
then Ether_Type
with First => Type_Length_TPID'First
if Type_Length_TPID >= 1536 and Type_Length_TPID /= 16#8100#;
TPID : TPID;
TCI : TCI;
Ether_Type : Ether_Type
then Payload
with Size => Message'Last - Ether_Type'Last;
Payload : Opaque
then null
if Payload'Size / 8 >= 46 and Payload'Size / 8 <= 1500;
end message;

TLS Server Hello: Legacy_Compression_Method wrong value constraint

This field should allow other values than 0 .. 0. The server selects a method from the suggestions the client sent in Client Hello, so I would assume it should allow values 0 .. 2 ** 8 - 1. This is not explicitly stated in the RFC.

pyrflx: error: Error while parsing nested message TLS_Handshake::Server_Hello
pyrflx: error: cannot set value for field Legacy_Compression_Method
pyrflx: error: value 1 not in type range 0 .. 0

Checking of Python code

All Python code in this repository should be checked by the same tools/linters as in our other repositories. The necessary configs and CI jobs should be added.

Test coverage of message specifications

It would be helpful to determine the test coverage of the message specifications. The validation tool (#7) would need to analyze how many paths of the message graph are covered by the existing test data.


Implementation Plan

MessageValue

  • Add attribute (property) covered_links: List[Link]
  • Add _next_link(field_name) -> Link method which returns the next valid link
  • Call next_link inside next_field and store the last returned link in covered_links
  • Add get_sdu_messages -> List[MessageValue] which returns the list of all messages contained in all fields of type OpaqueValue and ArrayValue
  • Add tests

Validation Tool

  • create dict to store the coverage of all involved messages (models) - total coverage
  • method to update the total coverage on every iteration
  • generate output
  • tests

Output

Short Output:

------------------------------------------------------------------------------
                     RecordFlux Validation Coverage Report
Directory: .
------------------------------------------------------------------------------
File                                       Links    Used   Coverage  
------------------------------------------------------------------------------
ethernet.rflx                                100     100   100%
in_ethernet.rflx                              34      34   100%
ipv4.rflx                                    206      97    47%   
------------------------------------------------------------------------------
TOTAL                                        340     231    68%
------------------------------------------------------------------------------

Full Output:
<file_name>:<line>:<col>: error: missing link <link_source_field> -> <link_target_field>: <link_condition>

TLS Client Hello: Legacy_Compression_Methods_Length wrong value constraint

The field value of TLS Client Hello: Legacy_Compression_Methods_Length is contraint to 1..1 but should allow values 1..2^8-1 (see RFC 5246).

This occured while parsing the sample tests/data/tls_handshake/handshake/valid/client_hello_0_header_removed.raw which is currently on the issue_10 branch.

pyrflx: error: Error while parsing nested message TLS_Handshake::Client_Hello
pyrflx: error: cannot set value for field Legacy_Compression_Methods_Length
pyrflx: error: value 2 not in type range 1 .. 1

When changing this in the specification and repeating the parsing test (with compression length = 2), the outgoing conditions of Legacy_Compression_Methods fail.

AssertionError: unresolved field conditions in Client_Hello.Legacy_Compression_Methods: 1255 / 8 /= 351 / 8, 1255 / 8 = 351 / 8`

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.