geändert: README.md

neue Datei:     client/client.py
	neue Datei:     client/sec/client.crt.pem
	neue Datei:     client/sec/client.csr.pem
	neue Datei:     client/sec/client.key.pem
	neue Datei:     container/Dockerfile
	neue Datei:     container/requirements.txt
	neue Datei:     lib/__pycache__/crypto_utils.cpython-313.pyc
	neue Datei:     lib/__pycache__/jebp_utils.cpython-313.pyc
	neue Datei:     lib/__pycache__/terminal_table.cpython-313.pyc
	neue Datei:     lib/crypto_utils.py
	neue Datei:     lib/jebp_utils.py
	neue Datei:     lib/terminal_table.py
	neue Datei:     server/clients_management/chclient.py
	neue Datei:     server/clients_management/lsclients.py
	neue Datei:     server/clients_management/mkclient.py
	neue Datei:     server/clients_management/rmclient.py
	neue Datei:     server/config/clients/fingerprints
	neue Datei:     server/main.py
	neue Datei:     server/sec/ca/certs/ca.cert.pem
	neue Datei:     server/sec/ca/private/ca.key.pem
	neue Datei:     server/sec/server.crt.pem
	neue Datei:     server/sec/server.csr.pem
	neue Datei:     server/sec/server.key.pem
	gelöscht:       main.py
	gelöscht:       sec/cert.pem
	gelöscht:       sec/key.pem
This commit is contained in:
2025-12-30 01:43:23 +01:00
parent f9e7d51015
commit 1ac4aefdc8
24 changed files with 676 additions and 1 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
+32
View File
@@ -0,0 +1,32 @@
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
def generate_keypair():
private_key = ec.generate_private_key(ec.SECP256R1())
return private_key, private_key.public_key()
def serialize_public_key(public_key: ec.EllipticCurvePublicKey) -> bytes:
return public_key.public_bytes(
encoding=serialization.Encoding.X962,
format=serialization.PublicFormat.UncompressedPoint,
)
def deserialize_public_key(data: bytes) -> ec.EllipticCurvePublicKey:
return ec.EllipticCurvePublicKey.from_encoded_point(
ec.SECP256R1(), data
)
def derive_aes_key(private_key, peer_public_key) -> bytes:
shared_secret = private_key.exchange(ec.ECDH(), peer_public_key)
return HKDF(
algorithm=hashes.SHA256(),
length=32,
salt=None,
info=b'handshake',
).derive(shared_secret)
+47
View File
@@ -0,0 +1,47 @@
import asyncio
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from cryptography import x509
from datetime import datetime, timezone
MSG_START_BYTE = b'\x01'
class MessageFormatError(Exception): ...
class InvalidCertificateError(Exception): ...
def int_to_bytes(n: int, signed = False):
n = int(n)
return n.to_bytes((n.bit_length() + 7) // 8, signed = signed)
async def sendmsg(m, writer: asyncio.StreamWriter, aesgcm: AESGCM = None, aesnonce = None, start_byte = MSG_START_BYTE):
if type(m) == str:
m = m.encode()
if aesgcm:
m = aesgcm.encrypt(aesnonce, m, None)
content_length = int_to_bytes(len(m))
writer.write(start_byte + bytes([len(content_length)]) + content_length + m)
await writer.drain()
async def readmsg(reader: asyncio.StreamReader, aesgcm: AESGCM = None, aesnonce = None, start_byte = MSG_START_BYTE):
if await reader.readexactly(1) != start_byte:
raise MessageFormatError('invalid message format')
content_length_length = await reader.readexactly(1)
content_length = await reader.readexactly(int.from_bytes(content_length_length))
m = await reader.readexactly(int.from_bytes(content_length))
if aesgcm:
return aesgcm.decrypt(aesnonce, m, None)
return m
def validate_cert(cert: x509.Certificate, common_name, issuer_common_name, now = datetime.now(timezone.utc)):
if not cert.not_valid_before_utc <= now <= cert.not_valid_after_utc:
return False
cn = [a.value for a in cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)]
if len(cn) < 1:
return False
if common_name not in cn:
return False
cn = [a.value for a in cert.issuer.get_attributes_for_oid(x509.NameOID.COMMON_NAME)]
if len(cn) < 1:
return False
if issuer_common_name not in cn:
return False
return True
+106
View File
@@ -0,0 +1,106 @@
#!/usr/bin/env python3
class TableBorderCharset:
def __init__(self,
corner_top_left, corner_top_right, corner_bottom_left, corner_bottom_right,
line_horizontal, line_vertical,
t_junction_horizontal_top, t_junction_horizontal_bottom, t_junction_vertical_left, t_junction_vertical_right,
intersection
):
self.corner_top_left = corner_top_left
self.corner_top_right = corner_top_right
self.corner_bottom_left = corner_bottom_left
self.corner_bottom_right = corner_bottom_right
self.line_horizontal = line_horizontal
self.line_vertical = line_vertical
self.t_junction_horizontal_top = t_junction_horizontal_top
self.t_junction_horizontal_bottom = t_junction_horizontal_bottom
self.t_junction_vertical_left = t_junction_vertical_left
self.t_junction_vertical_right = t_junction_vertical_right
self.intersection = intersection
BORDER_THIN = TableBorderCharset(
'', '', '', '',
'', '',
'', '', '', '',
''
)
BORDER_THICK = TableBorderCharset(
'', '', '', '',
'', '',
'', '', '', '',
''
)
BORDER_DOUBLE = TableBorderCharset(
'', '', '', '',
'', '',
'', '', '', '',
''
)
BORDER_ROUND = TableBorderCharset(
'', '', '', '',
'', '',
'', '', '', '',
''
)
def get_max_widths(data):
max_widths = {}
for row in data:
for col in row:
max_widths[col] = max(len(str(row[col])), max_widths.get(col, 0))
return max_widths
def ascii_table(data, *, borders = False, border_charset = BORDER_THIN, column_space = 1, uppercase_column_headers = True):
column_widths = get_max_widths(data)
columns = list(column_widths.keys())
table = f'''{(column_space * ' ').join([(c.upper() if uppercase_column_headers else c) + ' ' * (column_widths[c] - len(c)) for c in columns])}'''
table = ''
for col in columns:
column_widths[col] = max(column_widths[col], len(col))
for col in columns:
table += col.upper() if uppercase_column_headers else col
table += ' ' * (column_widths[col] - len(col))
table += ' ' * column_space
if borders:
table += border_charset.line_vertical + ' '
for row in data:
table += '\n'
for column in columns:
value = str(row.get(column, ''))
table += value
table += ' ' * (column_widths[column] - len(str(value)))
table += column_space * ' '
if borders:
table += border_charset.line_vertical + ' '
if borders:
table_without_borders = table
table_width = max([len(r) for r in table_without_borders.split('\n')])
table = border_charset.corner_top_left
for col in columns:
table += border_charset.line_horizontal * (column_widths[col] + 2)
table += border_charset.t_junction_horizontal_bottom
table = table[:-1] + border_charset.corner_top_right
table += '\n'
for row in table_without_borders.split('\n'):
table += border_charset.line_vertical + ' '
table += row
table += '\n'
table += border_charset.t_junction_vertical_right
for i in range(len(columns)):
table += border_charset.line_horizontal * (column_widths[columns[i]] + 2)
table += border_charset.intersection if i != (len(columns) - 1) else border_charset.t_junction_vertical_left
table += '\n'
table = '\n'.join(table.split('\n')[:-2]) + '\n'
table += border_charset.corner_bottom_left
for col in columns:
table += border_charset.line_horizontal * (column_widths[col] + 2)
table += border_charset.t_junction_horizontal_top
table = table[:-1] + border_charset.corner_bottom_right
return table