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

This commit is contained in:
DESKTOP-DPA61F8\Benedek 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',
@ -61,15 +81,15 @@ if not os.path.isfile(CONFIG_LOCATION) or os.stat(CONFIG_LOCATION).st_size == 0:
sys.exit(1)
#SERVER_PUBLIC_KEY = loadPublicKey()
# CLIENT_PRIVATE_KEY = loadPrivateKey(PASSPHRASE)
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,31 +105,37 @@ 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':
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':
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

1
client/config/config.txt Normal file
View File

@ -0,0 +1 @@
{"passphrase": "amla", "privateClientKey": "3082050e304006092a864886f70d01050d3033301b06092a864886f70d01050c300e0408dd933c665c01d9cc020203e8301406082a864886f70d03070408adf603cfba0dad71048204c8e294801a5a1033d2979c3934677ad838c3e56c3df52c0d5a2bb2312277dee0a8e3117c9eb7974609334f128f1bae07d2c3b11fa01053045960b1ee0c023c4ea26fd1591656adb541c768d9cf998140aec65e108dee3b65bd0f3801401d2f66c5c025540af8785d97ea18caba21fba2c43e043f094720457aa1bdd98282eb4f2b481d6660a88d7146b329a39a9835d8948d3659e520dfe3380560cb80f7832d637270324229d569b52d25827caad81b88995ed09be7efac4b76feb16940a6fb129972936fa0f770226ce3fe4ba0dfff276a401bda35e91f657302b3ace514c31479ac7b7f1e14652973f1253fbe583c7bba0c45ea36fb8527ee12d8b10409dbc83c9a87ee75843e1ff1daefd08b139c540cee3430bc7d7720e148420cc422da1230ea8c9503e5d465393a2741a10532b7a6c42a14a7faf52859683a0d84e101db88d6f9aa7d7c5a5f74567f30091aa426d78e462decb6b634152f917263a59dbe798116c1e749591a84d4cdcf5b2219fab998489ab40408634e3f20801b21c4a7a0192cea025a28e2cde83b582afbc9aa40b46dc7cdcc9db7fef092ed8c4d1ffb2fb6c5bdc4909b6ded19e837149b12f39e8ab1ff250ddbaa2ac44e28e49a57a34da6186c2dcd20b88a62d100beb72f0d6f84db24b3c436c6331f887e7bb4e184217397ac7ea2201af3a9e5b7a3d3963775e44358dd0e70011a089481a8c98b2ed29f428df55646746181c50ec861ca404d1938662c69b74d0cc6876e1ac7ed92e47e495a63113bc673d7eae96dfb083eea607c3149bb2adf7321a40f68c8b16c4f1951b36e9cbd8d69fe1bdbe8156759ce51e1fb09b740684706b6cad56fdd247ea9c9241312513648dba82344af418a2f58ee8476d1a5010bac73582b6d8123b8d5ca2dabcb4b5355f0726131732e2cc2b86b63bc988c136822cabd0a4447b4d25cabaea6cb2f676d7be97dd4f8f74987827a412cbb30dd2983ec4ac48dcb0d96e455ac7cd70673d125390ce4f708067eb313c96b16a3919e2fe477f204acdbe5299003b734ebd6029bfaba421d5494dba79f9c28a4d7e89455cc231771cdaa06cfc518e6e3b79777b3a2ed1fc5de74ac64e6a007db9879a90b4a9e9f385901ee20d7e5fa6cf871806d691432697cb89cce7356b81f8b29364e5ce34e0c6b6e289502f5c08f07380357f9f3859f6d6010ce561da76655844b11be2e2094576289056615d7f6c6648b4b5fd3dd0474c174327b5359473a361e169437990d467f6662e9628c761a54c17d165900da8f118464047e97b7820c05c6c5f1cd0e60e073f7776f01ba29e5fbc54ce61cf961e28cf5b25dc6061b621a72177b43ede84c62c0d36c4bbedec7eb3b567ef2ae812f6445e0d3c9ac294f49792a0d795946e0717674f00c7557fa7d53b0c8fb862967287120cc7338ed35279b3eb38666828a200434890f808315b84e132e4e692a4959cb167be6185c72e45f545677cf014509cdf30af2647f5973577b6a053509c77f47f4c161279fb1b206c751e582eb293183ec30c9ca324c2da0338d1cf7de510d60a94b2656f1fa37fb9b9d2663322ebeea20324f156f93aea296bccee061b440588796c9c99287607509625c9d47c098f65d949c713803e963a2430a53fedbf0f9b02ecd7c0b16ea0e785199098f617fcf37ec519c287859fc49991760ffaf59e6c157aabfd16438cf7d6dee4614944ef5fe277a7dbb07", "publicServerKey": ""}