Self-Signed Certificates Explained: What They Are and When to Use Them

Sundaram GSundaram G
3 min read

A self-signed SSL certificate is a digital certificate that you sign yourself, rather than obtaining it from a trusted Certificate Authority (CA). While not valid for production use, it’s incredibly useful for local development and testing purposes.

Example Scenario: Local Testing of a Login Page

You are a cybersecurity student working on a lab project where you've set up a simple login page on your local machine — something like http://localhost/login.html.

Now, you want to:

  • Simulate secure user login (so usernames and passwords are not sent in plain text)

  • Test how HTTPS behaves

  • Practice intercepting traffic using tools like Burp Suite or Wireshark

But here's the problem:

  • Your browser or tools may block or limit features if you're using plain HTTP

  • Some security features (like secure cookies or testing SSL/TLS behavior) only work with HTTPS


What You Do Instead

You generate a self-signed SSL certificate, set up HTTPS, and access your site at:
https://localhost/login.html

Now, everything behaves like a real-world secure website:

  • Data (like login credentials) is encrypted

  • You can observe how SSL works locally

  • Tools like Burp Suite can capture and analyze encrypted traffic

  • You simulate a realistic attack-defense environment

Why Use a Self-Signed Certificate Locally?

1. Encrypt Local Traffic

Simulate a secure environment, even when working on localhost. This ensures that data passed between your browser and server is encrypted.

2. Test HTTPS-Only Features

Modern web features and APIs demand HTTPS — even for local development. A self-signed cert unlocks this functionality.

3. Cost-Free & Easy

No need to purchase or renew certificates. Self-signed certs are free and fast to create.

4. Bypass HTTPS Warnings for Local Dev

Yes, browsers will complain — but for local use, you can manually trust your cert and continue testing securely.

How to Use a Self-Signed Certificate (Quick Steps)

Step 1: Generate the Certificate Using OpenSSL

Open your terminal and run:

openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365

Now you have:

  • key.pem → your private key

  • cert.pem → your self-signed certificate


Step 2: Configure Your Local Server

You need to tell your web server to use the self-signed certificate:

🔸 For Node.js it will be like:

const https = require('https');
const fs = require('fs');

const options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('Hello from HTTPS!');
}).listen(3000, () => {
  console.log('Server running at https://localhost:3000/');
});

You can also configure Apache, Nginx, or XAMPP similarly. NOTE: the keys are stored in the directory from where you ran the command.


Step 3: Access Your Site Locally with HTTPS

Open your browser and go to:

https://localhost:3000

You’ll see a browser warning ("Connection not secure" or "Untrusted certificate").

Click:

  • Advanced → Proceed anyway (in Chrome)

  • Accept the Risk and Continue (in Firefox)

Now your local site is using HTTPS with encryption.

Limitations

  • Not Trusted by Browsers: You’ll see "Your connection is not private" warnings.

  • Not for Production: Never use self-signed certs for public websites. They lack chain of trust.

  • Manual Trust Needed: Users (you) must manually approve them each time or install them into the trusted certificate store (in browser settings).

0
Subscribe to my newsletter

Read articles from Sundaram G directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sundaram G
Sundaram G