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.1.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.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cvg_core-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 83f9a9ae371a2684a1a42dcdfe7042a3c9c41301860888e97b2b226859c427ea
MD5 b6bf33c4f03951feb9cec4bf5729dc9c
BLAKE2b-256 5ca61f2f7d2547f5deab565da5324f9ff26bd224a9b778caae8139e7ee3a391a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cvg_core-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d625d782553789bbe9e589b9fbde95ac88bb4299ca2ca3a7d62d7b053afd0bf
MD5 7fb4fe997fed02a94dfab350d623c084
BLAKE2b-256 ea60c138684e474065a7f5f96d18e77a4c2e9356276e7ba0b1992d3a4c7d8cda

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