CSS Mproject Certificate in Cryptography Implementation
CSS Mproject Certificate in Cryptography Implementation
Activity Topic:
Implement a certificate-based authentication mechanisms in Python or Java
By Sanjana Bhosle (A-09)
Implementation steps:
Install OpenSSL and open its command prompt to run the following command to create a
setup for certificate-based authentication using SSL.
Command to create private key:
Openssl genrsa -aes256 -out private.key 2048
This private key is used for securely encrypting and decrypting data during SSL/TLS
communication.
Command to update the private key:
Openssl rsa -in private.key -out private.key
We only have one certificate and one private key that will be used by both the server and
client for certificate-based authentication.
Program Implementation:
Server Implementation (Server.py):
The server sets up a TCP socket and binds it to a specific host and port
(localhost:1227 in this case).
It configures an SSL context using the ssl.create_default_context method for client
authentication (ssl.Purpose.CLIENT_AUTH) and loads the certificate and private key
using context.load_cert_chain.
When a client connects, the server accepts the connection and wraps the socket with
SSL/TLS using the SSL context (context.wrap_socket). This establishes a secure
connection between the server and the client.
During the SSL/TLS handshake, the server verifies the client's certificate using
conn.getpeercert(). If the client provides a valid certificate, the server proceeds with
the connection.
Client Implementation (Client.py):
The client sets up a TCP connection to the server (localhost:1227).
It configures an SSL context using the ssl.create_default_context method for server
authentication (ssl.Purpose.SERVER_AUTH) and loads the certificate and private key
using context.load_cert_chain.
The client wraps the socket with SSL/TLS using the SSL context, establishing a
secure connection with the server.
During the SSL/TLS handshake, the client verifies the server's certificate. If the server
provides a valid certificate, the client proceeds with the connection.
Authentication:
During the SSL/TLS handshake, both the server and client authenticate each other
using their certificates. This mutual authentication ensures that both parties are who
they claim to be.
If the server verifies the client's certificate and the client verifies the server's
certificate successfully, the connection is established, and data can be securely
exchanged between the server and the client.
Server.py
import socket
import ssl
HOST = 'localhost'
PORT = 1227
print("Server is ready")
HOST = 'localhost'
PORT = 1227
print("Connection closed.")
Client.py Output:
Server.py Output:
Conclusion:
By adopting this method, we ensure that only trusted entities can access our network
resources, thus enhancing our overall security posture. Through the utilization of certificates
and private keys, we establish a secure environment where mutual authentication guarantees
the identities of both the server and the client. This approach not only strengthens the security
of our communication channels but also instills trust and confidence in the integrity of our
systems, paving the way for a safer digital future.