Skip to main content

A network protocol dependancy. Objects & Procedures.

Project description

Client - Vault - Guard: Core

This is the core tooling for a network/data sharing protocol.
Main functionality is for wrapping a socket.


  • It can encrypt a socket connection with ECDH-SECP521R1 -> AES256.

    • If the server has encryption enabled but the client doesn't it will-
      Force the client to enable encryption before continuing the connection.

    • If the server has encryption disabled and the client does it will-
      Force the client to disable encryption before continuing the connection
      I'm probably not going to leave this as a 'feature' for obvious reasons

  • Automatically streams the data via chunks when packet size exceeds 4096 bytes.


How do you use it?

Here are some brief examples on establishing a connection using cvg-core.

from time import sleep
from threading import Thread

from socket import socket, AF_INET, SOCK_STREAM

from cvg_core.proper_procedures import SendReceiveProcedures
from cvg_core.procedures.establish_connection import establish_connection

from cvg_core.objects.network_object.packet_object import PacketType, PacketObject
from cvg_core.objects.network_object.connection_object import ConnectionType, ConnectionObject

# [Shared]
password = None # or b"bytes"

# [Client Implementation]
def client_example():
    client_connection = ConnectionObject(
        address=("127.0.0.1", 5000),
        socket=socket(AF_INET, SOCK_STREAM),
        type=ConnectionType.CLIENT_TO_SERVER,
        encryption_enabled=True
    )

    client_connection.socket.connect(
        client_connection.address
    )

    establish_connection(client_connection, password)

    client_procedures = SendReceiveProcedures(client_connection)

    # At this point it's up to on what you want to do.
    command_result_a = client_procedures.send_and_receive(
        PacketObject(b"hello", PacketType.COMMAND, id=b"\x03"),
        PacketType.RESPONSE
    )

    command_result_b = client_procedures.send_and_receive(
        PacketObject(b"hello", PacketType.COMMAND, id=b"\x03"),
        PacketType.RESPONSE
    )

    sleep(0.1) # sometimes the prints stack on each other.

    print("[client] command result a:", command_result_a)
    print("[client] command result b:", command_result_b)


# [Server Implementation]
def server_example():
    server_socket = socket(AF_INET, SOCK_STREAM)
    server_socket.bind(("127.0.0.1", 5000))
    server_socket.listen(1)

    client_connection = ConnectionObject(
        *server_socket.accept(), 
        type=ConnectionType.SERVER_TO_CLIENT,
        encryption_enabled=True
    ) 
        
    establish_connection(client_connection, password)

    client_procedures = SendReceiveProcedures(client_connection)

    # At this point it's up to on what you want to do.

    # Function wrapping on receive.
    @client_procedures.receive_into_and_send(PacketType.COMMAND)
    def command(packet: PacketObject):
        print("[server] client command received", packet)
        
        if packet.payload.startswith(b"hello"):
            return PacketObject(b"world_a", PacketType.RESPONSE, packet.id)

    # Or send a premade packet upon receive.
    command_packet = client_procedures.receive_and_send(
        PacketObject(b"world_b", PacketType.RESPONSE),
        PacketType.COMMAND
    )
    
    print("[server] client command received", command_packet)


Thread(target=server_example).start()
sleep(1)
client_example()

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

cvg_core-0.1.3.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cvg_core-0.1.3-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file cvg_core-0.1.3.tar.gz.

File metadata

  • Download URL: cvg_core-0.1.3.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for cvg_core-0.1.3.tar.gz
Algorithm Hash digest
SHA256 eeef235bdf041b7fe87db303f1b413dc6d83f975a4cc6afed9a7afb91d10a2f2
MD5 279f6b9912bee2d4f38810a7dabff03c
BLAKE2b-256 8ea7ea14f2ab6fa5cf9744648d615e6e1ee92babb7557da46721471e62a4bd58

See more details on using hashes here.

File details

Details for the file cvg_core-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: cvg_core-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for cvg_core-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dd4aa4fea41009d05d8accfbe85af3ea4621daca9d2f8c856428885b3d33fe9d
MD5 2434a71d3696c61879980f1e32f3fbe8
BLAKE2b-256 7fcab52d586a961b46a73d872b00775b360a8268de3fde0a11755f242ce14d0d

See more details on using hashes here.

Supported by

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