Question: I have this code that I made so far but I don't know how to complete it . I have to: At the browser /

I have this code that I made so far but I don't know how to complete it. I have to:
At the browser/client side:
*Validate the self-signed certificate
*Generate a random session key for AES
*Use RSA to encrypt the session key using the servers public key extracted from the certificate
*Send the encrypted session key to the server
At the server side:
*Use the servers private key to decrypt the ession key
*Print out ************ Now both parties have the session key ***************
*The server uses AES to encrypt a message saying Hello Browser
At the browser/client side:
*The Client received the encrypted message and check that it says Hello Browser
*The client uses AES to encrypt a message saying Hello Browser123
At the server side:
*The server decrypts the message and check that it says Hello Browser123
*Print out ************** Secure communicate can start now ******************
The code:
from OpenSSL import crypto, SSL
from socket import gethostname
from pprint import pprint
from time import gmtime, mktime
CERT_FILE = "selfsigned.crt"
KEY_FILE = "private.key"
def create_self_signed_cert():
# create a key pair
k = crypto.PKey()
k.generate_key(crypto.TYPE_RSA, 1024)
# create a self-signed cert
cert = crypto.X509()
cert.get_subject().C ="UK" #The country of the entity
cert.get_subject().ST = "Buckinghshire" #State Or Province Name
cert.get_subject().L = "Buckingham" #locality Name
cert.get_subject().O = "The University of Buckignham" #Organization Name
cert.get_subject().OU = "Computing School" #organizational Unit Name
cert.get_subject().CN = "Kiundae Tuzo" # commonName.. you could use gethostname()
cert.get_subject().emailAddress="hisham.al-assam@buckingham.ac.uk"
cert.set_serial_number(1000)
cert.gmtime_adj_notBefore(0) #time before which the certificate is not valid
cert.gmtime_adj_notAfter(10*365*24*60*60) #time after which the certificate is not validcert.set_issuer(cert.get_subject())
cert.set_pubkey(k)
cert.sign(k, 'sha1')
open(CERT_FILE, "wb").write( crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
open(KEY_FILE, "wb").write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k))
create_self_signed_cert()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!