Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is an extension of previous assignment. Using only symmetric key crypto (AES), extend your previous system: (a) to support integrity (in addition to confidentiality)

This is an extension of previous assignment. Using only symmetric key crypto (AES), extend your previous system: (a) to support integrity (in addition to confidentiality) of exchanged files (b) allow for files to be exchanged in either direction that is, from client to server and server to client.

previous assignment was: Build a file server from which a client can request files. Pick a programming language and investigate how to use its networking libraries. Conduct some research on network or socket programming in the language you choose. I recommend Python, Java or C++. Build on the above so as to provide confidentiality of the files transmitted by the server to the client. Use a symmetric key crypto algorithm such as AES in CBC mode. Generate a key on the server side. Export this key into a file. Using a secure channel, copy this file (key) to the client computer. Consult the crypto libraries for the programming language you chose. For example, for Java, do an Internet search on Java Crypto library or Java encryption example. You can find crypto libs for C++ and Python as well. The goal is to learn how to use the crypto APIs for symmetric key encryption and decryption, key generation and for exporting the key so it can be shared between the client and the server. Extended the given code

import os import socket from cryptography.fernet import Fernet

# Generate a symmetric key using AES in CBC mode key = Fernet.generate_key()

# Write the key to a file on the server side with open('keyfile.key', 'wb') as file: file.write(key)

# Define a function to securely send the key file to the client def send_key(conn): # Open the key file and read its contents with open('keyfile.key', 'rb') as file: key_data = file.read() # Send the size of the key file to the client conn.sendall(len(key_data).to_bytes(4, byteorder='big')) # Send the key file itself to the client conn.sendall(key_data)

# Define a function to securely receive the key file on the client sidea def receive_key(conn): # Receive the size of the key file from the server key_size = int.from_bytes(conn.recv(4), byteorder='big') # Receive the key file itself from the server key_data = b'' while len(key_data) < key_size: chunk = conn.recv(min(key_size - len(key_data), 1024)) if not chunk: raise Exception('Failed to receive key') key_data += chunk # Write the key file to disk on the client side with open('keyfile.key', 'wb') as file: file.write(key_data)

# Set up a socket server to listen for client connections server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind(('localhost', 8000)) server_socket.listen(1)

# Wait for a client to connect and receive the key file from the server conn, addr = server_socket.accept() receive_key(conn)

# Once the key file is received, create a Fernet instance on the client side with open('keyfile.key', 'rb') as file: key = file.read() fernet = Fernet(key)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

Define Scientific Management

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago