Skip to content

Add unit test for VerifyMac#912

Merged
dgarske merged 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:f_2482
Apr 14, 2026
Merged

Add unit test for VerifyMac#912
dgarske merged 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:f_2482

Conversation

@yosuke-wolfssl
Copy link
Copy Markdown
Contributor

This PR adds the unit test that injects a packet with a corrupted MAC (e.g., flip one byte in the MAC region of a captured packet buffer) and verify that DoReceive returns WS_FATAL_ERROR with ssh->error == WS_VERIFY_MAC_E.
We can't call VerifyMac() directly because it's static function in src/internal.c.
That's why I introduced wolfSSH_TestDoReceive() under the WOLFSSH_TEST_INTERNAL guard so that this would be compiled for tests only.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Apr 10, 2026
Copilot AI review requested due to automatic review settings April 10, 2026 08:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds coverage for the MAC verification failure path by injecting a packet with a deliberately corrupted MAC and asserting DoReceive() fails with WS_FATAL_ERROR and ssh->error == WS_VERIFY_MAC_E. To make DoReceive() callable from tests without exposing internal static helpers, it introduces a test-only wrapper function guarded by WOLFSSH_TEST_INTERNAL.

Changes:

  • Add wolfSSH_TestDoReceive() (guarded by WOLFSSH_TEST_INTERNAL) as a test-only entrypoint to DoReceive().
  • Add a unit test that builds a minimal SSH packet, computes its MAC, flips a MAC byte, and validates the expected failure.
  • Update the unit test build to compile/link against the libwolfssh_test.la convenience library with -DWOLFSSH_TEST_INTERNAL.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
wolfssh/internal.h Declares the new test-only wolfSSH_TestDoReceive() API under WOLFSSH_TEST_INTERNAL.
src/internal.c Implements wolfSSH_TestDoReceive() as a thin wrapper around DoReceive().
tests/unit.c Adds the corrupted-MAC unit test and wires it into the unit test runner.
tests/include.am Builds unit tests with WOLFSSH_TEST_INTERNAL and links them against src/libwolfssh_test.la.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/unit.c
@dgarske
Copy link
Copy Markdown
Member

dgarske commented Apr 13, 2026

@yosuke-wolfssl please resolve merge conflicts. Thanks!

Copilot AI review requested due to automatic review settings April 13, 2026 23:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a unit test that validates MAC verification failures in DoReceive() by injecting a packet with a corrupted MAC, enabled only under WOLFSSH_TEST_INTERNAL.

Changes:

  • Expose a test-only wrapper wolfSSH_TestDoReceive() for calling internal DoReceive().
  • Add a unit test that crafts packets for multiple HMAC algorithms, corrupts the MAC, and asserts WS_FATAL_ERROR + WS_VERIFY_MAC_E.
  • Adjust the unit-test build to compile with internal-test APIs and link against a test library.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
wolfssh/internal.h Declares test-only wolfSSH_TestDoReceive() under WOLFSSH_TEST_INTERNAL.
src/internal.c Implements the wolfSSH_TestDoReceive() wrapper around DoReceive().
tests/unit.c Adds DoReceive MAC-failure unit test and required includes.
tests/include.am Builds unit tests with WOLFSSH_TEST_INTERNAL and links against libwolfssh_test.la.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/unit.c
Comment thread tests/unit.c
Comment thread tests/unit.c
Comment thread src/internal.c
Copilot AI review requested due to automatic review settings April 14, 2026 00:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a unit test that verifies corrupted packet MACs are detected during receive processing, without exposing VerifyMac() (static) in the public API. It does so by adding a test-only exported wrapper for DoReceive() and updating the unit test build to link against the test-only library variant.

Changes:

  • Add wolfSSH_TestDoReceive() under WOLFSSH_TEST_INTERNAL to call DoReceive() from tests.
  • Add a new unit test that builds a minimal packet, computes a correct HMAC, flips a MAC byte, and asserts DoReceive fails with WS_VERIFY_MAC_E.
  • Update the unit test build to compile with -DWOLFSSH_TEST_INTERNAL and link against src/libwolfssh_test.la.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
wolfssh/internal.h Declares the new test-only wolfSSH_TestDoReceive() hook under WOLFSSH_TEST_INTERNAL.
src/internal.c Implements wolfSSH_TestDoReceive() as a thin wrapper around DoReceive() for test builds.
tests/unit.c Adds test_DoReceive_VerifyMacFailure() covering MAC verification failures across enabled HMAC algorithms.
tests/include.am Switches unit.test to use -DWOLFSSH_TEST_INTERNAL and link against src/libwolfssh_test.la.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dgarske dgarske merged commit b6652e6 into wolfSSL:master Apr 14, 2026
135 checks passed
@yosuke-wolfssl yosuke-wolfssl deleted the f_2482 branch April 16, 2026 05:57
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