Configuring SSL/TLS Protocols and Ciphers
1. Setting SSL Protocols
| Directive | Values | Description |
|---|---|---|
| SSLProtocol | -all, SSLv2, SSLv3, TLSv1, TLSv1.1, TLSv1.2, TLSv1.3 |
Configures the SSL/TLS protocols to be used. It is recommended to use TLSv1.2 and TLSv1.3 only for security reasons. |
| SSLHonorCipherOrder | On, Off |
If set to On, the server will prefer its cipher list over the client's. This is useful for enforcing a specific order of cipher suites. |
Example: Enabling TLS 1.2 and 1.3
<VirtualHost *:443>
SSLEngine on
SSLProtocol -all +TLSv1.2 +TLSv1.3
SSLHonorCipherOrder on
SSLCertificateFile /path/to/certificate.crt
SSLCertificateKeyFile /path/to/private.key
</VirtualHost>
2. Disabling Deprecated Protocols
| Protocol | Status | Description | Recommended Action |
|---|---|---|---|
| SSLProtocol | DEPRECATED | SSL v2 and v3 protocols | Disable using -SSLv2 -SSLv3 |
| SSLProtocol | NEW | TLS v1.0 and v1.1 | Disable using -TLSv1 -TLSv1.1 |
Example: Disabling Deprecated Protocols
<VirtualHost *:443>
SSLEngine on
SSLProtocol -all +TLSv1.2 +TLSv1.3
SSLCipherSuite HIGH:!aNULL:!MD5
</VirtualHost>
Note: Ensure that your clients support TLS v1.2 or higher before disabling older protocols.
3. Configuring SSL Cipher Suites
| Cipher Suite | Description | Security Level | Notes |
|---|---|---|---|
| ECDHE-RSA-AES256-GCM-SHA384 | Elliptic Curve Diffie-Hellman with RSA key exchange, AES-256 in GCM mode, SHA-384 hash | High | Recommended for strong security |
| ECDHE-ECDSA-AES256-GCM-SHA384 | Elliptic Curve Diffie-Hellman with ECDSA key exchange, AES-256 in GCM mode, SHA-384 hash | High | Alternative to RSA-based cipher suite |
| ECDHE-RSA-AES128-GCM-SHA256 | Elliptic Curve Diffie-Hellman with RSA key exchange, AES-128 in GCM mode, SHA-256 hash | Medium | Good balance of performance and security |
| ECDHE-ECDSA-AES128-GCM-SHA256 | Elliptic Curve Diffie-Hellman with ECDSA key exchange, AES-128 in GCM mode, SHA-256 hash | Medium | Alternative to RSA-based cipher suite |
| ECDHE-RSA-AES256-SHA384 | Elliptic Curve Diffie-Hellman with RSA key exchange, AES-256 in CBC mode, SHA-384 hash | Medium | Legacy cipher suite, less preferred due to CBC mode |
| ECDHE-ECDSA-AES256-SHA384 | Elliptic Curve Diffie-Hellman with ECDSA key exchange, AES-256 in CBC mode, SHA-384 hash | Medium | Alternative to RSA-based cipher suite |
Example: Setting Cipher Suites in Apache Configuration
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /path/to/certificate.crt
SSLCertificateKeyFile /path/to/private.key
SSLCipherSuite ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256
SSLProtocol all -SSLv2 -SSLv3
</VirtualHost>
Note: The
SSLCipherSuite directive specifies the list of cipher suites that are allowed for use in TLS connections. It is important to prioritize secure and modern cipher suites while disabling older, insecure ones.
4. Enabling Perfect Forward Secrecy
| Directive | Values | Description |
|---|---|---|
| SSLProtocol | -all +TLSv1.2 +TLSv1.3 |
Enables TLS 1.2 and 1.3, disables older versions for security |
| SSLCipherSuite | ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256 |
Modern cipher suites supporting forward secrecy |
| SSLHonorCipherOrder | on |
Enforces server preference over client cipher order |
Example: Enabling Perfect Forward Secrecy
<VirtualHost *:443>
SSLEngine on
SSLProtocol -all +TLSv1.2 +TLSv1.3
SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256
SSLHonorCipherOrder on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/private.key
</VirtualHost>
Note: Perfect Forward Secrecy is achieved by using ECDHE (Elliptic Curve Diffie-Hellman Ephemeral) key exchange algorithms in the cipher suite.
5. Setting Cipher Order
| Cipher | Security Level | Description |
|---|---|---|
| ECDHE-RSA-AES256-GCM-SHA384 | NEW | High security, modern TLS 1.2/1.3 |
| ECDHE-ECDSA-AES256-GCM-SHA384 | NEW | High security, ECDSA variant |
| ECDHE-RSA-AES128-GCM-SHA256 | High | Fast, secure, widely supported |
| ECDHE-ECDSA-AES128-GCM-SHA256 | High | ECDSA variant of above |
| ECDHE-RSA-AES256-SHA384 | Medium | Legacy TLS 1.2, still secure |
| ECDHE-ECDSA-AES256-SHA384 | Medium | ECDSA variant of above |
| ECDHE-RSA-AES128-SHA256 | Medium | Legacy TLS 1.2, still secure |
| ECDHE-ECDSA-AES128-SHA256 | Medium | ECDSA variant of above |
| AES256-GCM-SHA384 | DEPRECATED | Legacy, not recommended for new setups |
| AES128-GCM-SHA256 | DEPRECATED | Legacy, not recommended for new setups |
Example: Setting Cipher Order in Apache Config
<IfModule mod_ssl.c>
SSLCipherSuite ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256
</IfModule>
Note: The order of ciphers in
SSLCipherSuite determines which cipher is selected first when negotiating a secure connection. Place more preferred ciphers at the beginning of the list.
6. Configuring SSL Session Cache
| Directive | Values | Description |
|---|---|---|
| SSLSessionCache | shmcb:/path/to/cache(size), dbm:/path/to/cache, none |
Configures the SSL session cache to store session data for reuse. shmcb is recommended for performance. |
| SSLSessionCacheTimeout | 300 (seconds) |
Defines how long a session is cached before it's considered expired. |
Example: Setting up Shared Memory Session Cache
SSLSessionCache shmcb:/var/cache/mod_ssl/scache(512000)
SSLSessionCacheTimeout 300
Note: The
shmcb cache is shared among worker processes and is the most efficient for high-traffic sites.
Warning: Session cache paths must be writable by the Apache user.
7. Setting SSL Session Timeout
| Directive | Values | Description |
|---|---|---|
| SSLSessionCache | shmcb:/path/to/cache(size), shared:foo:size, none |
Configures the SSL session cache. The shmcb type is recommended for production use. |
| SSLSessionTimeout | seconds |
Defines the timeout for SSL sessions in seconds. Default is 300 (5 minutes). |
Example: Configuring SSL Session Cache and Timeout
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/key.pem
# Session cache with 512MB shared memory
SSLSessionCache shmcb:/var/cache/mod_ssl/(1048576)
# Session timeout of 1 hour (3600 seconds)
SSLSessionTimeout 3600
</VirtualHost>
Note: The
SSLSessionCache directive must be set to enable session caching. If not configured, sessions will not be reused, and each client will need to re-negotiate the SSL/TLS handshake for every new connection.
8. Enabling OCSP Stapling
OCSP (Online Certificate Status Protocol) stapling allows the web server to provide the certificate status directly to the client, reducing the need for clients to contact the CA's OCSP server.
| Directive | Description | Default | Notes |
|---|---|---|---|
| SSLUseStapling | Enables OCSP stapling for SSL/TLS connections. | Off | Requires OpenSSL 1.0.2 or later. |
| SSLStaplingCache | Configures the cache for OCSP responses. | shmcb:logs/ssl_stapling(128000) | Must be set to enable stapling. |
| SSLStaplingTimeout | Maximum time (in seconds) to wait for OCSP response. | 30 | Set to prevent long delays in connection establishment. |
| SSLStaplingReturnResponderErrors | Controls whether to return OCSP errors to the client. | On | Set to Off to suppress OCSP errors from client. |
Example: Enabling OCSP Stapling
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/key.pem
SSLUseStapling on
SSLStaplingCache "shmcb:logs/ssl_stapling(128000)"
SSLStaplingTimeout 30
</VirtualHost>
Note: OCSP stapling is supported in Apache 2.4.8+ with OpenSSL 1.0.2+. Ensure that the certificate issuer supports OCSP stapling.
9. Configuring OCSP Responder Settings
| Directive | Description | Default | Notes |
|---|---|---|---|
| SSLUseStapling | Enables OCSP stapling for SSL connections | Off | Requires mod_ssl and OpenSSL 0.9.8 or later |
| SSLStaplingCache | Configures the cache for OCSP responses | shmcb:logs/ssl_stapling(128000) | Can use 'shmcb', 'dbm', or 'socache' |
| SSLStaplingTimeout | Timeout for OCSP response fetching | 30 seconds | Set to 0 to disable OCSP fetching |
| SSLStaplingReturnResponderErrors | Whether to return OCSP errors to clients | On | Set to Off to suppress OCSP errors |
| SSLStaplingResponderTimeout | Timeout for OCSP responder connection | 5 seconds | Used when fetching OCSP responses |
Example: Enabling OCSP Stapling
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/private.key
# Enable OCSP stapling
SSLUseStapling on
# Configure stapling cache
SSLStaplingCache "shmcb:/var/run/ssl_stapling(128000)"
# Set timeout for OCSP response fetching
SSLStaplingTimeout 30
# Return OCSP errors to client
SSLStaplingReturnResponderErrors on
</VirtualHost>
Note: OCSP stapling reduces the need for clients to contact the CA directly, improving performance and privacy.
10. Forcing HTTPS Redirects
| Directive | Description | Example |
|---|---|---|
| Redirect | Permanently redirects HTTP requests to HTTPS | Redirect permanent / https://example.com/ |
| RewriteEngine | Enables rewrite engine for conditional redirects | RewriteEngine on |
| RewriteCond | Condition to check if HTTPS is off | RewriteCond %{HTTPS} off |
| RewriteRule | Redirects all HTTP traffic to HTTPS | RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] |
Example: Basic HTTPS Redirect
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
Example: Conditional HTTP to HTTPS Redirect
<VirtualHost *:80>
ServerName example.com
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
Note: Ensure that the SSL certificate is properly configured before setting up redirects to avoid mixed content issues.
11. Testing SSL Configuration
Example: Test SSL configuration with OpenSSL
openssl s_client -connect example.com:443 -servername example.com
| Command | Description | Notes |
|---|---|---|
| openssl s_client | Connects to an SSL/TLS server and displays the certificate | Useful for debugging SSL handshake issues |
| -connect | Specifies the host and port to connect to | Format: host:port |
| -servername | Specifies the SNI (Server Name Indication) hostname | Required for servers with multiple SSL certificates |
Note: Ensure that the server supports SNI for accurate testing.
Example: Check supported TLS versions
openssl ciphers -v 'ALL:COMPLEMENTOFALL' | grep -E 'TLSv1|TLSv1.1|TLSv1.2|TLSv1.3'
Comparison: SSL/TLS Protocol Support
- TLS 1.3: Most secure, fastest handshake
- TLS 1.2: Widely supported, secure
- TLS 1.1: Deprecated, insecure
- TLS 1.0: Deprecated, insecure
- SSL 2/3: Deprecated, insecure
12. Implementing Modern SSL Best Practices
Example: Basic SSL Configuration with Modern Practices
<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/private.key
SSLCertificateChainFile /path/to/chain.pem
# Modern TLS protocols
SSLProtocol -all +TLSv1.2 +TLSv1.3
# Strong cipher suites
SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256
# Disable weak ciphers and protocols
SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256
SSLHonorCipherOrder off
# Security headers
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "DENY"
# OCSP stapling
SSLUseStapling on
SSLStaplingCache "shmcb:logs/ocsp(128000)"
# HSTS preloading (requires manual submission)
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</IfModule>
</VirtualHost>
| Directive | Description | Notes |
|---|---|---|
| SSLProtocol | Enables/disables SSL/TLS versions | Use -all +TLSv1.2 +TLSv1.3 for modern security |
| SSLCipherSuite | Defines allowed cipher suites | Must exclude weak and outdated ciphers |
| SSLHonorCipherOrder | Controls cipher preference order | off allows server to choose best cipher |
| SSLUseStapling | Enables OCSP stapling | Improves performance and security |
| SSLStaplingCache | Configures OCSP cache | Use shmcb: for shared memory caching |
Note: Ensure that your certificate and key files are properly secured with restricted permissions (e.g.,
chmod 600) to prevent unauthorized access.
Warning: Older protocols like SSLv2 and SSLv3 must be disabled to avoid vulnerabilities such as POODLE.
Modern SSL Best Practices Summary
- Enable only TLSv1.2 and TLSv1.3
- Use strong cipher suites (ECDHE + AES256/GCM or ChaCha20)
- Disable weak ciphers and protocols
- Enable OCSP stapling for improved performance
- Set HSTS headers to enforce secure connections
- Secure private keys with appropriate file permissions