The Complete Public Key Infrastructure (PKI) Process: From Key Generation to Certificate Verification
Public Key Infrastructure (PKI) is the backbone of secure communication on the internet. It ensures that sensitive data exchanged between clients and servers remains private and authentic. This blog post will guide you through the entire PKI process, from generating keys to verifying certificates and ensuring they haven't been revoked.
1. Key Pair Generation
The first step in PKI is generating a public-private key pair using an asymmetric cryptographic algorithm, such as RSA or ECDSA:
The private key is securely stored on the server and never shared.
The public key is included in the certificate and shared with the Certificate Authority (CA) during the certificate request process.
This key pair enables encryption and decryption, which are essential for secure communication.
2. Creating a Certificate Signing Request (CSR)
The server creates a Certificate Signing Request (CSR) to request a certificate from a trusted CA. The CSR includes:
The public key.
The server’s identity details (e.g., domain name, organization, location).
The CSR is then submitted to the CA for validation.
3. CA Issues the Certificate
Once the CA receives the CSR, it performs the following steps:
a. Validation
The CA verifies the server's identity using various methods, such as domain ownership verification or organizational checks. This ensures that the entity requesting the certificate is legitimate.
b. Hashing and Signing
The CA creates a hash of the certificate data (e.g., public key and identity information) using a secure hashing algorithm like SHA-256.
The CA then encrypts this hash with its private key to create a digital signature.
The CA packages the public key, server identity details, and the digital signature into the certificate.
The resulting certificate guarantees the authenticity of the server and the integrity of the data.
4. Installing the Certificate on the Server
After receiving the signed certificate, the server installs it along with the private key. The certificate is often accompanied by intermediate CA certificates to establish a chain of trust. These certificates are essential for ensuring compatibility with all client devices.
5. Client-Server Communication (TLS Handshake)
When a client (e.g., a browser) connects to the server, the server presents its certificate during the TLS handshake. The client then validates the certificate through the following steps:
a. Signature Verification
The client extracts the digital signature from the server’s certificate.
Using the CA’s public key (from the client’s trusted root store), the client decrypts the signature to retrieve the original hash.
The client recomputes the hash of the certificate data and compares it with the decrypted hash.
If the hashes match, the certificate is authentic and untampered.
If they don’t match, the certificate is invalid.
b. Domain Validation
The client ensures that the certificate’s Common Name (CN) or Subject Alternative Name (SAN) matches the domain it’s trying to connect to.
c. Validity Period Check
The client verifies that the certificate is within its validity period. Expired certificates are deemed invalid.
6. Checking Certificate Revocation
To ensure that the certificate hasn’t been revoked, the client performs one of the following checks:
a. Certificate Revocation List (CRL)
The certificate contains a link to a CRL provided by the CA.
The client downloads the CRL and checks whether the certificate’s serial number is on the list.
b. Online Certificate Status Protocol (OCSP)
The certificate includes an OCSP endpoint (URL) provided by the CA.
The client sends a real-time query to the CA’s OCSP server to check the certificate’s revocation status.
c. OCSP Stapling
The server pre-fetches the OCSP response from the CA and includes it in the TLS handshake.
This method reduces latency and improves performance by eliminating the need for the client to query the CA directly.
7. Establishing Secure Communication
Once the certificate is verified, the client and server establish a secure channel:
The client generates a session key for encryption.
The client encrypts the session key using the server’s public key (from the certificate).
The server decrypts the session key using its private key.
Both parties use the session key for symmetric encryption to ensure fast and secure communication.
8. Summary of the Entire Process
Preparation
Generate a public-private key pair.
Create and submit a CSR to a CA.
CA’s Role
Validate the server’s identity.
Hash the CSR data, sign it with the CA’s private key, and issue the certificate.
Server Installs the Certificate
Install the certificate and the private key on the server.
TLS Handshake (Client-Server Communication)
Server sends its certificate to the client.
Client validates the certificate:
Signature verification.
Domain name match.
Check revocation (via CRL or OCSP).
Establish Secure Communication
Client and server establish a secure connection using symmetric encryption.
Comments
Post a Comment