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.
- You can add a password/key to the server the client requires to get authorized.
NOTE: If the server has encryption enabled, it will only do key exchange after encryption has been established
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cvg_core-0.1.2.tar.gz.
File metadata
- Download URL: cvg_core-0.1.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
433804832a57dae4a6801636daa711147c486e2123e05494093eafeff2d00c45
|
|
| MD5 |
60f193c7b084574881293078b48a7fc0
|
|
| BLAKE2b-256 |
2cc8b33946f649d3539fe009f1e6df9e62c802036283f1460c83da6f0437dac2
|
File details
Details for the file cvg_core-0.1.2-py3-none-any.whl.
File metadata
- Download URL: cvg_core-0.1.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98b58bde809a6a81f4fb62f3e50b6a3fe0c8a5bdd07800450fa7d61588239a5d
|
|
| MD5 |
7d15cf2735367174c7f98e4746dd3270
|
|
| BLAKE2b-256 |
b437ec2f3384d4156abbd3aeae3a778a151fafce5c0dbfc97df1c35607f96166
|