Network interface needed for implementing!
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-04-21 18:31:01 +02:00
parent 9d43cc3f24
commit 30d582227e
2 changed files with 43 additions and 16 deletions

View File

@ -1,8 +1,12 @@
import os, sys, getopt, json
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'
PASSPHRASE = ''
LOGGED_IN = False
@ -13,13 +17,28 @@ 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'])
key = data['publicServerKey']
key = bytes.fromhex(key)
try:
rsaKey = RSA.import_key(key)
except ValueError:
print('Invalid server public key!')
sys.exit(1)
return RSA.import_key(key)
def loadPrivateKey(passphrase: str) -> RsaKey:
with open(CONFIG_LOCATION) as json_file:
data = json.load(json_file)
return RSA.import_key(data['privateClientKey'], passphrase)
key = data['privateClientKey']
key = bytes.fromhex(key)
try:
rsaKey = RSA.import_key(key, passphrase)
except ValueError:
print('Invalid client key!')
sys.exit(1)
return rsaKey
def printCommand():
@ -34,6 +53,7 @@ def printCommand():
' 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',
@ -60,16 +80,16 @@ 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)
#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!")
continue
if command[0] == 'LIN':
if command[0] == 'LIN' and len(command) == 3:
print('TODO: Implement!')
LOGGED_IN = True
continue
@ -85,32 +105,38 @@ while True:
print('TODO: Implement!')
continue
if command[0] == 'MKD':
if command[0] == 'MKD' and len(command) == 2:
print('TODO: Implement!')
continue
if command[0] == 'RMD':
if command[0] == 'RMD' and len(command) == 2:
print('TODO: Implement!')
continue
if command[0] == 'GWD':
if command[0] == 'GWD' and len(command) == 1:
print('TODO: Implement!')
continue
if command[0] == 'CWD':
if command[0] == 'CWD' and len(command) == 2:
print('TODO: Implement!')
continue
if command[0] == 'LST':
if command[0] == 'LST' and len(command) == 1:
print('TODO: Implement!')
continue
if command[0] == 'UPL':
print('TODO: Implement!')
if command[0] == 'UPL' and len(command) == 2:
if os.path.isfile(command[1]):
with open(command[1], "rb") as file:
print('TODO: Implement!')
else:
print('Invalid argument for file upload: '+command[1])
continue
if command[0] == 'DNL':
print('TODO: Implement!')
if command[0] == 'DNL' and len(command) == 2:
dnlFilename = command[1].rsplit(os.apth.sep, 1)[-1]
with open(DOWNLOAD_LOCATION + dnlFilename, "wb") as file:
print('TODO: Implement!')
continue
printCommand()
printCommand()