All Projects → etingof → Pyasn1

etingof / Pyasn1

Licence: bsd-2-clause
Generic ASN.1 library for Python

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Pyasn1

aquarium
The Aquarium Lab Operating System
Stars: ✭ 44 (-74.71%)
Mutual labels:  protocols
Kalm
Moved to https://github.com/kalm/kalm.js
Stars: ✭ 449 (+158.05%)
Mutual labels:  protocols
Backfuzz
protocol fuzzing toolkit
Stars: ✭ 106 (-39.08%)
Mutual labels:  protocols
PRE-list
List of (automatic) protocol reverse engineering tools for network protocols
Stars: ✭ 52 (-70.11%)
Mutual labels:  protocols
Mockolo
Efficient Mock Generator for Swift
Stars: ✭ 327 (+87.93%)
Mutual labels:  protocols
Netzob
Netzob: Protocol Reverse Engineering, Modeling and Fuzzing
Stars: ✭ 584 (+235.63%)
Mutual labels:  protocols
ma-core-public
Mango Automation Core public code
Stars: ✭ 66 (-62.07%)
Mutual labels:  protocols
Irremoteesp8266
Infrared remote library for ESP8266/ESP32: send and receive infrared signals with multiple protocols. Based on: https://github.com/shirriff/Arduino-IRremote/
Stars: ✭ 1,964 (+1028.74%)
Mutual labels:  protocols
Decentralized Internet
A SDK/library for decentralized web and distributing computing projects
Stars: ✭ 406 (+133.33%)
Mutual labels:  protocols
Ics Security Tools
Tools, tips, tricks, and more for exploring ICS Security.
Stars: ✭ 749 (+330.46%)
Mutual labels:  protocols
Omnetpp
OMNeT++ Discrete Event Simulator
Stars: ✭ 259 (+48.85%)
Mutual labels:  protocols
Bo
The Swiss army knife of data examination and manipulation
Stars: ✭ 327 (+87.93%)
Mutual labels:  protocols
Applicationcoordinator
Coordinators Essential tutorial
Stars: ✭ 694 (+298.85%)
Mutual labels:  protocols
UcsFiscalPrinters
Unicontsoft Fiscal Printers Component 2.0
Stars: ✭ 16 (-90.8%)
Mutual labels:  protocols
Dubbo Go Pixiu
Based on the proxy gateway service of dubbo-go, it solves the problem that the external protocol calls the internal Dubbo cluster. At present, it supports HTTP and gRPC[developing].
Stars: ✭ 124 (-28.74%)
Mutual labels:  protocols
tsharkVM
tshark + ELK analytics virtual machine
Stars: ✭ 51 (-70.69%)
Mutual labels:  protocols
Nsmartproxy
NSmartProxy是一款开源免费的内网穿透工具。采用.NET CORE的全异步模式打造。(NSmartProxy is an open source reverse proxy tool that creates a secure tunnel from a public endpoint to a locally service.)
Stars: ✭ 547 (+214.37%)
Mutual labels:  protocols
Mpyc
MPyC for Secure Multiparty Computation in Python
Stars: ✭ 142 (-18.39%)
Mutual labels:  protocols
4minitz
4Minitz - Simply a decent free webapp for taking collaborative meeting minutes. (Keywords: Meeting Protocols, Action Items, Open Source). Check it out on our demo server:
Stars: ✭ 125 (-28.16%)
Mutual labels:  protocols
Bedrockframework
High performance, low level networking APIs for building custom servers and clients.
Stars: ✭ 697 (+300.57%)
Mutual labels:  protocols

ASN.1 library for Python

PyPI Python Versions Build status Coverage Status GitHub license

This is a free and open source implementation of ASN.1 types and codecs as a Python package. It has been first written to support particular protocol (SNMP) but then generalized to be suitable for a wide range of protocols based on ASN.1 specification.

Features

  • Generic implementation of ASN.1 types (X.208)
  • Standards compliant BER/CER/DER codecs
  • Can operate on streams of serialized data
  • Dumps/loads ASN.1 structures from Python types
  • 100% Python, works with Python 2.7 and 3.5+
  • MT-safe
  • Contributed ASN.1 compiler Asn1ate

Why using pyasn1

ASN.1 solves the data serialisation problem. This solution was designed long ago by the wise Ancients. Back then, they did not have the luxury of wasting bits. That is why ASN.1 is designed to serialise data structures of unbounded complexity into something compact and efficient when it comes to processing the data.

That probably explains why many network protocols and file formats still rely on the 30+ years old technology. Including a number of high-profile Internet protocols and file formats.

Quite a number of books cover the topic of ASN.1. Communication between heterogeneous systems by Olivier Dubuisson is one of those high quality books freely available on the Internet.

The pyasn1 package is designed to help Python programmers tackling network protocols and file formats at the comfort of their Python prompt. The tool struggles to capture all aspects of a rather complicated ASN.1 system and to represent it on the Python terms.

How to use pyasn1

With pyasn1 you can build Python objects from ASN.1 data structures. For example, the following ASN.1 data structure:

Record ::= SEQUENCE {
  id        INTEGER,
  room  [0] INTEGER OPTIONAL,
  house [1] INTEGER DEFAULT 0
}

Could be expressed in pyasn1 like this:

class Record(Sequence):
    componentType = NamedTypes(
        NamedType('id', Integer()),
        OptionalNamedType(
            'room', Integer().subtype(
                implicitTag=Tag(tagClassContext, tagFormatSimple, 0)
            )
        ),
        DefaultedNamedType(
            'house', Integer(0).subtype(
                implicitTag=Tag(tagClassContext, tagFormatSimple, 1)
            )
        )
    )

It is in the spirit of ASN.1 to take abstract data description and turn it into a programming language specific form. Once you have your ASN.1 data structure expressed in Python, you can use it along the lines of similar Python type (e.g. ASN.1 SET is similar to Python dict, SET OF to list):

>>> record = Record()
>>> record['id'] = 123
>>> record['room'] = 321
>>> str(record)
Record:
 id=123
 room=321
>>>

Part of the power of ASN.1 comes from its serialisation features. You can serialise your data structure and send it over the network.

>>> from pyasn1.codec.der.encoder import encode
>>> substrate = encode(record)
>>> hexdump(substrate)
00000: 30 07 02 01 7B 80 02 01 41

Conversely, you can turn serialised ASN.1 content, as received from network or read from a file, into a Python object which you can introspect, modify, encode and send back.

>>> from pyasn1.codec.der.decoder import decode
>>> received_record, rest_of_substrate = decode(substrate, asn1Spec=Record())
>>>
>>> for field in received_record:
>>>    print('{} is {}'.format(field, received_record[field]))
id is 123
room is 321
house is 0
>>>
>>> record == received_record
True
>>> received_record.update(room=123)
>>> substrate = encode(received_record)
>>> hexdump(substrate)
00000: 30 06 02 01 7B 80 01 7B

The pyasn1 classes struggle to emulate their Python prototypes (e.g. int, list, dict etc.). But ASN.1 types exhibit more complicated behaviour. To make life easier for a Pythonista, they can turn their pyasn1 classes into Python built-ins:

>>> from pyasn1.codec.native.encoder import encode
>>> encode(record)
{'id': 123, 'room': 321, 'house': 0}

Or vice-versa -- you can initialize an ASN.1 structure from a tree of Python objects:

>>> from pyasn1.codec.native.decoder import decode
>>> record = decode({'id': 123, 'room': 321, 'house': 0}, asn1Spec=Record())
>>> str(record)
Record:
 id=123
 room=321
>>>

With ASN.1 design, serialisation codecs are decoupled from data objects, so you could turn every single ASN.1 object into many different serialised forms. As of this moment, pyasn1 supports BER, DER, CER and Python built-ins codecs. The extremely compact PER encoding is expected to be introduced in the upcoming pyasn1 release.

More information on pyasn1 APIs can be found in the documentation, compiled ASN.1 modules for different protocols and file formats could be found in the pyasn1-modules repo.

How to get pyasn1

The pyasn1 package is distributed under terms and conditions of 2-clause BSD license. Source code is freely available as a GitHub repo.

You could pip install pyasn1 or download it from PyPI.

If something does not work as expected, open an issue at GitHub or post your question on Stack Overflow or try browsing pyasn1 mailing list archives.

Copyright (c) 2005-2020, Ilya Etingof. All rights reserved.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].