Quotes prevent variable splitting if file name has spaces
This commit is contained in:
parent
5f1c8fdf47
commit
4352f2908b
@ -85,7 +85,7 @@ class Client:
|
|||||||
_subprocess = await asyncio.create_subprocess_shell(
|
_subprocess = await asyncio.create_subprocess_shell(
|
||||||
"openssl enc -aes-256-cbc "
|
"openssl enc -aes-256-cbc "
|
||||||
"-md sha512 -pbkdf2 -iter 100000 -salt "
|
"-md sha512 -pbkdf2 -iter 100000 -salt "
|
||||||
f"-in {input_file} -out {output_file} "
|
f"-in \"{input_file}\" -out \"{output_file}\" "
|
||||||
f"-pass pass:{self.password}"
|
f"-pass pass:{self.password}"
|
||||||
)
|
)
|
||||||
stdout, stderr = await _subprocess.communicate()
|
stdout, stderr = await _subprocess.communicate()
|
||||||
@ -105,14 +105,18 @@ class Client:
|
|||||||
file_path = self.file_path
|
file_path = self.file_path
|
||||||
if self.password:
|
if self.password:
|
||||||
file_path = self.file_path + '.enc'
|
file_path = self.file_path + '.enc'
|
||||||
|
# Remove already-encrypted file if present (salt would differ)
|
||||||
|
if os.path.isfile(file_path):
|
||||||
|
os.remove(file_path)
|
||||||
asyncio.ensure_future(
|
asyncio.ensure_future(
|
||||||
self.encrypt_file(
|
self.encrypt_file(
|
||||||
input_file=self.file_path,
|
input_file=self.file_path,
|
||||||
output_file=file_path
|
output_file=file_path
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
# Give encryption an edge
|
||||||
while not os.path.isfile(file_path):
|
while not os.path.isfile(file_path):
|
||||||
await asyncio.sleep(0.1) # Let the encryption begin
|
await asyncio.sleep(.5)
|
||||||
logging.info("Sending file...")
|
logging.info("Sending file...")
|
||||||
with open(file_path, 'rb') as file_to_send:
|
with open(file_path, 'rb') as file_to_send:
|
||||||
while not self.stopping:
|
while not self.stopping:
|
||||||
@ -146,6 +150,7 @@ class Client:
|
|||||||
async def receive(self, reader: asyncio.StreamReader):
|
async def receive(self, reader: asyncio.StreamReader):
|
||||||
self._working = True
|
self._working = True
|
||||||
file_path = self.file_path
|
file_path = self.file_path
|
||||||
|
logging.info("Receiving file...")
|
||||||
if self.password:
|
if self.password:
|
||||||
file_path += '.enc'
|
file_path += '.enc'
|
||||||
with open(file_path, 'wb') as file_to_receive:
|
with open(file_path, 'wb') as file_to_receive:
|
||||||
@ -154,6 +159,7 @@ class Client:
|
|||||||
if not input_data:
|
if not input_data:
|
||||||
break
|
break
|
||||||
file_to_receive.write(input_data)
|
file_to_receive.write(input_data)
|
||||||
|
logging.info("File received.")
|
||||||
if self.password:
|
if self.password:
|
||||||
logging.info("Decrypting file...")
|
logging.info("Decrypting file...")
|
||||||
stdout, stderr = ''.encode(), ''.encode()
|
stdout, stderr = ''.encode(), ''.encode()
|
||||||
@ -161,7 +167,7 @@ class Client:
|
|||||||
_subprocess = await asyncio.create_subprocess_shell(
|
_subprocess = await asyncio.create_subprocess_shell(
|
||||||
"openssl enc -aes-256-cbc "
|
"openssl enc -aes-256-cbc "
|
||||||
"-md sha512 -pbkdf2 -iter 100000 -salt -d "
|
"-md sha512 -pbkdf2 -iter 100000 -salt -d "
|
||||||
f"-in {file_path} -out {self.file_path} "
|
f"-in \"{file_path}\" -out \"{self.file_path}\" "
|
||||||
f"-pass pass:{self.password}"
|
f"-pass pass:{self.password}"
|
||||||
)
|
)
|
||||||
stdout, stderr = await _subprocess.communicate()
|
stdout, stderr = await _subprocess.communicate()
|
||||||
|
@ -11,9 +11,12 @@ class Server:
|
|||||||
self._host = host
|
self._host = host
|
||||||
self._port = port
|
self._port = port
|
||||||
self._stopping = False
|
self._stopping = False
|
||||||
self.buffer = collections.deque() # Shared queue of bytes
|
# Shared queue of bytes
|
||||||
self._buffer_chunk_size = buffer_chunk_size # How many bytes per chunk
|
self.buffer = collections.deque()
|
||||||
self._buffer_length_limit = buffer_length_limit # How many chunks in buffer
|
# How many bytes per chunk
|
||||||
|
self._buffer_chunk_size = buffer_chunk_size
|
||||||
|
# How many chunks in buffer
|
||||||
|
self._buffer_length_limit = buffer_length_limit
|
||||||
self._working = False
|
self._working = False
|
||||||
self._server = None
|
self._server = None
|
||||||
self._ssl_context = None
|
self._ssl_context = None
|
||||||
@ -102,15 +105,20 @@ class Server:
|
|||||||
"""
|
"""
|
||||||
client_hello = await reader.readline()
|
client_hello = await reader.readline()
|
||||||
peer_is_sender = client_hello.decode('utf-8') == 'sender\n'
|
peer_is_sender = client_hello.decode('utf-8') == 'sender\n'
|
||||||
writer.write("Start!\n".encode('utf-8')) # Send start signal to client
|
|
||||||
await writer.drain()
|
await writer.drain()
|
||||||
if peer_is_sender:
|
if peer_is_sender:
|
||||||
self._working = True
|
self._working = True
|
||||||
logging.info("Sender is connecting...")
|
logging.info("Sender is connecting...")
|
||||||
|
# Send start signal to client
|
||||||
|
writer.write("Start!\n".encode('utf-8'))
|
||||||
await self.run_reader(reader=reader)
|
await self.run_reader(reader=reader)
|
||||||
logging.info("Incoming transmission ended")
|
logging.info("Incoming transmission ended")
|
||||||
else:
|
else:
|
||||||
logging.info("Receiver is connecting...")
|
logging.info("Receiver is connecting...")
|
||||||
|
while len(self.buffer) == 0:
|
||||||
|
await asyncio.sleep(.5)
|
||||||
|
# Send start signal to client
|
||||||
|
writer.write("Start!\n".encode('utf-8'))
|
||||||
await self.run_writer(writer=writer)
|
await self.run_writer(writer=writer)
|
||||||
logging.info("Outgoing transmission ended")
|
logging.info("Outgoing transmission ended")
|
||||||
self._working = False
|
self._working = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user