All Projects → abhishek-ram → pyas2-lib

abhishek-ram / pyas2-lib

Licence: GPL-3.0 license
AS2 Library for building and parsing Messages and MDNs

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pyas2-lib

qd-templates
基于开源新版签到框架站发布的公共har模板库,整理自用 qiandao 框架可用的各种网站和App的 Har 模板,仅供学习参考。
Stars: ✭ 77 (+133.33%)
Mutual labels:  sign
JNI RSA Sign
通过JNI实现验证App签名获取公钥
Stars: ✭ 86 (+160.61%)
Mutual labels:  sign
cassh
SSH CA administration via CLI and GUI
Stars: ✭ 66 (+100%)
Mutual labels:  sign
Timeline
AS2 & AS3 CPPS Emulator, written in Python. (Club Penguin Private Server Emulator)
Stars: ✭ 49 (+48.48%)
Mutual labels:  as2
ti.imagefactory
The ImageFactory Module for Appcelerator Titanium
Stars: ✭ 68 (+106.06%)
Mutual labels:  compress
pgspeck
Small block size Speck encryption in PostgreSQL
Stars: ✭ 16 (-51.52%)
Mutual labels:  encrypt
xcompress
XCompress is a free file archiver utility on Linux, providing multi-format archiving to and extracting from ZIP, Z, GZIP, BZIP2, LZ, XZ, LZMA, 7ZIP, TAR, RAR and ZSTD.
Stars: ✭ 65 (+96.97%)
Mutual labels:  compress
swarm-cli
Manage your Bee node and interact with the Swarm network via the CLI
Stars: ✭ 36 (+9.09%)
Mutual labels:  sign
VIDEOconvertor
A stable and Fast telegram video convertor bot which can encode into different libs and resolution, compress videos, convert video into audio and other video formats, rename with thumbnail support, generate screenshot and trim videos.
Stars: ✭ 180 (+445.45%)
Mutual labels:  compress
LaraOutPress
This is simply compress your final out of Larvel Application and serve to the browser.
Stars: ✭ 56 (+69.7%)
Mutual labels:  compress
chaoxing
Make Github to help u for signing on Superstar Xuexitong every 5 minutes, base on github actions.
Stars: ✭ 58 (+75.76%)
Mutual labels:  sign
Berserker
Obfuscate your Python scripts better, faster.
Stars: ✭ 81 (+145.45%)
Mutual labels:  encrypt
minifier
Middleware to minify Html, CSS and Javascript responses
Stars: ✭ 15 (-54.55%)
Mutual labels:  compress
pclzip-doc-zh-cn
PHP 库 PclZip 的简体中文翻译文档(zh-cn translation for PHP lib: PclZip)
Stars: ✭ 25 (-24.24%)
Mutual labels:  compress
react-native-compress-image
compress image with react native
Stars: ✭ 22 (-33.33%)
Mutual labels:  compress
django-mirage-field
Django model field encrypt/decrypt your data, keep secret in database.
Stars: ✭ 86 (+160.61%)
Mutual labels:  encrypt
wp-pgp-encrypted-emails
🔐 📧 Encrypts WordPress emails using OpenPGP or S/MIME with a familiar API.
Stars: ✭ 35 (+6.06%)
Mutual labels:  smime
dofedex
A Dofus Retro encyclopedia
Stars: ✭ 45 (+36.36%)
Mutual labels:  as2
vue-cryptojs
A small wrapper for integrating crypto-js into VueJS
Stars: ✭ 17 (-48.48%)
Mutual labels:  encrypt
QArchive
Async C++ Cross-Platform library that modernizes libarchive using Qt5 🚀. Simply extracts 7z 🍔, Tarballs 🎱 and other supported formats by libarchive. ❤️
Stars: ✭ 66 (+100%)
Mutual labels:  compress

pyas2-lib

pypi package Run Tests codecov

A pure python library for building and parsing message as part of the AS2 messaging protocol. The message definitions follow the AS2 version 1.2 as defined in the RFC 4130.The library is intended to decouple the message construction/deconstruction from the web server/client implementation. The following functionality is part of this library:

  • Compress, Sign and Encrypt the payload to be transmitted.
  • Building the MIME Message from the processed payload.
  • Building a signed MDN Messages for a received payload.
  • Parsing a received MIME data and identifying if it as a Message or MDN.
  • Decompress, Decrypt and Verify Signature of the received payload.
  • Verify Signature of the received MDN and extract original message status.

Basic Usage

Let us take a look at how we can use this library for building and parsing of AS2 Messages.

Setup

  • First we would need to setup an organization and a partner
from pyas2lib.as2 import Organization, Partner

my_org = Organization(
    as2_name='my_unique_id',  # Unique AS2 Id for this organization
    sign_key=b'signature_key_bytes',  # PEM/DER encoded private key for signature
    sign_key_pass='password',  # Password private key for signature
    decrypt_key=b'decrypt_key_bytes',  # PEM/DER encoded private key for decryption
    decrypt_key_pass='password'  # Password private key for decryption
)

a_partner = Partner(
    as2_name='partner_unique_id',  # Unique AS2 Id of your partner
    sign=True,  # Set to true for signing the message
    verify_cert=b'verify_cert_bytes',  # PEM/DER encoded certificate for verifying partner signatures
    encrypt=True,  # Set to true for encrypting the message
    encrypt_cert=b'encrypt_cert_bytes',  # PEM/DER encoded certificate for encrypting messages
    mdn_mode='SYNC',  # Expect to receive synchronous MDNs from this partner
    mdn_digest_alg='sha256'  # Expect signed MDNs to be returned by this partner
)

Sending a message to your partner

  • The partner is now setup we can build and AS2 message
from pyas2lib.as2 import Message

msg = Message(sender=my_org, receiver=a_partner)
msg.build(b'data_to_transmit')
  • The message is built and now msg.content holds the message body and message.header dictionary holds the message headers. These need to be passed to any http library for HTTP POSTing to the partner.
  • We expect synchronous MDNs so we need to process the response to our HTTP POST
from pyas2lib.as2 import Mdn

msg_mdn = Mdn()  # Initialize an Mdn object

# Call the parse method with the HTTP response headers + content and a function that returns the related `pyas2lib.as2.Messsage` object.
status, detailed_status = msg_mdn.parse(b'response_data_with_headers', find_message_func)
  • We parse the response mdn to get the status and detailed status of the message that was transmitted.

Receiving a message from your partner

  • We need to setup and HTTP server with an endpoint for receiving POST requests fro your partner.
  • When a requests is received we need to first check if this is an Async MDN
from pyas2lib.as2 import Mdn

msg_mdn = Mdn()  # Initialize an Mdn object
# Call the parse method with the HTTP request headers + content and a function the returns the related `pyas2lib.as2.Messsage` object.
status, detailed_status = msg_mdn.parse(request_body, find_message_fumc)
  • If this is an Async MDN it will return the status of the original message.
  • In case the request is not an MDN then pyas2lib.exceptions.MDNNotFound is raised, which needs to be catched and parse the request as a message.
from pyas2lib.as2 import Message

msg = Message()
# Call the parse method with the HTTP request headers + content, a function to return the the related `pyas2lib.as2.Organization` object, a function to return the `pyas2lib.as2.Partner` object and a function to check for duplicates.
status, exception, mdn = msg.parse(
    request_body, find_organization, find_partner, check_duplicate_msg)
  • The parse function returns a 3 element tuple; the status of parsing, exception if any raised during parsing and an pyas2lib.as2.Mdn object for the message.
  • If the mdn.mdn_mode is SYNC then the mdn.content and mdn.header must be returned in the response.
  • If the mdn.mdn_mode is ASYNC then the mdn must be saved for later processing.

Contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
  3. Create your feature branch: git checkout -b my-new-feature
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to AUTHORS.
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].