Skip to main content

Transport secure layer version 294

Project description

Based on DCN

Setup guide

Using PyPi

Linux and MacOS

pip3 install tsl294

Windows

pip install tsl294

Using github

Linux and MacOS

git clone https://github.com/draklowell/TSL294 && cd TSL294 && python3 setup.py install

Windows

Download client and in downloaded folder run

python setup.py install

Dependencies

  1. dcn ( 2.0.0.4.1.2 )
  2. func-timeout ( 4.3.5 )

Info

Privacy

Connection between two nodes is wrapped by TLSv1.2 ( without certificate verification ), also packets are encrypted with RSA.

High-level protocols conflict

To avoid protocol conflicts, we recommend to use protocol sign, it is some bytes in begin of packet, that indicate what protocol is using

License

Apache License 2.0

Using guide

Packet format

18 BYTES - DCN Header
844 BYTES - TSL294 Header:
    294 BYTES - Source key ( Can be only RSA key )
    294 BYTES - Destination key ( Can be RSA key or zero bytes - broadcast to all clients)
    256 BYTES - Signature of encrypted content 
64676 BYTES - Encrypted ( if destination is RSA key ) content

Max size of content in packet - 64676 ( pow(2, 16) - 16 - 844 ).

Create client

There are three arguments - key, friendly_hosts and limit_queue

key - client RSA key ( only 2048 bits size )

friendly_hosts - known nodes in format ( example: ("1.2.3.4", 300) ), also it request official nodes, from official tracker

limit_queue - max size of queue ( -1 - unlimited ), recommended 65536

import tsl294
client = tsl294.client.Client(key = tsl294.crypto.key.Key.random(2048), friendly_hosts = [], limit_queue = -1)

Send packet

After generating packet, client sends it to user with known key. After that, it returns the count of successfully sent copies of the packet and packet hash ( as bytes )

import base64

# Load key from file
with open("target.pem", "rb") as file:
    key = tsl294.crypto.key.Key.importKey(file.read())

# Send packet
count, hash = client.send(b"Hello, world!", key)
print(f"Sended copies of packet: {count}")
print(f"Packet hash ( base64 encoded ): {base64.b64encode(hash).decode()}")

Output:

Sended copies of packet: 1
Packet hash ( base64 encoded ): L/78pQALheezMsoc9BTxfheAcNIw7fPQtYHsDBjwDSU=

Receive next packet

When the client gets the new massage from the server, client adds the packet to the queue. When we call client.accept(), we get the first element of the queue, and then remove it ( we can limit the queue, while initializing client )

import base64

content, key, hash = client.accept() # or client.next() or next(client)
print(f"Content of packet: {content.decode()}")
print(f"Source of packet: {base64.b64encode(key.getHash()).decode()}")
print(f"Packet hash ( base64 encoded ): {base64.b64encode(hash).decode()}")

Output:

Content of packet: Hello, world!
Source of packet: MEtdj9sSPdM0g00Hk6q1Jjvx72f53Gd4uIkMYWN4Khk=
Packet hash ( base64 encoded ): L/78pQALheezMsoc9BTxfheAcNIw7fPQtYHsDBjwDSU=

Close client

You need close client in end of work

client.close()

Simple app

Now, we can create a simple app using DCN-TSLv294, which allows to convert user's message to uppercase. When server gets new packet from the user, it converts packet content to uppercase and sends it back to the client. Example: User sends Hello, world! Server returns HELLO, WORLD!

Server side

from tsl294.client import Client
from tsl294 import Key

with open("private.pem", "rb") as file:
    key = Key.importKey(file.read())

client = Client(key)

try:
    while True:
        data, key, hash = client.accept()
        client.send(data.upper(), key)
except KeyboardInterrupt:
    pass
client.close()

To close server, just press Ctrl + C

Client side

from tsl294.client import Client
from tsl294 import Key

with open("public.pem", "rb") as file:
    server_key = Key.importKey(file.read())

message = input().encode("utf-8")

client = Client()
try:
    client.send(message, server_key)
    data, key, hash = client.accept()
    while key != server_key.getPublic():
        data, key, hash = client.accept()
    
    print(data.decode("utf-8"))
except KeyboardInterrupt:
    pass
client.close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tsl294-0.9.1.tar.gz (7.5 kB view details)

Uploaded Source

File details

Details for the file tsl294-0.9.1.tar.gz.

File metadata

  • Download URL: tsl294-0.9.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for tsl294-0.9.1.tar.gz
Algorithm Hash digest
SHA256 34fdd24d12cba054f1a094f7124d7596ac6507adb43544a4a820934d7edb5422
MD5 c90bbf6223963a538d882feba7a15d7d
BLAKE2b-256 326f6b70346e629375ae3cd3fe386cb8ea14a17ae69b34be6498ec1b29306522

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page