Reset server MAC after TransformFinalBlock on .NET FW - #1830
Conversation
b407a2d to
f8d1e3b
Compare
Add `#if NETFRAMEWORK` block to call `_serverMac.Initialize()` after `TransformFinalBlock` in `ReceiveMessage`. Ensures MAC is reset for reuse, addressing issues on older .NET Framework builds (e.g., mscorlib.dll 4.8.4110.0).
f8d1e3b to
b0a4569
Compare
There was a problem hiding this comment.
🟡 Changes recommended
MAC reinitialization should be unconditional per the API contract, with regression coverage for repeated verification.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes receive-MAC reuse after TransformFinalBlock, addressing second-packet failures on older .NET Framework builds.
Changes:
- Resets server MAC state in ETM and non-ETM receive paths.
- Applies resets conditionally to .NET Framework.
File summaries
| File | Description |
|---|---|
src/Renci.SshNet/Session.cs |
Resets receive-MAC state after packet verification. |
Review details
Suppressed comments (1)
src/Renci.SshNet/Session.cs:1386
- The same API contract applies in the non-ETM path: after
TransformFinalBlock, reusing the instance withoutInitialize()is not guaranteed on any target framework. Remove the conditional compilation here as well.
#if NETFRAMEWORK
// Ensure MAC is reset so that it can be reused for the next packet
// It is only required for certain older .NET Framework builds, e.g., mscorlib.dll version 4.8.4110.0
_serverMac.Initialize();
#endif
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| #if NETFRAMEWORK | ||
| // Ensure MAC is reset so that it can be reused for the next packet | ||
| // It is only required for certain older .NET Framework builds, e.g., mscorlib.dll version 4.8.4110.0 | ||
| _serverMac.Initialize(); | ||
| #endif |
| #if NETFRAMEWORK | ||
| // Ensure MAC is reset so that it can be reused for the next packet | ||
| // It is only required for certain older .NET Framework builds, e.g., mscorlib.dll version 4.8.4110.0 | ||
| _serverMac.Initialize(); |
WojciechNagorski
left a comment
There was a problem hiding this comment.
LGTM. I verified this PR using Copilot and it produced the same solution. #1834
I think it's good to leave #if NETFRAMEWORK, so that this change only applies to the old framework on which this problem occurs.
Call
_serverMac.Initialize()afterTransformFinalBlockwhen running on .NET Framework. This ensures the MAC is properly reset, addressing differences in cryptographic API behavior across different versions of mscorlib.dll.Close #1829