Skip to content

Self-Signed Certificates

Self-signed certificates are useful for development, testing, or internal deployments where you don’t need public certificate authority validation. While not recommended for production internet-facing deployments, they provide encryption and can be quickly generated without external dependencies.

Ensure you have OpenSSL installed on your system:

Terminal window
# RHEL/CentOS/Fedora
sudo dnf install openssl
# Ubuntu/Debian
sudo apt-get install openssl
# Verify installation
openssl version

Create a 2048-bit RSA private key:

Terminal window
openssl genrsa -out yourdomain.com.key 2048

Generate a Certificate Signing Request with your organization details:

Terminal window
openssl req -new -sha256 -key yourdomain.com.key \
-subj "/C=NL/ST=Noord Holland/L=Amsterdam/O=Your Organization/OU=IT Department/CN=yourdomain.com/emailAddress=admin@yourdomain.com" \
-out yourdomain.com.csr
  • C=NL - Country (2-letter code)
  • ST=Noord Holland - State or Province
  • L=Amsterdam - City or Locality
  • O=Your Organization - Organization name
  • OU=IT Department - Organizational Unit
  • CN=yourdomain.com - Common Name (your domain)
  • emailAddress=admin@yourdomain.com - Contact email

Create a configuration file to include Subject Alternative Names (SAN) for wildcard support:

Terminal window
cat > yourdomain.com.conf << EOF
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no
[req_distinguished_name]
C = NL
ST = Noord Holland
L = Amsterdam
O = Your Organization
OU = IT Department
CN = yourdomain.com
emailAddress = admin@yourdomain.com
[v3_req]
keyUsage = keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = yourdomain.com
DNS.2 = *.yourdomain.com
EOF

Create the self-signed certificate valid for 365 days:

Terminal window
openssl x509 -req -in yourdomain.com.csr \
-signkey yourdomain.com.key \
-out yourdomain.com.crt \
-days 365 \
-extensions v3_req \
-extfile yourdomain.com.conf

Alternative: Generate Key and Certificate in One Step

Section titled “Alternative: Generate Key and Certificate in One Step”

You can also generate both the key and certificate simultaneously:

Terminal window
openssl req -x509 -newkey rsa:2048 -keyout yourdomain.com.key -out yourdomain.com.crt \
-days 365 -nodes \
-config yourdomain.com.conf

The -nodes option creates an unencrypted private key (no passphrase required).

Surfly requires the private key and certificate to be combined in a single PEM file:

Terminal window
cat yourdomain.com.key yourdomain.com.crt > yourdomain.com.pem

Check that the combined file contains both the private key and certificate:

Terminal window
# Should show "RSA PRIVATE KEY"
grep -A 1 "BEGIN RSA PRIVATE KEY" yourdomain.com.pem
# Should show "CERTIFICATE"
grep -A 1 "BEGIN CERTIFICATE" yourdomain.com.pem

Copy the certificate to your Surfly installation directory:

Terminal window
# Create certificates directory if it doesn't exist
mkdir -p ~/surfly/certs/
# Copy the combined certificate
cp yourdomain.com.pem ~/surfly/certs/
# Set appropriate permissions
chmod 600 ~/surfly/certs/yourdomain.com.pem
chown client:client ~/surfly/certs/yourdomain.com.pem

For better browser compatibility in development environments, you can create your own Certificate Authority and install it as trusted:

Terminal window
openssl genrsa -out ca.key 4096
Terminal window
openssl req -x509 -new -nodes -key ca.key -days 3650 -out ca.crt \
-subj "/C=NL/ST=Noord Holland/L=Amsterdam/O=Your Organization CA/CN=Your Organization Root CA"
Terminal window
openssl x509 -req -in yourdomain.com.csr -CA ca.crt -CAkey ca.key \
-CAcreateserial -out yourdomain.com.crt -days 365 \
-extensions v3_req -extfile yourdomain.com.conf

Copy your root CA certificate to the Surfly trust directory:

Terminal window
mkdir -p ~/surfly/ca_trust/
cp ca.crt ~/surfly/ca_trust/

Check your certificate details:

Terminal window
# View certificate information
openssl x509 -in yourdomain.com.crt -text -noout
# Verify certificate against private key
openssl x509 -noout -modulus -in yourdomain.com.crt | openssl md5
openssl rsa -noout -modulus -in yourdomain.com.key | openssl md5

Both commands should return the same hash value, confirming the certificate matches the private key.

To avoid security warnings during development, you can add your self-signed certificate to your browser’s trusted certificates:

  1. Go to chrome://settings/certificates
  2. Click “Authorities” tab
  3. Click “Import” and select your ca.crt file (if you created a CA)
  4. Check “Trust this certificate for identifying websites”
  1. Go to about:preferences#privacy
  2. Scroll to “Certificates” and click “View Certificates”
  3. Go to “Authorities” tab
  4. Click “Import” and select your ca.crt file
  • Store private keys securely with restricted permissions (chmod 600)
  • Use separate certificates for different environments
  • Regularly rotate certificates (recommended: yearly)
  • Use self-signed certificates only on trusted networks
  • Consider using VPN or network isolation for services with self-signed certificates
  • Monitor certificate expiration dates