After CUHK.py and Blackboard.py are started, these two processes keep listening on ports 9335 and 3141 respectively.
At the same time, CUHK.py will generate key pairs and root certificates, store the root certificate and key in the local cuhk.cer and cuhk.key locations respectively.
Step 1
Running Student.py, then enter 10 digits as student ID.
Then, it will generate a key pair, and use it to generate a CSR request.
Serialize the CSR request and send it to CUHK.py ( port: 9335 )
Step 2
CUHK.py get CSR request from Student.py.
Sign CSR request and use CSR Request,cuhk.cer and cuhk.key to generate cert 2.
Send back cert 2 to Student.py by socket.
Student.py get cert 2 from CUHK.py ( port: 9335 ), then dispaly "SID: ********** sign finished." in terminal.
Step 3
Student.py initiate a request by concatenating, Request: "SID:********** requests to upload report !" | Cert 2
Blackboard.py get the request, and then take out Cert 2 from it.
Blackboard.py read root certificate from local filecuhk.cer.
Blackboard.py verify the validity of the Cert 2, if the verification is passed, go to the next step, or the program will terminate.
Step 4
Blackboard.py generate a session key.
Blackboard.py get the public key from Cert 2.
Use public key to encrypt session key, and then send it to Student.py.
Step 5
Student.py get encrypted session key, then use its private key that are used to generate the CSR request to decrypt the session key.
Then, Student.py send the decrypted session key to Blackboard.py.
Blackboard.py verify the decrypted session key.
If check pass, Student.py and Blackboard.py start to communicate.
Step 6
Student.py use session key and message content to generate HMAC, then concatenate message and HMAC: Message Content | HMAC, send it to Blackboard.py.
Blackboard.py get concatenated message and HMAC, then take message out, recalculate HMAC using session key.
Compare the HMAC from Student.py with the recalculated HMAC, if they are the same, the message is valid, output message in terminal.