This commit is contained in:
parent
eca394e7b7
commit
31dee1b7d5
@ -1,10 +1,11 @@
|
||||
import os, sys, getopt, json
|
||||
import getopt
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
from Crypto.PublicKey import RSA
|
||||
from Crypto.PublicKey.RSA import RsaKey
|
||||
|
||||
import ftplib
|
||||
|
||||
ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||
DOWNLOAD_LOCATION = ABSOLUTE_PATH + os.path.sep + 'download' + os.path.sep
|
||||
CONFIG_LOCATION = ABSOLUTE_PATH + os.path.sep + 'config' + os.path.sep + 'config.txt'
|
||||
|
@ -5,57 +5,91 @@ from netsim import network_interface
|
||||
class NetWrapper:
|
||||
SERVER_ADDRESS = 'A'
|
||||
|
||||
|
||||
|
||||
def __init__(self, publicKey: str, privateKey: str, clientAddress: str, cipherKey: str = ""):
|
||||
def __init__(self, publicKey: str, privateKey: str, clientAddress: str, username: str, cipherKey: str = ""):
|
||||
# Create network_interface: network_interface(path, addr) path root is shared with network / addr is own address
|
||||
self.network = network_interface('./network/',clientAddress)
|
||||
|
||||
self.network = network_interface('./network/', clientAddress)
|
||||
self.username = username
|
||||
self.publicKey = publicKey
|
||||
self.privateKey = privateKey
|
||||
self.cipherKey = cipherKey
|
||||
|
||||
def identifyServer(self,message: bytes) -> bytes:
|
||||
#Message is coded with Server RSA public key in string byte format
|
||||
#Creat json with format:
|
||||
# json = {
|
||||
def identifyServer(self) -> bytes:
|
||||
# Message is coded with Server RSA public key in string byte format
|
||||
# Creat json with format:
|
||||
# fos = {
|
||||
# 'type':'IDY',
|
||||
# 'source':self.network.own_addr,
|
||||
# 'message': message
|
||||
# 'username': self.username,
|
||||
# 'message': message <- random generalt, hogy biztos ne legyen elore ismert a challange
|
||||
# }
|
||||
#message = json.dump()
|
||||
#message.encode('utf-8')
|
||||
#network_interface.send_msg(self.SERVER_ADDRESS,message)
|
||||
#Listen for response
|
||||
#status, msg = network_interface.receive_msg(blocking=True) -> status is boolean flag, msg is message
|
||||
#return status, msg
|
||||
# jsonmsg = json.dump(fos)
|
||||
# asd = jsonmsg.encode('UTF-8')
|
||||
# network_interface.send_msg(self.SERVER_ADDRESS,asd)
|
||||
# Listen for response
|
||||
# status, msg = network_interface.receive_msg(blocking=True) -> status is boolean flag, msg is message
|
||||
# truemsg = msg.decode('UTF-8') nezd meg, h ez tenyleg bajttomb-e, testverem
|
||||
# jsonmsg = json.loads(truemsg)
|
||||
# plaintextrcvmsg = jsonmsg['message'] dekodolod rsa-val
|
||||
# if (plaintextrcvmsg == message): akkor goodness else: fail
|
||||
# return status, msg
|
||||
pass
|
||||
|
||||
|
||||
def authenticate(self, username: str, password: str):
|
||||
# json = {
|
||||
def createEncryptedChannel(self):
|
||||
# pyDH-t hasznalsz
|
||||
|
||||
# pydh = pyDH() #alapertelmezett cuccok jok
|
||||
# mypubkey = pydh.gen_public_key()
|
||||
# 'type':'DH',
|
||||
# 'source':self.network.own_addr
|
||||
# fos = {,
|
||||
# 'message': mypubkey <- pls titkosisd a szerver publikus rsa kulcsaval, hogy authentikalt legyen a dh procedura
|
||||
# }
|
||||
# jsonmsg = json.dump(fos)
|
||||
# asd = jsonmsg.encode('UTF-8')
|
||||
# self.network.send_msg(asd)
|
||||
# status, msg = network_interface.receive_msg(blocking=True) -> status is boolean flag, msg is message
|
||||
# truemsg = msg.decode('UTF-8') nezd meg, h ez tenyleg bajttomb-e, testverem
|
||||
# jsonmsg = json.loads(truemsg)
|
||||
# self.sharedkey = pydh.gen_shared_key(jsonmsg['message']<-dekoldold a sajat publikus rsa kulccsal)
|
||||
# self.chachageci = ChaChaGeci(self.sharedkey) <- a lenyeg, h a kapott osztott kulccsal legyen egy chacha stream ciphered
|
||||
pass
|
||||
|
||||
def authenticate(self, password: str):
|
||||
# message = self.chachageci.titkosisd_jol_testverem(f'LIN %self.username% %password%')
|
||||
# fos = {
|
||||
# 'type':'AUT',
|
||||
# 'source':self.network.own_addr,
|
||||
# 'message': message
|
||||
# }
|
||||
# jsonmsg = json.dump(fos)
|
||||
# asd = jsonmsg.encode('UTF-8')
|
||||
# network_interface.send_msg(self.SERVER_ADDRESS,asd)
|
||||
# status, msg = network_interface.receive_msg(blocking=True) -> status is boolean flag, msg is message
|
||||
# truemsg = msg.decode('UTF-8') nezd meg, h ez tenyleg bajttomb-e, testverem
|
||||
# jsonmsg = json.loads(truemsg)
|
||||
#
|
||||
pass
|
||||
|
||||
def connectToServer(self):
|
||||
#self.identifyServer()
|
||||
#self.createEncryptedChannel()
|
||||
#self.authenticate()
|
||||
pass
|
||||
|
||||
def sendMessage(self, message: bytes):
|
||||
#message: encoding message with chacha20
|
||||
#json = {
|
||||
# message: encoding message with chacha20
|
||||
# json = {
|
||||
# 'type':'CMD',
|
||||
# 'source':self.network.own_addr,
|
||||
# 'message': message
|
||||
#}
|
||||
#message = json.dump()
|
||||
#message.encode('utf-8')
|
||||
#network_interface.send_msg(self.SERVER_ADDRESS,message)
|
||||
# }
|
||||
# message = json.dump()
|
||||
# message.encode('utf-8')
|
||||
# network_interface.send_msg(self.SERVER_ADDRESS,message)
|
||||
pass
|
||||
|
||||
|
||||
def recieveMessage(self, message: bytes):
|
||||
#status, msg = network_interface.receive_msg(blocking=True) -> status is boolean flag, msg is message
|
||||
#Decode the message with chacha20
|
||||
# status, msg = network_interface.receive_msg(blocking=True) -> status is boolean flag, msg is message
|
||||
# Decode the message with chacha20
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user