Theory

Network Sockets

Socket - is one endpoint of a two way communication link between two programs running on the network. Sockets have two main states: They are either connected and facilitating an ongoing network communication, or they are waiting for an incoming connection to connect to them. The listening socket is called the server, and the socket that requests a connection with the listening socket is called a client. You could use netstat command to manage and discover your own sockets, for what and where are they used. The "Active Internet" section lists the network connections that are (or will be) established to external devices. The "UNIX domain" section lists the connections that have been established within your computer between different applications, processes, and elements of the operating system.

TCP Socket States

Socket State
Explanation

LISTEN

Servers-side. Socket waiting for a connection request

SYN-SENT

Client-side. Socket has made a connection request and wait.

SYN-RECEIVED

Server-side. Socket is waiting for a connection ack after accepting request

ESTABLISHED

Server and Client. A working connection has been established between the server and the client, allowing for data transfer

FIN-WAIT-1

Server and Client. Socket is waiting for a termination request or for ack of previous termination request

FIN-WAIT-2

Server and Client. Socket is waiting for a termination request

CLOSE-WAIT

Socket is waiting for a termination request ack from local user

CLOSING

Server and Client. Socket is waiting for a termination request ack from remote socket

LAST-ACK

Server and Client. Socket is waiting ack of termination from remote socket

TIME-WAIT

Server and Client. Server and Client. Checking if termination ack was received

CLOSED

No connection, socket is terminated

DMZ

DMZ, or Demilitarized Zone, in the context of computer networks, is a segregated area that acts as a buffer between a trusted internal network and an untrusted external network, such as the internet. It typically contains servers that need to be accessible from the internet. like web servers or email servers. The DMZ helps enhance security by isolation these servers from the internal network, by reducing the risk of unauthorized access to sensitive information.

SSL

SSL, or Secure Sockets Layer, is an encryption-based Internet security protocol. It was first developed by Netscape in 1995 for the purpose of ensuring privacy, authentication, and data integrity in Internet communications. SSL is the predecessor to the modern TLS encryption used today.

What is an SSL certificate?

SSL can only be implemented by websites that have an SSL certificate (technically a "TLS certificate"). An SSL certificate is like an ID card or a badge that proves someone is who they say they are. SSL certificates are stored and displayed on the Web by a website's or application's server.

One of the most important pieces of information in an SSL certificate is the website's public key. The public key makes encryption and authentication possible. A user's device views the public key and uses it to establish secure encryption keys with the web server. Meanwhile the web server also has a private key that is kept secret; the private key decrypts data encrypted with the public key.

What are the types of SSL certificates?

There are several different types of SSL certificates. One certificate can apply to a single website or several websites, depending on the type:

  • Single-domain: A single-domain SSL certificate applies to only one domain (a "domain" is the name of a website, like www.cloudflare.com).

  • Wildcard: Like a single-domain certificate, a wildcard SSL certificate applies to only one domain. However, it also includes that domain's subdomains. For example, a wildcard certificate could cover www.cloudflare.com, blog.cloudflare.com, and developers.cloudflare.com, while a single-domain certificate could only cover the first.

  • Multi-domain: As the name indicates, multi-domain SSL certificates can apply to multiple unrelated domains.

OpenSSL

OpenSSL is a widely-used open-source toolkit for implementing the SSL and TLS (Transport Layer Security) protocols. It provides a set of cryptographic functions and utilities that enable secure communication over a computer network. OpenSSL is commonly used for creating and managing SSL/TLS certificates, generating cryptographic keys, and performing various cryptographic operations.

Here are some basic and common OpenSSL commands on Linux:

  1. Check OpenSSL Version:

openssl version
  1. Generate a Private Key:

openssl genprsa -out private-key.pem 2048
  1. Generate a Public Key from a Private Key:

openssl rsa -in private-key.pem -pubout -out public-key.pem
  1. Generate a Self-Signed Certificate:

openssl req -x509 -newkey rsa:2048 -keyout private_key.pem -out certificate.pem -days 365
  1. View Certificate Information:

openssl x509 -in certificate.pem -text -noout
  1. Encrypt/Decrypt a File using RSA:

    • Encrypt:

      openssl rsautl -encrypt -inkey public_key.pem -pubin -in plaintext.txt -out encrypted_data.bin
    • Decrypt:

      openssl rsautl -decrypt -inkey private_key.pem -in encrypted_data.bin -out decrypted_data.txt
  2. Hashing:

    • Generate MD5 hash:

      openssl md5 file.txt
    • Generate SHA-256 hash:

      openssl sha256 file.txt

Last updated