Skip to content

Share the chunked body parser with the test servers - #53

Open
Frauschi wants to merge 1 commit into
wolfSSL:mainfrom
Frauschi:shared-chunked-parser
Open

Frauschi wants to merge 1 commit into
wolfSSL:mainfrom
Frauschi:shared-chunked-parser

Conversation

@Frauschi

@Frauschi Frauschi commented Oct 9, 2026

Copy link
Copy Markdown
Member

The EST test server kept its own copy of the chunked parser, which #26 never hardened. It rejected legal input (zero-padded sizes over eight digits, whitespace before a chunk-ext), accepted any trailer section, and reported malformed framing as complete.

  • http.c exports its framing scan and decoder, and wolfcert_server_read_chunked() serves both test servers. The SCEP server now accepts a chunked PKIOperation POST.
  • The framing scan resumes where it stopped instead of rescanning from offset 0 on every read. A body arriving one byte at a time was quadratic (12 s for 240 KB); it is now linear (2 ms for 1 MiB). The client's response reader shares the fix.
  • Both servers decode only an exact chunked coding and answer any other coding, or a repeated Transfer-Encoding header, with 400.
  • They close the connection after a request framed by both Transfer-Encoding and Content-Length, or an HTTP/1.0 request with Transfer-Encoding (RFC 9112 section 6.1).
  • The SCEP server rejects whitespace before a header colon, so Transfer-Encoding : chunked is no longer ignored.

Tests: test_est_chunked_robustness (framing and coding tables; the old server parser fails the padded size, both chunk-ext whitespace forms and both bad trailers), test_scep_roundtrip (chunked POST, keep-alive, bad framing, the closing cases) and test_http (reader caps, byte-at-a-time scan).

Outside the test servers, only the client changes: its chunked response reader now uses the resumable scan.

The EST test server carried its own copy of the chunk-size and framing
parser, and wolfSSL#26 hardened only the client copy. The server copy rejected
a zero-padded chunk size longer than eight digits and whitespace before
a chunk-ext, both legal per RFC 9112 section 7.1.1, and accepted any
trailer section without looking at it. Its framing scan also reported
malformed input as complete and left the rejection to the decode pass.

http.c now exports its framing scan and decoder, and the new
wolfcert_server_read_chunked() receives and decodes a chunked request
body for both servers. The EST server drops its own parser. The SCEP
server, which only read Content-Length bodies, now accepts a chunked
PKIOperation POST as well. The receive loop clamps its last read to the
raw cap instead of refusing a body that still fits, and grows its buffer
only when it is full.

The framing scan now resumes where the previous call stopped instead of
starting over at offset 0 after every read. A body sent in many small
pieces used to cost time quadratic in its size, about 12 s for 240 KB
fed one byte at a time; it is now linear, so a 1 MiB body takes a few
milliseconds. The client's chunked response reader shares the scan and
gets the same fix.

Both servers now take a Transfer-Encoding of exactly "chunked" and
answer any other coding, or a second Transfer-Encoding header, with 400;
the EST server used to accept any value starting with "chunked". RFC
9112 section 6.3 requires the 400 when chunked is not the final coding,
and section 6.1 would allow 501 for an unknown coding before it. A
request framed by both Transfer-Encoding and Content-Length, or an
HTTP/1.0 request carrying Transfer-Encoding, is decoded as chunked and
the connection closes after the response (RFC 9112 section 6.1). The
SCEP server also answers whitespace before a header's colon with 400
(RFC 9112 section 5.1), as the EST server does, so it no longer ignores
"Transfer-Encoding : chunked".

test_est_chunked_robustness checks a table of framings and one of
Transfer-Encoding values; against the old server parser the padded size,
both chunk-ext whitespace forms and both bad trailers fail.
test_scep_roundtrip posts a pkiMessage chunked, checks a chunked request
on a kept-alive connection, bad framing, other codings and the
conflicting-framing and HTTP/1.0 closes, and test_http drives the
reader's decoded and raw caps and feeds the framing scan one byte at a
time.
@Frauschi Frauschi self-assigned this Oct 9, 2026
Copilot AI balanced review requested due to automatic review settings October 9, 2026 14:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The shared implementation is bounded, consistently integrated, and covered by focused unit and integration tests.

0 open findings

What changed in this PR

Shares hardened, resumable chunked-body parsing across the HTTP client and EST/SCEP test servers.

Changes:

  • Extracts shared chunk framing, decoding, and server-reading helpers.
  • Adds strict Transfer-Encoding handling and connection-closing behavior.
  • Expands unit and integration coverage for framing, limits, and keep-alive.
File Description
src/​http.c Implements resumable shared chunk parsing and decoding.
src/​internal.h Declares shared internal chunk helpers and scan state.
src/​server.c Adds shared server-side chunk reading and coding validation.
src/​est/​est_server.c Replaces duplicated parser and hardens framing handling.
src/​scep/​scep_server.c Adds chunked request support and header validation.
tests/​unit/​test_http.c Tests resumable scanning and body limits.
tests/​integration/​test_est_chunked_robustness.c Tests EST framing and coding behavior.
tests/​integration/​test_scep_roundtrip.c Tests SCEP chunked POSTs, errors, and keep-alive.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Frauschi

Frauschi commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

@wolfSSL-Fenrir-bot review balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #53

Scan targets checked: wolfcert-src, wolfcert-bugs
Coverage: 3 of 5 in-scope changed file(s) opened by the reviewer; not opened: tests/integration/test_est_chunked_robustness.c, tests/unit/test_http.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Balanced

@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants