Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Establishing a Private Certificate Authority and Issuing Server Certificates

Tech 1

Prerequisites

Two CentOS 7 hosts are required: one for the Certificate Authority (CA) and another for the web server.

Creating the Private Certificate Authority

Verify OpenSSL Configuration

Ensure the OpenSSL configuration file specifies the correct CA directory structure.

cat /etc/pki/tls/openssl.cnf

Relevant configuration section:

[ CA_default ]
dir             = /etc/pki/CA
certs           = $dir/certs
crl_dir         = $dir/crl
database        = $dir/index.txt
new_certs_dir   = $dir/newcerts
certificate     = $dir/cacert.pem
serial          = $dir/serial
private_key     = $dir/private/cakey.pem

Create Required Directories and Files

mkdir -p /etc/pki/CA/{certs,crl,newcerts}
touch /etc/pki/CA/index.txt
echo 01 > /etc/pki/CA/serial

Generate CA Private Key

Create a secure 2048-bit RSA private key for the CA.

(umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)

Generate Self-Signed CA Certificate

Create the root certificate using the x509 format for private CAs.

openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem \
  -out /etc/pki/CA/cacert.pem -days 365

Note: The country, state, and locality information provided here must match subsequent certificate requests.

Generating a Certificate Signing Request for HTTP Server

Create SSL Directory

mkdir /etc/httpd/ssl

Generate Server Private Key

(umask 077; openssl genrsa -out /etc/httpd/ssl/server.key 2048)

Create Certificate Signing Request

openssl req -new -key /etc/httpd/ssl/server.key \
  -out /etc/httpd/ssl/server.csr -days 365

Ensure the geographic information matches the CA certificate details.

Create Certificate Extentions File

Define subject alternative names for the certificate.

echo "subjectAltName = DNS:*.example.com, DNS: example.com" > /etc/httpd/ssl/server.ext

Transfer both server.csr and server.ext files to the CA host's /tmp directory.

Signing the Server Certificate on the CA

Issue the Certificate

openssl ca -in /tmp/server.csr -out /tmp/server.crt \
  -days 365 -extfile /tmp/server.ext

Transfer the signed certificate server.crt back to the web server host.

Configuring Apache HTTP Server with SSL

Install SSL Module

yum install -y mod_ssl

Configure SSL Virtual Host

Edit the SSL configuration file:

vim /etc/httpd/conf.d/ssl.conf

Update the certificate paths:

SSLCertificateFile /etc/httpd/ssl/server.crt
SSLCertificateKeyFile /etc/httpd/ssl/server.key

Restart HTTP Service

systemctl restart httpd

Browser Configuration

Import Root Certificate

Import the CA root certificate (/etc/pki/CA/cacert.pem) into the browser's trusted root certificate authorities.

Configure Local DNS

Add server domain-to-IP mapping to the client's hosts file for testing.

Access via HTTPS

Navigate to https://example.com/ in the browser.

Advanced Certificate Extensions

IP Address SAN Example

keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectAltName=@alt_names

[alt_names]
IP.1=192.168.1.10
IP.2=192.168.1.20

DNS SAN Example

keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectAltName=@alt_names

[alt_names]
DNS.1=example.com
DNS.2=www.example.com

The extendedKeyUsage field specifeis certificate purposes:

  • serverAuth: Authenticates remote servers
  • clientAuth: Authenticates clients to servers
  • codeSigning: Verifies software integrity
  • emailProtection: Secures email messages
  • timeStamping: Timestamp signing authority

If unspecified, all application policies are permitted.

Tags: ssl

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.