Featured image of post SSL in a Nutshell

SSL in a Nutshell

SSL Explained


The History of SSL/TLS

SSL (Secure Sockets Layer) was first developed by Netscape in 1994 to secure web traffic. However, early versions (SSL 2.0 and 3.0) had serious vulnerabilities.

To fix these issues, SSL evolved into TLS (Transport Layer Security), which is the standard we use today.

Key SSL/TLS Milestones

YearVersionNotes
1994SSL 2.0First version, insecure
1996SSL 3.0Improved, but flawed
1999TLS 1.0Replaces SSL, more secure
2006TLS 1.1Fixes CBC attacks
2008TLS 1.2Stronger encryption
2018TLS 1.3Faster, more secure

💡 Verdict: SSL is dead, and TLS 1.2+ is the modern standard.

Further Reading:


SSL/TLS and Certificates

SSL/TLS relies on certificates to prove identity and enable encryption. These certificates are issued by a Certificate Authority (CA) and contain:

  • The domain name the certificate is for.
  • The public key used for encryption.
  • The CA’s signature to verify authenticity.

How SSL/TLS Works (Simplified)

  1. Client (Browser) connects to a website over HTTPS.
  2. Server sends its SSL certificate.
  3. Client verifies certificate using CA trust.
  4. Client and server establish an encrypted session using TLS.

This prevents man-in-the-middle attacks and ensures privacy.


SSL/TLS vs. Other Security Protocols

FeatureSSL/TLSSSHIPsecVPN
PurposeEncrypts web traffic (HTTPS)Secure remote accessSecure network packetsEncrypted tunnels
Used ByWebsites, APIsDevOps, SysAdminsVPNs, firewallsCorporate networks
AuthenticationCertificatesPublic keysShared keysMultiple methods
ProtocolApplication LayerApplication LayerNetwork LayerNetwork Layer

💡 Verdict: SSL/TLS is for web encryption, while SSH, IPsec, and VPNs serve different purposes.


10 SSL/TLS Code Examples

1. Checking SSL Certificates in Linux (CLI)

1
openssl s_client -connect google.com:443 -servername google.com

2. Generating a Self-Signed SSL Certificate (OpenSSL)

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

3. Using SSL in Python (Requests Library)

1
2
3
4
import requests

response = requests.get("https://example.com", verify=True)
print(response.text)

4. Enabling HTTPS in a Flask App

1
2
3
4
from flask import Flask

app = Flask(__name__)
app.run(ssl_context=('cert.pem', 'key.pem'))

5. Using SSL in C# (HttpClient)

1
2
3
4
5
using System.Net.Http;

HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("https://example.com");
Console.WriteLine(await response.Content.ReadAsStringAsync());

6. Using SSL in Java (HttpsURLConnection)

1
2
3
4
5
6
7
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;

URL url = new URL("https://example.com");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.connect();
System.out.println("Response Code: " + con.getResponseCode());

7. Using SSL in JavaScript (Node.js HTTPS Request)

1
2
3
4
5
const https = require("https");

https.get("https://example.com", (res) => {
    console.log("Status Code:", res.statusCode);
});

8. Enforcing HTTPS in an Nginx Server

1
2
3
4
5
6
7
server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/nginx/ssl/cert.pem;
    ssl_certificate_key /etc/nginx/ssl/key.pem;
}

9. Checking SSL/TLS Version of a Website (CLI)

1
openssl s_client -connect example.com:443 -tls1_2

10. Using SSL in Golang

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
package main

import (
    "crypto/tls"
    "net/http"
)

func main() {
    tr := &http.Transport{
        TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    }
    client := &http.Client{Transport: tr}
    resp, _ := client.Get("https://example.com")
    fmt.Println(resp.Status)
}

Key Takeaways

  • SSL is outdated—TLS 1.2 and TLS 1.3 are the modern standards.
  • SSL/TLS uses certificates for encryption and authentication.
  • HTTPS protects against eavesdropping and MITM attacks.
  • TLS alternatives include SSH (remote access), IPsec (network encryption), and VPNs (secure tunnels).

References

  1. TLS Wikipedia
  2. How HTTPS Works
  3. SSL vs. TLS
  4. OpenSSL Commands