BFEC (Bats' Fully Encrypted Chat)

This is a place to document my journey in building BFEC, a project aimed at learning how to implement a peer-to-peer chat. I chose Python for development because it allowed me to build the project quickly and focus on the core networking and encryption features.

To achieve this, I had to learn how to work with sockets and send data between peers.

image

Implementation

Connection Establishment

Establishing a connection between two peers involves following key steps:

Metadata & Message

Each packet is divided into three segments:

Software Security

Current Security Risks

It’s important to note that this method cannot fully protect against a Man-In-The-Middle attack that intercepts the connection and replaces both public keys from the start. This is a issue that can not be solved when working with an unsecured/untrusted line of communication.

Implemented Security Measures

The critical phase of this implementation is during the connection and key exchange between peers. The primary threat is a MITM attack, where an attacker might replace the RSA public keys.

Two layers of protection are implemented:

Layer 1: Client-Side Public Key Verification

Both peers automatically verify a checksum of the combined public keys. Although this can still be compromised by a sophisticated MITM attack, it adds a first layer of defense.

This protects against a replaced public key during the key exchange of only one participant.

Layer 2: 2. RSA Signature Verification

The message checksum is encrypted with the sender’s RSA private key. The receiver can verify the integrity of the message using the sender's public key, ensuring the message hasn’t been tampered with, as long as the public key exchange was secure.

This protects against manipulated or altered messages after the initial key exchange.


Written: 2024-09-16