security: TLS does not verify server certificate when no CA is provided #32

Closed
opened 2026-07-20 14:57:46 +02:00 by TapTap · 0 comments
Owner

In src/shared/transport_tls.c, create_ssl_ctx() only enables peer certificate verification when a CA path is specified:

Lines 66-75:

if (ca_path) {
    if (!SSL_CTX_load_verify_locations(ctx, ca_path, NULL)) { ... }
    SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
    SSL_CTX_set_verify_depth(ctx, 4);
}

When ca_path is NULL (no --ca flag), SSL_CTX_set_verify is never called, meaning OpenSSL default is SSL_VERIFY_NONE. The client will:

  1. Accept any certificate presented by the server
  2. Be vulnerable to MITM attacks
  3. Not validate the server identity at all

Additionally, the server never requests client certificates even when CA is set — only SSL_VERIFY_PEER is used server-side, but without SSL_VERIFY_FAIL_IF_NO_PEER_CERT, unauthenticated clients can still connect.

Fix: When --ca is provided, always set SSL_VERIFY_PEER on the client side. Consider setting SSL_VERIFY_FAIL_IF_NO_PEER_CERT for server when CA is provided.

Severity: critical

In `src/shared/transport_tls.c`, `create_ssl_ctx()` only enables peer certificate verification when a CA path is specified: **Lines 66-75:** ```c if (ca_path) { if (!SSL_CTX_load_verify_locations(ctx, ca_path, NULL)) { ... } SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL); SSL_CTX_set_verify_depth(ctx, 4); } ``` When `ca_path` is NULL (no `--ca` flag), `SSL_CTX_set_verify` is never called, meaning OpenSSL default is `SSL_VERIFY_NONE`. The client will: 1. Accept any certificate presented by the server 2. Be vulnerable to MITM attacks 3. Not validate the server identity at all Additionally, the server never requests client certificates even when CA is set — only `SSL_VERIFY_PEER` is used server-side, but without `SSL_VERIFY_FAIL_IF_NO_PEER_CERT`, unauthenticated clients can still connect. **Fix:** When `--ca` is provided, always set `SSL_VERIFY_PEER` on the client side. Consider setting `SSL_VERIFY_FAIL_IF_NO_PEER_CERT` for server when CA is provided. **Severity:** critical
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#32