- Install
Openssl
andPycrypto
libraries
pip3 install pyopenssl
pip3 install pycryptodome
- Run
CUHK.py
andBlackboard.py
- Run
Student.py
, enter student ID - Wait for the program to finish running
- CUHK (Port: 9335)
- Blackboard (Port: 3141)
- Student
- After
CUHK.py
andBlackboard.py
are started, these two processes keep listening on ports9335
and3141
respectively. - At the same time,
CUHK.py
will generate key pairs and root certificates, store the root certificate and key in the localcuhk.cer
andcuhk.key
locations respectively.
- 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 )
CUHK.py
get CSR request fromStudent.py
.- Sign CSR request and use
CSR Request
,cuhk.cer
andcuhk.key
to generate cert 2. - Send back cert 2 to
Student.py
by socket. Student.py
get cert 2 fromCUHK.py
( port: 9335 ), then dispaly"SID: ********** sign finished."
in terminal.
Student.py
initiate a request by concatenating, Request:"SID:********** requests to upload report !"
|Cert 2
Blackboard.py
get the request, and then take outCert 2
from it.Blackboard.py
read root certificate from local filecuhk.cer
.Blackboard.py
verify the validity of theCert 2
, if the verification is passed, go to the next step, or the program will terminate.
Blackboard.py
generate asession key
.Blackboard.py
get the public key fromCert 2
.- Use public key to encrypt
session key
, and then send it toStudent.py
.
Student.py
get encryptedsession key
, then use its private key that are used to generate the CSR request to decrypt thesession key
.- Then,
Student.py
send the decryptedsession key
toBlackboard.py
. Blackboard.py
verify the decryptedsession key
.- If check pass,
Student.py
andBlackboard.py
start to communicate.
Student.py
usesession key
and message content to generate HMAC, then concatenate message and HMAC:Message Content
|HMAC
, send it toBlackboard.py
.Blackboard.py
get concatenated message and HMAC, then take message out, recalculate HMAC usingsession key
.- Compare the HMAC from
Student.py
with the recalculated HMAC, if they are the same, the message is valid, output message in terminal.
- [1] Socket Programming 1: https://blog.csdn.net/a883774913/article/details/125395179
- [2] Socket Programming 2: https://blog.csdn.net/Dontla/article/details/103679153
- [3] OpenSSL Document: https://www.pyopenssl.org/en/latest/
- [4] Generate Self-Sign Certificate: https://blog.csdn.net/TheGreenSummer/article/details/110285923
- [5] SSL/TLS: https://blog.csdn.net/wuliganggang/article/details/78428866
- [6] SSL/TLS: https://blog.csdn.net/vip97yigang/article/details/84721027
- [7] Wraps pyOpenSSL for quick and easy PKI: https://github.com/LLNL/certipy
- [8] OpenSsl.crypto Usage: https://vimsky.com/zh-tw/examples/detail/python-method-OpenSSL.crypto.html
- [9] Definition Explain: https://blog.csdn.net/keke_Xin/article/details/84817391
- [10] CA, Crypto Process: https://blog.csdn.net/gaoshan12345678910/article/details/114737953
- [11] RSA Encryption and Decryption: https://www.jb51.net/article/244576.htm
- [12] HMAC: https://star-302.blog.csdn.net/article/details/126887090