fxamacker / senml

Disco SenML - Debloated cisco/senml that passes tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disco SenML - Debloated cisco/senml that passes tests

SenML

RFC 8428 Sensor Measurement Lists (SenML) defines a format for representing simple sensor measurements and device parameters in Sensor Measurement Lists.

Disco SenML

Disco SenML is a debloated fork of cisco/senml that produces programs 4 MB smaller. Also, CBOR representation no longer violates RFC 8428. Other benefits include having all unit tests pass, resolving some open issues, and having a smaller attack surface.

Disco SenML was created on Nov 23, 2019 using cisco/senml (4d43ea8) dated Oct 10, 2019.

Special thanks to Cullen Jennings at Cisco Systems for his work on RFC 8428 and creating cisco/senml. He did the heavy lifting and changes to his project were trivial by comparison. And also to Faye Amacker for adding requested features to her CBOR library that made the changes easy.

Improvements to cisco/senml

Primary improvements:

  • Reduce bloat: compiled programs are 4 MB smaller (senmlCat and senmlServer).
  • Pass tests: cisco/senml wasn't passing unit tests before any changes were made. Broken tests were fixed and a new test was added using the CBOR example from RFC 8428.
  • Improve safety: replaced a multi-codec library with a CBOR library (fxamacker/cbor) which properly handles tiny malicious CBOR messages. Attack surface was also reduced by removing MessagePack for reasons stated below.
  • Close issues: several important open issues at cisco/senml were resolved in this project.

Some resolved issues include:

  • CBOR does not encode or decode numeric field names cisco/senml #2 (2016). RFC 8428 requires this.
  • Base Value and Base Sum missing from the model cisco/senml #18 (2017).
  • CBOR support uses go-codec which adds bloat to the binary cisco/senml #22 (2019).

Other improvements:

  • Versioned: release versions to make using this library simpler for Go projects.
  • Go modules: use Go modules. See Using Go Modules at blog.golang.org for more info.

WARNING: ONLY MINIMAL CHANGES WERE MADE

  • Tests and Code Coverage: there's a lot of room for improvement here.
  • senmlCat and senmlServer: these programs were only modified to remove MessagePack representation. They probably need other improvements I don't have time to make.

MessagePack was removed because it:

  • increased bloat and attack surface.
  • isn't mentioned in SenML RFC 8428.
  • prevented having a CBOR library (fxamacker/cbor) as the only external dependency.

Limitations and Requirements

Known limitations:

  • Go 1.12: Go 1.12 or newer is required.
  • Security Audit: I didn't conduct a security audit of cisco/senml or this project. I just tackled the most obvious low-hanging fruit while helping fxamacker/cbor find a non-hobby project to use for a program size comparison.

Possible limitation (not sure if it matters yet):

  • CBOR Tags (major type 6): this might be a non-issue because I didn't see any used in cisco/senml. If CBOR tags are present in SenML, they'll be ignored until this project upgrades fxamacker/cbor v1.3.1 to v1.4 (when released).

senmlCat

Tool to convert SenML between formats and act as gateway server to other services

usage

convert JSON SenML to XML

senmlCat -json -i data.json > data.xml

convert JSON SenML to CBOR

senmlCat.go -ijson -cbor data.json > data.cbor

convert to Excel spreadsheet CSV file

senmlCat -expand -ijsons -csv -print data.json > foo.csv

Note that this moves times to excel times that are days since 1900

listen for posts of SenML in JSON and send to influxdb

This listens on port 880 then writes to an influx instance at localhost where to the database called "junk"

The -expand is needed to expand base values into each line of the Line Protocol

senmlCat -ijsons -http 8880 -expand -linp -print -post http://localhost:8086/write?db=junk

About

Disco SenML - Debloated cisco/senml that passes tests

License:BSD 2-Clause "Simplified" License


Languages

Language:Go 100.0%