Author: Arnel C. Reyes
Published: 15 September 2024
Last Updated: 16 September 2024
In today’s interconnected world, online security is paramount. Public Key Infrastructure (PKI) and digital certificates are the foundational technologies that protect our web communications, ensuring that sensitive information remains secure. This guide simplifies the complex concepts behind PKI, explaining how it works and how digital certificates build trust between web servers and users. Whether a user is a beginner or a tech enthusiast, this resource will help users understand the critical role of PKI in safeguarding the internet.
Background
As the internet grew in scope, so did the need for a reliable way to secure digital communications. Public Key Infrastructure (PKI) was developed to establish trust in the online world by authenticating identities and encrypting data exchanges. PKI operates through a system of public and private key pairs, with digital certificates serving as verifiable proof of identity for servers, applications, and individuals. Certificate Authorities (CAs) issue these certificates, acting as trusted entities that vouch for the authenticity of public keys.
At the heart of every secure transaction online—whether it’s accessing a user's bank account, sending an email, or shopping online—PKI and digital certificates play a crucial role. They ensure that data transmitted between a client (like a web browser) and a server remains confidential, untampered, and private. Without these technologies, the security and integrity of the internet would be significantly compromised.
A Certificate Signing Request (CSR) is a digital document generated by an individual or organization when applying for an SSL/TLS certificate from a Certificate Authority (CA). The CSR contains information such as the applicant's public key, domain name, and organization details. It is used by the CA to verify the applicant's identity and, upon approval, issue a digital certificate. The CSR is a critical step in establishing secure communication between a server and its users.
Overview of the Process
- Applicant Generates Certificate Signing Request (CSR):
- Server Admin generates the private key and CSR.
- Submits the CSR to the CA for validation.
- Server Admin generates the private key and CSR.
- Certificate Authority (CA) Validates Identity:
- CA Validates the information (domain, organization).
- CA Validates the information (domain, organization).
- CA Generate Certificate and Send to Applicant:
- CA Signs the server's public key and issues the digital certificate.
- CA Signs the server's public key and issues the digital certificate.
- Install Certificate on the Server:
- Server Admin installs the server certificate, private key, and CA intermediate certificates on the server.
- Configures the web server (e.g., Apache, Nginx) to use the installed certificates for secure communication.
- Server Admin installs the server certificate, private key, and CA intermediate certificates on the server.
Certificate Registration Process
[1] Server Side: Generate a Certificate Signing Request (CSR)
The server admin begins by generating a Certificate Signing Request (CSR). The CSR contains the server's public key, domain name, and additional organization information. A private key is generated along with the CSR, which must be kept secure on the server.
Detailed Steps:
- Generate a Private Key: This private key is used to sign the CSR and will later be used to decrypt messages encrypted with the corresponding public key.
$ openssl genrsa -out server.key 2048
¤ 'server.key' is the private key file.
¤ '2048' is the key size (can be 2048 or 4096 bits for better security). - Generate a CSR: The CSR is generated using the private key created earlier. Server admin be prompted to provide the domain name and organization information.
The following command generates the CSR ('server.csr') that will be sent to the CA.
$ openssl req -new -key server.key -out server.csr
The following details will be asked:- Country Name (C): The country where the organization is located.
- State or Province Name (ST): State or region.
- Locality Name (L): City or locality.
- Organization Name (O): Company or organization.
- Organizational Unit Name (OU): A department or division (optional).
- Common Name (CN): The domain name for which you are requesting the certificate (e.g., 'www.example.com').
- Email Address: An optional contact email.
- Country Name (C): The country where the organization is located.
- Submit CSR to the Certificate Authority (CA): After generating the CSR, the server admin submits the CSR to a CA, either through an online form or API. The CA will use the CSR to issue a digital certificate.
Here’s how the process works:
- Choose a CA: Some popular CAs include:
- DigiCert: DigiCert is a leading Certificate Authority (CA) known for providing high-assurance digital certificates, including SSL/TLS certificates, for securing websites and online communication. They offer enterprise-grade security solutions for businesses of all sizes.
- Comodo (Now Sectigo): Comodo, now known as Sectigo, is a global leader in web security solutions, offering a wide range of SSL/TLS certificates, including domain validation, organization validation, and extended validation certificates. They provide affordable options for website security.
- GoDaddy: GoDaddy is a popular domain registrar and web hosting company that also provides SSL/TLS certificates to secure websites. They offer a variety of certificate types, including standard SSL, wildcard SSL, and EV SSL certificates for enhanced site trust.
- GlobalSign: GlobalSign is a leading Certificate Authority offering SSL/TLS certificates and comprehensive digital identity solutions for securing websites, applications, and communications. They cater to businesses of all sizes, focusing on trust and encryption.
- Let’s Encrypt (free SSL certificates for websites): Let’s Encrypt is a nonprofit Certificate Authority providing free SSL/TLS certificates, making it easy for website owners to secure their sites at no cost. They aim to create a more secure and privacy-respecting web by offering automated and accessible encryption for all.
- DigiCert: DigiCert is a leading Certificate Authority (CA) known for providing high-assurance digital certificates, including SSL/TLS certificates, for securing websites and online communication. They offer enterprise-grade security solutions for businesses of all sizes.
- Select Certificate Type: Applicant can choose different types of certificates depending on needs:
- Domain Validated (DV): Verifies domain ownership. This is the fastest and cheapest option, often issued within minutes.
- Organization Validated (OV): Verifies both domain ownership and organization details. Requires some documentation and typically takes 1-2 days.
- Extended Validation (EV): Provides the highest level of validation. Requires extensive verification of your organization and can take several days.
- Domain Validated (DV): Verifies domain ownership. This is the fastest and cheapest option, often issued within minutes.
- Submit the CSR: During the purchase process, you’ll be asked to upload your CSR file ('server.csr'). The CA will use this to generate the certificate.
- Choose a CA: Some popular CAs include:
A Certificate Authority (CA) is responsible for verifying the identity of the applicant by validating the domain ownership and organizational details provided in the Certificate Signing Request (CSR). Once the information is confirmed, the CA signs the server’s public key using its private key, creating a digital certificate. This certificate is then sent to the applicant, establishing trust and enabling secure communication between the server and its users.
Overview of the Process
- Applicant Generates Certificate Signing Request (CSR):
- Server Admin generates the private key and CSR.
- Submits the CSR to the CA for validation.
- Server Admin generates the private key and CSR.
- Certificate Authority (CA) Validates Identity:
- CA Validates the information (domain, organization).
- CA Validates the information (domain, organization).
- CA Generate Certificate and Send to Applicant:
- CA Signs the server's public key and issues the digital certificate.
- CA Signs the server's public key and issues the digital certificate.
- Install Certificate on the Server:
- Server Admin installs the server certificate, private key, and CA intermediate certificates on the server.
- Configures the web server (e.g., Apache, Nginx) to use the installed certificates for secure communication.
- Server Admin installs the server certificate, private key, and CA intermediate certificates on the server.
Certificate Registration Process Continuation
[2] CA Side: Validates Identity in the CSR
The Certificate Authority (CA) reviews the Certificate Signing Request (CSR) to verify the applicant's domain ownership and organizational details. This validation process ensures the accuracy and legitimacy of the request before issuing a digital certificate, helping to establish trust in secure online communication.
Before issuing a certificate, the CA must validate the applicant’s identity. The validation process depends on the type of certificate:
- For Domain Validation (DV): The CA ensures that the applicant owns the domain by verifying domain control, typically via email, DNS records, or a file on the web server.
- For Organization Validation (OV): The CA verifies the applicant’s domain and business details by checking public business records and requiring documents.
- For Extended Validation (EV): The CA conducts a thorough vetting process, including confirming legal, operational, and physical existence, often taking several days.
Detailed Step:
CA Validation Process: The CA verifies the legitimacy of the CSR by performing domain ownership and possibly organization validation to ensure it's valid and accurate. This may involve:
- Verifying control over the domain (via DNS record, email verification, etc.).
- Checking business details (for OV/EV certificates).
- Validating the accuracy of the provided information.
» The domain name (does it match the domain requested?).
» The public key (ensure it’s strong and has the correct format).
» Any additional details provided (e.g., organization name, country, etc.).
Command to inspect a CSR file ('server.csr') before signing:
$ openssl req -in server.csr -noout -text
This command prints out the details of the CSR to verify it.
[3] CA Side: Generate Certificate and Send to Applicant
After validating the Certificate Signing Request (CSR), the Certificate Authority (CA) signs the server's public key using its private key and issues a digital certificate. This certificate is then sent to the applicant, confirming the server's identity and enabling secure communication with clients.
Detailed Steps:
- CA Signs the Server’s Public Key (CSR):
- The CA uses its private key to sign the public key and information included in the CSR, generating a digital certificate.
» The CA creates a **self-signed certificate** for the server, attaching the public key and metadata, then signs it with its **private key**.
» This certificate will be issued to the server admin. - This certificate establishes trust by linking the server's public key to its domain name and other verified details.
CA Command to Sign the CSR:
$ openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365 -sha256
This step links the server's public key to the domain and signs it with the CA’s private key, creating the server’s certificate ('server.crt').
Explanation:
- 'server.csr': The CSR from the server admin.
- 'ca.crt': The CA’s certificate (which contains the CA’s public key).
- 'ca.key': The CA’s private key (used to sign the certificate).
- '-CAcreateserial': Generates a new serial number for the certificate.
- 'server.crt': The resulting signed certificate issued to the server.
- '-days 365': Specifies the certificate’s validity period (in this case, 365 days).
- '-sha256': Uses SHA-256 for signing (modern standard).
- 'server.csr': The CSR from the server admin.
- The CA uses its private key to sign the public key and information included in the CSR, generating a digital certificate.
- Generate an Intermediate Certificate (if needed)
- If the CA is an intermediate CA (not a root CA), it will use the root CA to sign the intermediate CA certificate and link it to the chain of trust.
- The intermediate CA certificate may be provided to the server admin to install alongside their own certificate to complete the trust chain.
- The CA may also use the following command to generate an intermediate certificate if they are not directly using the root certificate:
$ openssl req -new -key intermediateCA.key -out intermediateCA.csr
$ openssl ca -in intermediateCA.csr -out intermediateCA.crt -cert rootCA.crt -keyfile rootCA.key -days 365 -sha256
Explanation:
- 'intermediateCA.key': Intermediate CA’s private key.
- 'intermediateCA.csr': The CSR for the intermediate CA.
- 'rootCA.crt' and 'rootCA.key': The root CA’s certificate and private key used to sign the intermediate certificate.
- 'intermediateCA.key': Intermediate CA’s private key.
- If the CA is an intermediate CA (not a root CA), it will use the root CA to sign the intermediate CA certificate and link it to the chain of trust.
- CA Sends the Signed Certificate to the Server Admin:
- Once the certificate is signed, the CA needs to send the signed certificate ('server.crt') back to the server admin. This is typically done via email or made available for download.
- Along with the server certificate, the CA usually provides intermediate certificates (also called a CA bundle) that form part of the trust chain.
- Create a CA Bundle (if necessary)
The CA bundle includes the intermediate certificates that browsers will use to verify the chain of trust up to the root CA.
For example, if the CA used an intermediate certificate, the server admin will need to install both the server certificate and the CA bundle (intermediate certificates) to ensure proper trust.
To combine the intermediate certificates into a bundle:
$ cat intermediate1.crt intermediate2.crt > ca_bundle.crt
Explanation:
¤ 'intermediate1.crt', 'intermediate2.crt': The intermediate certificates provided by the CA.
¤ 'ca_bundle.crt': The combined CA bundle to be installed on the server.
- Send the Signed Server Certificate and Intermediate Certificates
¤ The CA typically emails the **signed server certificate** ('server.crt') to the server admin, or it can be made available for download from a portal.
¤ The **CA bundle** (intermediate certificates) is also provided in the email or download link.
- Verify the Issued Certificate
¤ The CA and the server admin can verify the issued certificate before deploying to the server.
Command to verify the issued server certificate:
$ openssl x509 -in server.crt -text -noout
This command prints out the contents of the issued certificate for inspection, ensuring that the domain, validity period, and signature are correct.
- Create a CA Bundle (if necessary)
- Once the certificate is signed, the CA needs to send the signed certificate ('server.crt') back to the server admin. This is typically done via email or made available for download.
The CA's Role
A Certificate Authority (CA) is a trusted entity responsible for verifying the identities of organizations and individuals requesting digital certificates. By validating Certificate Signing Requests (CSRs) and issuing digital certificates, the CA ensures the authenticity and security of encrypted communications between servers and clients, creating a trusted foundation for secure online interactions.
- Validation: The CA validates the information in the CSR (e.g., domain ownership, organization details).
- Signing: The CA uses its private key to sign the server's public key, generating a digital certificate.
- Issuance: The CA provides the server admin with the signed server certificate and any necessary intermediate certificates to establish a chain of trust.
- Trust Chain: The root CA (or intermediate CA) certificates are used by the client (browser) to trust the server's certificate.
In summary, the CA's role involves validating the request, signing the CSR using its private key, and issuing the server certificate and intermediate certificates, which the server admin installs to establish secure communication with clients.
The server administrator installs the issued server certificate, along with the corresponding private key and CA intermediate certificates, on the server. This setup ensures that the server can establish secure, trusted connections with clients by proving its identity during the TLS handshake and creating a chain of trust back to the Certificate Authority (CA).
Overview of the Process
- Applicant Generates Certificate Signing Request (CSR):
- Server Admin generates the private key and CSR.
- Submits the CSR to the CA for validation.
- Server Admin generates the private key and CSR.
- Certificate Authority (CA) Validates Identity:
- CA Validates the information (domain, organization).
- CA Validates the information (domain, organization).
- CA Generate Certificate and Send to Applicant:
- CA Signs the server's public key and issues the digital certificate.
- CA Signs the server's public key and issues the digital certificate.
- Install Certificate on the Server:
- Server Admin installs the server certificate, private key, and CA intermediate certificates on the server.
- Configures the web server (e.g., Apache, Nginx) to use the installed certificates for secure communication.
- Server Admin installs the server certificate, private key, and CA intermediate certificates on the server.
[4] Server Side: Install the Certificate on the Server
On the server side, the administrator installs the issued digital certificate along with the corresponding private key. This allows the server to authenticate its identity to clients and establish secure, encrypted connections during the TLS handshake, ensuring safe communication.
Detailed Steps:
- Store the Server Certificate: Once the server admin receives the certificate ('server.crt') from the CA, they need to store it on the server, along with the **private key** ('server.key') generated earlier.
Typically, files are stored as follows:
- 'server.crt' (the certificate received from the CA).
- 'server.key' (the private key created earlier).
- 'ca_bundle.crt' (intermediate certificates from the CA).
- 'server.crt' (the certificate received from the CA).
- Configure the Web Server: The next step is configuring the web server to use the installed certificate and key. Here’s how to do it for common web servers:
- For Apache HTTP Server:
Edit the Apache configuration file ('httpd.conf' or site-specific '.conf' file):
$ nano httpd.conf
SSLCertificateFile /path/to/server.crt
SSLCertificateKeyFile /path/to/server.key
SSLCertificateChainFile /path/to/ca_bundle.crt
Then restart Apache to apply the changes:
$ sudo systemctl restart apache2 - For Nginx:
Edit the Nginx configuration file ('nginx.conf' or site-specific '.conf' file):
$ nano nginx.conf
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /path/to/server.crt;
ssl_certificate_key /path/to/server.key;
ssl_trusted_certificate /path/to/ca_bundle.crt;
}
Then restart Nginx to apply the changes:
$ sudo systemctl restart nginx - Verify Installation
After installing the certificate, server admin can verify the installation using online tools like SSL Labs' SSL Test or SSL Shopper's SSL Checker or the 'openssl' command to ensure the certificate is correctly installed and trusted:
$ openssl s_client -connect www.example.com:443 -servername www.example.com
This command checks the connection, and the output will show the server certificate, chain of trust, and other TLS details.
- For Apache HTTP Server:
The TLS handshake is a critical process that establishes secure communication between a client (e.g., a browser) and a server. During the handshake, both parties agree on encryption algorithms, authenticate identities using digital certificates, and securely exchange cryptographic keys. This process ensures that data transmitted between the client and server is encrypted and safe from eavesdropping or tampering, providing a foundation for secure online communication.
- Client Hello: The client (browser) initiates the handshake by sending a ClientHello message. This message includes:
- SSL/TLS Version: The TLS versions supported by the client (e.g., TLS 1.2, 1.3).
- Cryptographic Algorithms: A list of supported encryption algorithms (cipher suites) like RSA, AES, ECDHE.
- Data Compression Method: Usually not used in modern TLS (typically null, as compression can lead to vulnerabilities).
- Client Random: A randomly generated value used in key generation.
- SSL/TLS Version: The TLS versions supported by the client (e.g., TLS 1.2, 1.3).
- Server Hello: The server responds with a ServerHello message. It includes:
- Cryptographic Algorithm Agreement: The chosen cipher suite (a cryptographic algorithm) from the client’s offered list.
- Session ID: An ID used for session resumption.
- Server’s Digital Certificate: The server sends its digital certificate, which contains the server's public key and is signed by the CA.
- Server Public Key: Embedded within the server's certificate (used for encryption in key exchange).
- Server Random: A randomly generated value for key generation.
- Cryptographic Algorithm Agreement: The chosen cipher suite (a cryptographic algorithm) from the client’s offered list.
- Certificate Verification: The client’s browser validates the server’s certificate by:
- Checking that the certificate is signed by a trusted Certificate Authority (CA) (using the pre-installed root and intermediate certificates).
- Ensuring the certificate is valid (not expired or revoked).
- Verifying that the domain matches the one in the certificate (e.g., 'https://example.com' must match the CN/SAN in the certificate).
- Checking that the certificate is signed by a trusted Certificate Authority (CA) (using the pre-installed root and intermediate certificates).
- Client Key Exchange:
- The client now needs to send a pre-master secret to the server, which will be used to generate the symmetric session key.
- The pre-master secret is encrypted using the server’s public key (from the server’s certificate) and sent to the server.
- If using modern Elliptic Curve Diffie-Hellman (ECDHE), the client and server will securely exchange elliptic curve public keys and generate the shared secret independently.
- The client now needs to send a pre-master secret to the server, which will be used to generate the symmetric session key.
- Finished Message (Client):
- The client sends a Finished message, which is encrypted using the newly established session key (derived from the pre-master secret and random values exchanged earlier).
- This message signals that the client is ready to start secure communication.
- The client sends a Finished message, which is encrypted using the newly established session key (derived from the pre-master secret and random values exchanged earlier).
- Finished Message (Server):
- The server responds with its own Finished message, also encrypted using the same session key.
- This indicates the server has successfully set up the secure channel.
[ Handshake Complete ]
- The server responds with its own Finished message, also encrypted using the same session key.
- Exchange Messages (Between Client and Server):
- Once the handshake is complete, both the client and server use the shared session key to encrypt all future communication using symmetric encryption (e.g., AES).
- This ensures that the data sent between the client and the server is confidential and protected from eavesdropping.
- Once the handshake is complete, both the client and server use the shared session key to encrypt all future communication using symmetric encryption (e.g., AES).
Conclusion
Public Key Infrastructure (PKI) and digital certificates have become indispensable for maintaining a secure online environment. By authenticating identities and encrypting communication, these technologies ensure that our web interactions remain private and trustworthy. As digital threats evolve, understanding PKI and its role in securing web traffic becomes increasingly important. Through this simplified explanation, we’ve shown how PKI works behind the scenes to protect sensitive information and guarantee the safety of our digital lives. By mastering the basics of PKI, individuals and businesses alike can contribute to a safer, more secure internet.
Disclaimer: This documentation is intended for educational purposes only. The content provided herein is meant to inform and educate individuals about security practices, techniques, and tools. Security-Science does not support, endorse, or encourage any illegal or unethical activities, including but not limited to unauthorized access to computer systems, networks, or data. Users are advised to apply the knowledge gained responsibly and ensure compliance with all applicable laws and regulations. Security-Science shall not be held liable for any misuse of the information provided.