Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
7a6b530
tls support
Fatumayattani Aug 15, 2025
d0345b6
update tls docs
Fatumayattani Aug 15, 2025
7dd3469
update tls support
Fatumayattani Aug 15, 2025
bfbc389
update changes
Fatumayattani Aug 15, 2025
a9b510e
tls support
Fatumayattani Aug 15, 2025
6ea3016
tls support doc #700
Fatumayattani Aug 15, 2025
77f4764
Add tls-support.rst to docs toctree
Fatumayattani Aug 17, 2025
cc68f63
Merge branch 'main' into main
seetadev Aug 18, 2025
73d44ed
Replace asyncio with trio, fix newline, and run pre-commit checks on …
Fatumayattani Aug 19, 2025
4f9eabe
Add initial Eclipse attack simulation module with tests
Fatumayattani Sep 23, 2025
d801a91
Merge branch 'main' into feature/attack-simulation
seetadev Sep 23, 2025
c1df722
Merge branch 'libp2p:main' into feature/attack-simulation
yashksaini-coder Sep 24, 2025
5691e6e
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Sep 24, 2025
6312c95
Refactor code for consistency and clarity; update README and configur…
yashksaini-coder Sep 24, 2025
999d293
Add real integration tests and metrics collection for Eclipse attack …
yashksaini-coder Sep 24, 2025
b46cdef
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Sep 25, 2025
44044f8
Linting errors resolved
yashksaini-coder Sep 25, 2025
efffe92
Merge remote-tracking branch 'refs/remotes/origin/feature/attack-simu…
yashksaini-coder Sep 25, 2025
ba04a4f
Refactor real metrics collector and test structure
yashksaini-coder Sep 25, 2025
32483ac
Remove non-existent file
yashksaini-coder Sep 25, 2025
16708e3
Enhance type annotations and improve metrics collection in Eclipse at…
yashksaini-coder Sep 25, 2025
fd4d578
performed more test and test suite for multiple config scenarios and …
yashksaini-coder Sep 25, 2025
7004d94
add newsfragment for PR #950 (Eclipse attack simulation module)
Fatumayattani Sep 26, 2025
e19929e
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Sep 26, 2025
82531b1
Add connection exhaustion attack implementation and tests passed
yashksaini-coder Sep 27, 2025
d9bd1b7
Implement flooding attack module and corresponding tests
yashksaini-coder Sep 27, 2025
a3dfead
Add protocol attack implementation and tests
yashksaini-coder Sep 27, 2025
c417fce
Add Sybil attacks and tests
yashksaini-coder Sep 27, 2025
0cd848c
Add attack analysis framework and metrics collection with comprehensi…
yashksaini-coder Sep 27, 2025
7afdad7
Phase 2 completed:
yashksaini-coder Sep 27, 2025
950b155
Performed make fix & typecheck run to fix all linting and typechecke…
yashksaini-coder Sep 27, 2025
5ec1eec
Remove obsolete attack simulation result files to streamline testing …
yashksaini-coder Sep 30, 2025
e9d3215
Add results directory handling and update file paths in eclipse attac…
yashksaini-coder Sep 30, 2025
a1c8a31
Refactor real network builder to create multiple honest and malicious…
yashksaini-coder Sep 30, 2025
463f6ac
Fix host initialization in TLS examples by removing unnecessary await
yashksaini-coder Sep 30, 2025
a7b963e
Update test to use a random port for address changes in DHT reissue test
yashksaini-coder Sep 30, 2025
587aa6f
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Oct 4, 2025
6b3a421
Merge branch 'main' into feature/attack-simulation
acul71 Oct 4, 2025
d9e51e9
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Oct 5, 2025
f437fcf
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Oct 5, 2025
4c36e6c
Address pacrob feedback: remove duplicate AttackMetrics and cleanup t…
Fatumayattani Oct 6, 2025
8d9e7c8
refactor: improve temporary file handling and reduce test peer count …
yashksaini-coder Oct 6, 2025
003f4e5
refactor: standardize list type annotations in AttackMetrics class an…
yashksaini-coder Oct 6, 2025
0f81749
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Oct 6, 2025
8ef6ebf
update README
yashksaini-coder Oct 6, 2025
8b9c4b4
fix: correct whitespace in README and improve comment formatting in m…
yashksaini-coder Oct 7, 2025
f61574e
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Oct 10, 2025
1a5d9a9
Merge branch 'libp2p:main' into feature/attack-simulation
yashksaini-coder Oct 14, 2025
7777dd2
test: add replay and routing_poisoning attack simulations
Fatumayattani Oct 21, 2025
8bb588c
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Oct 21, 2025
0838067
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Oct 23, 2025
4bfd5e7
Enhance attack simulation framework with extended threat model and me…
yashksaini-coder Oct 24, 2025
14b8be7
Fix minor bugs and add mitigation documentation for attack simulations
Fatumayattani Oct 27, 2025
3cae619
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Oct 27, 2025
db52311
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Nov 14, 2025
34c24c9
Add time, latency, and topology attacks plus updated mitigations
Fatumayattani Nov 16, 2025
5a44b49
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Nov 17, 2025
4270535
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Nov 19, 2025
0d23489
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Nov 25, 2025
6d47ec1
chore: resolved all the lint, typecheck, and test case errors
yashksaini-coder Nov 27, 2025
19fe093
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Dec 2, 2025
ce16478
Refactor key generation to use string keys in real metrics collector …
yashksaini-coder Dec 4, 2025
b03fc28
Merge branch 'main' into feature/attack-simulation
seetadev Dec 5, 2025
f72ba9b
Improve connection teardown reliability in blacklist tests
yashksaini-coder Dec 6, 2025
7eaa26b
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Dec 7, 2025
71779f9
chore: remove the tls-support, gossibsub to examples
yashksaini-coder Dec 9, 2025
232372c
docs: add newsfragment for #57 issue
yashksaini-coder Dec 9, 2025
8eb7152
fix: improve attack metrics calculations for better accuracy and avoi…
yashksaini-coder Dec 9, 2025
12ae7f7
Attack simulation tests location update to tests/core/security/attack…
yashksaini-coder Dec 9, 2025
800c309
remove typo
yashksaini-coder Dec 9, 2025
0f95386
remove unecessary test file and performed make pr operation
yashksaini-coder Dec 9, 2025
069c2c4
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Dec 9, 2025
826b523
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Dec 11, 2025
4eeb85c
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Dec 13, 2025
c754833
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Dec 18, 2025
404ca32
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Dec 21, 2025
dfd0ff5
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Dec 23, 2025
9a01502
chore: fixed the example code-block and add an demo script
yashksaini-coder Dec 23, 2025
f9369ba
chore: Update example code-block in tls-support. And also add a demo …
yashksaini-coder Dec 23, 2025
c3c255d
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Dec 24, 2025
bb81bd8
Merge branch 'main' into feature/attack-simulation
seetadev Jan 5, 2026
506e8ae
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Jan 7, 2026
ab5f9c6
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Jan 8, 2026
32e0114
update examples code
yashksaini-coder Jan 8, 2026
02d5c0f
make pr completed
yashksaini-coder Jan 8, 2026
4406cc6
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Jan 11, 2026
0c11a45
update pytest paths
yashksaini-coder Jan 13, 2026
ffa5bf7
remove duplicated code
yashksaini-coder Jan 15, 2026
16f110f
remove docs
yashksaini-coder Jan 18, 2026
124c62f
remove emojis and refactor format
yashksaini-coder Jan 18, 2026
21d092e
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Jan 19, 2026
ed45766
Remove emojis from CI tests and reduce test delays
yashksaini-coder Jan 19, 2026
57735a4
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Jan 19, 2026
38a2fb1
Merge branch 'main' into feature/attack-simulation
seetadev Jan 22, 2026
e31cffd
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Jan 24, 2026
1039224
fix: remove duplicate block in test_invalid_block.py
yashksaini-coder Jan 24, 2026
89508da
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Jan 27, 2026
d8a4714
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Jan 29, 2026
97e945e
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Feb 1, 2026
082816b
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Feb 3, 2026
f939650
Phase 1: Convert all print statements to logging in test files
yashksaini-coder Feb 3, 2026
d7a2119
Add GitHub Actions workflow for attack simulation tests and update to…
yashksaini-coder Feb 3, 2026
50e2ab9
Optimize sleep intervals for faster test execution across attack simu…
yashksaini-coder Feb 3, 2026
9c8722d
Refactor logging and optimize sleep intervals in attack simulation te…
yashksaini-coder Feb 3, 2026
891d9b7
Update upload-artifact action to v4 in attack simulation workflow
yashksaini-coder Feb 3, 2026
33f37e4
fix whitespaces and lint errors along with python-version for ci cd job
yashksaini-coder Feb 3, 2026
43c940e
fix: add requests package to dependencies
yashksaini-coder Feb 3, 2026
e76a389
fix: add redis and factory-boy to dependencies in attack simulation w…
yashksaini-coder Feb 3, 2026
8b6ddfe
fix: update dependency installation to include test packages in attac…
yashksaini-coder Feb 3, 2026
b44ab16
Move to tests/examples
yashksaini-coder Feb 4, 2026
436635b
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Feb 5, 2026
a5c14b8
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Feb 7, 2026
8ae14d4
remove code no longer relevant
yashksaini-coder Feb 7, 2026
c39490e
Merge branch 'main' into feature/attack-simulation
yashksaini-coder Feb 10, 2026
8a949ef
Merge branch 'main' into feature/attack-simulation
seetadev Feb 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,6 @@ tests/interop/js_libp2p/js_node/src/package-lock.json
# Sphinx documentation build
_build/

# Attack simulation test results
tests/security/attack_simulation/results/
libp2p-forge
2 changes: 2 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Examples
examples.rendezvous
examples.random_walk
examples.multiple_connections
tls-support
gossipsub-1.2
examples.websocket
examples.tls
examples.autotls
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ The Python implementation of the libp2p networking stack

Examples <examples>
API <libp2p>
GossipSub 1.2 <gossipsub-1.2>

.. toctree::
:maxdepth: 1
Expand Down
186 changes: 186 additions & 0 deletions docs/tls-support.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
Py-libp2p – TLS Support Documentation
======================================================

.. contents::
:depth: 2
:local:

Overview of TLS in Libp2p
-------------------------

**Purpose of TLS in P2P networking**

- Encrypts data between peers.
- Authenticates peer identity using certificates.
- Prevents man-in-the-middle attacks.

**Integration in libp2p security modules**

- TLS is one of the supported secure channel protocols (alongside Noise).
- Negotiated during connection setup.

**Current status**

- **py-libp2p**: Experimental, usable for local and interop tests.
- **go-libp2p / js-libp2p**: Stable and production-ready.

Installation Requirements
-------------------------

**Additional dependencies**

Ubuntu / Debian:

.. code-block:: bash

sudo apt install build-essential python3-dev libffi-dev libssl-dev

macOS:

.. code-block:: bash

brew install openssl

Enabling TLS in py-libp2p
-------------------------

**Working example – Listener and Dialer**

Listener node:

.. code-block:: python

import trio
import multiaddr
from libp2p import new_host
from libp2p.crypto.secp256k1 import create_new_key_pair
from libp2p.security.tls.transport import PROTOCOL_ID, TLSTransport

async def main():
key_pair = create_new_key_pair(secret=None)
tls_transport = TLSTransport(libp2p_keypair=key_pair)
sec_opt = {PROTOCOL_ID: tls_transport}
host = new_host(key_pair=key_pair, sec_opt=sec_opt)
listen_addr = multiaddr.Multiaddr("/ip4/0.0.0.0/tcp/8000")
async with host.run(listen_addrs=[listen_addr]):
while not host.get_addrs():
await trio.sleep(0.1)
addrs = host.get_addrs()
peer_id = host.get_id()
print("TLS-enabled listener at:", addrs[0] if addrs else "No addresses")
print("Peer ID:", peer_id)
print("\nUse this address with the dialer:")
print(f" /ip4/127.0.0.1/tcp/8000/p2p/{peer_id}")
await trio.sleep_forever()

if __name__ == "__main__":
trio.run(main)

Dialer node:

.. code-block:: python

import trio
import multiaddr
from libp2p import new_host
from libp2p.crypto.secp256k1 import create_new_key_pair
from libp2p.security.tls.transport import PROTOCOL_ID, TLSTransport
from libp2p.peer.peerinfo import info_from_p2p_addr

async def main():
key_pair = create_new_key_pair(secret=None)
tls_transport = TLSTransport(libp2p_keypair=key_pair)
sec_opt = {PROTOCOL_ID: tls_transport}
host = new_host(key_pair=key_pair, sec_opt=sec_opt)

addr = "/ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAm3hATVnBDT13acn2utRJXsFa2LRRGrZwDsosJ1mFZsM2Q"
maddr = multiaddr.Multiaddr(addr)
peer_info = info_from_p2p_addr(maddr)

async with host.run(listen_addrs=[]):
await trio.sleep(0.5)
host.peerstore.add_addrs(peer_info.peer_id, peer_info.addrs, 120)

try:
await host.connect(peer_info)
print("Connected securely to", peer_info.peer_id)
await trio.sleep(1)
except Exception as e:
print(f"Connection failed: {e}")
raise

if __name__ == "__main__":
trio.run(main)

**Defaults if no configuration is provided**

- Generates a self-signed certificate automatically.

**Note for testing with self-signed certificates**

When testing with self-signed certificates, peers need to trust each other's certificates.
You can do this by calling ``trust_peer_cert_pem()`` on the TLS transport before creating the host:

.. code-block:: python

# For testing: trust peer certificates
listener_tls.trust_peer_cert_pem(dialer_tls.get_certificate_pem())
dialer_tls.trust_peer_cert_pem(listener_tls.get_certificate_pem())

Certificate Management
----------------------

**Generate a development certificate**

.. code-block:: bash

openssl req -x509 -newkey rsa:2048 \
-keyout key.pem -out cert.pem \
-days 365 -nodes -subj "/CN=py-libp2p"

- Store keys outside version control.
- Rotate certificates every 90 days in production.

Testing TLS Connections
-----------------------

**Local test steps**

1. Run the listener example.
2. Start the dialer with the listener's multiaddress.
3. Confirm the secure connection in logs.

**Interop testing**

- Ensure both nodes advertise `/tls/1.0.0`.
- Peer IDs must match certificate public keys.

Security Considerations
-----------------------

- Never disable certificate verification in production.
- Use TLS 1.3 or later.
- Pin certificates for critical peers.

Troubleshooting
---------------

.. list-table::
:header-rows: 1
:widths: 30 30 40

* - Problem
- Cause
- Solution
* - Certificate not trusted
- Self-signed without trust store entry
- Add cert to local trust store or disable verification **only** in testing.
* - Protocol negotiation failed
- One peer does not support `/tls/1.0.0`
- Enable TLS on both peers or use Noise.
* - SSL handshake failure
- TLS version mismatch or clock skew
- Enforce TLS 1.3, sync system clock.
* - Connection refused
- Port blocked or listener not running
- Check firewall rules and listener status.
Loading
Loading