Security, HTTPS

image

Man in the middle attack

MITM (Man-In-The-Middle attack) = When you have 2 machines communicating over HTTP, any malicious actor who is well trained can hijack the communication channel and then intercept the IP packet.

Encryption and decryption

Encryption is the process by which a readable message is converted to an unreadable form (cipher text) to prevent unauthorized parties from reading it.

Decryption is the process of converting an encrypted message back to its original (readable) format.

Types:

  • Symmetric Encryption
    • a type of encryption that relies on a single key on both encrypt and decrypt data. As the same key should be shared between two parties. A hacker may still steal the key.
  • Asymmetric Encryption
    • also known-as public-key encryption, and it relies on two keys (a public key and a private key) - to encrypt and decrypt data. But it is slower.

Public and private key

Plaintext + key = cipher text:

hello + 2jd8932kd8 = X5xJCSycg14=

Cipher text + key = plaintext:

X5xJCSycg14= + 2jd8932kd8 = hello

HTTPS

  • HTTPS is an extension of HTTP, that runs on top of TLS.
  • HTTPS = HTTP + TLS/SSL
  • TLS = Transport Layer Security
  • SSL = Secure Sockets Layer
  • HTTPS uses TLS (SSL) to encrypt normal HTTP requests and responses.

So, we need interceptors to encode and decode the data every time we send and receive data.

SSL Certificate = a digital certificate signed by certificate authority and it contains server's public key.

A website's SSL/TLS certificate, which is shared publicly, contains the public key, and the private key is installed on the origin server — it is "owned" by the website.

  • It is given to some Domain name or wildcard Domains (to all subdomains).

TLS handshake process:

  • The client sends a client hello (a string of random bytes) to the server
  • The server responds with a server hello (another string of random bytes) as well as its SSL certificate which contains the public key
  • The client verifies that the server's SSL certificate was issued by a certificate authority
  • The client sends a premaster secret (another string of random bytes encrypted with the server's public key and can be decrypted by server's private key) to the server
  • The server decrypts the premaster secret using its private key
  • The client and the server use the client hello, the server hello, and the premaster secret to then generate the same symmetric-encryption session keys
  • The client sends a "finished" message that is encrypted with a session key
  • The server sends a "finished" message that is encrypted with a session key
  • The handshake is completed, and communication continues using the session keys.
SuperMade with Super