Debug School

Cover image for Perfect Forward Secrecy
Suyash Sambhare
Suyash Sambhare

Posted on

Perfect Forward Secrecy

Perfect Forward Secrecy (PFS), sometimes known as forward secrecy (FS), is an encryption scheme that periodically and automatically changes the keys used to encrypt and decrypt information. This continuing process guarantees that even if the most recent key is compromised, only a small quantity of important information is revealed.
Web pages, calling applications, and messaging apps all use encryption tools with perfect forward secrecy, which change keys as frequently as each call or message in a conversation, or every reload of an encrypted webpage. This way, the loss or theft of a single decryption key does not jeopardise any other sensitive information, including additional keys.
Inspect the encrypted, plain-text version of the data exchange from the session beginning key agreement phase to see if forward secrecy is present. The encryption system of an application or website delivers perfect forward secrecy if the encryption key is not revealed during the session.

Perfect Forward Secrecy

Perfect forward secrecy helps prevent session keys against compromise, even if the server's private key is susceptible. An encryption system with forward secrecy generates a unique session key for each user-initiated session, as part of specialised key agreement protocols. In this way, even if a single session key is compromised, the remainder of the system's data is still safe. Only the data that is protected by the compromised key is vulnerable.
Prior to perfect forward secrecy, the Heartbleed flaw attacked OpenSSL, one of the most widely used SSL/TLS protocols. Even if passwords or secret long-term keys are compromised, man-in-the-middle attacks and similar attempts fail to extract and decrypt sessions and communications with forward secrecy enabled.

Backwards vs Forwards Secrecy

Perfect forward secrecy prevents against future compromises of prior sessions, which could lead the loss of sensitive data such as passwords or additional secret keys.
The loss of sensitive data from previous sessions and compromises are "self-healing" when backward secrecy is maintained. Although both concentrate on data from previous sessions, forward secrecy is preventative, and backward secrecy is mitigating, which makes this unclear. For instance, the Signal protocol achieves backward secrecy by using the self-healing Double Ratchet Algorithm.

Functionality

Completely private, brief key exchanges between a client and the server are made possible by encryption perfect forward secrecy. Web servers typically use unique encryption keys to safeguard communication sessions. The client creates a pre-primary secret and encrypts it using the server's unique key whenever it wishes to communicate with the server. After that, both users utilise this pre-primary secret to encrypt the remaining portion of the conversation. Discussions between the client and server can only be decrypted by those who own the original server key. For instance, the server is supported by the network team, which also has to keep an eye on communications to help find faults. An attacker can surreptitiously monitor the server's communications if full forward secrecy isn't maintained. The reason for this is that the server encrypts every pre-primary secret with every client using the same key.
Every time a new client initiates a conversation with the server, the two create a distinct private pre-primary secret if the server is configured to encrypt conversations with complete forward secrecy. Additionally, it is transient and only lasts for that single exchange of messages. The long-term key is never seen by the client, and a hacker can only access the information exchanged during that single chat.

Examine the following hypothetical illustration of a simple instant messaging protocol that employs perfect forward secrecy:

  • Step 1: Asymmetric, long-term public keys and private keys are produced by X and Y separately. They either check the public-key fingerprints in person or over an already-authenticated channel. To a high degree of certainty, the verification process proves that the person who claims ownership of the public key is indeed the one who actually owns it.
  • Step II: Using a key exchange method like Diffie-Hellman, X and Y safely decide on an ephemeral key for the session. Throughout this procedure, they use the keys from Step One to authenticate one another.
  • 3: X encrypts a message using a symmetric cypher using the session key that was negotiated in Step 2 and transmits the encrypted version to Y.
  • Step Four: Y uses the key from Step Two to decrypt the message. The first step is never repeated. Rather, for every new message delivered, the procedure is repeated, beginning with Step Two. The roles that X and Y play as sender and recipient may change depending on the interaction. Forward secrecy is achieved by creating fresh session keys for every transmission.

That key is only valid for a single message, even if Step Two is compromised at some point. Messages would remain unaltered if Step One were compromised, but it might allow an attacker to pose as X or Y in the future, making subsequent messages susceptible.

PFS

Benefits

The advantages of absolute forward secrecy are numerous. If given enough time and processing capacity to try different security key combinations, brute force assaults can eventually break even the most secure encryption. Encryption keys are used for sessions, or complete batches of transactions, without forward secrecy. Although brute force hacking takes a lot of time and money, the amount of sensitive data that may be recovered makes it worthwhile. Brute force attacks are certain to be less valuable when there is perfect advance secrecy.
Creating a unique session key for each transaction restricts hackers to collecting data from a single exchange per successful assault. A server secured by perfect forward secrecy is just less appealing to a hacker since it requires more effort and time. There is no future value in such an attack because the server with PFS creates a new set of Diffie-Hellman parameters for each session.

Blockchain.

Perfect forward secrecy protects against future compromises of passwords or secret keys from previous sessions. Forward secrecy ensures that previously recorded and encrypted sessions and communications cannot be accessed and decoded by an adversary who later compromises long-term secret keys. This is crucial for every blockchain use case. A leaked key has the ability to jeopardise a considerable number of assets in a blockchain scenario because all data is preserved indefinitely.

VPN

Perfect Forward Secrecy VPNs use perfect forward secrecy. PFS improves the security of VPN connections while marginally reducing performance in some circumstances.

Protocols

Several prominent protocol implementations, including SSH, IPsec (RFC 2412), and Off-the-Record Messaging, offer perfect forward secrecy as an optional feature. In Transport Layer Security (TLS) 1.3, the ephemeral Diffie–Hellman key exchange supports perfect forward secrecy. OpenSSL provides forward secrecy with elliptic curve Diffie–Hellman key exchange. The Signal Protocol supports forward security with the Double Ratchet Algorithm. However, WPA does not provide perfect forward secrecy.

Enable Perfect Forward Secrecy

Perfect forward secrecy is compatible with websites that use TLS or SSL sessions. Although both cryptographic protocols enable the establishment of secure connections, neither one specifies the encryption cypher to be employed nor requires the actual exchange of keys. Rather, the encryption type must be agreed upon by the user and server computers in order to achieve perfect forward secrecy. Consequently, configure your servers to provide compatible cypher suites while setting up forward secrecy:

  • Ephemeral Elliptic Curve Diffie-Hellman (ECDHE)
  • Ephemeral Diffie-Hellman (DHE)

In order for the server and client to generate a distinct set of Diffie-Hellman parameters and use the keys just once per session, the key exchange needs to be ephemeral. After the transaction is complete, the exchange-related encryption is removed from the server, making any session key virtually worthless to hackers. Choose Elliptic Curve DHE suites if at all possible. Compared to their conventional DHE counterparts, these are speedier. Check a website's security information to see if perfect forward secrecy is enabled. It is now employing forward secrecy if it is using "ECDHE" or "DHE."

If your server isn't already set up for perfect forward secrecy, follow these four steps to finish the process:

  1. Locate the SSL protocol configuration.
  2. Add the protocol to your configuration.
  3. Set the SSL cipher. Ensure you enforce the ordering of your ciphers by using SSLHonorCipherOrder on in Apache and ssl_prefer_server_ciphers on; in nginx.
  4. Restart.

It is important to note that perfect forward secrecy is easily configured wrong. A typical error is to allow support for DHE or ECDHE without ensuring cypher ordering. Simply activating them does not imply that the server is employing perfect forward secrecy.

Furthermore, prioritise perfect forward secrecy over other security measures to ensure that it functions effectively. In some circumstances, you may need to disable other types of security to prevent lesser forms of encryption from taking priority inadvertently, allowing for FREAK attacks and other SSL/TLS flaws.

It is also necessary to discontinue long-term session tickets or session IDs. These retain session information on the user's end for an extended length of time, sometimes until the machine is rebooted.

Ref: https://www.vmware.com/topics/perfect-forward-secrecy

Top comments (0)