DONE: Client command reciever
continuous-integration/drone/push Build is passing Details

ERROR: On RSA decoding
TODO: Implement functions
This commit is contained in:
DESKTOP-DPA61F8\Benedek 2021-04-21 00:45:42 +02:00
parent 2ce15de03d
commit 9d43cc3f24
2 changed files with 118 additions and 0 deletions

116
client/client.py Normal file
View File

@ -0,0 +1,116 @@
import os, sys, getopt, json
from Crypto.PublicKey import RSA
from Crypto.PublicKey.RSA import RsaKey
ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
CONFIG_LOCATION = ABSOLUTE_PATH + os.path.sep + 'config' + os.path.sep + 'config.txt'
PASSPHRASE = ''
LOGGED_IN = False
SERVER_PUBLIC_KEY = None
CLIENT_PRIVATE_KEY = None
def loadPublicKey() -> RsaKey:
with open(CONFIG_LOCATION) as json_file:
data = json.load(json_file)
return RSA.import_key(data['publicServerKey'])
def loadPrivateKey(passphrase: str) -> RsaKey:
with open(CONFIG_LOCATION) as json_file:
data = json.load(json_file)
return RSA.import_key(data['privateClientKey'], passphrase)
def printCommand():
print('\nInvalid command! Available commands:\n' +
' Create directory -> MKD <directory name> \n' +
' Remove directory -> RMV <directory name> \n' +
' Get current directory -> GWD \n' +
' Change current directory -> CWD <path> \n' +
' List content of current directory -> LST \n' +
' Upload file to current directory -> UPL <filename> \n' +
' Download file from current directory -> DNL <filename> \n' +
' Login -> LIN <username> <password> \n' +
' Logout -> LOUT \n')
def printCommandsWihtoutLogin():
print('\nYou must log in before issuing other commads!\n',
' Login -> LIN <username> <password> \n',
' Exit -> EXIT\n')
try:
opts, args = getopt.getopt(sys.argv[1:], 'hp:')
except getopt.GetoptError:
print('Error: Unknown option detected.')
sys.exit(1)
for opt, arg in opts:
if opt in '-p':
PASSPHRASE = arg
if PASSPHRASE == '':
print('Key required to start client!')
print('Usage:')
print(' client.py -p <passphrase>')
sys.exit(1)
if not os.path.isfile(CONFIG_LOCATION) or os.stat(CONFIG_LOCATION).st_size == 0:
print('Invalid client config file')
sys.exit(1)
# SERVER_PUBLIC_KEY = loadPublicKey()
# CLIENT_PRIVATE_KEY = loadPrivateKey(PASSPHRASE)
while True:
command = input("Type a command:").split(" ")
if len(command) > 3 or len(command) < 1:
print("Invalid command format!")
if command[0] == 'LIN':
print('TODO: Implement!')
LOGGED_IN = True
continue
if command[0] == 'EXIT':
sys.exit(1)
if not LOGGED_IN:
printCommandsWihtoutLogin()
continue
if command[0] == 'LOUT':
print('TODO: Implement!')
continue
if command[0] == 'MKD':
print('TODO: Implement!')
continue
if command[0] == 'RMD':
print('TODO: Implement!')
continue
if command[0] == 'GWD':
print('TODO: Implement!')
continue
if command[0] == 'CWD':
print('TODO: Implement!')
continue
if command[0] == 'LST':
print('TODO: Implement!')
continue
if command[0] == 'UPL':
print('TODO: Implement!')
continue
if command[0] == 'DNL':
print('TODO: Implement!')
continue
printCommand()

2
client/client_test.py Normal file
View File

@ -0,0 +1,2 @@